《操作系统》的实验代码。
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

89 řádky
2.9 KiB

před 12 roky
  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. /* Hardware IRQ numbers. We receive these as (IRQ_OFFSET + IRQ_xx) */
  27. #define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET
  28. #define IRQ_TIMER 0
  29. #define IRQ_KBD 1
  30. #define IRQ_COM1 4
  31. #define IRQ_IDE1 14
  32. #define IRQ_IDE2 15
  33. #define IRQ_ERROR 19
  34. #define IRQ_SPURIOUS 31
  35. /* *
  36. * These are arbitrarily chosen, but with care not to overlap
  37. * processor defined exceptions or interrupt vectors.
  38. * */
  39. #define T_SWITCH_TOU 120 // user/kernel switch
  40. #define T_SWITCH_TOK 121 // user/kernel switch
  41. /* registers as pushed by pushal */
  42. struct pushregs {
  43. uint32_t reg_edi;
  44. uint32_t reg_esi;
  45. uint32_t reg_ebp;
  46. uint32_t reg_oesp; /* Useless */
  47. uint32_t reg_ebx;
  48. uint32_t reg_edx;
  49. uint32_t reg_ecx;
  50. uint32_t reg_eax;
  51. };
  52. struct trapframe {
  53. struct pushregs tf_regs;
  54. uint16_t tf_gs;
  55. uint16_t tf_padding0;
  56. uint16_t tf_fs;
  57. uint16_t tf_padding1;
  58. uint16_t tf_es;
  59. uint16_t tf_padding2;
  60. uint16_t tf_ds;
  61. uint16_t tf_padding3;
  62. uint32_t tf_trapno;
  63. /* below here defined by x86 hardware */
  64. uint32_t tf_err;
  65. uintptr_t tf_eip;
  66. uint16_t tf_cs;
  67. uint16_t tf_padding4;
  68. uint32_t tf_eflags;
  69. /* below here only when crossing rings, such as from user to kernel */
  70. uintptr_t tf_esp;
  71. uint16_t tf_ss;
  72. uint16_t tf_padding5;
  73. } __attribute__((packed));
  74. void idt_init(void);
  75. void print_trapframe(struct trapframe *tf);
  76. void print_regs(struct pushregs *regs);
  77. bool trap_in_kernel(struct trapframe *tf);
  78. #endif /* !__KERN_TRAP_TRAP_H__ */