This is a rather large commit, so the gist of it is this: User context switching is now functional, after a change to the TSS, and a few minor details in the scheduler and loader. ELF parsing is rather primitive, but basically functional, as long as it only loads code. The interrupt 0x80 is for syscalls, and will switch from user mode to kernel mode. It is currently the only interrupt that can be called from user mode This adds the syscall functionality, which currently uses a red-black tree to store the function pointers, although when the table is more flushed out, it will probably be replaced with an array The pager now correctly marks the parent nodes with attributes as it allocates them. Without doing this, the page table entries will never be reached in lower privilege modes, causing page faults Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
57 lines
926 B
C
57 lines
926 B
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#include <kernel/common.h>
|
|
#include <kernel/pio.h>
|
|
#include <kernel/proc.h>
|
|
#include <dev/pic.h>
|
|
|
|
void pic_mask(uint8_t irq, uint8_t i)
|
|
{
|
|
uint16_t port;
|
|
uint8_t val;
|
|
|
|
i = !(!i);
|
|
|
|
if (irq < 8) {
|
|
port = PIC1_DATA;
|
|
} else {
|
|
port = PIC2_DATA;
|
|
irq -= 8;
|
|
}
|
|
|
|
val = inb(port) & ~(1 << irq);
|
|
val |= (i << irq);
|
|
|
|
outb(port, val);
|
|
}
|
|
|
|
void pic_eoi(uint8_t irq)
|
|
{
|
|
if (irq > 8)
|
|
outb(PIC2_CMD, 0x20);
|
|
|
|
outb(PIC1_CMD, 0x20);
|
|
}
|
|
|
|
void exception(int vector, int error)
|
|
{
|
|
kprintf(LOG_WARN "EXCEPTION: %x, error code: %d\n", vector, error);
|
|
pid_t pid = getpid();
|
|
|
|
struct proc *proc = proc_find(pid);
|
|
|
|
if (proc->is_kernel) {
|
|
kprintf(LOG_ERROR "Kernel process %d crashed\n", pid);
|
|
panic();
|
|
} else {
|
|
proc_term(pid);
|
|
kprintf(LOG_WARN "Process %d terminated\n", pid);
|
|
yield();
|
|
}
|
|
}
|
|
|
|
void pic_init()
|
|
{
|
|
/* disable the PIC */
|
|
outb(PIC1_DATA, 0xFF);
|
|
outb(PIC2_DATA, 0xFF);
|
|
}
|