syscall.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. #define SYS_GETCWD 48 /* (char *buf, unsigned max) -> 0; the caller's cwd */
  66. /* Process snapshot for the `top` command (see process.c). */
  67. #define SYS_PROCINFO 49 /* (unsigned int index, struct sys_procinfo *out)
  68. -> 1 when found, 0 at the end of the table */
  69. #define SYS_GET_CURSOR 50 /* () -> cursor position of the caller's screen */
  70. #define SYS_SET_CURSOR 51 /* (unsigned int pos) -> 0 */
  71. /* Window graphics service (see sys_gfx.c): a ring-3 command maps its terminal
  72. * window's RGB565 back buffer and draws directly into it; SYS_GFX_PRESENT
  73. * copies it into the composited front buffer (double buffering, so the WM
  74. * never shows a half-drawn frame). One session per process and per window. */
  75. #define SYS_GFX_BEGIN 52 /* (struct sys_gfx_info *out) -> 0/-1 */
  76. #define SYS_GFX_PRESENT 53 /* () -> 0/-1; publish a finished frame */
  77. #define SYS_GFX_END 54 /* () -> 0/-1; unmap + free the canvas */
  78. #define SYS_KEY_POLL 55 /* () -> 0 none, ASCII, or IO_KEY_*; gfx session only */
  79. #define SYS_RTC_HMS 56 /* (struct sys_time *out) -> 0/-1 */
  80. /* Window-manager service (see wm_abi.h). Only the kernel-spawned WM process
  81. * may call the WM_* entries; ordinary commands get -1. */
  82. #define SYS_WM_ATTACH 57 /* (struct wm_screen_info *out) -> 0/-1 */
  83. #define SYS_WM_INFO 58 /* (index, struct wm_window_info *out) -> 1/0/-1 */
  84. #define SYS_WM_MAP 59 /* (index, struct wm_map_info *out) -> 0/-1 */
  85. #define SYS_WM_ACK 60 /* (index, dirty_seq) -> 0/-1 */
  86. #define SYS_WM_FOCUS 61 /* (index) -> 0/-1 */
  87. #define SYS_WM_SET_GEOM 62 /* (index, struct wm_geom *in) -> 0/-1 */
  88. #define SYS_WM_CREATE_TERM 63 /* () -> index / -1 */
  89. #define SYS_WM_CLOSE 64 /* (index) -> 0/-1 */
  90. #define SYS_WM_POLL 65 /* (struct wm_status *out) -> 0/-1 */
  91. #define SYS_WM_BEGIN 66 /* () -> 0/-1; erase cursor, frame active */
  92. #define SYS_WM_PRESENT 67 /* (struct wm_present_info *in) -> 0/-1 */
  93. #define SYS_WM_SYNC 68 /* () -> 0/-1; run deferred gfx cleanup */
  94. #define SYS_RTC_DATETIME 69 /* (char *buf, unsigned max) -> 0/-1 */
  95. #define SYS_WIN_CREATE 70 /* (struct win_create *in, struct win_info *out) */
  96. #define SYS_WIN_PRESENT 71 /* () -> 0/-1; publish the back canvas */
  97. #define SYS_WIN_CLOSE 72 /* () -> 0/-1; close the caller's window */
  98. #define SYS_WM_RESIZE 83 /* (index, struct wm_size *content) -> 0/-1 */
  99. #define SYS_WIN_INFO 84 /* (struct win_info *out) -> 0/-1 */
  100. #define SYS_WIN_ACK_RESIZE 85 /* () -> 0/-1; swap in the pending canvas */
  101. #define SYS_WIN_POINTER 86 /* (struct win_pointer *out) -> 0/-1 */
  102. #define SYS_WIN_EVENT 87 /* (struct win_event *out) -> 1 event, 0 none */
  103. /* Per-process anonymous heap (see sys_mem.c). One growable arena at
  104. * USER_HEAP_BASE (0x60000000), at most USER_HEAP_MAX (32 MB), freed when the
  105. * process exits. SYS_MEM_ALLOC returns the base address, or <0. */
  106. #define SYS_MEM_ALLOC 88 /* (unsigned bytes) -> VA or <0 */
  107. #define SYS_MEM_GROW 89 /* (unsigned total_bytes) -> 0/-1; new pages not zeroed */
  108. #define SYS_MEM_FREE 90 /* () -> 0/-1 */
  109. /* CPU temperature (see thermal.c): the hottest core's DTS reading. */
  110. #define SYS_CPU_TEMP 91 /* (struct sys_cputemp *out) -> 0/-1 */
  111. /* IT87xx Super I/O hardware monitor (see it87.c); read-only. */
  112. #define SYS_SENSORS 92 /* (struct sys_sensors *out) -> 0/-1 */
  113. /* TCP server (WebDAV listener). The caller must own the NIC (SYS_NET_ACQUIRE).
  114. * SYS_TCP_ACCEPT polls a few frames and returns 1 once a connection is ready,
  115. * 0 when nothing arrived, or -3 when a netkexec header was captured (the
  116. * command should exit and let the kworker take over). */
  117. #define SYS_TCP_LISTEN 93 /* (port) -> 0/-1 */
  118. #define SYS_TCP_ACCEPT 94 /* () -> 1/0/-2/-3 */
  119. #define SYS_TCP_SRV_RECV 95 /* (buf, max, timeout_ms) -> >0/0/-1/-2 */
  120. #define SYS_TCP_SRV_SEND 96 /* (buf, len) -> 0/-1/-2/-3 */
  121. #define SYS_TCP_SRV_CLOSE 97
  122. #define SYS_TCP_PEER 99 /* (ip[4], unsigned *port) -> 0/-1 (debug log) */
  123. /* Stat one path (the file service has no open handle). */
  124. #define SYS_FS_STAT 98 /* (path, struct sys_stat *out) -> 0/<0 */
  125. /* Terminal / process services used by the ring-3 shell. */
  126. #define SYS_TTY_CREATE 73 /* () -> tty id 1..TTY_MAX / -1 */
  127. #define SYS_TTY_READ 74 /* (id, buf, max) -> bytes / 0 / -1 */
  128. #define SYS_SPAWN 75 /* (path, arg, tty, cwd) -> pid / <0 */
  129. #define SYS_SPAWN_KCMD 76 /* (name, arg, tty) -> pid / <0 */
  130. #define SYS_ALIVE 77 /* (pid) -> 1/0 */
  131. #define SYS_KILL 78 /* (pid) -> 0/-1 */
  132. #define SYS_CHDIR 79 /* (path) -> 0/-1 */
  133. #define SYS_WIN_KEY_WAIT 80 /* (timeout_ms) -> key / 0 timeout / -1 */
  134. #define SYS_SCHEDINFO 81 /* (struct sys_schedinfo *out) -> 0/-1 */
  135. struct sys_spawn {
  136. const char *path;
  137. const char *arg;
  138. const char *cwd;
  139. unsigned int tty;
  140. };
  141. struct sys_netinfo {
  142. unsigned int present;
  143. unsigned char mac[6];
  144. unsigned char ip[4];
  145. unsigned char mask[4];
  146. unsigned char gw[4];
  147. unsigned char dns[4];
  148. unsigned int mirror_on;
  149. unsigned char mirror_host[4];
  150. char name[8];
  151. char chip[16];
  152. };
  153. /* Error codes returned by the file syscalls. */
  154. #define SYS_EIO (-1) /* disk I/O error */
  155. #define SYS_ENODEV (-2) /* no such device / unusable path prefix */
  156. #define SYS_ENOFS (-3) /* device exists but has no mounted filesystem */
  157. #define SYS_ENOENT (-4) /* file/directory not found */
  158. #define SYS_EINVAL (-5) /* path is not valid for this operation */
  159. #define SYS_EWRITE (-6) /* write refused (full, or FAT rejected it) */
  160. #define SYS_EROFS (-7) /* read-only filesystem (ramfs) */
  161. #define SYS_ENOSPC (-8) /* no space left on the filesystem */
  162. /* One directory entry. `name` is a display name: raw 8.3 for FAT mounts
  163. * (space padded, `raw_83` set) or the plain name for name-string filesystems
  164. * such as ramfs and /share. */
  165. struct sys_dirent {
  166. char name[64];
  167. unsigned int size;
  168. unsigned int is_dir;
  169. unsigned int raw_83;
  170. };
  171. /* One mounted filesystem (for `ls /`). */
  172. struct sys_mount {
  173. char name[16];
  174. char type[8]; /* "FAT12", "FAT16", "FAT32", "ramfs", "share" */
  175. unsigned int total_sectors;
  176. char label[12];
  177. unsigned int ro;
  178. };
  179. /* Result of SYS_FS_STAT. */
  180. struct sys_stat {
  181. unsigned int size;
  182. unsigned int is_dir;
  183. unsigned int ro;
  184. };
  185. struct sys_meminfo {
  186. unsigned int total_kb;
  187. unsigned int free_pages;
  188. unsigned int page_size;
  189. unsigned int e820_count;
  190. };
  191. /* One live process, for `top` (PROC_NAME_LEN = 12). cpu_ticks/life_ticks
  192. * are PIT ticks (1 kHz), so lifecycle percentages can be derived. */
  193. struct sys_procinfo {
  194. unsigned int pid;
  195. unsigned int state; /* PROC_*: 1 ready, 2 running, 4 sleep, 5 block */
  196. unsigned int cpu_ticks; /* ticks spent as the running process */
  197. unsigned int life_ticks; /* ticks since creation, >= 1 */
  198. unsigned int pages; /* resident 4 KB pages (stack + dir + user) */
  199. unsigned int weight; /* CFS weight, 1..SCHED_WEIGHT_MAX */
  200. unsigned int cpu; /* CPU id, or 0xFFFFFFFF when not running */
  201. char name[12];
  202. };
  203. /* Scheduler counters for `top` and the `sched` command. */
  204. struct sys_schedinfo {
  205. unsigned int ncpus;
  206. unsigned int runnable;
  207. unsigned int sleeping;
  208. unsigned int blocked;
  209. unsigned int zombies;
  210. unsigned int switches;
  211. unsigned int wakeups;
  212. unsigned int idle_ticks;
  213. unsigned int slice_ticks;
  214. };
  215. /* CPU temperature snapshot (see thermal.c). temp_c is the hottest core's
  216. * last DTS sample; a negative value means no Intel DTS is available. delta_c
  217. * and status are from the CPU that serviced the syscall (for diagnostics).
  218. * cpu_temp_c[] holds the per-logical-CPU cached samples. */
  219. #define SYS_CPU_MAX 8
  220. struct sys_cputemp {
  221. int temp_c;
  222. int tjmax_c;
  223. int delta_c;
  224. unsigned int status;
  225. int cpu_temp_c[SYS_CPU_MAX];
  226. unsigned int ncpus;
  227. };
  228. /* IT87xx hardware monitor snapshot (temps are signed; -128 = unconnected). */
  229. struct sys_sensors {
  230. unsigned int present;
  231. unsigned int chip_id;
  232. unsigned int base;
  233. unsigned int temp_enable;
  234. unsigned int temp_extra;
  235. int temp_c[3];
  236. unsigned int fan_rpm[3];
  237. };
  238. /* Window canvas handed to a ring-3 graphics command (see sys_gfx.c). */
  239. struct sys_gfx_info {
  240. unsigned int width; /* canvas (= window content) size in pixels */
  241. unsigned int height;
  242. void *fb; /* user VA of the mapped RGB565 canvas */
  243. };
  244. /* Wall clock for the ring-3 clock (see rtc.c). */
  245. struct sys_time {
  246. unsigned int hour; /* 0-23 */
  247. unsigned int minute; /* 0-59 */
  248. unsigned int second; /* 0-59 */
  249. };
  250. struct sys_e820 {
  251. unsigned int base; /* low 32 bits, as meminfo always printed */
  252. unsigned int length;
  253. unsigned int type;
  254. };
  255. struct sys_mouseinfo {
  256. unsigned int present;
  257. unsigned int ps2;
  258. unsigned int ps2_id;
  259. unsigned int ps2_packet_size;
  260. unsigned int ps2_streaming;
  261. unsigned int usb;
  262. unsigned int usb_ctrl;
  263. unsigned int usb_addr;
  264. unsigned int usb_ep;
  265. unsigned int usb_mps;
  266. unsigned int usb_low;
  267. unsigned int usb_keyboard;
  268. unsigned int cursor_visible;
  269. char hcd[8];
  270. char backend[16];
  271. };
  272. struct sys_storage_info {
  273. unsigned int ahci_present;
  274. unsigned int blkdev_count;
  275. };
  276. struct sys_blkdev {
  277. char name[8];
  278. char model[41];
  279. unsigned int kind; /* 0 = floppy, 1 = IDE, 2 = SATA */
  280. unsigned int present;
  281. unsigned int total_sectors;
  282. };
  283. int syscall_dispatch(int num, int a1, int a2, int a3);
  284. #endif