Skip to content

Commit

Permalink
arch: add SAVE_ALL_REGS and RESTORE_ALL_REGS for 32/64 bit C code
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 6dc58d5 commit 2d77428
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions include/arch/x86/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,53 @@ name ## _end:

#else

/* clang-format off */
#if defined(__x86_64__)
#define SAVE_ALL_REGS64() \
"push %%r8\n" \
"push %%r9\n" \
"push %%r10\n" \
"push %%r11\n" \
"push %%r12\n" \
"push %%r13\n" \
"push %%r14\n" \
"push %%r15\n"

#define RESTORE_ALL_REGS64() \
"pop %%" STR(r15) "\n" \
"pop %%" STR(r14) "\n" \
"pop %%" STR(r13) "\n" \
"pop %%" STR(r12) "\n" \
"pop %%" STR(r11) "\n" \
"pop %%" STR(r10) "\n" \
"pop %%" STR(r9) "\n" \
"pop %%" STR(r8) "\n"
#else
#define SAVE_ALL_REGS64()
#define RESTORE_ALL_REGS64()
#endif

#define SAVE_ALL_REGS() \
"push %%" STR(_ASM_AX) "\n" \
"push %%" STR(_ASM_BX) "\n" \
"push %%" STR(_ASM_CX) "\n" \
"push %%" STR(_ASM_DX) "\n" \
"push %%" STR(_ASM_SI) "\n" \
"push %%" STR(_ASM_DI) "\n" \
"push %%" STR(_ASM_BP) "\n" \
SAVE_ALL_REGS64()

#define RESTORE_ALL_REGS() \
RESTORE_ALL_REGS64() \
"pop %%" STR(_ASM_BP) "\n" \
"pop %%" STR(_ASM_DI) "\n" \
"pop %%" STR(_ASM_SI) "\n" \
"pop %%" STR(_ASM_DX) "\n" \
"pop %%" STR(_ASM_CX) "\n" \
"pop %%" STR(_ASM_BX) "\n" \
"pop %%" STR(_ASM_AX) "\n"
/* clang-format on */

#if defined(__x86_64__)
#define POPF() "popfq\n"
#else
Expand Down

0 comments on commit 2d77428

Please sign in to comment.