summaryrefslogtreecommitdiff
path: root/kernel/cpu
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-02-07 11:36:21 +0100
committerAnton Kling <anton@kling.gg>2024-02-07 22:25:47 +0100
commit35958c8c6b600482f68fef08ac26547b5655e987 (patch)
treea3329136adc1b92885c60462e7dd74c98eaa0953 /kernel/cpu
parentb7fa1457727338416499d1b0144f1042a6878a97 (diff)
A lot of small changes
Diffstat (limited to 'kernel/cpu')
-rw-r--r--kernel/cpu/idt.c37
-rw-r--r--kernel/cpu/idt.h10
-rw-r--r--kernel/cpu/int_syscall.s3
-rw-r--r--kernel/cpu/syscall.c20
4 files changed, 52 insertions, 18 deletions
diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c
index 46782b5..f4d025a 100644
--- a/kernel/cpu/idt.c
+++ b/kernel/cpu/idt.c
@@ -69,11 +69,36 @@ __attribute__((interrupt)) void double_fault(registers_t *regs) {
for (;;)
;
}
+
+void tmp_jump_process(u32, u32, u32, u32);
+void jump_process(const process_t *p) {
+ // tmp_jump_process(p->eip, p->cr3->physical_address, p->ebp, p->esp);
+}
+
+void none_save_switch(void);
+extern PageDirectory *active_directory;
__attribute__((interrupt)) void page_fault(registers_t *regs) {
- if (0xFFFFDEAD == regs->eip) {
- asm("sti");
- for (;;)
- switch_task();
+ volatile uint32_t cr2;
+ asm volatile("mov %%cr2, %0" : "=r"(cr2));
+ kprintf("CR2: %x\n", cr2);
+ if (0xFFFFDEAD == cr2) {
+ /*
+ process_t *current = get_current_task();
+ if (!current) {
+ kprintf("WHYYYYYY!\n");
+ for (;;)
+ asm("cli");
+ }
+ current->useresp = regs->esp;*/
+ // active_directory = current->cr3;
+// get_current_task()->esp = get_current_task()->saved_esp;
+// get_current_task()->ebp = get_current_task()->saved_ebp;
+// get_current_task()->eip = get_current_task()->saved_eip;
+ for (;;) {
+ switch_task(0);
+ }
+ // jump_process(current);
+ return;
}
klog("Page Fault", LOG_ERROR);
if (get_current_task()) {
@@ -83,10 +108,6 @@ __attribute__((interrupt)) void page_fault(registers_t *regs) {
kprintf("Error Code: %x\n", regs->error_code);
kprintf("Instruction Pointer: %x\n", regs->eip);
- volatile uint32_t cr2;
- asm volatile("mov %%cr2, %0" : "=r"(cr2));
- kprintf("CR2: %x\n", cr2);
-
if (regs->error_code & (1 << 0))
kprintf("page-protection violation\n");
else
diff --git a/kernel/cpu/idt.h b/kernel/cpu/idt.h
index 9341887..fdd6a3e 100644
--- a/kernel/cpu/idt.h
+++ b/kernel/cpu/idt.h
@@ -55,13 +55,9 @@ typedef struct registers registers_t;
struct interrupt_frame;
struct registers {
- u32 error_code;
- u32 eip;
- u32 cs;
- u32 eflags;
- u32 esp;
- u32 ss;
-};
+ uintptr_t error_code;
+ uintptr_t eip, cs, eflags, esp, ss;
+} __attribute__((packed));
void idt_init(void);
__attribute__((no_caller_saved_registers)) void EOI(unsigned char irq);
diff --git a/kernel/cpu/int_syscall.s b/kernel/cpu/int_syscall.s
index 8c3c25f..ec7693a 100644
--- a/kernel/cpu/int_syscall.s
+++ b/kernel/cpu/int_syscall.s
@@ -2,6 +2,7 @@
.global int_syscall
.extern syscall_function_handler
int_syscall:
+ push esp
push ebp
push edi
push esi
@@ -10,7 +11,7 @@ int_syscall:
push ebx
push eax
call syscall_function_handler
- add esp, 4
+ add esp, 8
pop ebx
pop ecx
pop edx
diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c
index 3a2b1ca..5e51d53 100644
--- a/kernel/cpu/syscall.c
+++ b/kernel/cpu/syscall.c
@@ -7,6 +7,7 @@
#include <fs/tmpfs.h>
#include <fs/vfs.h>
#include <kmalloc.h>
+#include <network/ethernet.h>
#include <string.h>
#include <syscalls.h>
#include <typedefs.h>
@@ -35,6 +36,11 @@ int syscall_exec(SYS_EXEC_PARAMS *args) {
return -1;
}
+void syscall_tmp_handle_packet(void *packet, u32 len) {
+ kprintf("syscall tmp handle packet\n");
+ handle_ethernet((u8 *)packet, len);
+}
+
int syscall_pipe(int fd[2]) {
pipe(fd); // FIXME: Error checking
return 0;
@@ -75,7 +81,7 @@ void syscall_wait(int *status) {
return;
}
get_current_task()->halts[WAIT_CHILD_HALT] = 1;
- switch_task();
+ switch_task(1);
if (status)
*status = get_current_task()->child_rc;
}
@@ -159,10 +165,20 @@ void (*syscall_functions[])() = {
(void(*))syscall_ipc_read,
(void(*))syscall_ipc_write,
(void(*))syscall_ipc_write_to_process,
+ (void(*))syscall_outw,
+ (void(*))syscall_inl,
+ (void(*))syscall_outl,
+ (void(*))syscall_map_frames,
+ (void(*))syscall_virtual_to_physical,
+ (void(*))syscall_install_irq,
+ (void(*))syscall_tmp_handle_packet,
};
void syscall_function_handler(u32 eax, u32 arg1, u32 arg2, u32 arg3, u32 arg4,
- u32 arg5) {
+ u32 arg5, u32 ebp, u32 esp) {
+ if (esp <= 0x90000000) {
+ get_current_task()->useresp = esp;
+ }
assert(eax < sizeof(syscall_functions) / sizeof(syscall_functions[0]));
syscall_functions[eax](arg1, arg2, arg3, arg4, arg5);
}