physical page list mapping
[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 #include <lunaix/bits.h>
7 #include <asm/aa64_spsr.h>
8
9 #define SYNDROME_ETYPE  BITFIELD(63, 56)
10
11 struct hart_state;
12
13 struct regcontext
14 {
15     union {
16         reg_t x[31];
17         struct {
18             reg_t x_[29];
19             reg_t fp;
20             reg_t lr;
21         };
22     };
23 } compact align(8);
24
25 struct exec_param
26 {
27     struct hart_state* parent_state;
28     reg_t spsr;
29     reg_t link;
30     struct {
31         reg_t sp_el0;
32         reg_t rsvd;
33     };
34     
35     reg_t syndrome;
36 } compact align(8);
37
38 struct hart_state
39 {
40     reg_t depth;
41     struct regcontext registers;
42     struct exec_param execp;
43 } compact align(16);
44
45 static inline int
46 hart_vector_stamp(struct hart_state* hstate) 
47 {
48     return BITS_GET(hstate->execp.syndrome, SYNDROME_ETYPE);
49 }
50
51 static inline unsigned int
52 hart_ecause(struct hart_state* hstate) 
53 {
54     return hstate->execp.syndrome;
55 }
56
57 static inline struct hart_state*
58 hart_parent_state(struct hart_state* hstate)
59 {
60     return hstate->execp.parent_state;
61 }
62
63 static inline void
64 hart_push_state(struct hart_state* p_hstate, struct hart_state* hstate)
65 {
66     hstate->execp.parent_state = p_hstate;
67 }
68
69 static inline ptr_t
70 hart_pc(struct hart_state* hstate)
71 {
72     return hstate->execp.link;
73 }
74
75 static inline ptr_t
76 hart_sp(struct hart_state* hstate)
77 {
78     return __ptr(&hstate[-1]);
79 }
80
81 static inline bool
82 kernel_context(struct hart_state* hstate)
83 {
84     reg_t spsr;
85
86     spsr = hstate->execp.spsr;
87     return !spsr_from_el0(spsr);
88 }
89
90 static inline ptr_t
91 hart_stack_frame(struct hart_state* hstate)
92 {
93     return hstate->registers.fp;
94 }
95
96 #endif
97
98 #endif /* __LUNAIX_ARCH_HART_H */