ARM11裸奔,软中断问题
求大神指点,这个问题都困扰了将近一个月了想裸奔,对系统感兴趣,打算研究一下swi,可是S3C6410调试看到,每次执行swi指令之后就会进入数据访问终止异常中,很是郁闷,简单三个文件,start.s,main.c,求大神指点个人实在没办法了
start.s
Mode_USR EQU 0x10
Mode_FIQ EQU 0x11
Mode_IRQ EQU 0x12
Mode_SVC EQU 0x13
Mode_ABT EQU 0x17
Mode_UND EQU 0x1B
Mode_SYS EQU 0x1F
UND_Stack_SizeEQU 0x00000400
SVC_Stack_SizeEQU 0x00001000
ABT_Stack_SizeEQU 0x00000400
FIQ_Stack_SizeEQU 0x00000400
IRQ_Stack_SizeEQU 0x00001000
USR_Stack_SizeEQU 0x00001000
Heap_Size EQU 0x00010000
I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
Stack_Top EQU 0x52000000
IMPORT Main
; IMPORT swi_service_func
; IMPORT __use_no_semihosting_swi
EXPORT SWI_Handler
IMPORT C_SWI_Handler
PRESERVE8
AREA |startup|,CODE,READONLY
ENTRY
Vector_Table
LDR PC, Reset_Addr
LDR PC, Undefined_Addr
LDR PC, SWI_Addr
LDR PC, Prefetch_Addr
LDR PC, Abort_Addr
NOP ; Reserved vector must be remained
LDR PC, IRQ_Addr
LDR PC, FIQ_Addr
Vector_Addr_Table
Reset_Addr DCD Reset_Handler
Undefined_AddrDCD Undefined_Handler
SWI_Addr DCD SWI_Handler
Prefetch_Addr DCD Prefetch_Handler
Abort_Addr DCD Abort_Handler
IRQ_Addr DCD IRQ_Handler
FIQ_Addr DCD FIQ_Handler
FUN_SWI DCD C_SWI_Handler
; 复位地址入口
Reset_Handler
; mrc p15,0,r0,c1,c0,0 ;使能VIC PORT功能
; orr r0,r0,#(1<<24)
; mcr p15,0,r0,c1,c0,0
LDR R0, =Stack_Top
MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #UND_Stack_Size
MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #ABT_Stack_Size
MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #FIQ_Stack_Size
MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #IRQ_Stack_Size
MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB SL, SP, #SVC_Stack_Size
MSR CPSR_c, #Mode_USR
MOV SP, R0
SUB SL, SP, #USR_Stack_Size
;使能IQR中断
;MRS R0,CPSR
; BIC R0,R0,#0x80
;MSR CPSR_c,R0
MSR CPSR_c, #Mode_USR ;intel user mode
STMFDsp!,{r0-r3, r12, lr} ;
bl Main ;uboot将CPU控制权交给main
LDMFDsp!,{r0-r3, r12, pc}^ ;main退出后,uboot重新获取CPU控制权
Undefined_Handler
B Undefined_Handler
T_bit EQU 0x20
SWI_Handler
STMFDsp!,{r0-r3, r12, lr} ; Store registers
MOV r1, sp ; Set pointer to parameters
MRS r0, spsr ; Get spsr
STMFDsp!,{r0} ; Store spsr onto stack
TST r0, #T_bit ; Occurred in Thumb state?
LDRNEH r0, ; Yes: Load halfword and...
BICNEr0, r0, #0xFF00 ; ...extract comment field
LDREQr0, ; No: Load word and...
BICEQr0, r0, #0xFF000000 ; ...extract comment field ; r0 now contains SWI number ; r1 now contains pointer to stacked registers
LDR PC, FUN_SWI ; Call main part of handler
LDMFDsp!,{r0} ; Get spsr from stack
MSR spsr_cf, r0 ; Restore spsr
LDMFDsp!,{r0-r3, r12, pc}^ ; Restore registers and return
Prefetch_Handler
B Prefetch_Handler
Abort_Handler
B Abort_Handler
IRQ_Handler
B IRQ_Handler
FIQ_Handler
B FIQ_Handler
END
main.c
//#include <uboot.h>
#include <printf.h>
#define rGPMCON (*(volatile unsigned *)(0x7F008820))
#define rGPMDAT (*(volatile unsigned *)(0x7F008824))
#define rGPMPUD (*(volatile unsigned *)(0x7F008828))
struct four_results
{
int a;
int b;
int c;
int d;
};
__swi(0) int multiply_two(int, int);
__swi(1) int add_two(int, int);
__swi(2) int add_multiply_two(int, int, int, int);
__swi(3) __value_in_regs struct four_results many_operations(int, int, int, int);
void msDelay(int time)
{
volatile unsigned int i,j;
for(i = 0; i < 200000; i++)
for(j=0; j<time; j++);
}
void GPIO_Init(void)
{
rGPMCON = 0x11111;
rGPMPUD = 0x00;
rGPMDAT = 0X1F;
}
void LedTest(void)
{
volatile unsigned int i;
unsigned char count=0;
while (1)
{
for(i=0; i<4; i++)
{
rGPMDAT = ~(1<<i);
msDelay(10);
}
count++;
if(count>3)
return;
}
}
unsigned Install_Handler( unsigned routine, unsigned *vector )
{
unsigned vec, old_vec;
vec = (routine - (unsigned)vector - 8) >> 2;
if (vec & 0xff000000)
{
printf("Handler greater than 32MBytes from vector");
}
vec = 0xea000000 | vec; /**//* OR in 'branch always' code */
old_vec = *vector;
*vector = vec;
return (old_vec);
}
/***********************/
unsigned *swi_vec = (unsigned *)0x08;
extern void SWI_Handler(void);
void C_SWI_Handler( int swi_num, int *regs )
{
switch( swi_num )
{
case 0:
regs = regs * regs; break;
case 1:
regs = regs + regs; break;
case 2:
regs = (regs * regs) + (regs * regs); break;
case 3:
{
int w, x, y, z;
w = regs;
x = regs;
y = regs;
z = regs;
regs = w + x + y + z;
regs = w - x - y - z;
regs = w * x * y * z;
regs =(w + x) * (y - z);
}
break;
}
}
void Main(void)
{
/* int result1, result2;
struct four_results res_3;
Install_Handler( (unsigned) SWI_Handler, swi_vec );
printf("result1 = multiply_two( 2, 4 ) = %d ", result1 = multiply_two( 2, 4 ));
printf("result2 = multiply_two( 3, 6 ) = %d ", result2 = multiply_two( 3, 6 ));
printf("add_two( result1, result2 ) = %d ", add_two( result1, result2 ));
printf("add_multiply_two( 2, 4, 3, 6 ) = %d ", add_multiply_two( 2, 4, 3, 6 ));
res_3 = many_operations( 12, 4, 3, 1 );
printf("res_3.a = %d ", res_3.a );
printf("res_3.b = %d ", res_3.b );
printf("res_3.c = %d ", res_3.c );
printf("res_3.d = %d ", res_3.d );
GPIO_Init();
printf("hello world\n");
LedTest();*/
__asm("swi 0");
}
就是这几行代码,快郁闷死了
一执行swi指令就会进入 Abort_Handler这个异常中
页:
[1]