frameasm.h revision 1.17 1 1.17 maxv /* $NetBSD: frameasm.h,v 1.17 2017/09/17 09:04:51 maxv Exp $ */
2 1.1 fvdl
3 1.1 fvdl #ifndef _I386_FRAMEASM_H_
4 1.1 fvdl #define _I386_FRAMEASM_H_
5 1.1 fvdl
6 1.1 fvdl #ifdef _KERNEL_OPT
7 1.1 fvdl #include "opt_multiprocessor.h"
8 1.11 bouyer #include "opt_xen.h"
9 1.11 bouyer #endif
10 1.11 bouyer
11 1.11 bouyer #if !defined(XEN)
12 1.16 maxv #define CLI(reg) cli
13 1.16 maxv #define STI(reg) sti
14 1.11 bouyer #else
15 1.11 bouyer /* XXX assym.h */
16 1.16 maxv #define TRAP_INSTR int $0x82
17 1.16 maxv #define XEN_BLOCK_EVENTS(reg) movb $1,EVTCHN_UPCALL_MASK(reg)
18 1.16 maxv #define XEN_UNBLOCK_EVENTS(reg) movb $0,EVTCHN_UPCALL_MASK(reg)
19 1.16 maxv #define XEN_TEST_PENDING(reg) testb $0xFF,EVTCHN_UPCALL_PENDING(reg)
20 1.16 maxv
21 1.16 maxv #define CLI(reg) movl CPUVAR(VCPU),reg ; \
22 1.16 maxv XEN_BLOCK_EVENTS(reg)
23 1.16 maxv #define STI(reg) movl CPUVAR(VCPU),reg ; \
24 1.11 bouyer XEN_UNBLOCK_EVENTS(reg)
25 1.16 maxv #define STIC(reg) movl CPUVAR(VCPU),reg ; \
26 1.11 bouyer XEN_UNBLOCK_EVENTS(reg) ; \
27 1.16 maxv testb $0xff,EVTCHN_UPCALL_PENDING(reg)
28 1.1 fvdl #endif
29 1.1 fvdl
30 1.1 fvdl /*
31 1.1 fvdl * These are used on interrupt or trap entry or exit.
32 1.1 fvdl */
33 1.1 fvdl #define INTRENTRY \
34 1.1 fvdl subl $TF_PUSHSIZE,%esp ; \
35 1.14 gmcgarry movw %gs,TF_GS(%esp) ; \
36 1.14 gmcgarry movw %fs,TF_FS(%esp) ; \
37 1.3 junyoung movl %eax,TF_EAX(%esp) ; \
38 1.14 gmcgarry movw %es,TF_ES(%esp) ; \
39 1.14 gmcgarry movw %ds,TF_DS(%esp) ; \
40 1.3 junyoung movl $GSEL(GDATA_SEL, SEL_KPL),%eax ; \
41 1.1 fvdl movl %edi,TF_EDI(%esp) ; \
42 1.1 fvdl movl %esi,TF_ESI(%esp) ; \
43 1.14 gmcgarry movw %ax,%ds ; \
44 1.1 fvdl movl %ebp,TF_EBP(%esp) ; \
45 1.14 gmcgarry movw %ax,%es ; \
46 1.1 fvdl movl %ebx,TF_EBX(%esp) ; \
47 1.14 gmcgarry movw %ax,%gs ; \
48 1.3 junyoung movl %edx,TF_EDX(%esp) ; \
49 1.1 fvdl movl $GSEL(GCPU_SEL, SEL_KPL),%eax ; \
50 1.3 junyoung movl %ecx,TF_ECX(%esp) ; \
51 1.1 fvdl movl %eax,%fs ; \
52 1.17 maxv cld
53 1.1 fvdl
54 1.5 yamt /*
55 1.5 yamt * INTRFASTEXIT should be in sync with trap(), resume_iret and friends.
56 1.5 yamt */
57 1.1 fvdl #define INTRFASTEXIT \
58 1.14 gmcgarry movw TF_GS(%esp),%gs ; \
59 1.14 gmcgarry movw TF_FS(%esp),%fs ; \
60 1.14 gmcgarry movw TF_ES(%esp),%es ; \
61 1.14 gmcgarry movw TF_DS(%esp),%ds ; \
62 1.1 fvdl movl TF_EDI(%esp),%edi ; \
63 1.1 fvdl movl TF_ESI(%esp),%esi ; \
64 1.1 fvdl movl TF_EBP(%esp),%ebp ; \
65 1.1 fvdl movl TF_EBX(%esp),%ebx ; \
66 1.1 fvdl movl TF_EDX(%esp),%edx ; \
67 1.1 fvdl movl TF_ECX(%esp),%ecx ; \
68 1.1 fvdl movl TF_EAX(%esp),%eax ; \
69 1.1 fvdl addl $(TF_PUSHSIZE+8),%esp ; \
70 1.1 fvdl iret
71 1.1 fvdl
72 1.8 yamt #define DO_DEFERRED_SWITCH \
73 1.4 yamt cmpl $0, CPUVAR(WANT_PMAPLOAD) ; \
74 1.4 yamt jz 1f ; \
75 1.4 yamt call _C_LABEL(pmap_load) ; \
76 1.4 yamt 1:
77 1.4 yamt
78 1.10 yamt #define DO_DEFERRED_SWITCH_RETRY \
79 1.10 yamt 1: ; \
80 1.10 yamt cmpl $0, CPUVAR(WANT_PMAPLOAD) ; \
81 1.10 yamt jz 1f ; \
82 1.10 yamt call _C_LABEL(pmap_load) ; \
83 1.10 yamt jmp 1b ; \
84 1.10 yamt 1:
85 1.10 yamt
86 1.8 yamt #define CHECK_DEFERRED_SWITCH \
87 1.4 yamt cmpl $0, CPUVAR(WANT_PMAPLOAD)
88 1.4 yamt
89 1.2 thorpej #define CHECK_ASTPENDING(reg) movl CPUVAR(CURLWP),reg ; \
90 1.12 yamt cmpl $0, L_MD_ASTPENDING(reg)
91 1.7 ad #define CLEAR_ASTPENDING(reg) movl $0, L_MD_ASTPENDING(reg)
92 1.1 fvdl
93 1.6 yamt /*
94 1.6 yamt * IDEPTH_INCR:
95 1.6 yamt * increase ci_idepth and switch to the interrupt stack if necessary.
96 1.6 yamt * note that the initial value of ci_idepth is -1.
97 1.6 yamt *
98 1.6 yamt * => should be called with interrupt disabled.
99 1.6 yamt * => save the old value of %esp in %eax.
100 1.6 yamt */
101 1.6 yamt
102 1.6 yamt #define IDEPTH_INCR \
103 1.6 yamt incl CPUVAR(IDEPTH); \
104 1.6 yamt movl %esp, %eax; \
105 1.6 yamt jne 999f; \
106 1.6 yamt movl CPUVAR(INTRSTACK), %esp; \
107 1.15 yamt 999: pushl %eax; /* eax == pointer to intrframe */ \
108 1.6 yamt
109 1.6 yamt /*
110 1.6 yamt * IDEPTH_DECR:
111 1.6 yamt * decrement ci_idepth and switch back to
112 1.6 yamt * the original stack saved by IDEPTH_INCR.
113 1.6 yamt *
114 1.6 yamt * => should be called with interrupt disabled.
115 1.6 yamt */
116 1.6 yamt
117 1.6 yamt #define IDEPTH_DECR \
118 1.6 yamt popl %esp; \
119 1.6 yamt decl CPUVAR(IDEPTH)
120 1.6 yamt
121 1.1 fvdl #endif /* _I386_FRAMEASM_H_ */
122