]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/asm.h
update
[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_or_vcpu_user | 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         popl    %edx
57         popl    %ebx
58 2:
59
60         .endm
61
62 #else   // ! DO_SANITY_CHECKS_BEFORE_IRET
63
64         .macro CHECK_SANITY csseg
65         .endm
66
67 #endif // DO_SANITY_CHECKS_BEFORE_IRET
68
69 #endif // ASM_SANITY_CHECK_H