Ensure SS and ESP are saved in trap frame
Some checks failed
Builds / ExectOS (amd64, release) (push) Successful in 36s
Builds / ExectOS (amd64, debug) (push) Failing after 45s
Builds / ExectOS (i686, debug) (push) Successful in 35s
Builds / ExectOS (i686, release) (push) Successful in 42s

This commit is contained in:
2026-03-15 00:33:09 +01:00
parent 428928c7e1
commit 6cdb66cbb3
2 changed files with 13 additions and 2 deletions

View File

@@ -75,12 +75,20 @@ _ArTrap\Vector:
/* Test previous mode and swap GS if needed */ /* Test previous mode and swap GS if needed */
movl $0, TrapPreviousMode(%ebp) movl $0, TrapPreviousMode(%ebp)
mov %cs, %ax mov %cs, %ax
and $1, %al and $3, %al
mov %al, TrapPreviousMode(%ebp) mov %al, TrapPreviousMode(%ebp)
jz KernelMode$\Vector jz KernelMode$\Vector
swapgs swapgs
jmp UserMode$\Vector
KernelMode$\Vector: KernelMode$\Vector:
/* Save kernel stack pointer (SS:ESP) as CPU did not push them */
movl %ss, %eax
mov %eax, TrapSegSs(%ebp)
lea TrapEsp(%ebp), %eax
mov %eax, TrapEsp(%ebp)
UserMode$\Vector:
/* Push Frame Pointer, clear direction flag and pass to trap dispatcher */ /* Push Frame Pointer, clear direction flag and pass to trap dispatcher */
push %esp push %esp
cld cld
@@ -100,6 +108,7 @@ KernelModeReturn$\Vector:
mov TrapSegDs(%ebp), %ds mov TrapSegDs(%ebp), %ds
mov TrapSegEs(%ebp), %es mov TrapSegEs(%ebp), %es
mov TrapSegFs(%ebp), %fs mov TrapSegFs(%ebp), %fs
mov TrapSegGs(%ebp), %gs
/* Free stack space */ /* Free stack space */
add $(TRAP_FRAME_SIZE - TRAP_REGISTERS_SIZE), %esp add $(TRAP_FRAME_SIZE - TRAP_REGISTERS_SIZE), %esp

View File

@@ -24,9 +24,11 @@
#define TrapSegEs 38 #define TrapSegEs 38
#define TrapSegFs 40 #define TrapSegFs 40
#define TrapSegGs 42 #define TrapSegGs 42
#define TrapEsp 92
#define TrapSegSs 96
/* KTRAP_FRAME length related definitions */ /* KTRAP_FRAME length related definitions */
#define TRAP_FRAME_SIZE 100 #define TRAP_FRAME_SIZE 100
#define TRAP_REGISTERS_SIZE 56 #define TRAP_REGISTERS_SIZE 56
#endif /* __XTOSKRNL_AMD64_ASMSUP_H */ #endif /* __XTOSKRNL_I686_ASMSUP_H */