xref: /titanic_51/usr/src/uts/i86pc/sys/asm_misc.h (revision f0f4f396d961830dba7fdb198cec178eae7b887b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*f0f4f396Ska153516  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_ASM_MISC_H
277c478bd9Sstevel@tonic-gate #define	_SYS_ASM_MISC_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef _ASM	/* The remainder of this file is only for assembly files */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /* Load reg with pointer to per-CPU structure */
387c478bd9Sstevel@tonic-gate #if defined(__amd64)
397c478bd9Sstevel@tonic-gate #define	LOADCPU(reg)			\
407c478bd9Sstevel@tonic-gate 	movq	%gs:CPU_SELF, reg;
417c478bd9Sstevel@tonic-gate #else
427c478bd9Sstevel@tonic-gate #define	LOADCPU(reg)			\
437c478bd9Sstevel@tonic-gate 	movl	%gs:CPU_SELF, reg;
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	RET_INSTR	0xc3
477c478bd9Sstevel@tonic-gate #define	NOP_INSTR	0x90
487c478bd9Sstevel@tonic-gate #define	STI_INSTR	0xfb
497c478bd9Sstevel@tonic-gate #define	JMP_INSTR	0x00eb
507c478bd9Sstevel@tonic-gate 
51ae115bc7Smrj 
52ae115bc7Smrj #if defined(__i386)
53ae115bc7Smrj 
54ae115bc7Smrj #define	_HOT_PATCH_PROLOG			\
55ae115bc7Smrj 	push	%ebp;				\
56ae115bc7Smrj 	mov	%esp, %ebp;			\
57ae115bc7Smrj 	push	%ebx;				\
58ae115bc7Smrj 	push	%esi;				\
59ae115bc7Smrj 	push	%edi
60ae115bc7Smrj 
61ae115bc7Smrj #define	_HOT_PATCH(srcaddr, dstaddr, size)	\
62ae115bc7Smrj 	movl	$srcaddr, %esi;			\
63ae115bc7Smrj 	movl	$dstaddr, %edi;			\
64ae115bc7Smrj 	movl	$size, %ebx;			\
65ae115bc7Smrj 0:	pushl	$1;				\
66ae115bc7Smrj 	/*CSTYLED*/				\
67ae115bc7Smrj 	movzbl	(%esi), %eax;			\
68ae115bc7Smrj 	pushl	%eax;				\
69ae115bc7Smrj 	pushl	%edi;				\
70ae115bc7Smrj 	call	hot_patch_kernel_text;		\
71ae115bc7Smrj 	addl	$12, %esp;			\
72ae115bc7Smrj 	inc	%edi;				\
73ae115bc7Smrj 	inc	%esi;				\
74ae115bc7Smrj 	dec	%ebx;				\
75ae115bc7Smrj 	test	%ebx, %ebx;			\
76ae115bc7Smrj 	jne	0b
77ae115bc7Smrj 
78ae115bc7Smrj #define	_HOT_PATCH_EPILOG			\
79ae115bc7Smrj 	pop	%edi;				\
80ae115bc7Smrj 	pop	%esi;				\
81ae115bc7Smrj 	pop	%ebx;				\
82ae115bc7Smrj 	mov	%ebp, %esp;			\
83ae115bc7Smrj 	pop	%ebp
84ae115bc7Smrj 
85ae115bc7Smrj #endif	/* __i386 */
86ae115bc7Smrj 
87*f0f4f396Ska153516 #if defined(__amd64)
88*f0f4f396Ska153516 
89*f0f4f396Ska153516 /*
90*f0f4f396Ska153516  * While as doesn't support fxsaveq/fxrstorq (fxsave/fxrstor with REX.W = 1)
91*f0f4f396Ska153516  * we will use the FXSAVEQ/FXRSTORQ macro
92*f0f4f396Ska153516  */
93*f0f4f396Ska153516 
94*f0f4f396Ska153516 #define	FXSAVEQ(x)	\
95*f0f4f396Ska153516 	.byte	0x48;	\
96*f0f4f396Ska153516 	fxsave	x
97*f0f4f396Ska153516 
98*f0f4f396Ska153516 #define	FXRSTORQ(x)	\
99*f0f4f396Ska153516 	.byte	0x48;	\
100*f0f4f396Ska153516 	fxrstor	x
101*f0f4f396Ska153516 
102*f0f4f396Ska153516 #endif	/* __amd64 */
103*f0f4f396Ska153516 
1047c478bd9Sstevel@tonic-gate #endif /* _ASM */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate #endif
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #endif	/* _SYS_ASM_MISC_H */
111