MAJOR RESTRUCTURE

This commit is contained in:
2024-12-28 21:23:58 +01:00
parent 12b07a9f70
commit 2e0b030324
81 changed files with 1168 additions and 579 deletions
+9
View File
@@ -0,0 +1,9 @@
#include <syscalls/syscalls.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_close(intFrame_t* iframe) {
// TODO
return -1;
}
+9
View File
@@ -0,0 +1,9 @@
#include <syscalls/syscalls.h>
#include <drivers/serial.h>
#include <cpu/isr.h>
int sys_exit(intFrame_t* iframe) {
debugf("Tried to exit with %d", iframe->eax);
return iframe->eax;
}
+10
View File
@@ -0,0 +1,10 @@
#include <syscalls/syscalls.h>
#include <memory/malloc.h>
#include <cpu/isr.h>
int sys_free(intFrame_t* iframe) {
void* ptr = (void*)iframe->ebx;
mallocFree(ptr);
return 0;
}
+18
View File
@@ -0,0 +1,18 @@
#include <syscalls/syscalls.h>
#include <memory/malloc.h>
#include <cpu/isr.h>
#include <stddef.h>
int sys_malloc(intFrame_t* iframe) {
size_t count = iframe->ebx;
// First Malloc()
if (!mallocListHead) {
mallocInit(count); // Setup malloc linked list
}
void* ptr = mallocNextNode(count);
mallocMergeFree();
return (size_t)ptr;
}
+9
View File
@@ -0,0 +1,9 @@
#include <syscalls/syscalls.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_open(intFrame_t* iframe) {
// TODO
return -1;
}
+11
View File
@@ -0,0 +1,11 @@
#include <syscalls/syscalls.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_read(intFrame_t* iframe) {
char* s = (char*)iframe->ebx;
gets(s, 0xffffffff);
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
#include <syscalls/syscalls.h>
#include <cpu/isr.h>
int sys_seek(intFrame_t* iframe) {
// TODO
return -1;
}
+14
View File
@@ -0,0 +1,14 @@
#include <syscalls/syscalls.h>
#include <memory/addresses.h>
#include <cpu/isr.h>
#include <stdint.h>
int sys_sleep(intFrame_t* iframe) {
uint32_t* sleepTimerTicks = (uint32_t*)SLEEP_TIMER;
*sleepTimerTicks = iframe->ebx;
while (*sleepTimerTicks > 0) { __asm__ volatile ("sti; hlt"); }
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#include <syscalls/syscalls.h>
#include <screen/tty.h>
#include <cpu/isr.h>
#include <stddef.h>
int sys_write(intFrame_t* iframe) {
int fd = iframe->ebx;
void* buf = (void*)iframe->ecx;
size_t len = iframe->edx;
if (fd == 1) {
return consoleWrite(buf, len);
} else { return -1; }
}
+28
View File
@@ -0,0 +1,28 @@
#include <syscalls/syscalls.h>
#include <drivers/serial.h>
#include <cpu/isr.h>
#include <syscall.h>
// System call table
int (*syscalls[SYSCALL_COUNT])(intFrame_t*) = {
[SYS_EXIT] = sys_exit,
[SYS_READ] = sys_read,
[SYS_WRITE] = sys_write,
[SYS_OPEN] = sys_open,
[SYS_CLOSE] = sys_close,
[SYS_SEEK] = sys_seek,
[SYS_MALLOC] = sys_malloc,
[SYS_FREE] = sys_free,
[SYS_SLEEP] = sys_sleep,
};
// Syscall handler
int syscallHandler(intFrame_t* iframe) {
if (iframe->eax > SYSCALL_COUNT-1) { // Syscall doesn't exist
debugf("Error: Syscall(%d) does not exist!\n", iframe->eax);
return -1;
}
return syscalls[iframe->eax](iframe);
}