Hi!
While debugging my project I've found out that my IRQ stack are mixed with application stack: both of them are allocated in the same RAM portion.
I managed to move the IRQ stack in its dedicated area but I would like to verify my code with some more expert people :-)
My "old" irq_handler was something like the following and my modifications are in red:
.equ SYS_MODE , 0x1F
.equ IRQ_MODE , 0x12
.equ INTC_ICCIAR_MASK , 0x1FFF
.equ INTC_ICCIAR_ADDR , 0xE820200C
.equ INTC_ICCEOIR_ADDR , 0xE8202010
.equ INTC_ICCHPIR_ADDR , 0xE8202018
.equ INTC_ICDIPR0_ADDR , 0xE8201400
.func irq_handler
irq_handler:
SUB lr, lr, #4
SRSDB sp!, #SYS_MODE
CPS #SYS_MODE #IRQ_MODE
PUSH {r0-r3, r12}
read_intc_icciar_addr:
/*; ++REE_SS Addressing ARM Errata 801120 */
/*; Perform a dummy read to ensure ICCIAR is correct */
LDR r1, =INTC_ICCHPIR_ADDR
LDR r0, [r1]
/*; --REE_SS Addressing ARM Errata 801120 */
/*; ++REE_SS Addressing ARM Errata 733075 */
/*; Check if ICCIAR is 0, 0x3FE or 0x3FF */
/*; Load in to R3 - it will be used later as ICCIAR */
LDR r1, =INTC_ICCIAR_ADDR
LDR r3, [r1]
CMP r3, #0
BEQ read_intc_icciar_addr
LDR r1, =1022
CMP r3, r1
BGE errata_733075_workaround
B post_733075_workaround
errata_733075_workaround:
/*; Perform a read from ulICDIPR0 and write value back */
/*; It is sufficient to write the value that is already in the register. */
/*; You can obtain the value to be written to the ICDIPR0 register by */
/*; reading from it, or through other means" */
LDR r1, =INTC_ICDIPR0_ADDR
LDR r0, [r1]
STR r0, [r1]
post_733075_workaround:
/*; Get interrupt acknowledge register, from R3 to R0 */
/*; ready to re-enter origional code */
MOV r0, r3
/*; --REE_SS Addressing ARM Errata 733075 */
PUSH {r0}
MOV r1, sp
AND r1, r1, #4
SUB sp, sp, r1
PUSH {r1, lr}
BL userdef_intc_handler_exe
POP {r1, lr}
ADD sp, sp, r1
POP {r0}
LDR r2, =INTC_ICCEOIR_ADDR
STR r0, [r2]
POP {r0-r3, r12}
CPS #SYS_MODE
RFEIA sp!
.endfunc
Stack pointer for each mode are initialized in another file (reset_handler.S)
Are my modifications correct and complete?
It seems to work but I am really not an ASM expert.
Thank you very much!