1
0
Fork 0
forked from len0rd/rockbox

mips: Use a separate IRQ stack & optimize IRQ handling a little

Should prevent the IRQ-related stack overflows seen on MIPS targets.

Change-Id: I447336ef3fe37e11b3276a78ba220ce64c2f87f5
This commit is contained in:
Solomon Peachy 2018-12-25 22:28:14 -05:00
parent 5e8db1662b
commit 36a50dd00f
3 changed files with 60 additions and 38 deletions

View file

@ -83,6 +83,9 @@ SECTIONS
stackbegin = .; stackbegin = .;
. += 0x2000; . += 0x2000;
stackend = .; stackend = .;
irqstackbegin = .;
. += 0x400;
irqstackend = .;
} > IRAM } > IRAM
.bss (NOLOAD): .bss (NOLOAD):

View file

@ -87,5 +87,8 @@ SECTIONS
stackbegin = .; stackbegin = .;
. += 0x2000; . += 0x2000;
stackend = .; stackend = .;
irqstackbegin = .;
. += 0x400;
irqstackend = .;
} > IRAM } > IRAM
} }

View file

@ -28,7 +28,7 @@
* e-mail: seeger.chin@gmail.com * e-mail: seeger.chin@gmail.com
* *
* Copyright (C) 2006 Ingenic Semiconductor Inc. * Copyright (C) 2006 Ingenic Semiconductor Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
@ -120,7 +120,7 @@ _cache_loop:
ori t0, 2 ori t0, 2
mtc0 t0, C0_CONFIG mtc0 t0, C0_CONFIG
nop nop
/* /*
---------------------------------------------------- ----------------------------------------------------
Copy IRAM section Copy IRAM section
@ -137,7 +137,7 @@ _iram_loop:
addiu t0, 4 addiu t0, 4
bne t1, t2, _iram_loop bne t1, t2, _iram_loop
sw t3, -4(t1) sw t3, -4(t1)
/* /*
---------------------------------------------------- ----------------------------------------------------
Clear BSS section Clear BSS section
@ -158,12 +158,25 @@ _bss_loop:
la sp, stackend la sp, stackend
la t0, stackbegin la t0, stackbegin
li t2, 0xDEADBEEF li t2, 0xDEADBEEF
_stack_loop: _stack_loop:
addiu t0, 4 addiu t0, 4
bne t0, sp, _stack_loop bne t0, sp, _stack_loop
sw t2, -4(t0) sw t2, -4(t0)
/*
----------------------------------------------------
Set up interrupt stack
----------------------------------------------------
*/
la k0, irqstackend
la t0, irqstackbegin
_irq_stack_loop:
addiu t0, 4
bne t0, k0, _irq_stack_loop
sw t2, -4(t0)
/* /*
---------------------------------------------------- ----------------------------------------------------
Jump to C code Jump to C code
@ -174,33 +187,43 @@ _stack_loop:
j main j main
nop nop
/* /*
* 0x0 - Simple TLB refill handler * 0x0 - Simple TLB refill handler
* 0x100 - Cache error handler * 0x100 - Cache error handler
* 0x180 - Exception/Interrupt handler * 0x180 - Exception/Interrupt handler
* 0x200 - Special Exception Interrupt handler (when IV is set in CP0_CAUSE) * 0x200 - Special Exception Interrupt handler (when IV is set in CP0_CAUSE)
*/ */
.section .vectors.1, "ax", %progbits .section .vectors.1, "ax", %progbits
j tlb_refill_handler j tlb_refill_handler
nop nop
.section .vectors.2, "ax", %progbits .section .vectors.2, "ax", %progbits
j real_exception_handler j real_exception_handler
nop nop
.section .vectors.3, "ax", %progbits .section .vectors.3, "ax", %progbits
j real_exception_handler j real_exception_handler
nop nop
.section .vectors.4, "ax", %progbits .section .vectors.4, "ax", %progbits
j real_exception_handler j real_exception_handler
nop nop
.section .vectors, "ax", %progbits .section .vectors, "ax", %progbits
real_exception_handler: real_exception_handler:
addiu sp, -0x80
/* Store stack pointer */
move k0, sp
/* jump to IRQ stack */
la sp, irqstackend
/* Push crap on frame */
addiu sp, -0x84
/* store current stack pointer */
sw k0, 0x80(sp)
sw ra, 0(sp) sw ra, 0(sp)
sw fp, 4(sp) sw fp, 4(sp)
sw gp, 8(sp) sw gp, 8(sp)
@ -236,18 +259,16 @@ real_exception_handler:
nop nop
sw k0, 0x74(sp) sw k0, 0x74(sp)
mfc0 k0, C0_STATUS mfc0 k0, C0_STATUS
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1
sw k0, 0x78(sp) sw k0, 0x78(sp)
mfc0 k0, C0_EPC mfc0 k0, C0_EPC
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1
sw k0, 0x7C(sp) sw k0, 0x7C(sp)
li k1, M_CauseExcCode li k1, M_CauseExcCode
mfc0 k0, C0_CAUSE mfc0 k0, C0_CAUSE
and k0, k1 and k0, k1
@ -255,24 +276,22 @@ real_exception_handler:
nop nop
j _exception j _exception
nop nop
_int: _int:
jal intr_handler jal intr_handler
nop nop
j _exception_return j _exception_return
_exception: _exception:
move a0, sp move a0, sp
mfc0 a1, C0_CAUSE mfc0 a1, C0_CAUSE
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1
mfc0 a2, C0_EPC mfc0 a2, C0_EPC
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1
jal exception_handler jal exception_handler
nop nop
@ -314,18 +333,15 @@ _exception_return:
lw k0, 0x78(sp) lw k0, 0x78(sp)
mtc0 k0, C0_STATUS mtc0 k0, C0_STATUS
nop nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1
sll zero, 1
lw k0, 0x7C(sp) lw k0, 0x7C(sp)
mtc0 k0, C0_EPC mtc0 k0, C0_EPC
nop nop
sll zero, 1 nop
sll zero, 1 nop
sll zero, 1 /* Restore previous stack pointer */
sll zero, 1 lw sp, 0x80(sp)
addiu sp, 0x80
eret eret
nop nop
.set reorder .set reorder