Architectural Support: x86_64 (#37)
[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, %%rax\n"
28         "movq %%rbp, %%rbx\n"
29
30         "movq %0, %%rsp\n"
31
32         "pushq %%rax\n"
33         "pushq %%rbx\n"
34         
35         "call do_failsafe_unrecoverable\n"
36         ::"r"(failsafe_stack_top) 
37         :"memory"
38     );
39 #else
40      asm (
41         "movl %%esp, %%eax\n"
42         "movl %%ebp, %%ebx\n"
43
44         "movl %0, %%esp\n"
45
46         "pushl %%eax\n"
47         "pushl %%ebx\n"
48         
49         "call do_failsafe_unrecoverable\n"
50         ::"r"(failsafe_stack_top) 
51         :"memory"
52     );
53 #endif
54     unreachable;
55 }
56
57 #endif
58
59 #endif /* __LUNAIX_FAILSAFE_H */