coverity appeasement
[minix.git] / kernel / arch / i386 / sconst.h
blob1262f6cd62ffdc05fca368126c469e6358498081
1 #ifndef __SCONST_H__
2 #define __SCONST_H__
4 #include "kernel/const.h"
5 #include "kernel/procoffsets.h"
7 /*
8 * offset to current process pointer right after trap, we assume we always have
9 * error code on the stack
11 #define CURR_PROC_PTR 20
14 * tests whether the interrupt was triggered in kernel. If so, jump to the
15 * label. Displacement tell the macro ha far is the CS value saved by the trap
16 * from the current %esp. The kernel code segment selector has the lower 3 bits
17 * zeroed
19 #define TEST_INT_IN_KERNEL(displ, label) \
20 cmpl $KERN_CS_SELECTOR, displ(%esp) ;\
21 je label ;
24 * saves the basic interrupt context (no error code) to the process structure
26 * displ is the displacement of %esp from the original stack after trap
27 * pptr is the process structure pointer
28 * tmp is an available temporary register
30 #define SAVE_TRAP_CTX(displ, pptr, tmp) \
31 movl (0 + displ)(%esp), tmp ;\
32 movl tmp, PCREG(pptr) ;\
33 movl (4 + displ)(%esp), tmp ;\
34 movl tmp, CSREG(pptr) ;\
35 movl (8 + displ)(%esp), tmp ;\
36 movl tmp, PSWREG(pptr) ;\
37 movl (12 + displ)(%esp), tmp ;\
38 movl tmp, SPREG(pptr) ;\
39 movl tmp, STREG(pptr)
42 * restore kernel segments. %cs is aready set and %fs, %gs are not used */
43 #define RESTORE_KERNEL_SEGS \
44 mov $KERN_DS_SELECTOR, %si ;\
45 mov %si, %ds ;\
46 mov %si, %es ;\
47 movw $0, %si ;\
48 mov %si, %gs ;\
49 mov %si, %fs ;
51 #define SAVE_GP_REGS(pptr) \
52 mov %eax, AXREG(pptr) ;\
53 mov %ecx, CXREG(pptr) ;\
54 mov %edx, DXREG(pptr) ;\
55 mov %ebx, BXREG(pptr) ;\
56 mov %esi, SIREG(pptr) ;\
57 mov %edi, DIREG(pptr) ;
59 #define RESTORE_GP_REGS(pptr) \
60 movl AXREG(pptr), %eax ;\
61 movl CXREG(pptr), %ecx ;\
62 movl DXREG(pptr), %edx ;\
63 movl BXREG(pptr), %ebx ;\
64 movl SIREG(pptr), %esi ;\
65 movl DIREG(pptr), %edi ;
68 * save the context of the interrupted process to the structure in the process
69 * table. It pushses the %ebp to stack to get a scratch register. After %esi is
70 * saved, we can use it to get the saved %ebp from stack and save it to the
71 * final location
73 * displ is the stack displacement. In case of an exception, there are two extra
74 * value on the stack - error code and the exception number
76 #define SAVE_PROCESS_CTX(displ) \
78 cld /* set the direction flag to a known state */ ;\
80 push %ebp ;\
82 movl (CURR_PROC_PTR + 4 + displ)(%esp), %ebp ;\
84 SAVE_GP_REGS(%ebp) ;\
85 pop %esi /* get the orig %ebp and save it */ ;\
86 mov %esi, BPREG(%ebp) ;\
88 RESTORE_KERNEL_SEGS ;\
89 SAVE_TRAP_CTX(displ, %ebp, %esi) ;
92 * clear the IF flag in eflags which are stored somewhere in memory, e.g. on
93 * stack. iret or popf will load the new value later
95 #define CLEAR_IF(where) \
96 mov where, %eax ;\
97 andl $0xfffffdff, %eax ;\
98 mov %eax, where ;
100 #endif /* __SCONST_H__ */