summaryrefslogtreecommitdiff
path: root/src/kernel/arch
diff options
context:
space:
mode:
authordzwdz2021-07-24 18:53:34 +0200
committerdzwdz2021-07-24 18:53:34 +0200
commitae9c1d1b16061242068353ff9064c8c9ef63b577 (patch)
tree59c91ac4d15d8231cab1174b7402128ce895fb0f /src/kernel/arch
parentb0690678bef7d51bbdadce6b606c835ce76d4d92 (diff)
sysexit() now overrides all registers
when doing anything more complex than starting a new program, you pretty much need to pass a full register dump. otherwise stuff will break
Diffstat (limited to 'src/kernel/arch')
-rw-r--r--src/kernel/arch/generic.h2
-rw-r--r--src/kernel/arch/i386/registers.h6
-rw-r--r--src/kernel/arch/i386/sysenter.c21
-rw-r--r--src/kernel/arch/i386/sysenter.s12
4 files changed, 34 insertions, 7 deletions
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h
index f208aa3..d5f8b3c 100644
--- a/src/kernel/arch/generic.h
+++ b/src/kernel/arch/generic.h
@@ -16,7 +16,7 @@ __attribute__((noreturn))
void halt_cpu();
// src/arch/i386/sysenter.s
-void sysexit(void (*fun)(), void *stack_top);
+void sysexit(struct registers);
int syscall_handler(int, int, int, int);
// all of those can allocate memory
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