mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-04 02:23:10 +00:00
Major interrupt change
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int sys_close(intFrame_t* iframe) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <error/debug.h>
|
||||
|
||||
int sys_exit(intFrame_t* iframe) {
|
||||
debugf("Tried to exit with %d", iframe->eax);
|
||||
return iframe->eax;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <memory/malloc.h>
|
||||
|
||||
int sys_free(intFrame_t* iframe) {
|
||||
void* ptr = (void*)iframe->ebx;
|
||||
mallocFree(ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <memory/malloc.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;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int sys_open(intFrame_t* iframe) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int sys_read(intFrame_t* iframe) {
|
||||
char* s = (char*)iframe->ebx;
|
||||
reads(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
|
||||
int sys_seek(intFrame_t* iframe) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <memory/addresses.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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <tty/tty.h>
|
||||
#include <interrupt/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; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <syscalls/syscalls.h>
|
||||
#include <interrupt/isr.h>
|
||||
#include <error/debug.h>
|
||||
#include <syscall.h>
|
||||
|
||||
// System call table
|
||||
int (*syscalls[MAX_SYSCALLS])(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 > MAX_SYSCALLS-1) { // Syscall doesn't exist
|
||||
debugf("Error: Syscall(%d) does not exist!\n", iframe->eax);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return syscalls[iframe->eax](iframe);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user