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