xref: /openbsd/sys/arch/amd64/include/frameasm.h (revision 264ca280)
1 /*	$OpenBSD: frameasm.h,v 1.9 2015/07/17 15:37:58 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_RPL,56(%rsp)	; \
36 	je	98f			; \
37 	swapgs				; \
38 98: 	INTR_SAVE_GPRS
39 
40 #define INTRFASTEXIT \
41 	jmp	intr_fast_exit
42 
43 #define INTR_RECURSE_HWFRAME \
44 	movq	%rsp,%r10		; \
45 	movl	%ss,%r11d		; \
46 	pushq	%r11			; \
47 	pushq	%r10			; \
48 	pushfq				; \
49 	movl	%cs,%r11d		; \
50 	pushq	%r11			; \
51 	pushq	%r13			;
52 
53 /*
54  * Restore FS.base if it's not already in the CPU, and do the cli/swapgs.
55  * Uses %rax, %rcx, and %rdx
56  */
57 #define INTR_RESTORE_SELECTORS						\
58 	btsl	$CPUF_USERSEGS_BIT, CPUVAR(FLAGS)			; \
59 	jc	99f							; \
60 	movq	CPUVAR(CURPCB),%rdx	/* for below */			; \
61 	movq	PCB_FSBASE(%rdx),%rax					; \
62 	cmpq	$0,%rax							; \
63 	je	99f		/* setting %fs has zeroed FS.base */	; \
64 	movq	%rax,%rdx						; \
65 	shrq	$32,%rdx						; \
66 	movl	$MSR_FSBASE,%ecx					; \
67 	wrmsr								; \
68 99:	movw    $(GSEL(GUDATA_SEL, SEL_UPL)),%ax			; \
69 	cli								; \
70 	swapgs								; \
71 	movw	%ax,%gs
72 
73 
74 #define CHECK_ASTPENDING(reg)	movq	CPUVAR(CURPROC),reg		; \
75 				cmpq	$0, reg				; \
76 				je	99f				; \
77 				cmpl	$0, P_MD_ASTPENDING(reg)	; \
78 				99:
79 
80 #define CLEAR_ASTPENDING(reg)	movl	$0, P_MD_ASTPENDING(reg)
81 
82 #endif /* _AMD64_MACHINE_FRAMEASM_H */
83