test.c,up.h,Makefile,vector.S
#include "up.h"}
up.h:
#define VIC0IRQSTATUS (*(volatile unsigned long *)0x71200000)
#define VIC0RAWINTR (*(volatile unsigned long *)0x71200008)
#define VIC0INTSELECT (*(volatile unsigned long *)0x7120000C)
#define VIC0INTENABLE (*(volatile unsigned long *)0x71200010)
#define VIC0SOFTINT (*(volatile unsigned long *)0x71200018)
#define VIC1IRQSTATUS (*(volatile unsigned long *)0x71300000)
#define VIC1RAWINTR (*(volatile unsigned long *)0x71300008)
#define VIC1INTSELECT (*(volatile unsigned long *)0x7130000C)
#define VIC1INTENABLE (*(volatile unsigned long *)0x71300010)
#define VIC1SOFTINT (*(volatile unsigned long *)0x71300018)
#define WTCON (*(volatile unsigned long *)0x7E004000)
#define WTDAT (*(volatile unsigned long *)0x7E004004)
#define WTCNT (*(volatile unsigned long *)0x7E004008)
#define WTCLRINT (*(volatile unsigned long *)0x7E00400C)
#define ADCCON (*(volatile unsigned long *)0x7E00B000)
#define ADCTSC (*(volatile unsigned long *)0x7E00B004)
#define ADCDLY (*(volatile unsigned long *)0x7E00B008)
#define ADCDAT0 (*(volatile unsigned long *)0x7E00B00C)
#define ADCDAT1 (*(volatile unsigned long *)0x7E00B010)
#define ADCUPDN (*(volatile unsigned long *)0x7E00B014)
#define ADCCLRINT (*(volatile unsigned long *)0x7E00B018)
#define ADCCLRINTPNDNUP (*(volatile unsigned long *)0x7E00B020)
vector.S
当发生中断时候 ,我们处理器进入异常向量表中:再从b irq中跳到,我们的irq中:
b reset
b und
b swi
b pre_abt
b data_abt
.word 0x0
b irq
b fiq
reset:
und:
mov sp, #0x56000000
stmfd sp!, {r0-r12, lr}
ldr r2, printf
ldr r0, =string_und
blx r2
mov sp, #0x56000000
ldmea sp, {r0-r12, pc}^
string_und:
.asciz "undefined\n"
.align 2
swi:
mov sp, #0x56000000
stmfd sp!, {r0-r12, lr}
ldr r1, [lr, #-4]
and r1, r1, #0xffffff
ldr r0, =string
ldr r2, printf
blx r2
mov sp, #0x56000000
ldmea sp, {r0-r12, pc}^
pre_abt:
mov sp, #0x56000000
sub lr, lr, #4
stmfd sp!, {r0-r12, lr}
mov sp, #0x56000000
ldmea sp, {r0-r12, pc}^
data_abt:
mov sp, #0x56000000
sub lr, lr, #4
stmfd sp!, {r0-r12, lr}
ldr r0, =string_data
ldr r2, printf
blx r2
mov sp, #0x56000000
ldmea sp, {r0-r12, pc}^
string_data:
.asciz "data\n"
.align 2
irq:
mov sp, #0x56000000 //开辟我们栈
sub lr, lr, #4
stmfd sp!, {r0-r12, lr} //保护现场
mov r1, #0x56000000
ldr r0, [r1]
blx r0 //跳到0x56000000 中保存的do_irq中的函数中执行:
//ldr r0, =0x7E00400C
//mov r1, #100
//str r1, [r0]
//
//ldr r0, =wdt_string
//ldr r2, printf
//blx r2
mov sp, #0x56000000 //恢复现场
ldmea sp, {r0-r12, pc}^
wdt_string:
.asciz "wang wang wang\n"
.align 2
fiq:
mov sp, #0x56000000
sub lr, lr, #4
stmfd sp!, {r0-r12, lr}
mov sp, #0x56000000
ldmea sp, {r0-r12, pc}^
printf:
.word 0x57e11d4c
string:
.asciz "swi %x\n"
.align 2
Makefile:
all:
arm-none-linux-gnueabi-gcc test.c -c -o test.o
arm-none-linux-gnueabi-ld -Ttext=0x50000000 test.o -o test
arm-none-linux-gnueabi-objcopy -Ielf32-littlearm -Obinary test /tftpboot/test.bin
arm-none-linux-gnueabi-gcc -c vector.S -o vector.o
arm-none-linux-gnueabi-ld -Ttext=0x0 vector.o -o vector
arm-none-linux-gnueabi-objcopy -Ielf32-littlearm -Obinary vector /tftpboot/vector.bin
clean:
rm -rf test.o test /tftpboot/test.bin
rm -rf vector.o vector /tftpboot/vector.bin