《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.8 KiB

10 years ago
10 years ago
  1. #ifndef __KERN_TRAP_TRAP_H__
  2. #define __KERN_TRAP_TRAP_H__
  3. #include <defs.h>
  4. /* Trap Numbers */
  5. /* Processor-defined: */
  6. #define T_DIVIDE 0 // divide error
  7. #define T_DEBUG 1 // debug exception
  8. #define T_NMI 2 // non-maskable interrupt
  9. #define T_BRKPT 3 // breakpoint
  10. #define T_OFLOW 4 // overflow
  11. #define T_BOUND 5 // bounds check
  12. #define T_ILLOP 6 // illegal opcode
  13. #define T_DEVICE 7 // device not available
  14. #define T_DBLFLT 8 // double fault
  15. // #define T_COPROC 9 // reserved (not used since 486)
  16. #define T_TSS 10 // invalid task switch segment
  17. #define T_SEGNP 11 // segment not present
  18. #define T_STACK 12 // stack exception
  19. #define T_GPFLT 13 // general protection fault
  20. #define T_PGFLT 14 // page fault
  21. // #define T_RES 15 // reserved
  22. #define T_FPERR 16 // floating point error
  23. #define T_ALIGN 17 // aligment check
  24. #define T_MCHK 18 // machine check
  25. #define T_SIMDERR 19 // SIMD floating point error
  26. #define T_SYSCALL 0x80 // SYSCALL, ONLY FOR THIS PROJ
  27. /* Hardware IRQ numbers. We receive these as (IRQ_OFFSET + IRQ_xx) */
  28. #define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET
  29. #define IRQ_TIMER 0
  30. #define IRQ_KBD 1
  31. #define IRQ_COM1 4
  32. #define IRQ_IDE1 14
  33. #define IRQ_IDE2 15
  34. #define IRQ_ERROR 19
  35. #define IRQ_SPURIOUS 31
  36. /* *
  37. * These are arbitrarily chosen, but with care not to overlap
  38. * processor defined exceptions or interrupt vectors.
  39. * */
  40. #define T_SWITCH_TOU 120 // user/kernel switch
  41. #define T_SWITCH_TOK 121 // user/kernel switch
  42. // 在VSCode中可以正常看到中文,但在QEMU中看到的是乱码
  43. #define ENGLISH // 使用中文则不需要这一行
  44. #ifndef ENGLISH
  45. #define MSG_COUNTDOWN_STOP "倒计时到0了,停止,转到正计时。\n"
  46. #define MSG_COUNTUP_START "正计时\n"
  47. #define MSG_COUNTDOWN_START "倒计时,请输入秒数:\n"
  48. #define MSG_START "开始\n"
  49. #define MSG_PAUSE "暂停,当前秒数:%d.%d\n"
  50. #define MSG_STOP "停止,当前秒数:%d.%d\n"
  51. #else
  52. #define MSG_COUNTDOWN_STOP "Coutdown to 0, stopped, to be countup.\n"
  53. #define MSG_COUNTUP_START "Countup\n"
  54. #define MSG_COUNTDOWN_START "Countdown, please input seconds:\n"
  55. #define MSG_START "Started\n"
  56. #define MSG_PAUSE "Paused, current seconds: %d.%d\n"
  57. #define MSG_STOP "Stopped, current seconds: %d.%d\n"
  58. #endif
  59. /* registers as pushed by pushal */
  60. struct pushregs {
  61. uint32_t reg_edi;
  62. uint32_t reg_esi;
  63. uint32_t reg_ebp;
  64. uint32_t reg_oesp; /* Useless */
  65. uint32_t reg_ebx;
  66. uint32_t reg_edx;
  67. uint32_t reg_ecx;
  68. uint32_t reg_eax;
  69. };
  70. struct trapframe {
  71. struct pushregs tf_regs;
  72. uint16_t tf_gs;
  73. uint16_t tf_padding0;
  74. uint16_t tf_fs;
  75. uint16_t tf_padding1;
  76. uint16_t tf_es;
  77. uint16_t tf_padding2;
  78. uint16_t tf_ds;
  79. uint16_t tf_padding3;
  80. uint32_t tf_trapno;
  81. /* below here defined by x86 hardware */
  82. uint32_t tf_err;
  83. uintptr_t tf_eip;
  84. uint16_t tf_cs;
  85. uint16_t tf_padding4;
  86. uint32_t tf_eflags;
  87. /* below here only when crossing rings, such as from user to kernel */
  88. uintptr_t tf_esp;
  89. uint16_t tf_ss;
  90. uint16_t tf_padding5;
  91. } __attribute__((packed));
  92. void idt_init(void);
  93. void print_trapframe(struct trapframe *tf);
  94. void print_regs(struct pushregs *regs);
  95. bool trap_in_kernel(struct trapframe *tf);
  96. #endif /* !__KERN_TRAP_TRAP_H__ */