diff options
author | Anton Kling <anton@kling.gg> | 2024-03-14 13:09:59 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-03-14 13:09:59 +0100 |
commit | 2e8b474d4219e7faaac3823e73c8d528c2698a37 (patch) | |
tree | 7d93b5fd220e8b703ba69f9b55122d15c9d619fb /kernel/cpu | |
parent | 051ac9f1941e8bc6ad87beccb61a2d53111ba8ea (diff) |
random changes made
Diffstat (limited to 'kernel/cpu')
-rw-r--r-- | kernel/cpu/idt.c | 8 | ||||
-rw-r--r-- | kernel/cpu/int_syscall.s | 1 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 56 |
3 files changed, 42 insertions, 23 deletions
diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 805eb20..0d031f3 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -74,9 +74,9 @@ void page_fault(reg_t *regs) { } klog("Page Fault", LOG_ERROR); kprintf("CR2: %x\n", cr2); - if (get_current_task()) { - kprintf("PID: %x\n", get_current_task()->pid); - kprintf("Name: %s\n", get_current_task()->program_name); + if (current_task) { + kprintf("PID: %x\n", current_task->pid); + kprintf("Name: %s\n", current_task->program_name); } kprintf("Error Code: %x\n", regs->error_code); kprintf("Instruction Pointer: %x\n", regs->eip); @@ -101,7 +101,7 @@ void page_fault(reg_t *regs) { kprintf("Attempted instruction fetch\n"); } - dump_backtrace(12); + dump_backtrace(8); halt(); } diff --git a/kernel/cpu/int_syscall.s b/kernel/cpu/int_syscall.s index 5fff75b..4d0ef2e 100644 --- a/kernel/cpu/int_syscall.s +++ b/kernel/cpu/int_syscall.s @@ -2,7 +2,6 @@ .global int_syscall .extern syscall_functions int_syscall: -sti push ebp mov ebp,esp push edi diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 193367e..c982648 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -9,6 +9,7 @@ #include <interrupts.h> #include <kmalloc.h> #include <network/ethernet.h> +#include <socket.h> #include <string.h> #include <syscalls.h> #include <typedefs.h> @@ -73,22 +74,24 @@ void syscall_exit(int status) { void syscall_wait(int *status) { disable_interrupts(); - if (!get_current_task()->child) { + if (!current_task->child) { if (status) { *status = -1; } return; } - if (get_current_task()->child->dead) { + if (current_task->child->dead) { if (status) { - *status = get_current_task()->child_rc; + *status = current_task->child_rc; } return; } - get_current_task()->halts[WAIT_CHILD_HALT] = 1; - switch_task(); + do { + current_task->halts[WAIT_CHILD_HALT] = 1; + switch_task(); + } while (current_task->halts[WAIT_CHILD_HALT]); if (status) { - *status = get_current_task()->child_rc; + *status = current_task->child_rc; } } @@ -97,25 +100,24 @@ int syscall_fork(void) { } int syscall_getpid(void) { - return get_current_task()->pid; + return current_task->pid; } void *align_page(void *a); int syscall_brk(void *addr) { - void *end = get_current_task()->data_segment_end; + void *end = current_task->data_segment_end; if (!mmu_allocate_region(end, addr - end, MMU_FLAG_RW, NULL)) { return -ENOMEM; } - get_current_task()->data_segment_end = align_page(addr); + current_task->data_segment_end = align_page(addr); return 0; } void *syscall_sbrk(uintptr_t increment) { disable_interrupts(); - void *rc = get_current_task()->data_segment_end; - void *n = - (void *)((uintptr_t)(get_current_task()->data_segment_end) + increment); + void *rc = current_task->data_segment_end; + void *n = (void *)((uintptr_t)(current_task->data_segment_end) + increment); int rc2; if (0 > (rc2 = syscall_brk(n))) { return (void *)rc2; @@ -128,11 +130,26 @@ int syscall_close(int fd) { } int syscall_openpty(SYS_OPENPTY_PARAMS *args) { - assert(is_valid_userpointer(args, sizeof(SYS_OPENPTY_PARAMS))); + assert(mmu_is_valid_userpointer(args, sizeof(SYS_OPENPTY_PARAMS))); return openpty(args->amaster, args->aslave, args->name, args->termp, args->winp); } +u32 syscall_tcp_connect(u32 ip, u16 port, int *error) { + // TODO: Make sure error is a user address + return tcp_connect_ipv4(ip, port, error); +} + +int syscall_tcp_write(u32 socket, const u8 *buffer, u32 len, u64 *out) { + // TODO: Make sure out is a user address + return tcp_write(socket, buffer, len, out); +} + +int syscall_tcp_read(u32 socket, u8 *buffer, u32 buffer_size, u64 *out) { + // TODO: Make sure out is a user address + return tcp_read(socket, buffer, buffer_size, out); +} + int (*syscall_functions[])() = { (void(*))syscall_open, (void(*))syscall_read, @@ -180,14 +197,17 @@ int (*syscall_functions[])() = { (void(*))syscall_virtual_to_physical, (void(*))syscall_install_irq, (void(*))syscall_tmp_handle_packet, + + (void(*))syscall_tcp_connect, + (void(*))syscall_tcp_write, + (void(*))syscall_tcp_read, + + (void(*))syscall_queue_create, + (void(*))syscall_queue_add, + (void(*))syscall_queue_wait, }; void int_syscall(reg_t *r); -void syscall_function_handler(u32 eax, u32 arg1, u32 arg2, u32 arg3, u32 arg4, - u32 arg5, u32 ebp, u32 esp) { - assert(eax < sizeof(syscall_functions) / sizeof(syscall_functions[0])); - syscall_functions[eax](arg1, arg2, arg3, arg4, arg5); -} void syscalls_init(void) { install_handler(int_syscall, INT_32_INTERRUPT_GATE(0x3), 0x80); |