]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/32/low_level.h
Inital import
[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         movw    $ (GDT_DATA_USER|SEL_PL_U), %cx
39         movl    %ecx,%ds
40         movl    %ecx,%es
41         .endm
42
43         .macro  DO_SYSEXIT
44         addl    $8, %esp        /* skip ecx & edx */
45         popl    %esi
46         popl    %edi
47         popl    %ebx
48         //CHECK_SANITY $3               /* scratches ecx */
49         RESTORE_IOPL
50         movl    4(%esp), %eax
51         movl    8(%esp), %edx   /* user eip */
52         movl    20(%esp), %ecx  /* user esp */
53         //subl  $2, %edx        /* adj. eip */
54         sti                     /* the interrupts are enabled _after_ the
55                                  * next instruction (see Intel Ref-Manual) */
56         sysexit
57         .endm
58
59         .macro  RESET_THREAD_CANCEL_AT reg
60         andl    $~(Thread_cancel), OFS__THREAD__STATE (\reg)
61         .endm
62
63         .macro  RESET_THREAD_IPC_MASK_AT reg
64         andl    $~Thread_ipc_mask, OFS__THREAD__STATE (\reg)
65         .endm
66
67         .macro  ESP_TO_TCB_AT reg
68         movl    %esp, \reg
69         andl    $~(THREAD_BLOCK_SIZE - 1), \reg
70         .endm
71
72         .macro  SAVE_STATE
73         pushl   %ebp
74         pushl   %ebx
75         pushl   %edi
76         pushl   %esi
77         pushl   %edx
78         pushl   %ecx
79         .endm
80
81         .macro  RESTORE_STATE
82         popl    %ecx
83         popl    %edx
84         popl    %esi
85         popl    %edi
86         popl    %ebx
87         popl    %ebp
88         .endm
89
90         .macro  RESTORE_STATE_AFTER_IPC
91         addl    $4, %esp
92         popl    %edx
93         popl    %esi
94         popl    %edi
95         popl    %ebx
96         addl    $4, %esp
97         .endm
98
99 #define SCRATCH_REGISTER_SIZE 12
100         .macro  SAVE_SCRATCH
101         push    %eax
102         push    %ecx
103         push    %edx
104         .endm
105
106         .macro  RESTORE_SCRATCH
107         pop     %edx
108         pop     %ecx
109         pop     %eax
110         .endm
111
112         .macro  IRET_INSN
113         iret
114         .endm
115
116 #define PAGE_FAULT_ADDR %cr2
117 #define PAGE_DIR_ADDR   %cr3
118
119 #endif //LOW_LEVEL_H