syscall.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* Error codes returned by the file syscalls. */
  30. #define SYS_EIO (-1) /* disk I/O error */
  31. #define SYS_ENODEV (-2) /* no such device / unusable path prefix */
  32. #define SYS_ENOFS (-3) /* device exists but has no mounted filesystem */
  33. #define SYS_ENOENT (-4) /* file/directory not found */
  34. #define SYS_EINVAL (-5) /* path is not valid for this operation */
  35. #define SYS_EWRITE (-6) /* write refused (full, or FAT rejected it) */
  36. /* One directory entry, raw 8.3 name exactly as stored (space padded). */
  37. struct sys_dirent {
  38. char name[12];
  39. unsigned int size;
  40. unsigned int is_dir;
  41. };
  42. /* One mounted filesystem (for `ls /`). */
  43. struct sys_mount {
  44. char name[16];
  45. char type[8]; /* "FAT12", "FAT16", "FAT32" */
  46. unsigned int total_sectors;
  47. char label[12];
  48. };
  49. struct sys_meminfo {
  50. unsigned int total_kb;
  51. unsigned int free_pages;
  52. unsigned int page_size;
  53. unsigned int e820_count;
  54. };
  55. struct sys_e820 {
  56. unsigned int base; /* low 32 bits, as meminfo always printed */
  57. unsigned int length;
  58. unsigned int type;
  59. };
  60. struct sys_mouseinfo {
  61. unsigned int present;
  62. unsigned int ps2;
  63. unsigned int ps2_id;
  64. unsigned int ps2_packet_size;
  65. unsigned int ps2_streaming;
  66. unsigned int usb;
  67. unsigned int usb_ctrl;
  68. unsigned int usb_addr;
  69. unsigned int usb_ep;
  70. unsigned int usb_mps;
  71. unsigned int usb_low;
  72. unsigned int usb_keyboard;
  73. unsigned int cursor_visible;
  74. char hcd[8];
  75. char backend[16];
  76. };
  77. struct sys_storage_info {
  78. unsigned int ahci_present;
  79. unsigned int blkdev_count;
  80. };
  81. struct sys_blkdev {
  82. char name[8];
  83. char model[41];
  84. unsigned int kind; /* 0 = floppy, 1 = IDE, 2 = SATA */
  85. unsigned int present;
  86. unsigned int total_sectors;
  87. };
  88. int syscall_dispatch(int num, int a1, int a2, int a3);
  89. #endif