Permissions on IDTs.
[akaros.git] / kern / trapentry.S
1 /* See COPYRIGHT for copyright information. */
2
3 #include <inc/mmu.h>
4 #include <inc/memlayout.h>
5 #include <inc/trap.h>
6
7
8
9 ###################################################################
10 # exceptions/interrupts
11 ###################################################################
12
13 /* The TRAPHANDLER macro defines a globally-visible function for handling
14  * a trap.  It pushes a trap number onto the stack, then jumps to _alltraps.
15  * It also builds this traps portion of the trap_tbl.
16  * Use TRAPHANDLER for traps where the CPU automatically pushes an error code.
17  */ 
18 #define TRAPHANDLER(name, num)                                                                  \
19         .text;                                                                                                          \
20         .globl name;            /* define global symbol for 'name' */   \
21         .type name, @function;  /* symbol type is function */           \
22         .align 2;               /* align function definition */                         \
23         name:                   /* function starts here */                                      \
24         pushl $(num);                                                                                           \
25         jmp _alltraps;                                                                                          \
26         .data;                                                                                                          \
27         .long name;                                                                                                     \
28         .long num
29
30 /* Use TRAPHANDLER_NOEC for traps where the CPU doesn't push an error code.
31  * It pushes a 0 in place of the error code, so the trap frame has the same
32  * format in either case.
33  */
34 #define TRAPHANDLER_NOEC(name, num)             \
35         .text;                                                          \
36         .globl name;                                            \
37         .type name, @function;                          \
38         .align 2;                                                       \
39         name:                                                           \
40         pushl $0;                                                       \
41         pushl $(num);                                           \
42         jmp _alltraps;                                          \
43         .data;                                                          \
44         .long name;                                                     \
45         .long num
46
47 .data
48 .globl trap_tbl;
49 trap_tbl:
50
51 /*
52  * Lab 3: Your code here for generating entry points for the different traps.
53  */
54 TRAPHANDLER(ISR_divide_error, T_DIVIDE);
55 TRAPHANDLER(ISR_debug_exceptions, T_DEBUG);
56 TRAPHANDLER(ISR_breakpoint, T_BRKPT);
57 TRAPHANDLER(ISR_overflow, T_OFLOW);
58 TRAPHANDLER(ISR_bounds_check, T_BOUND);
59 TRAPHANDLER(ISR_invalid_opcode, T_ILLOP);
60 TRAPHANDLER(ISR_device_not_available, T_DEVICE);
61 TRAPHANDLER_NOEC(ISR_double_fault, T_DBLFLT);
62 TRAPHANDLER_NOEC(ISR_invalid_TSS, T_TSS);
63 TRAPHANDLER_NOEC(ISR_segment_not_present, T_SEGNP);
64 TRAPHANDLER_NOEC(ISR_stack_exception, T_STACK);
65 TRAPHANDLER_NOEC(ISR_general_protection_fault, T_GPFLT);
66 TRAPHANDLER_NOEC(ISR_page_fault, T_PGFLT);
67 TRAPHANDLER(ISR_floating_point_error, T_FPERR);
68 TRAPHANDLER(ISR_alignment_check, T_ALIGN);
69 TRAPHANDLER_NOEC(ISR_machine_check, T_MCHK);
70 TRAPHANDLER_NOEC(ISR_simd_error, T_SIMDERR);
71
72 TRAPHANDLER(ISR_syscall, T_SYSCALL);
73 /* make sure default is last */
74 TRAPHANDLER(ISR_default, T_DEFAULT);
75
76 .data
77 .globl trap_tbl_end;
78 trap_tbl_end:
79
80 .text
81 /*
82  * Lab 3: Your code here for _alltraps
83  */
84 _alltraps:
85         pushl %ds;
86         pushl %es;
87         pushal;
88         movw $GD_KD, %ax; /* data segments aren't accessible by default */
89         movw %ax, %ds;
90         movw %ax, %es;
91         pushl %esp;
92         call trap;
93         popl %esp;
94         popal;
95         popl %es;
96         popl %ds;
97         addl $0x8, %esp; /* skip trapno and err */
98         iret;