diff options
Diffstat (limited to 'src/kernel/arch/i386')
-rw-r--r-- | src/kernel/arch/i386/registers.h | 6 | ||||
-rw-r--r-- | src/kernel/arch/i386/sysenter.c | 21 | ||||
-rw-r--r-- | src/kernel/arch/i386/sysenter.s | 12 |
3 files changed, 33 insertions, 6 deletions
diff --git a/src/kernel/arch/i386/registers.h b/src/kernel/arch/i386/registers.h index feba157..1264139 100644 --- a/src/kernel/arch/i386/registers.h +++ b/src/kernel/arch/i386/registers.h @@ -1,11 +1,17 @@ #pragma once #include <stdint.h> +// TODO merge registers and registers_pushad + struct registers { uint32_t eax, ebx, ecx, edx, esi, edi; void *ebp, *esp, *eip; }; +struct registers_pushad { + uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; +} __attribute__((__packed__)); + // saves a return value according to the SysV ABI inline void regs_savereturn(struct registers *regs, uint64_t value) { regs->eax = value; diff --git a/src/kernel/arch/i386/sysenter.c b/src/kernel/arch/i386/sysenter.c index 91dac2e..f3f5987 100644 --- a/src/kernel/arch/i386/sysenter.c +++ b/src/kernel/arch/i386/sysenter.c @@ -1,6 +1,27 @@ #include <kernel/arch/generic.h> #include <kernel/proc.h> +struct registers_pushad _sysexit_regs; // a hack + +extern void _sysexit_real(); + +void sysexit(struct registers regs) { + _sysexit_regs = (struct registers_pushad) { + .eax = regs.eax, + .ebx = regs.ebx, + .ebp = regs.ebp, + .esi = regs.esi, + .edi = regs.edi, + + // sysexit args + .ecx = regs.esp, + .edx = regs.eip, + + // ESP doesn't matter + }; + _sysexit_real(); +} + void sysenter_stage2(int edi, int esi, void *ebp, void *esp, int ebx, int edx, int ecx, int eax) { diff --git a/src/kernel/arch/i386/sysenter.s b/src/kernel/arch/i386/sysenter.s index a982dd8..24cbc89 100644 --- a/src/kernel/arch/i386/sysenter.s +++ b/src/kernel/arch/i386/sysenter.s @@ -8,12 +8,9 @@ .set IA32_SYSENTER_EIP, 0x176 .section .text -.global sysexit -.type sysexit, @function -sysexit: - mov 4(%esp), %edx - mov 8(%esp), %ecx - +.global _sysexit_real +.type _sysexit_real, @function +_sysexit_real: mov $(SEG_r3data << 3 | 3), %ax mov %ax, %ds mov %ax, %es @@ -25,6 +22,9 @@ sysexit: or $0x80000000, %eax mov %eax, %cr0 + // restore the registers + mov $_sysexit_regs, %esp + popal // probably a bad idea sysexit |