1 /* $OpenBSD: frameasm.h,v 1.6 2011/07/04 15:54:24 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 movq PCB_FSBASE(%rdx),%rax ; \ 69 cmpq $0,%rax ; \ 70 jne 96f ; \ 71 movw TF_FS(%rsp),%fs /* zero FS.base by setting %fs */ ; \ 72 jmp 98f ; \ 73 96: cmpq CPUVAR(CUR_FSBASE),%rax ; \ 74 jne 97f ; \ 75 movw %fs,%cx /* FS.base same, how about %fs? */ ; \ 76 cmpw TF_FS(%rsp),%cx ; \ 77 je 99f ; \ 78 97: movw TF_FS(%rsp),%fs /* set them both */ ; \ 79 movq %rax,%rdx ; \ 80 shrq $32,%rdx ; \ 81 movl $MSR_FSBASE,%ecx ; \ 82 wrmsr ; \ 83 98: movq %rax,CPUVAR(CUR_FSBASE) ; \ 84 99: cli /* %fs done, so swapgs and do %gs */ ; \ 85 swapgs ; \ 86 movw TF_GS(%rsp),%gs 87 88 89 #define CHECK_ASTPENDING(reg) movq CPUVAR(CURPROC),reg ; \ 90 cmpq $0, reg ; \ 91 je 99f ; \ 92 cmpl $0, P_MD_ASTPENDING(reg) ; \ 93 99: 94 95 #define CLEAR_ASTPENDING(reg) movl $0, P_MD_ASTPENDING(reg) 96 97 #endif /* _AMD64_MACHINE_FRAMEASM_H */ 98