db_misc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_misc.c
  15. *
  16. * This file contains APIs for miscellaneous use.
  17. */
  18. #include "api.h"
  19. #include "pal.h"
  20. #include "pal_defs.h"
  21. #include "pal_error.h"
  22. #include "pal_internal.h"
  23. PAL_NUM DkSystemTimeQuery(void) {
  24. ENTER_PAL_CALL(DkSystemTimeQuery);
  25. unsigned long time = _DkSystemTimeQuery();
  26. return time;
  27. }
  28. PAL_NUM DkRandomBitsRead(PAL_PTR buffer, PAL_NUM size) {
  29. ENTER_PAL_CALL(DkRandomBitsRead);
  30. int ret = _DkRandomBitsRead((void*)buffer, size);
  31. LEAVE_PAL_CALL_RETURN(ret);
  32. }
  33. PAL_PTR DkSegmentRegister(PAL_FLG reg, PAL_PTR addr) {
  34. ENTER_PAL_CALL(DkSegmentRegister);
  35. void* seg_addr = (void*)addr;
  36. int ret;
  37. if (addr) {
  38. ret = _DkSegmentRegisterSet(reg, seg_addr);
  39. } else {
  40. ret = _DkSegmentRegisterGet(reg, &seg_addr);
  41. }
  42. if (ret < 0) {
  43. _DkRaiseFailure(-ret);
  44. seg_addr = NULL;
  45. }
  46. LEAVE_PAL_CALL_RETURN((PAL_PTR)seg_addr);
  47. }
  48. PAL_BOL DkInstructionCacheFlush(PAL_PTR addr, PAL_NUM size) {
  49. ENTER_PAL_CALL(DkInstructionCacheFlush);
  50. if (!addr || !size) {
  51. _DkRaiseFailure(PAL_ERROR_INVAL);
  52. LEAVE_PAL_CALL_RETURN(PAL_FALSE);
  53. }
  54. int ret = _DkInstructionCacheFlush((void*)addr, size);
  55. if (ret < 0) {
  56. _DkRaiseFailure(-ret);
  57. LEAVE_PAL_CALL_RETURN(PAL_FALSE);
  58. }
  59. LEAVE_PAL_CALL_RETURN(PAL_TRUE);
  60. }
  61. PAL_NUM DkMemoryAvailableQuota(void) {
  62. ENTER_PAL_CALL(DkMemoryAvailableQuota);
  63. long quota = _DkMemoryAvailableQuota();
  64. if (quota < 0)
  65. quota = 0;
  66. LEAVE_PAL_CALL_RETURN((PAL_NUM)quota);
  67. }
  68. PAL_BOL
  69. DkCpuIdRetrieve(PAL_IDX leaf, PAL_IDX subleaf, PAL_IDX values[4]) {
  70. ENTER_PAL_CALL(DkCpuIdRetrieve);
  71. unsigned int vals[4];
  72. int ret = _DkCpuIdRetrieve(leaf, subleaf, vals);
  73. if (ret < 0) {
  74. _DkRaiseFailure(-ret);
  75. LEAVE_PAL_CALL_RETURN(PAL_FALSE);
  76. }
  77. values[0] = vals[0];
  78. values[1] = vals[1];
  79. values[2] = vals[2];
  80. values[3] = vals[3];
  81. LEAVE_PAL_CALL_RETURN(PAL_TRUE);
  82. }