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 /* 22f0f4f396Ska * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*65f20420SRobert Mustacchi * Copyright 2019 Joyent, Inc. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_ASM_MISC_H 287c478bd9Sstevel@tonic-gate #define _SYS_ASM_MISC_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 34*65f20420SRobert Mustacchi #define RET_INSTR 0xc3 35*65f20420SRobert Mustacchi #define NOP_INSTR 0x90 36*65f20420SRobert Mustacchi #define STI_INSTR 0xfb 37*65f20420SRobert Mustacchi #define JMP_INSTR 0x00eb 38*65f20420SRobert Mustacchi 397c478bd9Sstevel@tonic-gate #ifdef _ASM /* The remainder of this file is only for assembly files */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* Load reg with pointer to per-CPU structure */ 427c478bd9Sstevel@tonic-gate #if defined(__amd64) 437c478bd9Sstevel@tonic-gate #define LOADCPU(reg) \ 447c478bd9Sstevel@tonic-gate movq %gs:CPU_SELF, reg; 457c478bd9Sstevel@tonic-gate #else 467c478bd9Sstevel@tonic-gate #define LOADCPU(reg) \ 477c478bd9Sstevel@tonic-gate movl %gs:CPU_SELF, reg; 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate 50ae115bc7Smrj #if defined(__i386) 51ae115bc7Smrj 52ae115bc7Smrj #define _HOT_PATCH_PROLOG \ 53ae115bc7Smrj push %ebp; \ 54ae115bc7Smrj mov %esp, %ebp; \ 55ae115bc7Smrj push %ebx; \ 56ae115bc7Smrj push %esi; \ 57ae115bc7Smrj push %edi 58ae115bc7Smrj 59ae115bc7Smrj #define _HOT_PATCH(srcaddr, dstaddr, size) \ 60ae115bc7Smrj movl $srcaddr, %esi; \ 61ae115bc7Smrj movl $dstaddr, %edi; \ 62ae115bc7Smrj movl $size, %ebx; \ 63ae115bc7Smrj 0: pushl $1; \ 64ae115bc7Smrj /*CSTYLED*/ \ 65ae115bc7Smrj movzbl (%esi), %eax; \ 66ae115bc7Smrj pushl %eax; \ 67ae115bc7Smrj pushl %edi; \ 68ae115bc7Smrj call hot_patch_kernel_text; \ 69ae115bc7Smrj addl $12, %esp; \ 70ae115bc7Smrj inc %edi; \ 71ae115bc7Smrj inc %esi; \ 72ae115bc7Smrj dec %ebx; \ 73ae115bc7Smrj test %ebx, %ebx; \ 74ae115bc7Smrj jne 0b 75ae115bc7Smrj 76ae115bc7Smrj #define _HOT_PATCH_EPILOG \ 77ae115bc7Smrj pop %edi; \ 78ae115bc7Smrj pop %esi; \ 79ae115bc7Smrj pop %ebx; \ 80ae115bc7Smrj mov %ebp, %esp; \ 81ae115bc7Smrj pop %ebp 82ae115bc7Smrj 83ae115bc7Smrj #endif /* __i386 */ 84ae115bc7Smrj 857c478bd9Sstevel@tonic-gate #endif /* _ASM */ 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #ifdef __cplusplus 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate #endif 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #endif /* _SYS_ASM_MISC_H */ 92