frameasm.h revision 1.35 1 1.35 riastrad /* $NetBSD: frameasm.h,v 1.35 2022/07/30 14:11:00 riastradh 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.28 cherry
12 1.28 cherry #ifdef XEN
13 1.11 bouyer /* XXX assym.h */
14 1.16 maxv #define TRAP_INSTR int $0x82
15 1.16 maxv #define XEN_BLOCK_EVENTS(reg) movb $1,EVTCHN_UPCALL_MASK(reg)
16 1.16 maxv #define XEN_UNBLOCK_EVENTS(reg) movb $0,EVTCHN_UPCALL_MASK(reg)
17 1.16 maxv #define XEN_TEST_PENDING(reg) testb $0xFF,EVTCHN_UPCALL_PENDING(reg)
18 1.28 cherry #endif /* XEN */
19 1.16 maxv
20 1.28 cherry #if defined(XENPV)
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.30 bouyer #define PUSHF(reg) movl CPUVAR(VCPU),reg ; \
29 1.30 bouyer movzbl EVTCHN_UPCALL_MASK(reg), reg; \
30 1.30 bouyer pushl reg
31 1.30 bouyer #define POPF(reg) call _C_LABEL(xen_write_psl); \
32 1.30 bouyer addl $4,%esp
33 1.28 cherry #else
34 1.28 cherry #define CLI(reg) cli
35 1.28 cherry #define STI(reg) sti
36 1.30 bouyer #define PUSHF(reg) pushf
37 1.30 bouyer #define POPF(reg) popf
38 1.28 cherry #ifdef XENPVHVM
39 1.28 cherry #define STIC(reg) sti ; \
40 1.28 cherry movl CPUVAR(VCPU),reg ; \
41 1.28 cherry XEN_UNBLOCK_EVENTS(reg) ; \
42 1.28 cherry testb $0xff,EVTCHN_UPCALL_PENDING(reg)
43 1.28 cherry #endif /* XENPVHVM */
44 1.28 cherry
45 1.28 cherry #endif /* XENPV */
46 1.1 fvdl
47 1.21 maxv #define HP_NAME_CLAC 1
48 1.21 maxv #define HP_NAME_STAC 2
49 1.21 maxv #define HP_NAME_NOLOCK 3
50 1.21 maxv #define HP_NAME_RETFENCE 4
51 1.35 riastrad #define HP_NAME_CAS_64 5
52 1.35 riastrad #define HP_NAME_SPLLOWER 6
53 1.35 riastrad #define HP_NAME_MUTEX_EXIT 7
54 1.20 maxv
55 1.19 maxv #define HOTPATCH(name, size) \
56 1.19 maxv 123: ; \
57 1.22 maxv .pushsection .rodata.hotpatch, "a" ; \
58 1.19 maxv .byte name ; \
59 1.19 maxv .byte size ; \
60 1.19 maxv .long 123b ; \
61 1.22 maxv .popsection
62 1.19 maxv
63 1.24 maxv #define SMAP_ENABLE \
64 1.24 maxv HOTPATCH(HP_NAME_CLAC, 3) ; \
65 1.26 maxv .byte 0x90, 0x90, 0x90
66 1.24 maxv
67 1.24 maxv #define SMAP_DISABLE \
68 1.24 maxv HOTPATCH(HP_NAME_STAC, 3) ; \
69 1.26 maxv .byte 0x90, 0x90, 0x90
70 1.24 maxv
71 1.1 fvdl /*
72 1.1 fvdl * These are used on interrupt or trap entry or exit.
73 1.1 fvdl */
74 1.1 fvdl #define INTRENTRY \
75 1.24 maxv SMAP_ENABLE ; \
76 1.1 fvdl subl $TF_PUSHSIZE,%esp ; \
77 1.22 maxv movw %gs,TF_GS(%esp) ; \
78 1.22 maxv movw %fs,TF_FS(%esp) ; \
79 1.3 junyoung movl %eax,TF_EAX(%esp) ; \
80 1.22 maxv movw %es,TF_ES(%esp) ; \
81 1.22 maxv movw %ds,TF_DS(%esp) ; \
82 1.3 junyoung movl $GSEL(GDATA_SEL, SEL_KPL),%eax ; \
83 1.1 fvdl movl %edi,TF_EDI(%esp) ; \
84 1.1 fvdl movl %esi,TF_ESI(%esp) ; \
85 1.22 maxv movw %ax,%ds ; \
86 1.1 fvdl movl %ebp,TF_EBP(%esp) ; \
87 1.22 maxv movw %ax,%es ; \
88 1.1 fvdl movl %ebx,TF_EBX(%esp) ; \
89 1.22 maxv movw %ax,%gs ; \
90 1.3 junyoung movl %edx,TF_EDX(%esp) ; \
91 1.1 fvdl movl $GSEL(GCPU_SEL, SEL_KPL),%eax ; \
92 1.3 junyoung movl %ecx,TF_ECX(%esp) ; \
93 1.22 maxv movl %eax,%fs ; \
94 1.17 maxv cld
95 1.1 fvdl
96 1.1 fvdl #define INTRFASTEXIT \
97 1.18 maxv jmp intrfastexit
98 1.1 fvdl
99 1.25 maxv #define INTR_RECURSE_HWFRAME \
100 1.25 maxv pushfl ; \
101 1.25 maxv pushl %cs ; \
102 1.25 maxv pushl %esi ;
103 1.25 maxv
104 1.8 yamt #define CHECK_DEFERRED_SWITCH \
105 1.4 yamt cmpl $0, CPUVAR(WANT_PMAPLOAD)
106 1.4 yamt
107 1.2 thorpej #define CHECK_ASTPENDING(reg) movl CPUVAR(CURLWP),reg ; \
108 1.12 yamt cmpl $0, L_MD_ASTPENDING(reg)
109 1.7 ad #define CLEAR_ASTPENDING(reg) movl $0, L_MD_ASTPENDING(reg)
110 1.1 fvdl
111 1.6 yamt /*
112 1.29 maxv * If the FPU state is not in the CPU, restore it. Executed with interrupts
113 1.29 maxv * disabled.
114 1.29 maxv *
115 1.29 maxv * %ebx must not be modified
116 1.29 maxv */
117 1.29 maxv #define HANDLE_DEFERRED_FPU \
118 1.29 maxv movl CPUVAR(CURLWP),%eax ; \
119 1.29 maxv testl $MDL_FPU_IN_CPU,L_MD_FLAGS(%eax) ; \
120 1.29 maxv jnz 1f ; \
121 1.29 maxv pushl %eax ; \
122 1.29 maxv call _C_LABEL(fpu_handle_deferred) ; \
123 1.29 maxv popl %eax ; \
124 1.29 maxv orl $MDL_FPU_IN_CPU,L_MD_FLAGS(%eax) ; \
125 1.29 maxv 1:
126 1.29 maxv
127 1.29 maxv /*
128 1.6 yamt * IDEPTH_INCR:
129 1.6 yamt * increase ci_idepth and switch to the interrupt stack if necessary.
130 1.6 yamt * note that the initial value of ci_idepth is -1.
131 1.6 yamt *
132 1.6 yamt * => should be called with interrupt disabled.
133 1.6 yamt * => save the old value of %esp in %eax.
134 1.6 yamt */
135 1.6 yamt
136 1.6 yamt #define IDEPTH_INCR \
137 1.6 yamt incl CPUVAR(IDEPTH); \
138 1.6 yamt movl %esp, %eax; \
139 1.6 yamt jne 999f; \
140 1.6 yamt movl CPUVAR(INTRSTACK), %esp; \
141 1.15 yamt 999: pushl %eax; /* eax == pointer to intrframe */ \
142 1.6 yamt
143 1.6 yamt /*
144 1.6 yamt * IDEPTH_DECR:
145 1.6 yamt * decrement ci_idepth and switch back to
146 1.6 yamt * the original stack saved by IDEPTH_INCR.
147 1.6 yamt *
148 1.6 yamt * => should be called with interrupt disabled.
149 1.6 yamt */
150 1.6 yamt
151 1.6 yamt #define IDEPTH_DECR \
152 1.6 yamt popl %esp; \
153 1.6 yamt decl CPUVAR(IDEPTH)
154 1.6 yamt
155 1.1 fvdl #endif /* _I386_FRAMEASM_H_ */
156