add ability to do intr-binding based on given device tree node
[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     return BITS_GET(hstate->execp.syndrome, SYNDROME_ETYPE);
48 }
49
50 static inline unsigned int
51 hart_ecause(struct hart_state* hstate) {
52     return hstate->execp.syndrome;
53 }
54
55 static inline struct hart_state*
56 hart_parent_state(struct hart_state* hstate)
57 {
58     return hstate->execp.parent_state;
59 }
60
61 static inline void
62 hart_push_state(struct hart_state* p_hstate, struct hart_state* hstate)
63 {
64     hstate->execp.parent_state = p_hstate;
65 }
66
67 static inline ptr_t
68 hart_pc(struct hart_state* hstate)
69 {
70     return hstate->execp.link;
71 }
72
73 static inline ptr_t
74 hart_sp(struct hart_state* hstate)
75 {
76     return __ptr(&hstate[-1]);
77 }
78
79 static inline bool
80 kernel_context(struct hart_state* hstate)
81 {
82     // TODO
83     return false;
84 }
85
86 static inline ptr_t
87 hart_stack_frame(struct hart_state* hstate)
88 {
89     return hstate->registers.fp;
90 }
91
92 #endif
93
94 #endif /* __LUNAIX_ARCH_HART_H */