add asm headers and linker scripts for aarch64
[lunaix-os.git] / lunaix-os / arch / aarch64 / includes / asm / hart.h
1 #ifndef __LUNAIX_ARCH_HART_H
2 #define __LUNAIX_ARCH_HART_H
3
4 #ifndef __ASM__
5 #include <lunaix/types.h>
6
7 struct hart_state;
8
9 struct regcontext
10 {
11     union {
12         reg_t x[32];
13         struct {
14             reg_t x[29];
15             reg_t fp;
16             reg_t lr;
17             reg_t sp;
18         };
19     };
20 } compact;
21
22 struct exec_param
23 {
24     struct hart_state* parent_state;
25     reg_t vector;
26     reg_t syndrome;
27     reg_t elink;
28     reg_t sp;
29 } compact;
30
31 struct hart_state
32 {
33     reg_t depth;
34     struct regcontext registers;
35     union
36     {
37         reg_t sp;
38         volatile struct exec_param* execp;
39     };
40 } compact;
41
42 static inline int
43 hart_vector_stamp(struct hart_state* hstate) {
44     return hstate->execp->vector;
45 }
46
47 static inline unsigned int
48 hart_ecause(struct hart_state* hstate) {
49     return hstate->execp->syndrome;
50 }
51
52 static inline struct hart_state*
53 hart_parent_state(struct hart_state* hstate)
54 {
55     return hstate->execp->parent_state;
56 }
57
58 static inline void
59 hart_push_state(struct hart_state* p_hstate, struct hart_state* hstate)
60 {
61     hstate->execp->parent_state = p_hstate;
62 }
63
64 static inline ptr_t
65 hart_pc(struct hart_state* hstate)
66 {
67     return hstate->execp->elink;
68 }
69
70 static inline ptr_t
71 hart_sp(struct hart_state* hstate)
72 {
73     return hstate->execp->sp;
74 }
75
76 static inline bool
77 kernel_context(struct hart_state* hstate)
78 {
79     // TODO
80     return false;
81 }
82
83 static inline ptr_t
84 hart_stack_frame(struct hart_state* hstate)
85 {
86     return hstate->registers.fp;
87 }
88
89 #endif
90
91 #endif /* __LUNAIX_ARCH_HART_H */