exception vector handling problem
Posted: Sat May 31, 2014 9:11 am
hello, i've been trying to handle an exception on my raspberry, and can't figure out what the problem is. instead of jump to my blink() function (which is just simple led blinking) execution just hangs somewhere. here is my code:
vector.S
boot.S
exception.c
main.c
v6.S
checker.c
addition.S
reg_debug.c
sorry for bulky code samples. to generate an interrupt i'm trying to read from 0xffffffff in main.c. but, as i said above, instead of blinking led i'm get nothing but black screen which is confusing me. i'll be appreciate for any guess.
vector.S
Code: Select all
#include "exception.h"
.global reset
.global _undefine_instruction
.global _svc_smc_call
.global _prefetch_abort
.global _data_abort
.global _not_used
.global _irq
.global _fiq
.global _start
.global temp_label
.section .vectors
.align 5
_start:
b _reset @0x0
b _undefine_instruction @0x4
b _svc_smc_call @0x8
b _prefetch_abort @0xc
b _data_abort @0x10
b _not_used @0x14
b _irq @0x18
b _fiq @0x1с
reset:
b _reset @hello_world
_undefine_instruction:
b undefine_instruction
_svc_smc_call:
b svc_smc_call
_prefetch_abort:
b prefetch_abort
_data_abort:
b data_abort
_not_used:
b .
_irq:
b .
_fiq:
b .
boot.S
Code: Select all
.equ Mode_USR , 0x10
.equ Mode_FIQ , 0x11
.equ Mode_IRQ , 0x12
.equ Mode_SVC , 0x13
.equ Mode_MON , 0x16
.equ Mode_ABT , 0x17
.equ Mode_UNDEF , 0x1B
.equ Mode_SYS , 0x1F
.equ I_Bit , 0x80 @ when I bit is set, IRQ is disabled
.equ F_Bit , 0x40 @ when F bit is set, FIQ is disabled
/* descriptors for Sections */
.equ L1_COHERENT , 0x00015c06 @ Template descriptor for coherent memory (and L2 cache enabled)
@.equ L1_COHERENT , 0x00014c02 @ Template descriptor for coherent memory (and L2 cache enabled)
.equ L1_NONCOHERENT , 0x00000c1e @ Template descriptor for non-coherent memory
.equ L1_DEVICE , 0x00000c06 @ Template descriptor for device memory
.equ temp , 0
.global _reset
tlbs_l1_base:
.word 0x8000
.section ".text"
.type _reset, %function
_reset:
.fnstart
.cantunwind
b main
.fnend
.size _reset, . - _reset
Code: Select all
#include <common.h>
#include "reg_debug.h"
#include "checker.h"
void svc_smc_call(){
blink();
};
void undefine_instruction(){
blink();
};
void prefetch_abort(){
blink();
};
void data_abort(){
blink();
};
main.c
Code: Select all
#include <common.h>
#include <exports.h>
#include "reg_debug.h"
#include "v6.h"
#include "addition.h"
int main() {
printf("\nhello\n");
asm volatile ("mvn r1, #0");
enableAbortException();
setVBAR(0x18000);
disableHighVecs();
unsigned int reg_value;
asm volatile ("mov %0, r1" : "=r" (reg_value) );
PRN_REG(reg_value, "reg_val")
asm volatile ("mov %0, r8" : "=r" (reg_value) );
PRN_REG(reg_value, "reg_val")
printf("\ntry to generate exception...\n");
asm volatile ("ldr r0, [r1]");
asm volatile ("mov %0,r0" : "=r" (reg_value) );
PRN_REG(reg_value, "reg_val")
for(;;) {}
return 0;
}
Code: Select all
.global enableAbortException
.global enableAbortExceptionSize
.type enableAbortException, %function
enableAbortException:
.fnstart
.cantunwind
CPSIE a
BX lr
.fnend
.size enableAbortException, . - enableAbortException
.global disableHighVecs
.global disableHighVecsSize
@ void invalidateCaches(void);
.type disableHighVecs, %function
disableHighVecs:
.fnstart
.cantunwind
MRC p15, 0, r0, c1, c0, 0 @ Read Control Register
BIC r0, r0, #(1 << 13) @ Set the V bit (bit 13)
MCR p15, 0, r0, c1, c0, 0 @ Write Control Register
BX lr
.fnend
.size disableHighVecs, . - disableHighVecs
Code: Select all
#define GPFSEL1 0x20200004
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
void blink() {
unsigned int ra;
ra=GET32(GPFSEL1);
ra&=~(7<<18);
ra|=1<<18;
PUT32(GPFSEL1,ra);
while(1)
{
PUT32(GPSET0,1<<16);
for(ra=0;ra<0x100000;ra++) _dummy(ra);
PUT32(GPCLR0,1<<16);
for(ra=0;ra<0x100000;ra++) _dummy(ra);
}
}
Code: Select all
.global PUT32
PUT32:
str r1, [r0]
bx lr
.global GET32
GET32:
ldr r0, [r0]
bx lr
.global _dummy
_dummy:
nop
bx lr
Code: Select all
#include <common.h>
/*#include <exports.h>*/
#include "reg_debug.h"
void prnSCR(){
int ret;
asm("mrc p15, 0, %0, c1, c1, 0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "SCR")
#endif
}
void prnSCTLR(){
int ret;
asm("mrc p15, 0, %0, c1, c0, 0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "SCTLR")
#endif
}
void prnCPSR(){
int ret;
asm("mrs %0, CPSR" : "=r" (ret));
#ifdef DEBUG
PRN_REG(ret, "CPSR")
#endif
}
void prnCPACR(){
int ret;
asm("mrc p15, 0, %0, c1, c0, 2" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "CPACR")
#endif
}
void prnACTLR(){
int ret;
asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "ACTLR")
#endif
}
void prnVBAR(){
int ret;
asm("MRC p15,0,%0,c12,c0,0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "VBAR")
#endif
}
void prnCLIDR(){
int ret;
asm("MRC p15,1,%0,c0,c0,1" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "CLIDR")
#endif
}
unsigned int getSCR(){
unsigned int ret;
asm("mrc p15, 0, %0, c1, c1, 0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "SCR")
#endif
return ret;
}
unsigned int getSCTLR(){
unsigned int ret;
asm("mrc p15, 0, %0, c1, c0, 0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "SCTLR")
#endif
return ret;
}
unsigned int getCPSR(){
unsigned int ret;
asm("mrs %0, CPSR" : "=r" (ret));
#ifdef DEBUG
PRN_REG(ret, "CPSR")
#endif
return ret;
}
unsigned int getCPACR(){
unsigned int ret;
asm("mrc p15, 0, %0, c1, c0, 2" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "CPACR")
#endif
return ret;
}
unsigned int getACTLR(){
unsigned int ret;
asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "ACTLR")
#endif
return ret;
}
unsigned int getVBAR(){
unsigned int ret;
asm("MRC p15,0,%0,c12,c0,0" : "=r" (ret) );
#ifdef DEBUG
PRN_REG(ret, "VBAR")
#endif
return ret;
}
///////////////// Register Set Functions //////////////////
void setVBAR(unsigned int var){
asm("MCR p15,0,%0,c12,c0,0" : :"r" (var) );
}