* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab3 / inc / trap.h
blob57e20f14ce29214e740c4c3460fb67ae557a5b06
1 #ifndef JOS_INC_TRAP_H
2 #define JOS_INC_TRAP_H
4 // Trap numbers
5 // These are 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 generated by recent processors)
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
27 // These are arbitrarily chosen, but with care not to overlap
28 // processor defined exceptions or interrupt vectors.
29 #define T_SYSCALL 48 // system call
30 #define T_DEFAULT 500 // catchall
32 // Hardware IRQ numbers. We receive these as (IRQ_OFFSET+IRQ_WHATEVER)
33 #define IRQ_TIMER 0
34 #define IRQ_KBD 1
35 #define IRQ_SERIAL 4
36 #define IRQ_SPURIOUS 7
37 #define IRQ_IDE 14
38 #define IRQ_ERROR 19
40 #ifndef __ASSEMBLER__
42 #include <inc/types.h>
44 struct PushRegs {
45 /* registers as pushed by pusha */
46 uint32_t reg_edi;
47 uint32_t reg_esi;
48 uint32_t reg_ebp;
49 uint32_t reg_oesp; /* Useless */
50 uint32_t reg_ebx;
51 uint32_t reg_edx;
52 uint32_t reg_ecx;
53 uint32_t reg_eax;
54 } __attribute__((packed));
56 struct Trapframe {
57 struct PushRegs tf_regs;
58 uint16_t tf_es;
59 uint16_t tf_padding1;
60 uint16_t tf_ds;
61 uint16_t tf_padding2;
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_padding3;
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_padding4;
73 } __attribute__((packed));
75 struct UTrapframe {
76 /* information about the fault */
77 uint32_t utf_fault_va; /* va for T_PGFLT, 0 otherwise */
78 uint32_t utf_err;
79 /* trap-time return state */
80 struct PushRegs utf_regs;
81 uintptr_t utf_eip;
82 uint32_t utf_eflags;
83 /* the trap-time stack to return to */
84 uintptr_t utf_esp;
85 } __attribute__((packed));
87 #endif /* !__ASSEMBLER__ */
89 // Must equal 'sizeof(struct Trapframe)'.
90 // A static_assert in kern/trap.c checks this.
91 #define SIZEOF_STRUCT_TRAPFRAME 0x44
93 #endif /* !JOS_INC_TRAP_H */