1.1 --- a/lib/cpu.S Mon Oct 29 01:46:31 2018 +0100
1.2 +++ b/lib/cpu.S Tue Oct 30 18:19:38 2018 +0100
1.3 @@ -21,6 +21,9 @@
1.4 #include "pic32.h"
1.5 #include "cpu.h"
1.6
1.7 +#define IRQ_STACK_LIMIT (KSEG0_BASE + IRQ_STACK_SIZE)
1.8 +#define IRQ_STACK_TOP (IRQ_STACK_LIMIT - 34 * 4)
1.9 +
1.10 .globl enable_interrupts
1.11 .globl handle_error_level
1.12 .globl init_interrupts
1.13 @@ -126,7 +129,19 @@
1.14 .org 0x180
1.15
1.16 exc_handler:
1.17 - j exception_handler
1.18 + move $k0, $sp
1.19 + move $k1, $t9
1.20 +
1.21 + /* Switch to the IRQ stack. */
1.22 +
1.23 + lui $sp, %hi(IRQ_STACK_TOP)
1.24 + ori $sp, $sp, %lo(IRQ_STACK_TOP)
1.25 +
1.26 + /* Obtain the address directly to avoid initialising $gp here. */
1.27 +
1.28 + lui $t9, %hi(exception_handler)
1.29 + ori $t9, $t9, %lo(exception_handler)
1.30 + jr $t9
1.31 nop
1.32
1.33
1.34 @@ -136,9 +151,6 @@
1.35 .org 0x200
1.36 .set noat
1.37
1.38 -#define IRQ_STACK_LIMIT (KSEG0_BASE + IRQ_STACK_SIZE)
1.39 -#define IRQ_STACK_TOP (IRQ_STACK_LIMIT - 34 * 4)
1.40 -
1.41 int_handler:
1.42
1.43 /* Store affected registers from IRQ_STACK_LIMIT - 4 downwards. */
1.44 @@ -163,7 +175,11 @@
1.45 lui $sp, %hi(IRQ_STACK_TOP)
1.46 ori $sp, $sp, %lo(IRQ_STACK_TOP)
1.47
1.48 - jal interrupt_handler
1.49 + /* Obtain the address directly to avoid initialising $gp here. */
1.50 +
1.51 + lui $t9, %hi(interrupt_handler)
1.52 + ori $t9, $t9, %lo(interrupt_handler)
1.53 + jalr $t9
1.54 nop
1.55
1.56 /* Restore affected registers. */