syscall.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Syscall interface (int 0x80), shared by the kernel and ring-3 commands. */
  2. #ifndef SYSCALL_H
  3. #define SYSCALL_H
  4. #define SYS_PUTSTR 1
  5. #define SYS_GET_TICKS_MS 2
  6. #define SYS_SLEEP_MS 3
  7. #define SYS_EXIT 4
  8. /* File service (see sys_fs.c). Paths are absolute VFS paths; buffers live in
  9. * the calling process's address space (the kernel runs on its CR3, so no copy
  10. * in/out is needed). */
  11. #define SYS_READ_FILE 5 /* (const char *path, void *buf, unsigned int max)
  12. -> bytes read, or <0 (SYS_E*) */
  13. #define SYS_WRITE_FILE 6 /* (const char *path, const void *buf, unsigned int len)
  14. -> 0, or <0 */
  15. #define SYS_LIST_DIR 7 /* (const char *path, unsigned int index,
  16. struct sys_dirent *out) -> 1 entry, 0 end, <0 */
  17. #define SYS_UNLINK 8 /* (const char *path) -> 0, or <0 */
  18. #define SYS_MKDIR 9 /* (const char *path) -> 0, or <0 */
  19. #define SYS_RMDIR 10 /* (const char *path) -> 0, or <0 */
  20. #define SYS_LIST_MOUNTS 11 /* (unsigned int index, struct sys_mount *out)
  21. -> 1 mount, 0 end */
  22. /* Kernel-state info for the info commands (see sys_info.c). */
  23. #define SYS_MEMINFO 12 /* (struct sys_meminfo *out) -> 0 */
  24. #define SYS_E820 13 /* (unsigned int index, struct sys_e820 *out)-> 1, 0 */
  25. #define SYS_MOUSEINFO 14 /* (struct sys_mouseinfo *out) -> 1 when present */
  26. #define SYS_STORAGE_INFO 15 /* (struct sys_storage_info *out) -> 0;
  27. refreshes the mount cache like `storage` did */
  28. #define SYS_BLKDEV 16 /* (unsigned int index, struct sys_blkdev *out) */
  29. /* Network service (see sys_net.c): the stack and NIC drivers stay in the
  30. * kernel; user commands get the configuration, the DNS/DHCP clients and the
  31. * raw frame paths (so the packet-level commands port unchanged). */
  32. #define SYS_NET_INFO 17 /* (struct sys_netinfo *out) -> 1 = NIC present */
  33. #define SYS_NET_PRINT_INFO 18 /* the driver's status lines */
  34. #define SYS_NET_ACQUIRE 19 /* take the receiver for this process (0/-1) */
  35. #define SYS_NET_RELEASE 20
  36. #define SYS_NET_MAC 21 /* (unsigned char mac[6]) -> 0/-1 */
  37. #define SYS_NET_GET_IP 22 /* (unsigned char ip[4]) */
  38. #define SYS_NET_SET_IP 23 /* (const unsigned char ip[4]) */
  39. #define SYS_NET_GET_MASK 24
  40. #define SYS_NET_GET_GW 25
  41. #define SYS_NET_GET_DNS 26
  42. #define SYS_NET_SET_DNS 27
  43. #define SYS_NET_TX 28 /* (const void *buf, unsigned len) -> 0/-1 */
  44. #define SYS_NET_RX 29 /* (void *buf, unsigned max) -> len/-1 */
  45. #define SYS_NET_DECODE 30 /* (const void *buf, unsigned len): one line */
  46. #define SYS_NET_REPLY 31 /* (in, len, out, max) -> reply length / 0 */
  47. #define SYS_NET_LOOPBACK 32 /* (int on) -> 0/-1 */
  48. #define SYS_NET_REGS 33 /* the driver's register dump */
  49. #define SYS_NET_RESET 34 /* driver re-init */
  50. #define SYS_DHCP_RUN 35 /* (timeout_ms) -> dhcp_run() result */
  51. #define SYS_DHCP_INFO 36 /* (unsigned char ip[4], unsigned *lease) -> 1 */
  52. #define SYS_DNS_RESOLVE 37 /* (name, unsigned char ip[4]) -> 0; caller owns */
  53. #define SYS_NETLOG 38 /* (const char *text) -> 0/-1 */
  54. #define SYS_NETLOG_CONF 39 /* (int enabled_or_-1, const ip[4] or NULL) */
  55. /* TCP client (see sys_net.c/tcp.c): one connection at a time; the caller
  56. * must own the NIC (SYS_NET_ACQUIRE). */
  57. #define SYS_TCP_CONNECT 40 /* (mac[6], ip[4], port) -> 0/-1/-2/-3 */
  58. #define SYS_TCP_PEER_MSS 41 /* () -> the peer's MSS of the current conn */
  59. #define SYS_TCP_SEND 42 /* (buf, len) -> 0/-1/-2/-3 */
  60. #define SYS_TCP_RECV 43 /* (buf, max, timeout_ms) -> >0/0/-1/-2 */
  61. #define SYS_TCP_CLOSE 44 /* () */
  62. #define SYS_NET_NEXT_HOP 45 /* (dst[4], hop[4]) */
  63. #define SYS_NET_ARP 46 /* (ip[4], mac[6]) -> 0/-1/-2 (net_arp_resolve) */
  64. #define SYS_NET_CONFIGURED 47 /* () -> 1 when an IP address is set */
  65. struct sys_netinfo {
  66. unsigned int present;
  67. unsigned char mac[6];
  68. unsigned char ip[4];
  69. unsigned char mask[4];
  70. unsigned char gw[4];
  71. unsigned char dns[4];
  72. unsigned int mirror_on;
  73. unsigned char mirror_host[4];
  74. char name[8];
  75. char chip[16];
  76. };
  77. /* Error codes returned by the file syscalls. */
  78. #define SYS_EIO (-1) /* disk I/O error */
  79. #define SYS_ENODEV (-2) /* no such device / unusable path prefix */
  80. #define SYS_ENOFS (-3) /* device exists but has no mounted filesystem */
  81. #define SYS_ENOENT (-4) /* file/directory not found */
  82. #define SYS_EINVAL (-5) /* path is not valid for this operation */
  83. #define SYS_EWRITE (-6) /* write refused (full, or FAT rejected it) */
  84. /* One directory entry, raw 8.3 name exactly as stored (space padded). */
  85. struct sys_dirent {
  86. char name[12];
  87. unsigned int size;
  88. unsigned int is_dir;
  89. };
  90. /* One mounted filesystem (for `ls /`). */
  91. struct sys_mount {
  92. char name[16];
  93. char type[8]; /* "FAT12", "FAT16", "FAT32" */
  94. unsigned int total_sectors;
  95. char label[12];
  96. };
  97. struct sys_meminfo {
  98. unsigned int total_kb;
  99. unsigned int free_pages;
  100. unsigned int page_size;
  101. unsigned int e820_count;
  102. };
  103. struct sys_e820 {
  104. unsigned int base; /* low 32 bits, as meminfo always printed */
  105. unsigned int length;
  106. unsigned int type;
  107. };
  108. struct sys_mouseinfo {
  109. unsigned int present;
  110. unsigned int ps2;
  111. unsigned int ps2_id;
  112. unsigned int ps2_packet_size;
  113. unsigned int ps2_streaming;
  114. unsigned int usb;
  115. unsigned int usb_ctrl;
  116. unsigned int usb_addr;
  117. unsigned int usb_ep;
  118. unsigned int usb_mps;
  119. unsigned int usb_low;
  120. unsigned int usb_keyboard;
  121. unsigned int cursor_visible;
  122. char hcd[8];
  123. char backend[16];
  124. };
  125. struct sys_storage_info {
  126. unsigned int ahci_present;
  127. unsigned int blkdev_count;
  128. };
  129. struct sys_blkdev {
  130. char name[8];
  131. char model[41];
  132. unsigned int kind; /* 0 = floppy, 1 = IDE, 2 = SATA */
  133. unsigned int present;
  134. unsigned int total_sectors;
  135. };
  136. int syscall_dispatch(int num, int a1, int a2, int a3);
  137. #endif