xref: /illumos-gate/usr/src/uts/i86pc/sys/asm_misc.h (revision 65f204200cf9a50fd6bad4093ee0b07bc35105ac)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  * Copyright 2019 Joyent, Inc.
25  */
26 
27 #ifndef _SYS_ASM_MISC_H
28 #define	_SYS_ASM_MISC_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	RET_INSTR	0xc3
35 #define	NOP_INSTR	0x90
36 #define	STI_INSTR	0xfb
37 #define	JMP_INSTR	0x00eb
38 
39 #ifdef _ASM	/* The remainder of this file is only for assembly files */
40 
41 /* Load reg with pointer to per-CPU structure */
42 #if defined(__amd64)
43 #define	LOADCPU(reg)			\
44 	movq	%gs:CPU_SELF, reg;
45 #else
46 #define	LOADCPU(reg)			\
47 	movl	%gs:CPU_SELF, reg;
48 #endif
49 
50 #if defined(__i386)
51 
52 #define	_HOT_PATCH_PROLOG			\
53 	push	%ebp;				\
54 	mov	%esp, %ebp;			\
55 	push	%ebx;				\
56 	push	%esi;				\
57 	push	%edi
58 
59 #define	_HOT_PATCH(srcaddr, dstaddr, size)	\
60 	movl	$srcaddr, %esi;			\
61 	movl	$dstaddr, %edi;			\
62 	movl	$size, %ebx;			\
63 0:	pushl	$1;				\
64 	/*CSTYLED*/				\
65 	movzbl	(%esi), %eax;			\
66 	pushl	%eax;				\
67 	pushl	%edi;				\
68 	call	hot_patch_kernel_text;		\
69 	addl	$12, %esp;			\
70 	inc	%edi;				\
71 	inc	%esi;				\
72 	dec	%ebx;				\
73 	test	%ebx, %ebx;			\
74 	jne	0b
75 
76 #define	_HOT_PATCH_EPILOG			\
77 	pop	%edi;				\
78 	pop	%esi;				\
79 	pop	%ebx;				\
80 	mov	%ebp, %esp;			\
81 	pop	%ebp
82 
83 #endif	/* __i386 */
84 
85 #endif /* _ASM */
86 
87 #ifdef	__cplusplus
88 }
89 #endif
90 
91 #endif	/* _SYS_ASM_MISC_H */
92