kernel: Patches to run processes in Ring 3.
This commit is contained in:
parent
8f6399e309
commit
e6a2c1e240
10 changed files with 271 additions and 22 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <stdint.h>
|
||||
#include <sys/arch/x86_64/gdt.h>
|
||||
#include <sys/log.h>
|
||||
#include <mm/memop.h>
|
||||
|
||||
gdt_table def_table = {
|
||||
{
|
||||
|
@ -25,10 +26,10 @@ gdt_table def_table = {
|
|||
|
||||
tssr tss_list[256]; // One tssr per CPU
|
||||
|
||||
void gdt_init() {
|
||||
void gdt_init( char* kstack ) {
|
||||
|
||||
// TODO: adapt for multiprocessor kernel
|
||||
tss_list[0].iopb = sizeof(tssr);
|
||||
tss_list[0].rsp[0] = (uint64_t)kstack;
|
||||
uintptr_t tss = (uintptr_t)&tss_list[0];
|
||||
|
||||
def_table.tss_entry.length = sizeof(tss_entry);
|
||||
|
|
|
@ -26,7 +26,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t resv;
|
||||
uint64_t rsp[3];
|
||||
uint64_t rsp[4];
|
||||
uint64_t resv1;
|
||||
uint64_t ist[7];
|
||||
uint64_t resv2;
|
||||
|
@ -34,4 +34,4 @@ typedef struct {
|
|||
uint16_t iopb;
|
||||
} __attribute__((packed)) tssr; // Per CPU
|
||||
|
||||
void gdt_init();
|
||||
void gdt_init(char* kstack);
|
|
@ -29,10 +29,16 @@ void idt_init() {
|
|||
idtr.limit = (uint16_t)sizeof(idt_entry_t) * 256 - 1;
|
||||
|
||||
for (uint16_t vector = 0; vector <= 256; vector++) {
|
||||
if (vector == 0x80)
|
||||
continue; // We skip the syscall handler, since it should be called from user space.
|
||||
idt_set_descriptor(vector, isr_stub_table[vector], 0x8E);
|
||||
vectors[vector] = 1;
|
||||
}
|
||||
|
||||
uint16_t vector = 0x80;
|
||||
idt_set_descriptor(vector, isr_stub_table[vector], 0xEE);
|
||||
vectors[vector] = 1;
|
||||
|
||||
pic_init();
|
||||
pic_unmask_irq(1);
|
||||
|
||||
|
|
|
@ -39,6 +39,14 @@ void exception_handler(registers_t *regs) {
|
|||
if (regs->int_no < 32) {
|
||||
//panic(kmode_cpu_exception, regs);
|
||||
log("ints - %d (RIP: %p, ERR: %d)\n", regs->int_no, regs->rip, regs->err_code);
|
||||
|
||||
if(regs->int_no == 0xe) {
|
||||
uint64_t cr2;
|
||||
asm ("mov %%cr2, %0" : "=r"(cr2));
|
||||
log("ints - PF: Faulting location: %p\n", cr2);
|
||||
log("ints - PF: Faulting page flags: %p\n", vmm_get_flags(vmm_current_pm, cr2));
|
||||
}
|
||||
|
||||
dump_backtrace(regs);
|
||||
asm ("cli");
|
||||
while (1)
|
||||
|
@ -63,7 +71,9 @@ void exception_handler(registers_t *regs) {
|
|||
}
|
||||
else if (regs->int_no == 0x80)
|
||||
{
|
||||
log("syscall - Hello World! Current process: %s", curr_proc->name);
|
||||
log("syscall - Hello World! Current process: %s\n", curr_proc->name);
|
||||
if (curr_proc->flags == SCHED_USER_PROCESS)
|
||||
log("syscall - Btw we made it to userspace, baby!\n", curr_proc->name);
|
||||
}
|
||||
//logln(info, "arch/ints", "Received interrupt %d\n", regs->int_no);
|
||||
pic_ack(regs->int_no - 32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue