tmr imts works. I'm not thrilled with how the interrupts and modes are

set... but I'm not sure what to do about it. The big problem is that I
have to be in user mode to service irqs, but I can't enable and
disable F and I in usermode. All I can do is an swi and then have
handler which lets me enable or disable them (like a mini-syscall).
This commit is contained in:
Mariano Alvira 2009-04-22 14:55:40 -04:00
parent 10fdafbcb2
commit bdbf279d0f
6 changed files with 98 additions and 54 deletions

View file

@ -1,15 +1,15 @@
#include "embedded_types.h"
#include "interrupt-utils.h"
//#include "interrupt-utils.h"
#include "isr.h"
#define reg32(x) (*(volatile uint32_t *)(x))
__attribute__ ((interrupt("IRQ")))
//__attribute__ ((interrupt("IRQ")))
void isr(void)
{
// ISR_ENTRY();
/* check for TMR0 interrupt */
// tmr_isr(); // led turns off if I have this, indicating that the isr does jump to tmr_isr
tmr_isr(); // led turns off if I have this, indicating that the isr does jump to tmr_isr
// if(reg32(INTSRC) & (1<<5)) { tmr_isr(); }
// asm("SUBS PC,R14_IRQ,#4")
// enableIRQ(); // I think this is necessary, but the LED never turns off when I have this
@ -17,4 +17,6 @@ void isr(void)
/* putting anything in here breaks the other code :( */
// asm("ldmfd sp!, {r0-r12,lr}");
// enableIRQ();
}

View file

@ -23,15 +23,33 @@
* MA 02111-1307 USA
*/
/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs */
.equ I_BIT, 0x80 /* when I bit is set, IRQ is disabled */
.equ F_BIT, 0x40 /* when F bit is set, FIQ is disabled */
.equ USR_MODE, 0x10
.equ FIQ_MODE, 0x11
.equ IRQ_MODE, 0x12
.equ SVC_MODE, 0x13
.equ ABT_MODE, 0x17
.equ UND_MODE, 0x1B
.equ SYS_MODE, 0x1F
.equ usr_stack_size, 256*4
.equ irq_stack_size, 128*4
.equ fiq_stack_size, 128*4
.equ und_stack_size, 32*4
.equ abt_stack_size, 32*4
.equ sup_stack_size, 32*4
/*
*************************************************************************
*
* Jump vector table as in table 3.1 in [1]
*
*************************************************************************
*/
*/
.set base, .
.set _rom_data_init, 0x108d0
@ -72,7 +90,37 @@ ROM_var_end: .word 0
.code 32
.align
_begin:
ldr r1,=_system_stack
msr cpsr_c,#(SVC_MODE | I_BIT | F_BIT)
add r1,r1,#sup_stack_size
mov sp,r1
msr cpsr_c,#(IRQ_MODE | I_BIT | F_BIT)
add r1,r1,#irq_stack_size
mov sp,r1
msr cpsr_c,#(FIQ_MODE | I_BIT | F_BIT)
add r1,r1,#fiq_stack_size
mov sp,r1
msr cpsr_c,#(ABT_MODE | I_BIT | F_BIT)
add r1,r1,#abt_stack_size
mov sp,r1
msr cpsr_c,#(UND_MODE | I_BIT | F_BIT)
add r1,r1,#und_stack_size
mov sp,r1
// msr cpsr_c,#(USR_MODE | I_BIT | F_BIT)
// add r1,r1,#usr_stack_size
// mov sp,r1
bl _rom_data_init+.-base
msr cpsr_c,#(SVC_MODE) // turn on interrupts --- for debug only
msr cpsr_c,#(USR_MODE) // turn on interrupts --- for debug only
// swi
b main
_undefined_instruction: .word undefined_instruction
@ -82,9 +130,8 @@ _data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word fiq
.balignl 16,0xdeadbeef
.balignl 16,0xdeadbeef
/*
*************************************************************************
*
@ -105,6 +152,10 @@ _TEXT_BASE:
_armboot_start:
.word _start
_system_stack:
. = . + usr_stack_size + irq_stack_size + fiq_stack_size + und_stack_size + abt_stack_size + sup_stack_size
/*
* These are defined in the board-specific linker script.
*/
@ -118,6 +169,8 @@ _bss_end:
_start_armboot: .word main
/*
*************************************************************************
*
@ -139,42 +192,6 @@ cpu_init_crit:
*************************************************************************
*/
@
@ IRQ stack frame.
@
#define S_FRAME_SIZE 72
#define S_OLD_R0 68
#define S_PSR 64
#define S_PC 60
#define S_LR 56
#define S_SP 52
#define S_IP 48
#define S_FP 44
#define S_R10 40
#define S_R9 36
#define S_R8 32
#define S_R7 28
#define S_R6 24
#define S_R5 20
#define S_R4 16
#define S_R3 12
#define S_R2 8
#define S_R1 4
#define S_R0 0
#define MODE_SVC 0x13
#define I_BIT 0x80
.macro get_irq_stack @ setup IRQ stack
ldr sp, IRQ_STACK_START
.endm
.macro get_fiq_stack @ setup FIQ stack
ldr sp, FIQ_STACK_START
.endm
/*
* exception handlers
@ -197,8 +214,18 @@ not_used:
.align 5
irq:
push {lr}
movs lr,pc
b isr
.align 5
pop {lr}
subs pc,r14,#4 // suggested irq return cmd
// STMFD sp!, {r0-r12,lr}
// MOVNE lr,pc
// ldr r0, =isr
// BX r0
// LDMFD r13!, {r0-r12,r14}
// MOVS PC, R14
// subs pc, r14, #4
fiq:
.align 5
@ -206,3 +233,4 @@ fiq:
.globl reset_cpu
reset_cpu:
mov pc, r0