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 2017 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 #ifdef _ASM /* The remainder of this file is only for assembly files */ 35 36 /* Load reg with pointer to per-CPU structure */ 37 #if defined(__amd64) 38 #define LOADCPU(reg) \ 39 movq %gs:CPU_SELF, reg; 40 #else 41 #define LOADCPU(reg) \ 42 movl %gs:CPU_SELF, reg; 43 #endif 44 45 #define RET_INSTR 0xc3 46 #define NOP_INSTR 0x90 47 #define STI_INSTR 0xfb 48 #define JMP_INSTR 0x00eb 49 50 51 #if defined(__i386) 52 53 #define _HOT_PATCH_PROLOG \ 54 push %ebp; \ 55 mov %esp, %ebp; \ 56 push %ebx; \ 57 push %esi; \ 58 push %edi 59 60 #define _HOT_PATCH(srcaddr, dstaddr, size) \ 61 movl $srcaddr, %esi; \ 62 movl $dstaddr, %edi; \ 63 movl $size, %ebx; \ 64 0: pushl $1; \ 65 /*CSTYLED*/ \ 66 movzbl (%esi), %eax; \ 67 pushl %eax; \ 68 pushl %edi; \ 69 call hot_patch_kernel_text; \ 70 addl $12, %esp; \ 71 inc %edi; \ 72 inc %esi; \ 73 dec %ebx; \ 74 test %ebx, %ebx; \ 75 jne 0b 76 77 #define _HOT_PATCH_EPILOG \ 78 pop %edi; \ 79 pop %esi; \ 80 pop %ebx; \ 81 mov %ebp, %esp; \ 82 pop %ebp 83 84 #endif /* __i386 */ 85 86 #endif /* _ASM */ 87 88 #ifdef __cplusplus 89 } 90 #endif 91 92 #endif /* _SYS_ASM_MISC_H */