fd8584991b6ce274f50e8c2832ef1098c06b5bf6
[lunaix-os.git] / lunaix-os / arch / aarch64 / exception / context.S
1 #define __ASM__
2 #include <asm/aa64_msrs.h>
3 #include "hart_field.inc"
4
5 .section .text
6     
7     .globl _aa64_evec_prehandle
8     .globl _aa64_switch_task
9
10     _aa64_evec_prehandle:
11         # reservation for struct exec_param
12         sub   sp,  sp,  #8         # push  sp_el1
13         sub   sp,  sp,  #16        # push {sp_el0, link}
14         sub   sp,  sp,  #16        # push {spsr,   parent_hart}
15
16         stp   lr,  fp, [sp, #-16]!  # push {x31-x1}
17         stp  x28, x27, [sp, #-16]!
18         stp  x26, x25, [sp, #-16]!
19         stp  x24, x23, [sp, #-16]!
20         stp  x22, x21, [sp, #-16]!
21         stp  x20, x19, [sp, #-16]!
22         stp  x18, x17, [sp, #-16]!
23         stp  x16, x15, [sp, #-16]!
24         stp  x14, x13, [sp, #-16]!
25         stp  x12, x11, [sp, #-16]!
26         stp  x10,  x9, [sp, #-16]!
27         stp   x8,  x7, [sp, #-16]!
28         stp   x6,  x5, [sp, #-16]!
29         stp   x4,  x3, [sp, #-16]!
30         stp   x2,  x1, [sp, #-16]!
31         stp   x0, xzr, [sp, #-16]!  # push {x0, xzr}
32
33         add   x1, sp,  #hart_execp
34
35         mrs   x0, SP_EL0
36         str   x0, [x1, #execp_spel0_saved]
37
38         mrs   x0, ELR_E1
39         str   x0, [x1, #execp_link]
40
41         mrs   x0, SPSR_EL1
42         str   x0, [x1, #execp_spsr]
43         
44         sub   x0, sp,  #hart_end
45         str   x0, [x1, #execp_spel1_saved]
46         
47         mov   x0, sp
48         bl    handle_exception
49         
50     do_eret:
51         mov   sp,   x0
52
53         add   x1,   x0, #hart_execp
54
55         ldr   x0,  [x1, #execp_spsr]
56         msr   SPSR_EL1, x0
57
58         ldr   x0,  [x1, #execp_link]
59         msr   ELR_E1,   x0
60
61         ldr   x0,  [x1, #execp_spel0_saved]
62         msr   SP_EL0,   x0
63
64         add   sp,  sp, #hart_regs
65
66         ldr   x0,      [sp, #8 ]!
67         ldp   x1,  x2, [sp, #16]!
68         ldp   x3,  x4, [sp, #16]!
69         ldp   x5,  x6, [sp, #16]!
70         ldp   x7,  x8, [sp, #16]!
71         ldp   x9, x10, [sp, #16]!
72         ldp  x11, x12, [sp, #16]!
73         ldp  x13, x14, [sp, #16]!
74         ldp  x15, x16, [sp, #16]!
75         ldp  x17, x18, [sp, #16]!
76         ldp  x19, x20, [sp, #16]!
77         ldp  x21, x22, [sp, #16]!
78         ldp  x23, x24, [sp, #16]!
79         ldp  x25, x26, [sp, #16]!
80         ldp  x27, x28, [sp, #16]!
81         ldp   fp,  lr, [sp, #16]!
82         
83         # sp now point to the start of exec_param
84
85         ldr   sp,  [sp, #execp_spel1_saved]
86
87         eret
88
89     _aa64_switch_task:
90         # TODO
91         b     do_eret