Merge branch 'master' into isa/arm64
[lunaix-os.git] / lunaix-os / includes / lunaix / hart_state.h
1 #ifndef __LUNAIX_CONTEXT_H
2 #define __LUNAIX_CONTEXT_H
3
4 struct exec_param;
5 struct regcontext;
6 struct hart_state;
7
8 #include <lunaix/compiler.h>
9 #include <asm/hart.h>
10
11 struct hart_transition 
12 {
13     ptr_t inject;
14     struct {
15         struct hart_state state;
16         struct exec_param eret;
17     } transfer;
18 };
19
20 bool
21 install_hart_transition(ptr_t vm_mnt, struct hart_transition* tctx);
22
23 void
24 hart_prepare_transition(struct hart_transition* tctx, 
25                       ptr_t kstack_tp, ptr_t ustack_pt, 
26                       ptr_t entry, bool to_user);
27
28 static inline void
29 hart_user_transfer(struct hart_transition* tctx, 
30                             ptr_t kstack_tp, ptr_t ustack_pt, 
31                             ptr_t entry) 
32 {
33     hart_prepare_transition(tctx, kstack_tp, ustack_pt, entry, true);
34 }
35
36 static inline void
37 hart_kernel_transfer(struct hart_transition* tctx, 
38                             ptr_t kstack_tp,  ptr_t entry) 
39 {
40     hart_prepare_transition(tctx, kstack_tp, 0, entry, false);
41 }
42
43 #endif /* __LUNAIX_CONTEXT_H */