Skip to content

Commit

Permalink
entry: SAVE/RESTORE_ALL_REGS cond. exclude AX
Browse files Browse the repository at this point in the history
Because syscalls provides the result in ax, we probably don't want to
restore it to its original value. Allow to conditionally exclude ax.

Signed-off-by: Johannes Wikner <[email protected]>
  • Loading branch information
sktt authored and wipawel committed Aug 30, 2023
1 parent 7c3c942 commit 9cf315a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions arch/x86/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ ENTRY(enter_usermode)
END_FUNC(enter_usermode)

ENTRY(syscall_handler_entry)
SAVE_ALL_REGS
SAVE_ALL_REGS include_ax=0
syscall_from_usermode

cmp $SYSCALL_EXIT, %_ASM_AX
Expand All @@ -219,12 +219,12 @@ ENTRY(syscall_handler_entry)
pop %_ASM_CX

syscall_to_usermode
RESTORE_ALL_REGS
RESTORE_ALL_REGS include_ax=0
SYSRET
END_FUNC(syscall_handler_entry)

ENTRY(sysenter_handler_entry)
SAVE_ALL_REGS
SAVE_ALL_REGS include_ax=0
syscall_from_usermode

MASK_USER_FLAGS
Expand All @@ -238,13 +238,13 @@ ENTRY(sysenter_handler_entry)
call syscall_handler

syscall_to_usermode
RESTORE_ALL_REGS
RESTORE_ALL_REGS include_ax=0

SYSEXIT
END_FUNC(sysenter_handler_entry)

ENTRY(int80_handler_entry)
SAVE_ALL_REGS
SAVE_ALL_REGS include_ax=0
syscall_from_usermode

MASK_USER_FLAGS
Expand All @@ -257,7 +257,7 @@ ENTRY(int80_handler_entry)
call syscall_handler

syscall_to_usermode
RESTORE_ALL_REGS
RESTORE_ALL_REGS include_ax=0
IRET
END_FUNC(int80_handler_entry)
GLOBAL(end_usermode_helpers)
Expand Down
8 changes: 6 additions & 2 deletions include/arch/x86/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@
pop %eax
.endm

.macro SAVE_ALL_REGS
.macro SAVE_ALL_REGS include_ax=1
.if \include_ax
push %_ASM_AX
.endif
push %_ASM_BX
push %_ASM_CX
push %_ASM_DX
Expand All @@ -108,7 +110,7 @@
#endif
.endm

.macro RESTORE_ALL_REGS
.macro RESTORE_ALL_REGS include_ax=1
#if defined(__x86_64__)
pop %r15
pop %r14
Expand All @@ -125,7 +127,9 @@
pop %_ASM_DX
pop %_ASM_CX
pop %_ASM_BX
.if \include_ax
pop %_ASM_AX
.endif
.endm

.macro SAVE_CALLEE_SAVED_REGS
Expand Down

0 comments on commit 9cf315a

Please sign in to comment.