4 #include "kernel/const.h"
5 #include "kernel/procoffsets.h"
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
19 #define TEST_INT_IN_KERNEL(displ, label) \
20 cmpl $KERN_CS_SELECTOR, displ(%esp) ;\
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 ;\
41 * restore kernel segments. %cs is already set and %fs, %gs are not used */
42 #define RESTORE_KERNEL_SEGS \
43 mov $KERN_DS_SELECTOR, %si ;\
50 #define SAVE_GP_REGS(pptr) \
51 mov %eax, AXREG(pptr) ;\
52 mov %ecx, CXREG(pptr) ;\
53 mov %edx, DXREG(pptr) ;\
54 mov %ebx, BXREG(pptr) ;\
55 mov %esi, SIREG(pptr) ;\
56 mov %edi, DIREG(pptr) ;
58 #define RESTORE_GP_REGS(pptr) \
59 movl AXREG(pptr), %eax ;\
60 movl CXREG(pptr), %ecx ;\
61 movl DXREG(pptr), %edx ;\
62 movl BXREG(pptr), %ebx ;\
63 movl SIREG(pptr), %esi ;\
64 movl DIREG(pptr), %edi ;
67 * save the context of the interrupted process to the structure in the process
68 * table. It pushses the %ebp to stack to get a scratch register. After %esi is
69 * saved, we can use it to get the saved %ebp from stack and save it to the
72 * displ is the stack displacement. In case of an exception, there are two extra
73 * value on the stack - error code and the exception number
75 #define SAVE_PROCESS_CTX(displ, trapcode) \
77 cld /* set the direction flag to a known state */ ;\
81 movl (CURR_PROC_PTR + 4 + displ)(%esp), %ebp ;\
84 movl $trapcode, P_KERN_TRAP_STYLE(%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) \
97 andl $0xfffffdff, %eax ;\
100 #endif /* __SCONST_H__ */