unistd.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 2020 Jeremiah Orians
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #define NULL 0
  18. #define __PATH_MAX 4096
  19. #define EOF 0xFFFFFFFF
  20. void* malloc(unsigned size);
  21. int access(char* pathname, int mode)
  22. {
  23. /* Completely meaningless in bare metal */
  24. return 0;
  25. }
  26. int chdir(char* path)
  27. {
  28. /* Completely meaningless in bare metal */
  29. return 0;
  30. }
  31. int fchdir(int fd)
  32. {
  33. /* Completely meaningless in bare metal */
  34. return 0;
  35. }
  36. void _exit(int value)
  37. {
  38. }
  39. int fork()
  40. {
  41. /* Completely meaningless in bare metal */
  42. return 0;
  43. }
  44. int waitpid (int pid, int* status_ptr, int options)
  45. {
  46. /* Completely meaningless in bare metal */
  47. return 0;
  48. }
  49. int execve(char* file_name, char** argv, char** envp)
  50. {
  51. /* Completely meaningless in bare metal */
  52. return 0;
  53. }
  54. int __read(int fd)
  55. {
  56. asm("LOAD R1 R14 0"
  57. "FGETC");
  58. }
  59. int read(int fd, char* buf, unsigned count)
  60. {
  61. unsigned i = 0;
  62. int c;
  63. while(i < count)
  64. {
  65. c = __read(fd);
  66. if(EOF == c) break;
  67. buf[i] = c;
  68. i = i + 1;
  69. }
  70. return i;
  71. }
  72. void __write(char s, int fd)
  73. {
  74. asm("LOAD R0 R14 0"
  75. "LOAD R1 R14 4"
  76. "FPUTC");
  77. }
  78. int write(int fd, char* buf, unsigned count)
  79. {
  80. unsigned i = 0;
  81. while(i < count)
  82. {
  83. __write(buf[i], fd);
  84. i = i + 1;
  85. }
  86. }
  87. int lseek(int fd, int offset, int whence)
  88. {
  89. asm("LOAD R0 R14 0"
  90. "LOAD R1 R14 4"
  91. "LOAD R2 R14 8"
  92. "FSEEK");
  93. }
  94. int close(int fd)
  95. {
  96. asm("LOAD R0 R14 0"
  97. "FCLOSE");
  98. }
  99. int _getcwd(char* buf, int size)
  100. {
  101. /* Completely meaningless in bare metal */
  102. return 0;
  103. }
  104. char* getcwd(char* buf, unsigned size)
  105. {
  106. /* Completely meaningless in bare metal */
  107. return 0;
  108. }
  109. char* getwd(char* buf)
  110. {
  111. /* Completely meaningless in bare metal */
  112. return 0;
  113. }
  114. char* get_current_dir_name()
  115. {
  116. /* Completely meaningless in bare metal */
  117. return 0;
  118. }
  119. /********************************************************************************
  120. * We are running on bare metal. Just don't go past the end of install RAM *
  121. ********************************************************************************/
  122. int brk(void *addr)
  123. {
  124. asm("LOAD R0 R14 0"
  125. "ADDU R0 R12 R0"
  126. "SWAP R0 R12");
  127. }
  128. int chmod(char *pathname, int mode)
  129. {
  130. /* Completely meaningless in bare metal */
  131. return 0;
  132. }
  133. struct utsname
  134. {
  135. char sysname[65]; /* Operating system name (e.g., "Linux") */
  136. char nodename[65]; /* Name within "some implementation-defined network" */
  137. char release[65]; /* Operating system release (e.g., "2.6.28") */
  138. char version[65]; /* Operating system version */
  139. char machine[65]; /* Hardware identifier */
  140. };
  141. int uname(struct utsname* unameData)
  142. {
  143. /* Completely meaningless in bare metal */
  144. return 0;
  145. }