1 #ifndef __X86_BUG_H__
2 #define __X86_BUG_H__
3 
4 /*
5  * Please do not include in the header any header that might
6  * use BUG/ASSERT/etc maros asthey will be defined later after
7  * the return to <xen/bug.h> from the current header:
8  *
9  * <xen/bug.h>:
10  *  ...
11  *   <asm/bug.h>:
12  *     ...
13  *     <any_header_which_uses_BUG/ASSERT/etc macros.h>
14  *     ...
15  *  ...
16  *  #define BUG() ...
17  *  ...
18  *  #define ASSERT() ...
19  *  ...
20  */
21 
22 #ifndef __ASSEMBLY__
23 
24 #define BUG_INSTR       "ud2"
25 #define BUG_ASM_CONST   "c"
26 
27 #else  /* !__ASSEMBLY__ */
28 
29 /*
30  * Construct a bugframe, suitable for using in assembly code.  Should always
31  * match the C version above.  One complication is having to stash the strings
32  * in .rodata
33  */
34     .macro BUG_FRAME type, line, file_str, second_frame, msg
35 
36     .if \type >= BUGFRAME_NR
37         .error "Invalid BUGFRAME index"
38     .endif
39 
40     .L\@ud: ud2a
41 
42     .pushsection .rodata.str1, "aMS", @progbits, 1
43          .L\@s1: .asciz "\file_str"
44     .popsection
45 
46     .pushsection .bug_frames.\type, "a", @progbits
47         .p2align 2
48         .L\@bf:
49         .long (.L\@ud - .L\@bf) + \
50                ((\line >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH)
51         .long (.L\@s1 - .L\@bf) + \
52                ((\line & ((1 << BUG_LINE_LO_WIDTH) - 1)) << BUG_DISP_WIDTH)
53 
54         .if \second_frame
55             .pushsection .rodata.str1, "aMS", @progbits, 1
56                 .L\@s2: .asciz "\msg"
57             .popsection
58             .long 0, (.L\@s2 - .L\@bf)
59         .endif
60     .popsection
61     .endm
62 
63 #define WARN BUG_FRAME BUGFRAME_warn, __LINE__, __FILE__, 0, 0
64 #define BUG  BUG_FRAME BUGFRAME_bug,  __LINE__, __FILE__, 0, 0
65 
66 #define ASSERT_FAILED(msg)                                      \
67      BUG_FRAME BUGFRAME_assert, __LINE__, __FILE__, 1, msg
68 
69 #endif /* !__ASSEMBLY__ */
70 
71 #endif /* __X86_BUG_H__ */
72