extract exceptions.h
This commit is contained in:
@@ -1,145 +1,23 @@
|
|||||||
/* Fuchsia's code is nice here, so I learn from it(fine, almost copy). thanks */
|
/* Fuchsia's code is nice here, so I learn from it(fine, almost copy). thanks */
|
||||||
|
|
||||||
.syntax unified
|
#include "exceptions.h"
|
||||||
.text
|
|
||||||
|
|
||||||
/* macros to align and unalign the stack on 8 byte boundary for ABI compliance */
|
.global arm_undefined
|
||||||
.macro stack_align, tempreg
|
.global arm_syscall
|
||||||
/* make sure the stack is aligned */
|
.global arm_prefetch_abort
|
||||||
mov \tempreg, sp
|
.global arm_data_abort
|
||||||
tst sp, #4
|
.global arm_reserved
|
||||||
subeq sp, #4
|
.global arm_irq
|
||||||
push { \tempreg }
|
.global arm_fiq
|
||||||
|
|
||||||
/* tempreg holds the original stack */
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro stack_restore, tempreg
|
|
||||||
/* restore the potentially unaligned stack */
|
|
||||||
pop { \tempreg }
|
|
||||||
mov sp, \tempreg
|
|
||||||
.endm
|
|
||||||
|
|
||||||
/* save and disable the vfp unit */
|
|
||||||
.macro vfp_save, temp1
|
|
||||||
/* save old fpexc */
|
|
||||||
vmrs \temp1, fpexc
|
|
||||||
|
|
||||||
push { \temp1 }
|
|
||||||
|
|
||||||
/* hard disable the vfp unit */
|
|
||||||
bic \temp1, #(1<<30)
|
|
||||||
vmsr fpexc, \temp1
|
|
||||||
.endm
|
|
||||||
|
|
||||||
/* restore the vfp enable/disable state */
|
|
||||||
.macro vfp_restore, temp1
|
|
||||||
/* restore fpexc */
|
|
||||||
pop { \temp1 }
|
|
||||||
|
|
||||||
vmsr fpexc, \temp1
|
|
||||||
.endm
|
|
||||||
|
|
||||||
/* Save callee trashed registers.
|
|
||||||
* At exit r0 contains a pointer to the register frame.
|
|
||||||
*/
|
|
||||||
.macro save
|
|
||||||
/* save spsr and r14 onto the svc stack */
|
|
||||||
srsdb #0x13!
|
|
||||||
|
|
||||||
/* switch to svc mode, interrupts disabled */
|
|
||||||
cpsid i, #0x13
|
|
||||||
|
|
||||||
/* save callee trashed regs and lr */
|
|
||||||
push { r0-r3, r12, lr }
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
|
||||||
/* save and disable the vfp unit */
|
|
||||||
vfp_save r0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* make sure the stack is 8 byte aligned */
|
|
||||||
stack_align r0
|
|
||||||
|
|
||||||
/* r0 now holds the pointer to the original iframe (before alignment) */
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro save_offset, offset
|
|
||||||
sub lr, \offset
|
|
||||||
save
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro restore
|
|
||||||
/* undo the stack alignment we did before */
|
|
||||||
stack_restore r0
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
|
||||||
/* restore the old state of the vfp unit */
|
|
||||||
vfp_restore r0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pop { r0-r3, r12, lr }
|
|
||||||
|
|
||||||
/* return to whence we came from */
|
|
||||||
rfeia sp!
|
|
||||||
.endm
|
|
||||||
|
|
||||||
/* Save all registers.
|
|
||||||
* At exit r0 contains a pointer to the register frame.
|
|
||||||
*/
|
|
||||||
.macro saveall
|
|
||||||
/* save spsr and r14 onto the svc stack */
|
|
||||||
srsdb #0x13!
|
|
||||||
|
|
||||||
/* switch to svc mode, interrupts disabled */
|
|
||||||
cpsid i,#0x13
|
|
||||||
|
|
||||||
/* save all regs */
|
|
||||||
push { r0-r12, lr }
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
|
||||||
/* save and disable the vfp unit */
|
|
||||||
vfp_save r0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* make sure the stack is 8 byte aligned */
|
|
||||||
stack_align r0
|
|
||||||
|
|
||||||
/* r0 now holds the pointer to the original iframe (before alignment) */
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro saveall_offset, offset
|
|
||||||
sub lr, \offset
|
|
||||||
saveall
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro restoreall
|
|
||||||
/* undo the stack alignment we did before */
|
|
||||||
stack_restore r0
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
|
||||||
/* restore the old state of the vfp unit */
|
|
||||||
vfp_restore r0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pop { r0-r12, r14 }
|
|
||||||
|
|
||||||
/* return to whence we came from */
|
|
||||||
rfeia sp!
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.extern tos_knl_irq_enter
|
.extern tos_knl_irq_enter
|
||||||
.extern tos_knl_irq_leave
|
.extern tos_knl_irq_leave
|
||||||
|
.extern interrupt_irq
|
||||||
|
|
||||||
.global arm_undefined
|
.syntax unified
|
||||||
|
.text
|
||||||
|
|
||||||
|
.type arm_undefined, %function
|
||||||
arm_undefined:
|
arm_undefined:
|
||||||
save
|
save
|
||||||
/* r0 now holds pointer to iframe */
|
/* r0 now holds pointer to iframe */
|
||||||
@@ -149,12 +27,12 @@ arm_undefined:
|
|||||||
restore
|
restore
|
||||||
|
|
||||||
|
|
||||||
.global arm_syscall
|
.type arm_syscall, %function
|
||||||
arm_syscall:
|
arm_syscall:
|
||||||
b .
|
b .
|
||||||
|
|
||||||
|
|
||||||
.global arm_prefetch_abort
|
.type arm_prefetch_abort, %function
|
||||||
arm_prefetch_abort:
|
arm_prefetch_abort:
|
||||||
saveall_offset #4
|
saveall_offset #4
|
||||||
/* r0 now holds pointer to iframe */
|
/* r0 now holds pointer to iframe */
|
||||||
@@ -164,7 +42,7 @@ arm_prefetch_abort:
|
|||||||
restoreall
|
restoreall
|
||||||
|
|
||||||
|
|
||||||
.global arm_data_abort
|
.type arm_data_abort, %function
|
||||||
arm_data_abort:
|
arm_data_abort:
|
||||||
saveall_offset #8
|
saveall_offset #8
|
||||||
/* r0 now holds pointer to iframe */
|
/* r0 now holds pointer to iframe */
|
||||||
@@ -174,12 +52,12 @@ arm_data_abort:
|
|||||||
restoreall
|
restoreall
|
||||||
|
|
||||||
|
|
||||||
.global arm_reserved
|
.type arm_reserved, %function
|
||||||
arm_reserved:
|
arm_reserved:
|
||||||
b .
|
b .
|
||||||
|
|
||||||
|
|
||||||
.global arm_irq
|
.type arm_irq, %function
|
||||||
arm_irq:
|
arm_irq:
|
||||||
saveall_offset #4
|
saveall_offset #4
|
||||||
|
|
||||||
@@ -194,7 +72,7 @@ arm_irq:
|
|||||||
restoreall
|
restoreall
|
||||||
|
|
||||||
|
|
||||||
.global arm_fiq
|
.type arm_fiq, %function
|
||||||
arm_fiq:
|
arm_fiq:
|
||||||
b .
|
b .
|
||||||
|
|
||||||
|
133
arch/arm/arm-v7a/cortex-a7/gcc/exceptions.h
Normal file
133
arch/arm/arm-v7a/cortex-a7/gcc/exceptions.h
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/* macros to align and unalign the stack on 8 byte boundary for ABI compliance */
|
||||||
|
.macro stack_align, tempreg
|
||||||
|
/* make sure the stack is aligned */
|
||||||
|
mov \tempreg, sp
|
||||||
|
tst sp, #4
|
||||||
|
subeq sp, #4
|
||||||
|
push { \tempreg }
|
||||||
|
|
||||||
|
/* tempreg holds the original stack */
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro stack_restore, tempreg
|
||||||
|
/* restore the potentially unaligned stack */
|
||||||
|
pop { \tempreg }
|
||||||
|
mov sp, \tempreg
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/* save and disable the vfp unit */
|
||||||
|
.macro vfp_save, temp1
|
||||||
|
/* save old fpexc */
|
||||||
|
vmrs \temp1, fpexc
|
||||||
|
|
||||||
|
push { \temp1 }
|
||||||
|
|
||||||
|
/* hard disable the vfp unit */
|
||||||
|
bic \temp1, #(1<<30)
|
||||||
|
vmsr fpexc, \temp1
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/* restore the vfp enable/disable state */
|
||||||
|
.macro vfp_restore, temp1
|
||||||
|
/* restore fpexc */
|
||||||
|
pop { \temp1 }
|
||||||
|
|
||||||
|
vmsr fpexc, \temp1
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/* Save callee trashed registers.
|
||||||
|
* At exit r0 contains a pointer to the register frame.
|
||||||
|
*/
|
||||||
|
.macro save
|
||||||
|
/* save spsr and r14 onto the svc stack */
|
||||||
|
srsdb #0x13!
|
||||||
|
|
||||||
|
/* switch to svc mode, interrupts disabled */
|
||||||
|
cpsid i, #0x13
|
||||||
|
|
||||||
|
/* save callee trashed regs and lr */
|
||||||
|
push { r0-r3, r12, lr }
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
||||||
|
/* save and disable the vfp unit */
|
||||||
|
vfp_save r0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* make sure the stack is 8 byte aligned */
|
||||||
|
stack_align r0
|
||||||
|
|
||||||
|
/* r0 now holds the pointer to the original iframe (before alignment) */
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro save_offset, offset
|
||||||
|
sub lr, \offset
|
||||||
|
save
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro restore
|
||||||
|
/* undo the stack alignment we did before */
|
||||||
|
stack_restore r0
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
||||||
|
/* restore the old state of the vfp unit */
|
||||||
|
vfp_restore r0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pop { r0-r3, r12, lr }
|
||||||
|
|
||||||
|
/* return to whence we came from */
|
||||||
|
rfeia sp!
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/* Save all registers.
|
||||||
|
* At exit r0 contains a pointer to the register frame.
|
||||||
|
*/
|
||||||
|
.macro saveall
|
||||||
|
/* save spsr and r14 onto the svc stack */
|
||||||
|
srsdb #0x13!
|
||||||
|
|
||||||
|
/* switch to svc mode, interrupts disabled */
|
||||||
|
cpsid i,#0x13
|
||||||
|
|
||||||
|
/* save all regs */
|
||||||
|
push { r0-r12, lr }
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
||||||
|
/* save and disable the vfp unit */
|
||||||
|
vfp_save r0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* make sure the stack is 8 byte aligned */
|
||||||
|
stack_align r0
|
||||||
|
|
||||||
|
/* r0 now holds the pointer to the original iframe (before alignment) */
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro saveall_offset, offset
|
||||||
|
sub lr, \offset
|
||||||
|
saveall
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.macro restoreall
|
||||||
|
/* undo the stack alignment we did before */
|
||||||
|
stack_restore r0
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
||||||
|
/* restore the old state of the vfp unit */
|
||||||
|
vfp_restore r0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pop { r0-r12, r14 }
|
||||||
|
|
||||||
|
/* return to whence we came from */
|
||||||
|
rfeia sp!
|
||||||
|
.endm
|
||||||
|
|
@@ -73,8 +73,10 @@ port_context_switch:
|
|||||||
port_irq_context_switch:
|
port_irq_context_switch:
|
||||||
/* we already store the k_curr_task's context onto its stack by arm_irq(see saveall_offset) */
|
/* we already store the k_curr_task's context onto its stack by arm_irq(see saveall_offset) */
|
||||||
|
|
||||||
/* ATTENTION: our kernel always runs in SVC mode even in user task,
|
/* ATTENTION:
|
||||||
|
our kernel always runs in SVC mode even in user task,
|
||||||
if one day we make the user task run in USR mode(although I cannot see any meaning to do this in RTOS),
|
if one day we make the user task run in USR mode(although I cannot see any meaning to do this in RTOS),
|
||||||
we must deal with more logic */
|
we must deal with more logic
|
||||||
|
*/
|
||||||
B .L__context_restore /* magnificent */
|
B .L__context_restore /* magnificent */
|
||||||
|
|
||||||
|
@@ -34,8 +34,6 @@ k_stack_t task2_stack[512];
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
unsigned char state = OFF;
|
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
led_init();
|
led_init();
|
||||||
beep_init();
|
beep_init();
|
||||||
@@ -54,10 +52,6 @@ int main(void)
|
|||||||
|
|
||||||
tos_knl_start();
|
tos_knl_start();
|
||||||
|
|
||||||
while (1) {
|
|
||||||
delay(3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user