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