1*a2021292SJérôme Duval /* 2*a2021292SJérôme Duval * Copyright 2018, Jérôme Duval, jerome.duval@gmail.com. 3*a2021292SJérôme Duval * Distributed under the terms of the MIT License. 4*a2021292SJérôme Duval */ 5*a2021292SJérôme Duval #ifndef _KERNEL_ARCH_x86_ALTCODEPATCH_H 6*a2021292SJérôme Duval #define _KERNEL_ARCH_x86_ALTCODEPATCH_H 7*a2021292SJérôme Duval 8*a2021292SJérôme Duval 9*a2021292SJérôme Duval #include <arch/x86/arch_kernel.h> 10*a2021292SJérôme Duval 11*a2021292SJérôme Duval 12*a2021292SJérôme Duval #define ASM_NOP1 .byte 0x90 13*a2021292SJérôme Duval #define ASM_NOP2 .byte 0x66, 0x90 14*a2021292SJérôme Duval #define ASM_NOP3 .byte 0x0f, 0x1f, 0x00 15*a2021292SJérôme Duval #define ASM_NOP4 .byte 0x0f, 0x1f, 0x40, 0x00 16*a2021292SJérôme Duval #define ASM_NOP5 .byte 0x0f, 0x1f, 0x44, 0x00, 0x00 17*a2021292SJérôme Duval #define ASM_NOP6 .byte 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 18*a2021292SJérôme Duval #define ASM_NOP7 .byte 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00 19*a2021292SJérôme Duval #define ASM_NOP8 .byte 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 20*a2021292SJérôme Duval #define ASM_NOP9 .byte 0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 21*a2021292SJérôme Duval 22*a2021292SJérôme Duval 23*a2021292SJérôme Duval #ifdef _ASSEMBLER 24*a2021292SJérôme Duval 25*a2021292SJérôme Duval #define CODEPATCH_START 990: 26*a2021292SJérôme Duval #define CODEPATCH_END(tag) 991: \ 27*a2021292SJérôme Duval .pushsection .altcodepatch, "a" ; \ 28*a2021292SJérôme Duval .long (990b - KERNEL_LOAD_BASE) ; \ 29*a2021292SJérôme Duval .short (991b - 990b) ; \ 30*a2021292SJérôme Duval .short tag ; \ 31*a2021292SJérôme Duval .popsection 32*a2021292SJérôme Duval 33*a2021292SJérôme Duval #else 34*a2021292SJérôme Duval 35*a2021292SJérôme Duval #define _STRINGIFY(x...) #x 36*a2021292SJérôme Duval #define STRINGIFY(x...) _STRINGIFY(x) 37*a2021292SJérôme Duval 38*a2021292SJérôme Duval #define CODEPATCH_START "990: \n" 39*a2021292SJérôme Duval #define CODEPATCH_END(tag) "991: \n" \ 40*a2021292SJérôme Duval ".pushsection .altcodepatch, \"a\" \n" \ 41*a2021292SJérôme Duval ".long (990b - " STRINGIFY(KERNEL_LOAD_BASE) ") \n" \ 42*a2021292SJérôme Duval ".short (991b - 990b) \n" \ 43*a2021292SJérôme Duval ".short " STRINGIFY(tag) " \n" \ 44*a2021292SJérôme Duval ".popsection" 45*a2021292SJérôme Duval 46*a2021292SJérôme Duval void arch_altcodepatch_replace(uint16 tag, void* newcodepatch, size_t length); 47*a2021292SJérôme Duval 48*a2021292SJérôme Duval 49*a2021292SJérôme Duval #endif 50*a2021292SJérôme Duval 51*a2021292SJérôme Duval #endif /* _KERNEL_ARCH_x86_ALTCODEPATCH_H */ 52