1 /* $OpenBSD: frameasm.h,v 1.7 2012/04/17 16:02:33 guenther Exp $ */ 2 /* $NetBSD: frameasm.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ 3 4 #ifndef _AMD64_MACHINE_FRAMEASM_H 5 #define _AMD64_MACHINE_FRAMEASM_H 6 7 /* 8 * Macros to define pushing/popping frames for interrupts, traps 9 * and system calls. Currently all the same; will diverge later. 10 */ 11 12 /* 13 * These are used on interrupt or trap entry or exit. 14 */ 15 #define INTR_SAVE_GPRS \ 16 subq $120,%rsp ; \ 17 movq %r15,TF_R15(%rsp) ; \ 18 movq %r14,TF_R14(%rsp) ; \ 19 movq %r13,TF_R13(%rsp) ; \ 20 movq %r12,TF_R12(%rsp) ; \ 21 movq %r11,TF_R11(%rsp) ; \ 22 movq %r10,TF_R10(%rsp) ; \ 23 movq %r9,TF_R9(%rsp) ; \ 24 movq %r8,TF_R8(%rsp) ; \ 25 movq %rdi,TF_RDI(%rsp) ; \ 26 movq %rsi,TF_RSI(%rsp) ; \ 27 movq %rbp,TF_RBP(%rsp) ; \ 28 movq %rbx,TF_RBX(%rsp) ; \ 29 movq %rdx,TF_RDX(%rsp) ; \ 30 movq %rcx,TF_RCX(%rsp) ; \ 31 movq %rax,TF_RAX(%rsp) 32 33 #define INTRENTRY \ 34 subq $32,%rsp ; \ 35 testq $SEL_UPL,56(%rsp) ; \ 36 je 98f ; \ 37 swapgs ; \ 38 movw %gs,0(%rsp) ; \ 39 movw %fs,8(%rsp) ; \ 40 movw %es,16(%rsp) ; \ 41 movw %ds,24(%rsp) ; \ 42 98: INTR_SAVE_GPRS 43 44 #define INTRFASTEXIT \ 45 jmp intr_fast_exit 46 47 #define INTR_RECURSE_HWFRAME \ 48 movq %rsp,%r10 ; \ 49 movl %ss,%r11d ; \ 50 pushq %r11 ; \ 51 pushq %r10 ; \ 52 pushfq ; \ 53 movl %cs,%r11d ; \ 54 pushq %r11 ; \ 55 pushq %r13 ; 56 57 /* 58 * Restore %ds, %es, %fs, and %gs, dealing with the FS.base MSR for 59 * %fs and doing the cli/swapgs for %gs. Uses %rax, %rcx, and %rdx 60 */ 61 #define INTR_RESTORE_SELECTORS \ 62 movq CPUVAR(CURPCB),%rdx /* for below */ ; \ 63 /* %es and %ds */ \ 64 movw TF_ES(%rsp),%es ; \ 65 movw $(GSEL(GUDATA_SEL, SEL_UPL)),%ax ; \ 66 movw %ax,%ds ; \ 67 /* Make sure both %fs and FS.base are the desired values */ \ 68 movw TF_FS(%rsp),%fs ; \ 69 movq PCB_FSBASE(%rdx),%rax ; \ 70 cmpq $0,%rax ; \ 71 je 99f /* setting %fs has zeroed FS.base */ ; \ 72 movq %rax,%rdx ; \ 73 shrq $32,%rdx ; \ 74 movl $MSR_FSBASE,%ecx ; \ 75 wrmsr ; \ 76 99: cli /* %fs done, so swapgs and do %gs */ ; \ 77 swapgs ; \ 78 movw TF_GS(%rsp),%gs 79 80 81 #define CHECK_ASTPENDING(reg) movq CPUVAR(CURPROC),reg ; \ 82 cmpq $0, reg ; \ 83 je 99f ; \ 84 cmpl $0, P_MD_ASTPENDING(reg) ; \ 85 99: 86 87 #define CLEAR_ASTPENDING(reg) movl $0, P_MD_ASTPENDING(reg) 88 89 #endif /* _AMD64_MACHINE_FRAMEASM_H */ 90