rework parsing of interupt-map in interrupt node.
[lunaix-os.git] / lunaix-os / includes / lunaix / switch.h
1 #ifndef __LUNAIX_SWITCH_H
2 #define __LUNAIX_SWITCH_H
3
4 #define SWITCH_MODE_NORMAL   0
5 #define SWITCH_MODE_FAST     1
6 #define SWITCH_MODE_GIVEUP   2
7
8 #ifndef __ASM__
9
10 #include <lunaix/types.h>
11
12 struct signpost_result
13 {
14     int mode;
15     ptr_t stack;
16 };
17
18 /**
19  * @brief Decide how current thread should perform the context switch
20  *        back to it's previously saved context. 
21  * 
22  *        Return a user stack pointer perform a temporary fast redirected 
23  *        context switch. 
24  *        No redirection is required if such pointer is null.
25  * 
26  *        This function might never return if the decision is made to give up
27  *        this switching.
28  * 
29  *        NOTE: This function might have side effects, it can only be
30  *         called within the twilight zone of context restore. (after entering
31  *         do_switch and before returning from exception)
32  * 
33  * @return ptr_t
34  */
35 ptr_t
36 switch_signposting();
37
38 static inline void
39 redirect_switch(struct signpost_result* res, ptr_t stack)
40 {
41     res->mode  = SWITCH_MODE_FAST;
42     res->stack = stack;
43 }
44
45 static inline void
46 continue_switch(struct signpost_result* res)
47 {
48     res->mode  = SWITCH_MODE_NORMAL;
49     res->stack = 0;
50 }
51
52 static inline void
53 giveup_switch(struct signpost_result* res)
54 {
55     res->mode  = SWITCH_MODE_GIVEUP;
56     res->stack = 0;
57 }
58
59 #endif
60 #endif /* __LUNAIX_SWITCH_H */