Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 3222 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2607
Line 28... Line 28...
28
 
28
 
29
#include <arch/asm/regname.h>
29
#include <arch/asm/regname.h>
30
#include <arch/mm/page.h>
30
#include <arch/mm/page.h>
31
#include <arch/asm/boot.h>
31
#include <arch/asm/boot.h>
32
#include <arch/context_offset.h>
32
#include <arch/context_offset.h>
-
 
33
#include <arch/stack.h>
33
	
34
	
34
.text
35
.text
35
 
36
 
36
.set noat
37
.set noat
37
.set noreorder
38
.set noreorder
Line 227... Line 228...
227
 
228
 
228
exception_entry:
229
exception_entry:
229
	j exception_handler
230
	j exception_handler
230
	nop	
231
	nop	
231
 
232
	
232
	
-
 
233
	
-
 
234
exception_handler:
233
exception_handler:
235
	KERNEL_STACK_TO_K0
234
	KERNEL_STACK_TO_K0
236
	sub $k0, REGISTER_SPACE
235
	sub $k0, REGISTER_SPACE
237
	sw $sp,EOFFSET_SP($k0)
236
	sw $sp, EOFFSET_SP($k0)
238
	move $sp, $k0
237
	move $sp, $k0
Line 254... Line 253...
254
 
253
 
255
	REGISTERS_LOAD $sp
254
	REGISTERS_LOAD $sp
256
	# The $sp is automatically restored to former value
255
	# The $sp is automatically restored to former value
257
	eret
256
	eret
258
 
257
 
-
 
258
## Syscall entry
-
 
259
#
-
 
260
# Registers:
-
 
261
#
-
 
262
# @param v0		Syscall number.
259
# it seems that mips reserves some space on stack for varfuncs???
263
# @param a0		1st argument.
260
#define SS_ARG4   16
264
# @param a1		2nd argument.
-
 
265
# @param a2		3rd argument.
-
 
266
# @param a3		4th argument.
-
 
267
# @param t0		5th argument.
-
 
268
# @param t1		6th argument.
-
 
269
#
-
 
270
# @return		The return value will be stored in v0.
-
 
271
#
261
#define SS_SP     EOFFSET_SP
272
#define SS_SP		EOFFSET_SP
262
#define SS_STATUS EOFFSET_STATUS
273
#define SS_STATUS	EOFFSET_STATUS
263
#define SS_EPC    EOFFSET_EPC
274
#define SS_EPC		EOFFSET_EPC
264
#define SS_K1     EOFFSET_K1
275
#define SS_K1		EOFFSET_K1
265
syscall_shortcut:
276
syscall_shortcut:
266
	# We have a lot of space on the stack, with free use
277
	# We have a lot of space on the stack, with free use
267
	mfc0 $t1, $epc
278
	mfc0 $t3, $epc
268
	mfc0 $t0, $status
279
	mfc0 $t2, $status
269
	sw $t1,SS_EPC($sp)  # Save EPC
280
	sw $t3, SS_EPC($sp)		# Save EPC
270
	sw $k1,SS_K1($sp)   # Save k1, which is not saved during context switch
281
	sw $k1, SS_K1($sp)   		# Save k1 not saved on context switch
271
	
282
	
272
	and $t2, $t0, REG_SAVE_MASK # Save only KSU,EXL,ERL,IE
283
	and $t4, $t2, REG_SAVE_MASK	# Save only KSU, EXL, ERL, IE
273
	li $t3, ~(0x1f)
284
	li $t5, ~(0x1f)
274
	and $t0, $t0, $t3           # Clear KSU,EXL,ERL
285
	and $t2, $t2, $t5		# Clear KSU, EXL, ERL
275
	ori $t0, $t0, 0x1           # Set IE
286
	ori $t2, $t2, 0x1		# Set IE
276
 
287
 
277
	sw $t2,SS_STATUS($sp)
288
	sw $t4, SS_STATUS($sp)
278
	mtc0 $t0, $status
289
	mtc0 $t2, $status
279
 
290
 
-
 
291
	#
280
	# CALL Syscall handler
292
	# Call the higher level system call handler
-
 
293
	# We are going to reuse part of the unused exception stack frame
-
 
294
	#
-
 
295
	sw $t0, STACK_ARG4($sp)		# save the 5th argument on the stack
-
 
296
	sw $t1, STACK_ARG5($sp)		# save the 6th argument on the stack
281
	jal syscall_handler
297
	jal syscall_handler
282
	sw $v0, SS_ARG4($sp)        # save v0 - arg4 to stack
298
	sw $v0, STACK_ARG6($sp)		# save the syscall number on the stack
283
 
299
 
284
	# restore status
300
	# restore status
285
	mfc0 $t0, $status
301
	mfc0 $t2, $status
286
	lw $t1,SS_STATUS($sp)
302
	lw $t3, SS_STATUS($sp)
287
 
303
 
288
	# Change back to EXL=1(from last exception), otherwise
304
	# Change back to EXL = 1 (from last exception), otherwise
289
	# an interrupt could rewrite the CP0-EPC
305
	# an interrupt could rewrite the CP0 - EPC
290
	li $t2, ~REG_SAVE_MASK      # Mask UM,EXL,ERL,IE
306
	li $t4, ~REG_SAVE_MASK		# Mask UM, EXL, ERL, IE
291
	and $t0, $t0, $t2
307
	and $t2, $t2, $t4
292
	or $t0, $t0, $t1            # Copy UM,EXL,ERL,IE from saved status
308
	or $t2, $t2, $t3		# Copy saved UM, EXL, ERL, IE
293
	mtc0 $t0, $status
309
	mtc0 $t2, $status
294
			
310
			
295
	# restore epc+4
311
	# restore epc + 4
296
	lw $t0,SS_EPC($sp)
312
	lw $t2, SS_EPC($sp)
297
	lw $k1,SS_K1($sp)
313
	lw $k1, SS_K1($sp)
298
	addi $t0, $t0, 4
314
	addi $t2, $t2, 4
299
	mtc0 $t0, $epc
315
	mtc0 $t2, $epc
300
	
316
	
301
	lw $sp,SS_SP($sp) # restore sp
317
	lw $sp, SS_SP($sp)		# restore sp
302
	
318
	
303
	eret
319
	eret
304
		
320