Skip to content

Commit

Permalink
arch: add SAVE/RESTORE macros for clobbered registers (32/64 bits)
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 8, 2022
1 parent 2d77428 commit 72c2e67
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/arch/x86/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 72c2e67

Please sign in to comment.