1 /* $OpenBSD: frameasm.h,v 1.5 2011/04/13 02:49:12 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 INTR_RESTORE_GPRS \ 34 movq TF_R15(%rsp),%r15 ; \ 35 movq TF_R14(%rsp),%r14 ; \ 36 movq TF_R13(%rsp),%r13 ; \ 37 movq TF_R12(%rsp),%r12 ; \ 38 movq TF_R11(%rsp),%r11 ; \ 39 movq TF_R10(%rsp),%r10 ; \ 40 movq TF_R9(%rsp),%r9 ; \ 41 movq TF_R8(%rsp),%r8 ; \ 42 movq TF_RDI(%rsp),%rdi ; \ 43 movq TF_RSI(%rsp),%rsi ; \ 44 movq TF_RBP(%rsp),%rbp ; \ 45 movq TF_RBX(%rsp),%rbx ; \ 46 movq TF_RDX(%rsp),%rdx ; \ 47 movq TF_RCX(%rsp),%rcx ; \ 48 movq TF_RAX(%rsp),%rax ; \ 49 addq $120,%rsp 50 51 #define INTRENTRY \ 52 subq $32,%rsp ; \ 53 testq $SEL_UPL,56(%rsp) ; \ 54 je 98f ; \ 55 swapgs ; \ 56 movw %gs,0(%rsp) ; \ 57 movw %fs,8(%rsp) ; \ 58 movw %es,16(%rsp) ; \ 59 movw %ds,24(%rsp) ; \ 60 98: INTR_SAVE_GPRS 61 62 #define INTRFASTEXIT \ 63 jmp intr_fast_exit 64 65 #define INTR_RECURSE_HWFRAME \ 66 movq %rsp,%r10 ; \ 67 movl %ss,%r11d ; \ 68 pushq %r11 ; \ 69 pushq %r10 ; \ 70 pushfq ; \ 71 movl %cs,%r11d ; \ 72 pushq %r11 ; \ 73 pushq %r13 ; 74 75 /* 76 * Restore %ds, %es, %fs, and %gs, dealing with the FS.base MSR for 77 * %fs and doing the cli/swapgs for %gs. Uses %rax, %rcx, and %rdx 78 */ 79 #define INTR_RESTORE_SELECTORS \ 80 movq CPUVAR(CURPCB),%rdx /* for below */ ; \ 81 /* %es and %ds */ \ 82 movw TF_ES(%rsp),%es ; \ 83 movw $(GSEL(GUDATA_SEL, SEL_UPL)),%ax ; \ 84 movw %ax,%ds ; \ 85 /* Make sure both %fs and FS.base are the desired values */ \ 86 movq PCB_FSBASE(%rdx),%rax ; \ 87 cmpq $0,%rax ; \ 88 jne 96f ; \ 89 movw TF_FS(%rsp),%fs /* zero FS.base by setting %fs */ ; \ 90 jmp 98f ; \ 91 96: cmpq CPUVAR(CUR_FSBASE),%rax ; \ 92 jne 97f ; \ 93 movw %fs,%cx /* FS.base same, how about %fs? */ ; \ 94 cmpw TF_FS(%rsp),%cx ; \ 95 je 99f ; \ 96 97: movw TF_FS(%rsp),%fs /* set them both */ ; \ 97 movq %rax,%rdx ; \ 98 shrq $32,%rdx ; \ 99 movl $MSR_FSBASE,%ecx ; \ 100 wrmsr ; \ 101 98: movq %rax,CPUVAR(CUR_FSBASE) ; \ 102 99: cli /* %fs done, so swapgs and do %gs */ ; \ 103 swapgs ; \ 104 movw TF_GS(%rsp),%gs 105 106 107 #define CHECK_ASTPENDING(reg) movq CPUVAR(CURPROC),reg ; \ 108 cmpq $0, reg ; \ 109 je 99f ; \ 110 cmpl $0, P_MD_ASTPENDING(reg) ; \ 111 99: 112 113 #define CLEAR_ASTPENDING(reg) movl $0, P_MD_ASTPENDING(reg) 114 115 #endif /* _AMD64_MACHINE_FRAMEASM_H */ 116