]> rtime.felk.cvut.cz Git - arc.git/blob - arch/arm/arm_cm3/kernel/arch_krn.sx
Again, loads of refactoring and removing and adding files.
[arc.git] / arch / arm / arm_cm3 / kernel / arch_krn.sx
1 \r
2 \r
3 #define _ASSEMBLER_\r
4 #include "kernel_offset.h"\r
5 #include "arch_offset.h"\r
6 #include "stack.h"\r
7 \r
8 .extern os_sys\r
9 \r
10         .syntax unified\r
11         .cpu cortex-m3\r
12         .fpu softvfp\r
13         .thumb\r
14 \r
15         .section .text\r
16 \r
17         .global Irq_Handler\r
18     .type       Irq_Handler, %function\r
19 \r
20 #define IRQ_ENABLE()            cpsie   i\r
21 #define IRQ_DISABLE()           cpsid   i\r
22 \r
23 Irq_Handler:\r
24     push    {r4-r8,r10,r11,lr}\r
25     sub.w   sp,sp,#C_SIZE\r
26     mov.w   r4,#LC_PATTERN\r
27     str     r4,[sp,#C_CONTEXT_OFFS]    \r
28     mov         r0,sp                   // stack as first arg\r
29     bl      Irq_Entry\r
30     mov     sp, r0                      // pop from returned stack\r
31     b           os_lc_restore\r
32         \r
33         \r
34 /* r0 - pcb for old task\r
35  * r1 pcb for new task\r
36  *\r
37  * -------------- higher addr\r
38  * r4-r8,etc\r
39  * -------\r
40  * 4 - Large or Small context indicator\r
41  * 0 - ?\r
42  * ----------    <- JABBA\r
43  *\r
44  */\r
45         .global Os_ArchSwapContext\r
46         .type   Os_ArchSwapContext, %function\r
47 Os_ArchSwapContext:\r
48 //    mov     r2, sp\r
49     push    {r4-r8,r10,r11,lr}\r
50 \r
51     // Store c-frame\r
52     sub.w   sp,sp,#C_SIZE\r
53 \r
54     mov.w   r4,#SC_PATTERN\r
55     str     r4,[sp,#C_CONTEXT_OFFS]\r
56 //    str     r2,[sp,#C_SP_OFF]\r
57         // ---> We have saved NVGPR+C\r
58 \r
59     // store old stack for old task\r
60     mov.w       r4,sp\r
61     str     r4,[r0,#PCB_STACK_CURR_P]\r
62 \r
63 // R1 - new PCB\r
64         .global Os_ArchSwapContextTo\r
65         .type   Os_ArchSwapContextTo, %function\r
66 Os_ArchSwapContextTo:\r
67 \r
68     // Get stack for new task\r
69     ldr         r2,[r1,#PCB_STACK_CURR_P]\r
70 //    msr               msp,r2\r
71     mov.w       sp,r2\r
72     \r
73 \r
74 // TODO: Fix this for all arch's..call pre,post hooks. Done here or after?\r
75 // Set new current pcb\r
76     ldr     r5,= os_sys\r
77     str     r1,[r5,#SYS_CURR_PCB_P]\r
78 \r
79 // Restore C context\r
80     ldr     r6,[sp,#C_CONTEXT_OFFS]\r
81     cmp     r6,#SC_PATTERN\r
82     beq     os_sc_restore\r
83     cmp     r6,#LC_PATTERN\r
84     beq     os_lc_restore\r
85 os_stack_problem:\r
86 // TODO: Jump to error handler\r
87     b os_stack_problem\r
88 \r
89 os_sc_restore:\r
90     add.w   sp,sp,#C_SIZE\r
91 \r
92     pop     {r4-r8,r10,r11,lr}\r
93         // ehh, we are in handler mode so a bx instruction works here\r
94     IRQ_ENABLE()\r
95     bx      lr\r
96 \r
97 os_lc_restore:\r
98     add.w   sp,sp,#C_SIZE\r
99     pop     {r4-r8,r10,r11,lr}\r
100     // ehh, we are in handler mode so a bx instruction works here\r
101     IRQ_ENABLE()\r
102     bx      lr\r
103 \r
104 \r
105 \r