Rev 1094 | Rev 1097 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1094 | Rev 1096 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | .global tlb_refill_entry |
41 | .global tlb_refill_entry |
42 | .global cache_error_entry |
42 | .global cache_error_entry |
43 | .global exception_entry |
43 | .global exception_entry |
44 | .global userspace_asm |
44 | .global userspace_asm |
45 | 45 | ||
- | 46 | # Which status bits should are thread-local |
|
- | 47 | #define REG_SAVE_MASK 0x1f # KSU(UM), EXL, ERL, IE |
|
- | 48 | ||
46 | # Save registers to space defined by \r |
49 | # Save registers to space defined by \r |
47 | # We will change $at on the way |
50 | # We will change status: Disable ERL,EXL,UM,IE |
- | 51 | # These changes will be automatically reversed in REGISTER_LOAD |
|
48 | .macro REGISTERS_STORE r |
52 | .macro REGISTERS_STORE_AND_EXC_RESET r |
49 | sw $at,EOFFSET_AT(\r) |
53 | sw $at,EOFFSET_AT(\r) |
50 | sw $v0,EOFFSET_V0(\r) |
54 | sw $v0,EOFFSET_V0(\r) |
51 | sw $v1,EOFFSET_V1(\r) |
55 | sw $v1,EOFFSET_V1(\r) |
52 | sw $a0,EOFFSET_A0(\r) |
56 | sw $a0,EOFFSET_A0(\r) |
53 | sw $a1,EOFFSET_A1(\r) |
57 | sw $a1,EOFFSET_A1(\r) |
Line 83... | Line 87... | ||
83 | 87 | ||
84 | sw $gp,EOFFSET_GP(\r) |
88 | sw $gp,EOFFSET_GP(\r) |
85 | sw $ra,EOFFSET_RA(\r) |
89 | sw $ra,EOFFSET_RA(\r) |
86 | sw $sp,EOFFSET_SP(\r) |
90 | sw $sp,EOFFSET_SP(\r) |
87 | 91 | ||
88 | mfc0 $at, $status |
92 | mfc0 $t0, $status |
- | 93 | mfc0 $t1, $epc |
|
- | 94 | ||
- | 95 | and $t2, $t0, REG_SAVE_MASK # Save only KSU,EXL,ERL,IE |
|
- | 96 | li $t3, ~(0x1f) |
|
- | 97 | and $t0, $t0, $t3 # Clear KSU,EXL,ERL,IE |
|
- | 98 | ||
89 | sw $at,EOFFSET_STATUS(\r) |
99 | sw $t2,EOFFSET_STATUS(\r) |
90 | mfc0 $at, $epc |
- | |
91 | sw $at,EOFFSET_EPC(\r) |
100 | sw $t1,EOFFSET_EPC(\r) |
- | 101 | mtc0 $t0, $status |
|
92 | .endm |
102 | .endm |
93 | 103 | ||
94 | .macro REGISTERS_LOAD r |
104 | .macro REGISTERS_LOAD r |
- | 105 | # Update only UM,EXR,IE from status, the rest |
|
- | 106 | # is controlled by OS and not bound to task |
|
- | 107 | mfc0 $t0, $status |
|
- | 108 | lw $t1,EOFFSET_STATUS(\r) |
|
- | 109 | ||
- | 110 | li $t2, ~REG_SAVE_MASK # Mask UM,EXL,ERL,IE |
|
- | 111 | and $t0, $t0, $t2 |
|
- | 112 | ||
- | 113 | or $t0, $t0, $t1 # Copy UM,EXL,ERL,IE from saved status |
|
- | 114 | mtc0 $t0, $status |
|
- | 115 | ||
95 | lw $v0,EOFFSET_V0(\r) |
116 | lw $v0,EOFFSET_V0(\r) |
96 | lw $v1,EOFFSET_V1(\r) |
117 | lw $v1,EOFFSET_V1(\r) |
97 | lw $a0,EOFFSET_A0(\r) |
118 | lw $a0,EOFFSET_A0(\r) |
98 | lw $a1,EOFFSET_A1(\r) |
119 | lw $a1,EOFFSET_A1(\r) |
99 | lw $a2,EOFFSET_A2(\r) |
120 | lw $a2,EOFFSET_A2(\r) |
Line 126... | Line 147... | ||
126 | lw $at,EOFFSET_LO(\r) |
147 | lw $at,EOFFSET_LO(\r) |
127 | mtlo $at |
148 | mtlo $at |
128 | lw $at,EOFFSET_HI(\r) |
149 | lw $at,EOFFSET_HI(\r) |
129 | mthi $at |
150 | mthi $at |
130 | 151 | ||
131 | lw $at,EOFFSET_STATUS(\r) |
- | |
132 | mtc0 $at, $status |
- | |
133 | lw $at,EOFFSET_EPC(\r) |
152 | lw $at,EOFFSET_EPC(\r) |
134 | mtc0 $at, $epc |
153 | mtc0 $at, $epc |
135 | 154 | ||
136 | lw $at,EOFFSET_AT(\r) |
155 | lw $at,EOFFSET_AT(\r) |
137 | lw $sp,EOFFSET_SP(\r) |
156 | lw $sp,EOFFSET_SP(\r) |
Line 186... | Line 205... | ||
186 | 205 | ||
187 | 206 | ||
188 | 207 | ||
189 | exception_handler: |
208 | exception_handler: |
190 | KERNEL_STACK_TO_K0 |
209 | KERNEL_STACK_TO_K0 |
- | 210 | ||
- | 211 | mfc0 $k1, $cause |
|
191 | sub $k0, REGISTER_SPACE |
212 | sub $k0, REGISTER_SPACE |
- | 213 | ||
- | 214 | sra $k1, $k1, 0x2 # cp0_exc_cause() part 1 |
|
- | 215 | andi $k1, $k1, 0x1f # cp0_exc_cause() part 2 |
|
- | 216 | sub $k1, 8 # 8=SYSCALL |
|
- | 217 | ||
- | 218 | beqz $k1, uspace_shortcut |
|
- | 219 | add $k1, 8 # Revert $k1 back to correct exc number |
|
- | 220 | ||
192 | REGISTERS_STORE $k0 |
221 | REGISTERS_STORE_AND_EXC_RESET $k0 |
193 | add $sp, $k0, 0 |
222 | move $sp, $k0 |
194 | 223 | ||
195 | add $a0, $sp, 0 |
224 | move $a1, $sp |
196 | jal exception /* exception(register_space) */ |
225 | jal exc_dispatch # exc_dispatch(excno, register_space) |
197 | nop |
226 | move $a0, $k1 |
198 | 227 | ||
199 | REGISTERS_LOAD $sp |
228 | REGISTERS_LOAD $sp |
200 | # The $sp is automatically restored to former value |
229 | # The $sp is automatically restored to former value |
201 | eret |
230 | eret |
202 | nop |
231 | nop |
- | 232 | ||
- | 233 | # it seems that mips reserves some space on stack for varfuncs??? |
|
- | 234 | #define SS_ARG4 16 |
|
- | 235 | #define SS_SP 20 |
|
- | 236 | #define SS_STATUS 24 |
|
- | 237 | #define SS_EPC 28 |
|
- | 238 | #define SS_RA 32 |
|
- | 239 | uspace_shortcut: |
|
- | 240 | # We have a lot of space on the stack, with free use |
|
- | 241 | sw $sp, SS_SP($k0) |
|
- | 242 | move $sp, $k0 |
|
- | 243 | sw $ra, SS_RA($k0) |
|
- | 244 | ||
- | 245 | mfc0 $t1, $epc |
|
- | 246 | mfc0 $t0, $status |
|
- | 247 | sw $t1,SS_EPC($sp) # Save EPC |
|
- | 248 | ||
- | 249 | and $t2, $t0, REG_SAVE_MASK # Save only KSU,EXL,ERL,IE |
|
- | 250 | li $t3, ~(0x1f) |
|
- | 251 | and $t0, $t0, $t3 # Clear KSU,EXL,ERL |
|
- | 252 | ori $t0, $t0, 0x1 # Set IE |
|
- | 253 | ||
- | 254 | sw $t2,SS_STATUS($sp) |
|
- | 255 | mtc0 $t0, $status |
|
- | 256 | ||
- | 257 | jal syscall_handler |
|
- | 258 | sw $v0, SS_ARG4($sp) # save v0 - arg4 to stack |
|
- | 259 | ||
- | 260 | # Restore RA |
|
- | 261 | lw $ra, SS_RA($sp) |
|
- | 262 | ||
- | 263 | # restore epc+4 |
|
- | 264 | lw $t0,SS_EPC($sp) |
|
- | 265 | addi $t0, $t0, 4 |
|
- | 266 | mtc0 $t0, $epc |
|
- | 267 | ||
- | 268 | # restore status |
|
- | 269 | mfc0 $t0, $status |
|
- | 270 | lw $t1,SS_STATUS($sp) |
|
- | 271 | ||
- | 272 | li $t2, ~REG_SAVE_MASK # Mask UM,EXL,ERL,IE |
|
- | 273 | and $t0, $t0, $t2 |
|
- | 274 | or $t0, $t0, $t1 # Copy UM,EXL,ERL,IE from saved status |
|
- | 275 | mtc0 $t0, $status |
|
- | 276 | ||
- | 277 | lw $sp,SS_SP($sp) # restore sp |
|
- | 278 | ||
- | 279 | eret |
|
203 | 280 | ||
204 | tlb_refill_handler: |
281 | tlb_refill_handler: |
205 | KERNEL_STACK_TO_K0 |
282 | KERNEL_STACK_TO_K0 |
206 | sub $k0, REGISTER_SPACE |
283 | sub $k0, REGISTER_SPACE |
207 | REGISTERS_STORE $k0 |
284 | REGISTERS_STORE_AND_EXC_RESET $k0 |
208 | add $sp, $k0, 0 |
285 | add $sp, $k0, 0 |
209 | 286 | ||
210 | add $a0, $sp, 0 |
287 | add $a0, $sp, 0 |
211 | jal tlb_refill /* tlb_refill(register_space) */ |
288 | jal tlb_refill /* tlb_refill(register_space) */ |
212 | nop |
289 | nop |
213 | 290 | ||
214 | REGISTERS_LOAD $sp |
291 | REGISTERS_LOAD $sp |
215 | 292 | ||
216 | eret |
293 | eret |
217 | nop |
- | |
218 | 294 | ||
219 | cache_error_handler: |
295 | cache_error_handler: |
220 | KERNEL_STACK_TO_K0 |
296 | KERNEL_STACK_TO_K0 |
221 | sub $sp, REGISTER_SPACE |
297 | sub $sp, REGISTER_SPACE |
222 | REGISTERS_STORE $sp |
298 | REGISTERS_STORE_AND_EXC_RESET $sp |
223 | add $sp, $k0, 0 |
299 | add $sp, $k0, 0 |
224 | 300 | ||
225 | jal cache_error |
301 | jal cache_error |
226 | nop |
302 | nop |
227 | 303 | ||
228 | REGISTERS_LOAD $sp |
304 | REGISTERS_LOAD $sp |
229 | 305 | ||
230 | eret |
306 | eret |
231 | nop |
- | |
232 | 307 | ||
233 | userspace_asm: |
308 | userspace_asm: |
234 | add $sp, $a0, 0 |
309 | add $sp, $a0, 0 |
235 | add $v0, $a1, 0 |
310 | add $v0, $a1, 0 |
236 | eret |
311 | eret |
237 | nop |
- | |
238 | 312 |