syscall.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include "../common/glib.h"
  3. #include "../common/kprint.h"
  4. #include "../process/ptrace.h"
  5. // 定义最大系统调用数量
  6. #define MAX_SYSTEM_CALL_NUM 128
  7. #define ESYSCALL_NOT_EXISTS 1
  8. typedef unsigned long (*system_call_t)(struct pt_regs *regs);
  9. extern void ret_from_system_call(void); // 导出从系统调用返回的函数(定义在entry.S)
  10. /**
  11. * @brief 初始化系统调用模块
  12. *
  13. */
  14. void syscall_init();
  15. /**
  16. * @brief 用户态系统调用入口函数
  17. * 从用户态进入系统调用
  18. * @param syscall_id 系统调用id
  19. * @return long 错误码
  20. */
  21. long enter_syscall(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg4, ul arg5, ul arg6, ul arg7);
  22. ul enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg4, ul arg5, ul arg6, ul arg7);
  23. /**
  24. * @brief 系统调用不存在时的处理函数
  25. *
  26. * @param regs 进程3特权级下的寄存器
  27. * @return ul
  28. */
  29. ul system_call_not_exists(struct pt_regs *regs)
  30. {
  31. kerror("System call [ ID #%d ] not exists.", regs->rax);
  32. return ESYSCALL_NOT_EXISTS;
  33. }
  34. /**
  35. * @brief 打印字符串的系统调用
  36. *
  37. * 当arg1和arg2均为0时,打印黑底白字,否则按照指定的前景色和背景色来打印
  38. *
  39. * @param regs 寄存器
  40. * @param arg0 要打印的字符串
  41. * @param arg1 前景色
  42. * @param arg2 背景色
  43. * @return ul 返回值
  44. */
  45. ul sys_printf(struct pt_regs *regs);
  46. // 系统调用的内核入口程序
  47. void do_syscall_int(struct pt_regs *regs, unsigned long error_code);
  48. system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] =
  49. {
  50. [0] = system_call_not_exists,
  51. [1] = sys_printf,
  52. [2 ... MAX_SYSTEM_CALL_NUM - 1] = system_call_not_exists};