summaryrefslogtreecommitdiff
path: root/libcpu
diff options
context:
space:
mode:
authorGrissiom <[email protected]>2013-10-20 23:00:44 +0800
committerGrissiom <[email protected]>2013-10-20 23:46:50 +0800
commit377c6e6cc9b415793d4787c86d0e9dea5e47e914 (patch)
treec71e0989dcf510d7471f38adf3e968529ed1acfc /libcpu
parente1e563e85c831e40c43cb7801434700e779dd750 (diff)
cortex-r4: dump register on traps
We could not handle any traps except IRQ/FIQ.
Diffstat (limited to 'libcpu')
-rw-r--r--libcpu/arm/cortex-r4/armv7.h7
-rw-r--r--libcpu/arm/cortex-r4/start_ccs.asm53
-rw-r--r--libcpu/arm/cortex-r4/start_gcc.S40
-rw-r--r--libcpu/arm/cortex-r4/trap.c36
-rw-r--r--libcpu/arm/cortex-r4/vector_ccs.asm20
-rw-r--r--libcpu/arm/cortex-r4/vector_gcc.S16
6 files changed, 121 insertions, 51 deletions
diff --git a/libcpu/arm/cortex-r4/armv7.h b/libcpu/arm/cortex-r4/armv7.h
index bca4e516e1..7dc3471c70 100644
--- a/libcpu/arm/cortex-r4/armv7.h
+++ b/libcpu/arm/cortex-r4/armv7.h
@@ -5,10 +5,9 @@
#define VFP_DATA_NR 32
#endif
-/* the stack without VFP registers */
-struct rt_hw_base_stack
+/* the exception stack without VFP registers */
+struct rt_hw_exp_stack
{
- unsigned long cpsr;
unsigned long r0;
unsigned long r1;
unsigned long r2;
@@ -22,8 +21,10 @@ struct rt_hw_base_stack
unsigned long r10;
unsigned long fp;
unsigned long ip;
+ unsigned long sp;
unsigned long lr;
unsigned long pc;
+ unsigned long cpsr;
};
#define USERMODE 0x10
diff --git a/libcpu/arm/cortex-r4/start_ccs.asm b/libcpu/arm/cortex-r4/start_ccs.asm
index 186d4f28ab..4334fa9b0f 100644
--- a/libcpu/arm/cortex-r4/start_ccs.asm
+++ b/libcpu/arm/cortex-r4/start_ccs.asm
@@ -492,14 +492,54 @@ turnon_VFP
subs pc, lr, #4
.endasmfunc
- .def _dabort
+_push_svc_reg .macro
+ sub sp, sp, #17 * 4 ;/* Sizeof(struct rt_hw_exp_stack) */
+ stmia sp, {r0 - r12} ;/* Calling r0-r12 */
+ mov r0, sp
+ mrs r6, spsr ;/* Save CPSR */
+ str lr, [r0, #15*4] ;/* Push PC */
+ str r6, [r0, #16*4] ;/* Push CPSR */
+ cps #0x13
+ str sp, [r0, #13*4] ;/* Save calling SP */
+ str lr, [r0, #14*4] ;/* Save calling PC */
+ .endm
+
+ .ref rt_hw_trap_svc
+ .def vector_svc
.asmfunc
+vector_svc:
+ _push_svc_reg
+ bl rt_hw_trap_svc
+ sub pc, pc, #-4
+ .endasmfunc
-_dabort
- stmfd r13!, {r0 - r12, lr}
- ldmfd r13!, {r0 - r12, lr}
- subs pc, lr, #8
+ .ref rt_hw_trap_pabt
+ .def vector_pabort
+ .asmfunc
+vector_pabort:
+ _push_svc_reg
+ bl rt_hw_trap_pabt
+ sub pc, pc, #-4
.endasmfunc
+
+ .ref rt_hw_trap_dabt
+ .def vector_dabort
+ .asmfunc
+vector_dabort:
+ _push_svc_reg
+ bl rt_hw_trap_dabt
+ sub pc, pc, #-4
+ .endasmfunc
+
+ .ref rt_hw_trap_resv
+ .def vector_resv
+ .asmfunc
+vector_resv:
+ _push_svc_reg
+ bl rt_hw_trap_resv
+ sub pc, pc, #-4
+ .endasmfunc
+
;-------------------------------------------------------------------------------
; C++ construct table pointers
@@ -509,7 +549,4 @@ _dabort
__TI_PINIT_Base .long SHT$$INIT_ARRAY$$Base
__TI_PINIT_Limit .long SHT$$INIT_ARRAY$$Limit
-
-
;-------------------------------------------------------------------------------
-
diff --git a/libcpu/arm/cortex-r4/start_gcc.S b/libcpu/arm/cortex-r4/start_gcc.S
index 00d459dd34..20a1ccfc0f 100644
--- a/libcpu/arm/cortex-r4/start_gcc.S
+++ b/libcpu/arm/cortex-r4/start_gcc.S
@@ -445,8 +445,38 @@ turnon_VFP:
LDMIA sp!, {r0}
subs pc, lr, #4
- .globl _dabort
-_dabort:
- stmfd r13!, {r0 - r12, lr}
- ldmfd r13!, {r0 - r12, lr}
- subs pc, lr, #8
+ .macro push_svc_reg
+ sub sp, sp, #17 * 4 @/* Sizeof(struct rt_hw_exp_stack) */
+ stmia sp, {r0 - r12} @/* Calling r0-r12 */
+ mov r0, sp
+ mrs r6, spsr @/* Save CPSR */
+ str lr, [r0, #15*4] @/* Push PC */
+ str r6, [r0, #16*4] @/* Push CPSR */
+ cps #Mode_SVC
+ str sp, [r0, #13*4] @/* Save calling SP */
+ str lr, [r0, #14*4] @/* Save calling PC */
+ .endm
+
+ .globl vector_svc
+vector_svc:
+ push_svc_reg
+ bl rt_hw_trap_svc
+ b .
+
+ .globl vector_pabort
+vector_pabort:
+ push_svc_reg
+ bl rt_hw_trap_pabt
+ b .
+
+ .globl vector_dabort
+vector_dabort:
+ push_svc_reg
+ bl rt_hw_trap_dabt
+ b .
+
+ .globl vector_resv
+vector_resv:
+ push_svc_reg
+ bl rt_hw_trap_resv
+ b .
diff --git a/libcpu/arm/cortex-r4/trap.c b/libcpu/arm/cortex-r4/trap.c
index 6b36b0bd87..b72237dac2 100644
--- a/libcpu/arm/cortex-r4/trap.c
+++ b/libcpu/arm/cortex-r4/trap.c
@@ -30,14 +30,14 @@
*
* @param regs the registers point
*/
-void rt_hw_show_register (struct rt_hw_base_stack *regs)
+void rt_hw_show_register (struct rt_hw_exp_stack *regs)
{
rt_kprintf("Execption:\n");
rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
- rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs+1, regs->lr, regs->pc);
+ rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
}
@@ -49,7 +49,7 @@ void rt_hw_show_register (struct rt_hw_base_stack *regs)
*
* @note never invoke this function in application
*/
-void rt_hw_trap_udef(struct rt_hw_base_stack *regs)
+void rt_hw_trap_udef(struct rt_hw_exp_stack *regs)
{
rt_kprintf("undefined instruction\n");
rt_hw_show_register(regs);
@@ -67,12 +67,13 @@ void rt_hw_trap_udef(struct rt_hw_base_stack *regs)
*
* @note never invoke this function in application
*/
-void rt_hw_trap_swi(struct rt_hw_base_stack *regs)
+void rt_hw_trap_svc(struct rt_hw_exp_stack *regs)
{
rt_kprintf("software interrupt\n");
rt_hw_show_register(regs);
- if (rt_thread_self() != RT_NULL)
- rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
rt_hw_cpu_shutdown();
}
@@ -84,12 +85,13 @@ void rt_hw_trap_swi(struct rt_hw_base_stack *regs)
*
* @note never invoke this function in application
*/
-void rt_hw_trap_pabt(struct rt_hw_base_stack *regs)
+void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs)
{
rt_kprintf("prefetch abort\n");
rt_hw_show_register(regs);
- if (rt_thread_self() != RT_NULL)
- rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
rt_hw_cpu_shutdown();
}
@@ -101,12 +103,13 @@ void rt_hw_trap_pabt(struct rt_hw_base_stack *regs)
*
* @note never invoke this function in application
*/
-void rt_hw_trap_dabt(struct rt_hw_base_stack *regs)
+void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs)
{
rt_kprintf("Data Abort ");
rt_hw_show_register(regs);
- if (rt_thread_self() != RT_NULL)
- rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
rt_hw_cpu_shutdown();
}
@@ -117,12 +120,13 @@ void rt_hw_trap_dabt(struct rt_hw_base_stack *regs)
*
* @note never invoke this function in application
*/
-void rt_hw_trap_resv(struct rt_hw_base_stack *regs)
+void rt_hw_trap_resv(struct rt_hw_exp_stack *regs)
{
- rt_kprintf("not used\n");
+ rt_kprintf("Reserved trap\n");
rt_hw_show_register(regs);
- if (rt_thread_self() != RT_NULL)
- rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
rt_hw_cpu_shutdown();
}
diff --git a/libcpu/arm/cortex-r4/vector_ccs.asm b/libcpu/arm/cortex-r4/vector_ccs.asm
index 0ac6647266..df2bcec925 100644
--- a/libcpu/arm/cortex-r4/vector_ccs.asm
+++ b/libcpu/arm/cortex-r4/vector_ccs.asm
@@ -11,25 +11,23 @@
; import reference for interrupt routines
.ref _reset
- .ref _dabort
.ref turnon_VFP
+ .ref vector_svc
+ .ref vector_pabort
+ .ref vector_dabort
+ .ref vector_resv
.ref IRQ_Handler
- .def resetEntry
-
;-------------------------------------------------------------------------------
; interrupt vectors
-
+ .def resetEntry
resetEntry
b _reset
b turnon_VFP
-svcEntry
- b svcEntry
-prefetchEntry
- b prefetchEntry
- b _dabort
-reservedEntry
- b reservedEntry
+ b vector_svc
+ b vector_pabort
+ b vector_dabort
+ b vector_resv
b IRQ_Handler
ldr pc,[pc,#-0x1b0]
diff --git a/libcpu/arm/cortex-r4/vector_gcc.S b/libcpu/arm/cortex-r4/vector_gcc.S
index b21d5d4910..da91421f43 100644
--- a/libcpu/arm/cortex-r4/vector_gcc.S
+++ b/libcpu/arm/cortex-r4/vector_gcc.S
@@ -11,8 +11,11 @@
@ import reference for interrupt routines
.globl _reset
- .globl _dabort
.globl turnon_VFP
+ .globl vector_svc
+ .globl vector_pabort
+ .globl vector_dabort
+ .globl vector_resv
.globl IRQ_Handler
@@ -20,12 +23,9 @@
system_vectors:
b _reset
b turnon_VFP
-svcEntry:
- b svcEntry
-prefetchEntry:
- b prefetchEntry
- b _dabort
-reservedEntry:
- b reservedEntry
+ b vector_svc
+ b vector_pabort
+ b vector_dabort
+ b vector_resv
b IRQ_Handler
ldr pc,[pc,#-0x1b0]