《操作系统》的实验代码。
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.

91 lines
2.9 KiB

  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. /* registers as pushed by pushal */
  43. struct pushregs {
  44. uint32_t reg_edi;
  45. uint32_t reg_esi;
  46. uint32_t reg_ebp;
  47. uint32_t reg_oesp; /* Useless */
  48. uint32_t reg_ebx;
  49. uint32_t reg_edx;
  50. uint32_t reg_ecx;
  51. uint32_t reg_eax;
  52. };
  53. struct trapframe {
  54. struct pushregs tf_regs;
  55. uint16_t tf_gs;
  56. uint16_t tf_padding0;
  57. uint16_t tf_fs;
  58. uint16_t tf_padding1;
  59. uint16_t tf_es;
  60. uint16_t tf_padding2;
  61. uint16_t tf_ds;
  62. uint16_t tf_padding3;
  63. uint32_t tf_trapno;
  64. /* below here defined by x86 hardware */
  65. uint32_t tf_err;
  66. uintptr_t tf_eip;
  67. uint16_t tf_cs;
  68. uint16_t tf_padding4;
  69. uint32_t tf_eflags;
  70. /* below here only when crossing rings, such as from user to kernel */
  71. uintptr_t tf_esp;
  72. uint16_t tf_ss;
  73. uint16_t tf_padding5;
  74. } __attribute__((packed));
  75. void idt_init(void);
  76. void print_trapframe(struct trapframe *tf);
  77. void print_regs(struct pushregs *regs);
  78. bool trap_in_kernel(struct trapframe *tf);
  79. #endif /* !__KERN_TRAP_TRAP_H__ */