C userspace programs
This commit is contained in:
@ -11,6 +11,8 @@
|
||||
#include "apic.h"
|
||||
#include "pit.h"
|
||||
#include "proc/proc.h"
|
||||
#include "syscall/syscall.h"
|
||||
#include "errors.h"
|
||||
|
||||
void hal_intr_disable(void) {
|
||||
asm volatile("cli");
|
||||
@ -122,6 +124,9 @@ void intr_init(void) {
|
||||
MKINTR(45, 0);
|
||||
MKINTR(46, 0);
|
||||
MKINTR(47, 0);
|
||||
|
||||
extern void intr_vec128(void);
|
||||
idt_setentry(0x80, (uint64_t)&intr_vec128, 0, 0xEE);
|
||||
|
||||
idt_init();
|
||||
}
|
||||
@ -149,14 +154,33 @@ void intr_dumpframe(IntrStackFrame *frame) {
|
||||
);
|
||||
}
|
||||
|
||||
void hal_syscalldispatch(IntrStackFrame *frame) {
|
||||
uint64_t sysnum = frame->regs.rax;
|
||||
if (sysnum < SYSCALLS_MAX) {
|
||||
SyscallFn fn = SYSCALL_TABLE[sysnum];
|
||||
if (fn == NULL) {
|
||||
frame->regs.rax = E_BADSYSCALL;
|
||||
return;
|
||||
}
|
||||
int32_t ret = fn(frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
|
||||
frame->regs.r10, frame->regs.r8, frame->regs.r9);
|
||||
|
||||
if (sysnum == SYS_QUITPROC) {
|
||||
proc_sched((void *)frame);
|
||||
}
|
||||
frame->regs.rax = *(uint64_t *)&ret;
|
||||
}
|
||||
}
|
||||
|
||||
void intr_handleintr(IntrStackFrame *frame) {
|
||||
if (frame->trapnum <= 31) {
|
||||
kprintf("ERROR %s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
|
||||
intr_dumpframe(frame);
|
||||
if (frame->trapnum == 14 && frame->errnum & 0x4) {
|
||||
kprintf("killed pid %ld %s\n", PROCS.current->pid, PROCS.current->name);
|
||||
proc_killself();
|
||||
proc_sched((void *)frame);
|
||||
}
|
||||
kprintf("ERROR %s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
|
||||
intr_dumpframe(frame);
|
||||
hal_hang();
|
||||
} else if (frame->trapnum >= 32 && frame->trapnum <= 47) {
|
||||
if (frame->trapnum == INTR_TIMER) {
|
||||
@ -167,6 +191,8 @@ void intr_handleintr(IntrStackFrame *frame) {
|
||||
lapic_write(LAPIC_EOI, 0x00);
|
||||
|
||||
proc_sched((void *)frame);
|
||||
} else if (frame->trapnum == 0x80) {
|
||||
hal_syscalldispatch(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user