Boot framework rework (#45)
[lunaix-os.git] / lunaix-os / arch / x86 / includes / sys / failsafe.h
1 #ifndef __LUNAIX_ARCH_FAILSAFE_H
2 #define __LUNAIX_ARCH_FAILSAFE_H
3
4 #define STACK_SANITY            0xbeefc0de
5
6 #ifndef __ASM__
7
8 #include <lunaix/types.h>
9
10 static inline bool
11 check_bootstack_sanity()
12 {
13     extern unsigned int __kinit_stack_end[];
14
15     return ( __kinit_stack_end[0] 
16            | __kinit_stack_end[1]
17            | __kinit_stack_end[2]
18            | __kinit_stack_end[3]) == STACK_SANITY;
19 }
20
21 static inline void must_inline noret
22 failsafe_diagnostic() {
23     // asm ("jmp __fatal_state");
24     extern int failsafe_stack_top[];
25 #ifdef CONFIG_ARCH_X86_64
26      asm (
27         "movq %%rsp, %%rdi\n"
28         "movq %%rbp, %%rsi\n"
29
30         "movq %0, %%rsp\n"
31         
32         "call do_failsafe_unrecoverable\n"
33         ::"r"(failsafe_stack_top) 
34         :"memory"
35     );
36 #else
37      asm (
38         "movl %%esp, %%eax\n"
39         "movl %%ebp, %%ebx\n"
40
41         "movl %0, %%esp\n"
42
43         "pushl %%eax\n"
44         "pushl %%ebx\n"
45         
46         "call do_failsafe_unrecoverable\n"
47         ::"r"(failsafe_stack_top) 
48         :"memory"
49     );
50 #endif
51     unreachable;
52 }
53
54 #endif
55
56 #endif /* __LUNAIX_FAILSAFE_H */