Commit 8e231276 by malcolm

degbug and i dunno maybe i fixed something cr3 is wrong i know that plz help

parent 7907bdb5
#include "PCB.h" #include "PCB.h"
#include "serial.h" #include "serial.h"
#include "term.h" #include "term.h"
#include "idt.h"
#define NUM_SYSCALLS 256 #define NUM_SYSCALLS 256
#define NUM_PROCS 16 #define NUM_PROCS 16
...@@ -26,13 +27,19 @@ void settf(trapframe* tf) ...@@ -26,13 +27,19 @@ void settf(trapframe* tf)
void schedule() void schedule()
{ {
int old = curproc; int old = curproc;
curproc++; curproc=0;//++;
while(procs[curproc]==0 || procs[curproc]->state!=RUNNABLE) /*while(procs[curproc]==0 || procs[curproc]->state!=RUNNABLE)
{ {
curproc=(curproc<NUM_PROCS-1)?curproc+1:0; curproc=(curproc<NUM_PROCS-1)?curproc+1:0;
} }*/
serial_writestring("about to switch\n"); serial_writestring("about to switch\nto ctxt at: ");
//context_switch(&procs[old]->ctxt, procs[curproc]->ctxt); serial_hexword((uintptr_t)procs[curproc]->ctxt);
serial_writestring("\neip: ");
serial_hexword(procs[curproc]->ctxt->eip);
serial_writestring("\ncr3: ");
serial_hexword(procs[curproc]->ctxt->cr3);
serial_writestring("\n");
context_switch(&procs[old]->ctxt, procs[curproc]->ctxt);
serial_writestring("switched\n"); serial_writestring("switched\n");
//procs[old]->state=RUNNABLE; //procs[old]->state=RUNNABLE;
procs[curproc]->state=RUNNING; procs[curproc]->state=RUNNING;
......
...@@ -28,8 +28,8 @@ typedef struct//all regs in proc ...@@ -28,8 +28,8 @@ typedef struct//all regs in proc
uint32_t trap; uint32_t trap;
uint32_t mmm; //uint32_t mmm;
uint32_t why; //uint32_t why;
uint32_t err; uint32_t err;
......
...@@ -5,10 +5,14 @@ ...@@ -5,10 +5,14 @@
*/ */
#include "elf.h" #include "elf.h"
#include "idt.h"
void load_elf(elf_header* elf_start) void load_elf(elf_header* elf_start)
{ {
// The elf will get its own memory space. // The elf will get its own memory space.
serial_writestring("_elf_start entry: ");
serial_hexword((uintptr_t)elf_start->program_entry_position);
serial_writestring("\n");
page_directory_entry* pgdir = page_new_directory(); page_directory_entry* pgdir = page_new_directory();
void* highest_vpage = (void*)0; void* highest_vpage = (void*)0;
...@@ -65,12 +69,15 @@ void load_elf(elf_header* elf_start) ...@@ -65,12 +69,15 @@ void load_elf(elf_header* elf_start)
page_map(pgdir, highest_vpage + 0x2000); page_map(pgdir, highest_vpage + 0x2000);
// initial esp = highest_vpage + 0x1000 // initial esp = highest_vpage + 0x1000
process* pcb = kmalloc(sizeof(process) + sizeof(context) + sizeof(trapframe)); process* pcb = kmalloc(sizeof(process));// + sizeof(context) + sizeof(trapframe));
pcb->ctxt = (context*)((size_t)pcb + sizeof(process)); //pcb->ctxt = (context*)((size_t)pcb + sizeof(process));
pcb->tf = (trapframe*)((size_t)pcb + sizeof(process) + sizeof(context)); //pcb->tf = (trapframe*)((size_t)pcb + sizeof(process) + sizeof(context));
// And of course, a kstack // And of course, a kstack
pcb->kstack = (char*)kmalloc(0x1000); pcb->kstack = (char*)kmalloc(0x1000);
pcb->tf = (trapframe*)(pcb->kstack);// + sizeof(trapframe));
pcb->ctxt = (context*)(pcb->tf + sizeof(trapframe));//sizeof(context));
pcb->mem = pgdir; pcb->mem = pgdir;
pcb->pid = -1; pcb->pid = -1;
...@@ -79,13 +86,15 @@ void load_elf(elf_header* elf_start) ...@@ -79,13 +86,15 @@ void load_elf(elf_header* elf_start)
//pcb->name = "debugstuff"; //pcb->name = "debugstuff";
pcb->state = RUNNABLE; pcb->state = RUNNABLE;
pcb->ctxt->cr3 = pgdir; pcb->ctxt->cr3 = (uintptr_t)pgdir;
pcb->ctxt->edi = 0; pcb->ctxt->edi = 0;
pcb->ctxt->esi = 0; pcb->ctxt->esi = 0;
pcb->ctxt->ebx = 0; pcb->ctxt->ebx = 0;
pcb->ctxt->ebp = (uint32_t)highest_vpage + 0x1000; pcb->ctxt->ebp = (uintptr_t)pcb->tf;//(uint32_t)highest_vpage + 0x1000;
pcb->ctxt->eip = (uint32_t)elf_start->program_entry_position; pcb->ctxt->eip = (uintptr_t)default_handler;//(uint32_t)elf_start->program_entry_position;
pcb->tf->eax = 4;
pcb->tf->trap = 0x80;
pcb->tf->ebp = (uint32_t)highest_vpage + 0x1000; pcb->tf->ebp = (uint32_t)highest_vpage + 0x1000;
pcb->tf->eip = (uint32_t)elf_start->program_entry_position; pcb->tf->eip = (uint32_t)elf_start->program_entry_position;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
#ifndef _ELF_INC #ifndef _ELF_INC
#define _ELF_INT #define _ELF_INC
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
......
...@@ -86,7 +86,9 @@ void kernel_main(multiboot_info* mbt, uint32_t magic) ...@@ -86,7 +86,9 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
pit_init(); pit_init();
pit_start_counter(100, PIT_OCW_CONT_0, PIT_OCW_MODE_SQWVGEN); pit_start_counter(100, PIT_OCW_CONT_0, PIT_OCW_MODE_SQWVGEN);
serial_writestring("enabling interrupts\n"); serial_writestring("_kernel_end: ");
serial_hexword((uintptr_t)&_kernel_end);
serial_writestring("\nenabling interrupts\n");
enable_int(); enable_int();
......
...@@ -53,6 +53,10 @@ void* page_allocate() ...@@ -53,6 +53,10 @@ void* page_allocate()
*index = *index | (1<<i); *index = *index | (1<<i);
uint32_t page_number = ((uint32_t)(index - (uint8_t*)_kernel_end) * 8) + (8-i); uint32_t page_number = ((uint32_t)(index - (uint8_t*)_kernel_end) * 8) + (8-i);
//serial_hexword(page_number);
//serial_writestring(" page allocated at address ");
//serial_hexword((uintptr_t)(void*)&_kernel_end + 0x1000 * page_number);
//serial_writestring("\n");
return (void*)&_kernel_end + 0x1000 * page_number; return (void*)&_kernel_end + 0x1000 * page_number;
} }
......
...@@ -10,6 +10,10 @@ context_switch: ...@@ -10,6 +10,10 @@ context_switch:
mov ecx, cr3 mov ecx, cr3
push ecx push ecx
; CR3 PROBLEM - STACK CHANGES, CANT ACCESS NEW MEM?
; WHY IS PROCS[CURPROC]->CTXT IN PROCESS MEM, NOT
; IN KERNEL MEM? INTERROGATE FREMMA
mov [eax], esp mov [eax], esp
mov esp, edx mov esp, edx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment