1 | /************************************************************************************ |
---|
2 | * GIET: Interruption/Exception/Trap Handler for MIPS32 processor |
---|
3 | * |
---|
4 | * The base address of the segment containing this code MUST be 0x80000000, in |
---|
5 | * order to have the entry point at address 0x80000180!!! All messages are |
---|
6 | * printed on the TTY corresponding to the task&processor identifiers. |
---|
7 | * |
---|
8 | * It uses two arrays of functions: |
---|
9 | * - the _cause_vector[16] array defines the 16 causes to enter the GIET |
---|
10 | * it is initialized in th exc_handler.c file |
---|
11 | * - the _syscall_vector[64] array defines the 64 system calls entry points |
---|
12 | * it is initialised in the sys_handler.c file |
---|
13 | ***********************************************************************************/ |
---|
14 | |
---|
15 | .section .giet, "ax", @progbits |
---|
16 | .space 0x180 |
---|
17 | |
---|
18 | /* |
---|
19 | * GIET Entry point (at address 0x80000180) |
---|
20 | */ |
---|
21 | |
---|
22 | .func _giet |
---|
23 | .type _giet, %function |
---|
24 | |
---|
25 | _giet: |
---|
26 | mfc0 $27, $13 /* $27 <= Cause register */ |
---|
27 | la $26, _cause_vector /* $26 <= _cause_vector */ |
---|
28 | andi $27, $27, 0x3c /* $27 <= XCODE*4 */ |
---|
29 | addu $26, $26, $27 /* $26 <= &_cause_vector[XCODE] */ |
---|
30 | lw $26, ($26) /* $26 <= _cause_vector[XCODE] */ |
---|
31 | jr $26 /* Jump indexed by XCODE */ |
---|
32 | |
---|
33 | .endfunc |
---|
34 | .size _giet, .-_giet |
---|
35 | |
---|
36 | /* |
---|
37 | * *** System Call Handler *** |
---|
38 | * |
---|
39 | * A system call is handled as a special function call. |
---|
40 | * - $2 contains the system call index (< 64). |
---|
41 | * - $3 is used to store the syscall address |
---|
42 | * - $4, $5, $6, $7 contain the arguments values. |
---|
43 | * - The return address (EPC) and the (SR) are saved in the stack. |
---|
44 | * - Interrupts are enabled before branching to the syscall. |
---|
45 | * - All syscalls must return to the syscall handler. |
---|
46 | * - $2, $3, $4, $5, $6, $7 as well as $26 & $27 can be modified. |
---|
47 | * |
---|
48 | * In case of undefined system call, an error message displays |
---|
49 | * the value of EPC on the kernel TTY, and the user program is killed. |
---|
50 | */ |
---|
51 | |
---|
52 | .globl _sys_handler |
---|
53 | .func _sys_handler |
---|
54 | .type _sys_handler, %function |
---|
55 | |
---|
56 | _sys_handler: |
---|
57 | addiu $29, $29, -24 /* 2 slots for SR & EPC, 4 slots for args */ |
---|
58 | mfc0 $27, $14 /* $27 <= EPC */ |
---|
59 | addiu $27, $27, 4 /* increment EPC for return address */ |
---|
60 | sw $27, 20($29) /* save EPC in the stack */ |
---|
61 | mfc0 $27, $12 /* $27 <= SR */ |
---|
62 | sw $27, 16($29) /* save SR in the stack */ |
---|
63 | |
---|
64 | andi $26, $2, 0x3F /* $26 <= syscall index (i < 64) */ |
---|
65 | sll $26, $26, 2 /* $26 <= index * 4 */ |
---|
66 | la $27, _syscall_vector /* $27 <= &_syscall_vector[0] */ |
---|
67 | addu $27, $27, $26 /* $27 <= &_syscall_vector[i] */ |
---|
68 | lw $3, 0($27) /* $3 <= syscall address */ |
---|
69 | li $27, 0xFFFFFFED /* Mask for UM & EXL bits */ |
---|
70 | mfc0 $26, $12 /* $26 <= SR */ |
---|
71 | and $26, $26, $27 /* UM = 0 / EXL = 0 */ |
---|
72 | mtc0 $26, $12 /* interrupt enabled */ |
---|
73 | jalr $3 /* jump to the proper syscall */ |
---|
74 | |
---|
75 | mtc0 $0, $12 /* SR <= 0 : interrupt disabled */ |
---|
76 | lw $26, 16($29) /* $26 <= SR from stack */ |
---|
77 | mtc0 $26, $12 /* restore SR */ |
---|
78 | lw $26, 20($29) /* $26 <= EPC from stack */ |
---|
79 | mtc0 $26, $14 /* restore EPC */ |
---|
80 | addiu $29, $29, 24 /* restore stack pointer */ |
---|
81 | eret /* exit GIET */ |
---|
82 | |
---|
83 | .endfunc |
---|
84 | .size _sys_handler, .-_sys_handler |
---|
85 | |
---|
86 | /* |
---|
87 | * *** Interrupt Handler *** |
---|
88 | * |
---|
89 | * This simple interrupt handler cannot be interrupted. |
---|
90 | * |
---|
91 | * All non persistant registers, such as $1 to $15, and $24 to $25, as well as |
---|
92 | * register $31 and EPC, are saved in the interrupted program stack, before |
---|
93 | * calling the Interrupt Service Routine. These registers can be used by the |
---|
94 | * ISR code. |
---|
95 | */ |
---|
96 | |
---|
97 | .globl _int_handler |
---|
98 | .func _int_handler |
---|
99 | .type _int_handler, %function |
---|
100 | |
---|
101 | _int_handler: |
---|
102 | addiu $29, $29, -25*4 /* stack space reservation (21 registers to |
---|
103 | save and 4 free words to call function) */ |
---|
104 | .set noat |
---|
105 | sw $1, 4*4($29) /* save $1 */ |
---|
106 | .set at |
---|
107 | sw $2, 5*4($29) /* save $2 */ |
---|
108 | sw $3, 6*4($29) /* save $3 */ |
---|
109 | sw $4, 7*4($29) /* save $4 */ |
---|
110 | sw $5, 8*4($29) /* save $5 */ |
---|
111 | sw $6, 9*4($29) /* save $6 */ |
---|
112 | sw $7, 10*4($29) /* save $7 */ |
---|
113 | sw $8, 11*4($29) /* save $8 */ |
---|
114 | sw $9, 12*4($29) /* save $9 */ |
---|
115 | sw $10, 13*4($29) /* save $10 */ |
---|
116 | sw $11, 14*4($29) /* save $11 */ |
---|
117 | sw $12, 15*4($29) /* save $12 */ |
---|
118 | sw $13, 16*4($29) /* save $13 */ |
---|
119 | sw $14, 17*4($29) /* save $14 */ |
---|
120 | sw $15, 18*4($29) /* save $15 */ |
---|
121 | sw $24, 19*4($29) /* save $24 */ |
---|
122 | sw $25, 20*4($29) /* save $25 */ |
---|
123 | sw $31, 21*4($29) /* save $31 */ |
---|
124 | mflo $26 |
---|
125 | sw $26, 22*4($29) /* save LO */ |
---|
126 | mfhi $26 |
---|
127 | sw $26, 23*4($29) /* save HI */ |
---|
128 | mfc0 $27, $14 |
---|
129 | sw $27, 24*4($29) /* save EPC */ |
---|
130 | |
---|
131 | la $26, _irq_demux |
---|
132 | jalr $26 /* jump to a C function to find the proper ISR */ |
---|
133 | |
---|
134 | restore: |
---|
135 | .set noat |
---|
136 | lw $1, 4*4($29) /* restore $1 */ |
---|
137 | .set at |
---|
138 | lw $2, 4*5($29) /* restore $2 */ |
---|
139 | lw $3, 4*6($29) /* restore $3 */ |
---|
140 | lw $4, 4*7($29) /* restore $4 */ |
---|
141 | lw $5, 4*8($29) /* restore $5 */ |
---|
142 | lw $6, 4*9($29) /* restore $6 */ |
---|
143 | lw $7, 4*10($29) /* restore $7 */ |
---|
144 | lw $8, 4*11($29) /* restore $8 */ |
---|
145 | lw $9, 4*12($29) /* restore $9 */ |
---|
146 | lw $10, 4*13($29) /* restore $10 */ |
---|
147 | lw $11, 4*14($29) /* restore $11 */ |
---|
148 | lw $12, 4*15($29) /* restore $12 */ |
---|
149 | lw $13, 4*16($29) /* restore $13 */ |
---|
150 | lw $14, 4*17($29) /* restore $14 */ |
---|
151 | lw $15, 4*18($29) /* restore $15 */ |
---|
152 | lw $24, 4*19($29) /* restore $24 */ |
---|
153 | lw $25, 4*20($29) /* restore $25 */ |
---|
154 | lw $31, 4*21($29) /* restore $31 */ |
---|
155 | lw $26, 4*22($29) |
---|
156 | mtlo $26 /* restore LO */ |
---|
157 | lw $26, 4*23($29) |
---|
158 | mthi $26 /* restore HI */ |
---|
159 | lw $27, 4*24($29) /* return address (EPC) */ |
---|
160 | addiu $29, $29, 25*4 /* restore stack pointer */ |
---|
161 | mtc0 $27, $14 /* restore EPC */ |
---|
162 | eret /* exit GIET */ |
---|
163 | |
---|
164 | .endfunc |
---|
165 | .size _int_handler, .-_int_handler |
---|
166 | |
---|