From 72c2e676f7b09e767f36b5ddadcdde5acd32cbfe Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Fri, 8 Jul 2022 14:00:07 +0200 Subject: [PATCH] arch: add SAVE/RESTORE macros for clobbered registers (32/64 bits) Signed-off-by: Pawel Wieczorkiewicz --- include/arch/x86/asm-macros.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/arch/x86/asm-macros.h b/include/arch/x86/asm-macros.h index 46ac1e92..24f9644c 100644 --- a/include/arch/x86/asm-macros.h +++ b/include/arch/x86/asm-macros.h @@ -251,6 +251,37 @@ name ## _end: "pop %%" STR(_ASM_CX) "\n" \ "pop %%" STR(_ASM_BX) "\n" \ "pop %%" STR(_ASM_AX) "\n" + +#if defined(__x86_64__) +#define SAVE_CLOBBERED_REGS64() \ + "push %%r8\n" \ + "push %%r9\n" \ + "push %%r10\n" \ + "push %%r11\n" \ + +#define RESTORE_CLOBBERED_REGS64() \ + "pop %%" STR(r11) "\n" \ + "pop %%" STR(r10) "\n" \ + "pop %%" STR(r9) "\n" \ + "pop %%" STR(r8) "\n" +#else +#define SAVE_CLOBBERED_REGS64() +#define RESTORE_CLOBBERED_REGS64() +#endif + +#define SAVE_CLOBBERED_REGS() \ + "push %%" STR(_ASM_CX) "\n" \ + "push %%" STR(_ASM_DX) "\n" \ + "push %%" STR(_ASM_SI) "\n" \ + "push %%" STR(_ASM_DI) "\n" \ + SAVE_CLOBBERED_REGS64() + +#define RESTORE_CLOBBERED_REGS() \ + RESTORE_CLOBBERED_REGS64() \ + "pop %%" STR(_ASM_DI) "\n" \ + "pop %%" STR(_ASM_SI) "\n" \ + "pop %%" STR(_ASM_DX) "\n" \ + "pop %%" STR(_ASM_CX) "\n" \ /* clang-format on */ #if defined(__x86_64__)