diff --git a/lib/CPUs/MIPS/bsp/examples/kernel.S b/lib/CPUs/MIPS/bsp/examples/kernel.S index bcffffb..aa0648b 100644 --- a/lib/CPUs/MIPS/bsp/examples/kernel.S +++ b/lib/CPUs/MIPS/bsp/examples/kernel.S @@ -1,9 +1,13 @@ #include #include - .section .ktext,"ax" + .section .exc_vect +_xcpt_vector_tbl: + .fill 16, 4, 0 + + .text -LEAF(xcptlow_handler) +LEAF(_xcpt_handler) .set noreorder .set noat /* Note: exceptions do not save and restore registers k0 and k1. @@ -91,21 +95,21 @@ LEAF(xcptlow_handler) /* and call the C exception handler */ move a0, sp # arg1 = &xcp subu sp, 16 # (arg save area) - j _xcptcall + j _xcpt_call move ra, zero # fake return address - /* This strange call to _xcptcall with zero return address is to + /* This strange call to _xcpt_call with zero return address is to * help exception-aware debuggers to trace back over the exception event. * We are basically interposing a bogus stackframe (with a zero return * address) between the C exception handler and the actual machine * exception. */ -xcptrest: +$xcptrest: .set noat add AT, sp, 16 /* at points to exception frame */ -xcptrestother: +$xcptrestother: /* restore all state */ /* restore most general registers */ lw t0, XCP_T0(AT) @@ -160,10 +164,10 @@ xcptrestother: .set reorder .set at -END(xcptlow_handler) +END(_xcpt_handler) - -LEAF(_xcptcall) + +LEAF(_xcpt_call) /* on entry: a0 == &xcp */ subu sp, 24 sw ra, 16(sp) @@ -173,8 +177,8 @@ LEAF(_xcptcall) nop lw ra, 16(sp) addu sp, 24 - beqz ra, xcptrest + beqz ra, $xcptrest nop j ra nop -END(_xcptcall) +END(_xcpt_call) diff --git a/lib/CPUs/MIPS/bsp/examples/link.ld b/lib/CPUs/MIPS/bsp/examples/link.ld index 2eb2b86..44b93b3 100644 --- a/lib/CPUs/MIPS/bsp/examples/link.ld +++ b/lib/CPUs/MIPS/bsp/examples/link.ld @@ -31,9 +31,11 @@ SECTIONS *(.start) } /* Kernel text with low-level exception handler */ - .ktext __executable_start + 0x180 : + .exc_vector __executable_start + 0x080 : { - *(.ktext) + _exc_vect_start = .; + *(.exc_vect) + _exc_vect_end = .; } .init : { diff --git a/lib/CPUs/MIPS/bsp/examples/startup.S b/lib/CPUs/MIPS/bsp/examples/startup.S index d595475..605631a 100644 --- a/lib/CPUs/MIPS/bsp/examples/startup.S +++ b/lib/CPUs/MIPS/bsp/examples/startup.S @@ -9,11 +9,19 @@ argv: .word argv0 .section .start, "ax" .extern _init .extern dbg_init + .extern _exc_vect_start + .extern _xcpt_handler .align 2 .globl _start _start: .set noreorder + j init + nop + .set reorder + .text + .set noreorder +init: # Set stack pointer la $sp, stack_ptr # Set global pointer @@ -27,6 +35,17 @@ $zeroise: bne $8, $9, $zeroise addiu $8, 4 + # Install exception vector jump code + la $t1, _exc_vect_copy_start + la $t2, _exc_vect_copy_end + la $t0, _exc_vect_start + +$install: lw $v0, 0($t1) + addiu $t1, 4 + sw $v0, 0($t0) + bne $t1, $t2, $install + addiu $t0, 4 + # Call _init la $k0, _init jalr $k0 @@ -41,6 +60,12 @@ $zeroise: li $a0, 1 la $a1, argv + # Set user-mode + mfc0 $a0, $12 + li $a1, 3 + or $a0, $a1 + mtc0 $a0, $12 + # Call main la $k0, main jalr $k0 @@ -52,5 +77,11 @@ _terminate: la $t0, exit jalr $t0 move $a0, $v0 + +_exc_vect_copy_start: + la $k0, _xcpt_handler + jr $k0 + nop +_exc_vect_copy_end: .set reorder