]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/asm.h
a939d6585ebf870c0dd1c9edaf1c6e8a74d50222
[l4.git] / kernel / fiasco / src / kern / ia32 / asm.h
1 #ifndef ASM_SANITY_CHECK_H
2 #define ASM_SANITY_CHECK_H
3
4 #include "globalconfig.h"
5 #include "shortcut.h"
6 #include "tcboffset.h"
7
8 #define kdb_ke_asm(msg)         \
9         int3                    ;\
10         jmp     9f              ;\
11         .ascii  msg             ;\
12 9:
13
14 //.macro REGS this_ptr, dst
15 //      leal    (THREAD_BLOCK_SIZE - OFS__ENTRY_FRAME__MAX)(\this_ptr), \dst
16 //.endm
17
18 #ifdef CONFIG_BEFORE_IRET_SANITY
19
20         // some sanity checks before return to user
21         // touches ecx and the thread-stack
22         .macro CHECK_SANITY csseg
23
24         .ifnc   \csseg,$3
25         // don't check if we return to kernelmode
26         movl    \csseg, %ecx
27         andb    $3, %cl
28         jz      2f
29         .endif
30
31         pushl   %ebx
32         pushl   %edx
33         ESP_TO_TCB_AT %ebx
34
35         // are we holding locks?
36         cmpl    $0, OFS__THREAD__LOCK_CNT(%ebx)
37         jne     1f
38         .text   1
39 1:      kdb_ke_asm("Before IRET: Thread holds a lock")
40         jmp     1f
41         .previous
42 1:
43
44         // check for the right thread state 
45         // (cancel and fpu_owner might also be set)
46         movl    OFS__THREAD__STATE(%ebx), %edx
47         andl    $~(Thread_cancel | Thread_fpu_owner | Thread_alien | Thread_dis_alien), %edx
48         cmpl    $(Thread_ready), %edx
49         jne     1f
50         .text   1
51 1:      kdb_ke_asm("Before IRET: Wrong thread state")
52         jmp     1f
53         .previous
54 1:
55
56         // test if we are locked
57         cmpl    $0, OFS__THREAD__THREAD_LOCK__SWITCH_LOCK__LOCK_OWNER (%ebx)
58         jne     1f
59         .text   1
60 1:      kdb_ke_asm("Before IRET: Thread is locked")
61         jmp     1f
62         .previous
63 1:
64
65         popl    %edx
66         popl    %ebx
67 2:
68
69         .endm
70
71 #else   // ! DO_SANITY_CHECKS_BEFORE_IRET
72
73         .macro CHECK_SANITY csseg
74         .endm
75
76 #endif // DO_SANITY_CHECKS_BEFORE_IRET
77
78 #endif // ASM_SANITY_CHECK_H