still fighting an issue
This commit is contained in:
@@ -33,7 +33,7 @@ init_pic:
|
||||
outb %al, $PIC2_DATA
|
||||
|
||||
# mask
|
||||
mov $0xFF, %al
|
||||
mov $0xFE, %al
|
||||
outb %al, $PIC1_DATA
|
||||
mov $0xFF, %al
|
||||
outb %al, $PIC2_DATA
|
||||
|
||||
@@ -41,11 +41,12 @@ ISR_ERRCODE 14 # Page Fault (Has Error Code!)
|
||||
// This is a special case so we need to handle it for task switching
|
||||
.global isr32
|
||||
.extern switch_context # scheduler.c
|
||||
.extern send_eoi_master # drivers/pic/pic.c
|
||||
.extern send_eoi_master # drivers/pic/pic.S
|
||||
isr32:
|
||||
cli
|
||||
pushal
|
||||
|
||||
xorl %eax, %eax
|
||||
movw %ds, %ax
|
||||
pushl %eax
|
||||
|
||||
@@ -54,13 +55,13 @@ isr32:
|
||||
movw %ax, %es
|
||||
movw %ax, %fs
|
||||
movw %ax, %gs
|
||||
|
||||
call send_eoi_master
|
||||
|
||||
pushl %esp
|
||||
call switch_context
|
||||
movl %eax, %esp
|
||||
|
||||
call send_eoi_master
|
||||
|
||||
popl %eax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <lib/print.h>
|
||||
|
||||
#include "syscall.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <drivers/pic/pic.h>
|
||||
#include <drivers/ps2/ps2.h>
|
||||
@@ -110,7 +111,14 @@ void common_interrupt_handler(registers *args) {
|
||||
case 13:
|
||||
case 15:
|
||||
case 16:
|
||||
kprintf("CPU Error: %s, %d\n", err_messages[args->int_no], args->error_code);
|
||||
kprintf("CPU Error: [%d]%s\n", args->int_no, err_messages[args->int_no]);
|
||||
kprintf("Error Code: 0x%x\n", args->error_code);
|
||||
kprintf("Instruction Pointer: 0x%x\n", args->eip);
|
||||
kprintf("Stack Pointer: 0x%x\n", args->useresp);
|
||||
kprintf("EAX: 0x%x\n", args->eax);
|
||||
kprintf("EFLAGS: 0x%x\n", args->eflags);
|
||||
kprintf("cr3: 0x%x\n", fetch_cr3());
|
||||
while(1);
|
||||
break;
|
||||
case 14:{
|
||||
uint32_t faulting_address;
|
||||
|
||||
@@ -59,6 +59,7 @@ vfs_node_t* load_initrd() {
|
||||
void load_root_program(const char* path) {
|
||||
uint32_t kernel_cr3 = fetch_cr3();
|
||||
void* cr3 = create_task_pd();
|
||||
kprintf("new task cr3 0x%x\n", cr3);
|
||||
load_pd(cr3);
|
||||
flush_tlb();
|
||||
|
||||
@@ -131,7 +132,7 @@ void load_root_program(const char* path) {
|
||||
create_task(e_hdr->e_entry, (uint32_t)cr3, 1, (uint32_t)u_esp);
|
||||
|
||||
load_pd((void*)kernel_cr3);
|
||||
flush_tlb();
|
||||
flush_tlb();
|
||||
}
|
||||
|
||||
void kmain(uint32_t magic, multiboot_info* mbi) {
|
||||
@@ -171,6 +172,5 @@ void kmain(uint32_t magic, multiboot_info* mbi) {
|
||||
init_scheduler();
|
||||
enable_interrupts();
|
||||
|
||||
kprintf("loading origin program\n");
|
||||
load_root_program("/origin.elf");
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@ static process_t* process_table;
|
||||
static int current_process = 0;
|
||||
static int total_processes = 0;
|
||||
|
||||
#define IDLE_TASK_PID 1
|
||||
static void idle_task() {
|
||||
while (1) asm volatile("hlt");
|
||||
}
|
||||
#define IDLE_TASK_PID 0
|
||||
|
||||
static void lock_scheduler() {
|
||||
disable_interrupts();
|
||||
@@ -94,8 +91,6 @@ void init_scheduler() {
|
||||
process->flags = PROCESS_FLAG_KERNEL;
|
||||
total_processes++;
|
||||
|
||||
create_task((uint32_t)idle_task, fetch_cr3(), 0, 0);
|
||||
|
||||
current_process = 0;
|
||||
}
|
||||
|
||||
@@ -131,15 +126,13 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
|
||||
uint32_t* esp = (uint32_t*)kstack_top;
|
||||
if (user) {
|
||||
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
|
||||
*(--esp) = u_esp; // User Stack Pointer (ESP) - location mapped in user space
|
||||
*(--esp) = u_esp; // User Stack Pointer (ESP) - location mapped in user space
|
||||
*(--esp) = 0x0202; // EFLAGS (Interrupts enabled)
|
||||
*(--esp) = 0x1B; // User Code Segment (CS) with RPL 3 (0x18 | 3)
|
||||
*(--esp) = entry_point; // EIP
|
||||
*(--esp) = 0x23;
|
||||
} else {
|
||||
// IRET values for Ring 0
|
||||
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
|
||||
*(--esp) = kstack_top; // User Stack Pointer (ESP) - location mapped in user space
|
||||
*(--esp) = 0x0202; // EFLAGS
|
||||
*(--esp) = 0x08; // Kernel Code Segment (CS)
|
||||
*(--esp) = entry_point; // EIP
|
||||
@@ -155,12 +148,6 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
|
||||
*(--esp) = 0; // ESI
|
||||
*(--esp) = 0; // EDI
|
||||
|
||||
if (user) {
|
||||
*(--esp) = 0x23; // User Data Segment
|
||||
} else {
|
||||
*(--esp) = 0x10; // Kernel Data Segment
|
||||
}
|
||||
|
||||
process->esp = (uint32_t)esp;
|
||||
if (!reuse) {
|
||||
total_processes++;
|
||||
|
||||
Reference in New Issue
Block a user