]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/low_level.h
Update
[l4.git] / kernel / fiasco / src / kern / ia32 / 32 / low_level.h
1 #ifndef LOW_LEVEL_H
2 #define LOW_LEVEL_H
3
4 #include "asm.h"
5 #include "regdefs.h"
6 #include "shortcut.h"
7 #include "tcboffset.h"
8
9 #define REGISTER_SIZE 4
10
11         .macro save_all_regs
12         pusha
13         .endm
14
15         .macro restore_all_regs
16         popa
17         .endm
18
19 /* be sure that we do not enable the interrupts here! */
20         .macro  RESTORE_IOPL
21         pushl   16(%esp)
22         andl    $~EFLAGS_IF,(%esp)
23         popf
24         .endm
25
26 /** Some shared macros and stuff shared by the two different 
27  *  assembler kernel entry sources.
28  */
29
30 /** Setting up ds/es resp. fs/gs when entering/
31  * leaving the kernel is not neccessary anymore
32  * since the user can only load the null selector
33  * without exception. But then, the first access
34  * to code/data with the wrong selector loaded
35  * raises an exception 13 which is handled properly.
36  */
37         .macro  RESET_KERNEL_SEGMENTS_FORCE_DS_ES
38         mov     %ds, %cx
39         cmp     $ (GDT_DATA_USER|SEL_PL_U), %cx
40         jne     9f
41
42         mov     %es, %cx
43         cmpw    $ (GDT_DATA_USER|SEL_PL_U), %cx
44         je      8f
45
46 9:      movw    $ (GDT_DATA_USER|SEL_PL_U), %cx
47         movl    %ecx,%ds
48         movl    %ecx,%es
49 8:
50         .endm
51
52         .macro  DO_SYSEXIT
53         addl    $8, %esp        /* skip ecx & edx */
54         popl    %esi
55         popl    %edi
56         popl    %ebx
57         //CHECK_SANITY $3               /* scratches ecx */
58         RESTORE_IOPL
59         movl    4(%esp), %eax
60         movl    8(%esp), %edx   /* user eip */
61         movl    20(%esp), %ecx  /* user esp */
62         //subl  $2, %edx        /* adj. eip */
63         sti                     /* the interrupts are enabled _after_ the
64                                  * next instruction (see Intel Ref-Manual) */
65         sysexit
66         .endm
67
68         .macro  RESET_THREAD_CANCEL_AT reg
69         andl    $~(VAL__Thread_cancel), OFS__THREAD__STATE (\reg)
70         .endm
71
72         .macro  RESET_THREAD_IPC_MASK_AT reg
73         andl    $~VAL__Thread_ipc_mask, OFS__THREAD__STATE (\reg)
74         .endm
75
76         .macro  ESP_TO_TCB_AT reg
77         movl    %esp, \reg
78         andl    $~(THREAD_BLOCK_SIZE - 1), \reg
79         .endm
80
81         .macro  SAVE_STATE
82         pushl   %ebp
83         pushl   %ebx
84         pushl   %edi
85         pushl   %esi
86         pushl   %edx
87         pushl   %ecx
88         .endm
89
90         .macro  RESTORE_STATE
91         popl    %ecx
92         popl    %edx
93         popl    %esi
94         popl    %edi
95         popl    %ebx
96         popl    %ebp
97         .endm
98
99         .macro  RESTORE_STATE_AFTER_IPC
100         addl    $4, %esp
101         popl    %edx
102         popl    %esi
103         popl    %edi
104         popl    %ebx
105         addl    $4, %esp
106         .endm
107
108 #define SCRATCH_REGISTER_SIZE 12
109         .macro  SAVE_SCRATCH
110         push    %eax
111         push    %ecx
112         push    %edx
113         .endm
114
115         .macro  RESTORE_SCRATCH
116         pop     %edx
117         pop     %ecx
118         pop     %eax
119         .endm
120
121         .macro  IRET_INSN
122         iret
123         .endm
124
125 #define PAGE_FAULT_ADDR %cr2
126 #define PAGE_DIR_ADDR   %cr3
127
128 #endif //LOW_LEVEL_H