summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-09-02 18:11:49 +0200
committerMichal Idziorek <m.i@gmx.at>2014-09-02 18:11:49 +0200
commit779c5755f6ddcc8680a2b4a3fa3606d930309ecc (patch)
tree36437d59d94ea70b1bf8b34c890db5cb01100c68 /kernel
parent1e00cdb70f80705751a6f84266171654ed3ab523 (diff)
Finally Fix paging bug! Hooray!
Diffstat (limited to 'kernel')
-rw-r--r--kernel/console.c7
-rw-r--r--kernel/kernel.c63
-rw-r--r--kernel/mp.c2
-rw-r--r--kernel/vesa.c2
-rw-r--r--kernel/vmem.c16
-rw-r--r--kernel/x86.c7
6 files changed, 34 insertions, 63 deletions
diff --git a/kernel/console.c b/kernel/console.c
index 16cf04f..e06da45 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -1,7 +1,6 @@
#include "console.h"
-#define FOOLOS_CONSOLE
-//#undef FOOLOS_CONSOLE
+//#define FOOLOS_CONSOLE
static int posx=0;
static int posy=0;
@@ -10,11 +9,11 @@ static int posy=0;
void print_char_col(int x, int y, char c, char col)
{
-//#ifdef FOOLOS_CONSOLE
+#ifdef FOOLOS_CONSOLE
char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2;
video_mem[0]=c;
video_mem[1]=col;
-//#endif
+#endif
}
void print_char(int x, int y, char c)
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 429a286..373eea1 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,6 +1,7 @@
#define FOOLOS_MODULE_NAME "kernel"
#include "x86.h"
+#include "console.h"
#include "../lib/logger/log.h" // logger facilities
// TODO: WHHYY can i compile it without the includes!???
@@ -20,22 +21,20 @@ uint32_t read_eip();
//
// this is the very heart of our operating system!
//
-
void kernel_main(uint32_t initial_stack, int mp)
{
- volatile static uint32_t cpu1_counter=0;
// catch the APs (Application Processors)
- /*
if(mp==1)
{
- //while(1) { static uint16_t c=0; PutString("cpu2: %03d", 200,560,0b1111100000000000, (c++)/100); }
- while(1) { static uint16_t c=0; PutString("cpu1counter: %d", 200,560,0b1111100000000000, (cpu1_counter)); }
- }
- */
+ volatile static uint16_t proc=1;
+ int p=proc;
+ uint32_t cpu_counter=0;
+ while(1)PutString("mp: %d", 200,580,0b1111100000000000, (cpu_counter++));
+ }
//
// We want to get output to the screen as fast as possible!
@@ -67,31 +66,14 @@ void kernel_main(uint32_t initial_stack, int mp)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack);
//
- // Initialize other processors
+ // Initialize other processors (run this before entering paged mode)
//
// This currently uses the MP Floating Pointer Struct.
// Should support APCI in future too.
//
-
if(!init_mp()) panic(FOOLOS_MODULE_NAME,"Can not Find _MP_");
-
- //
- // Memory Init
- //
-
- // we know that here, the bootloader placed the mamory map!
- mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600)));
-
-
- // paging (pass the vesa physbase address for identity mapping)
- vmem_init(vesa_physbase);
-
- while(1) {
- PutString("cpu1counter: %d", 10,560,0b1111100000000000, (cpu1_counter));
- cpu1_counter++;
- }
//
// Setup PIC
//
@@ -101,14 +83,20 @@ void kernel_main(uint32_t initial_stack, int mp)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC.");
pic_setup();
- //while(1);
-
//
// Configuring the PIT timer.
//
timer_init();
+ //
+ // Memory Init
+ //
+
+ // we know that here, the bootloader placed the mamory map!
+ mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600)));
+ // paging (pass the vesa physbase address for identity mapping)
+ vmem_init(vesa_physbase);
//
// Interrupts
@@ -133,19 +121,7 @@ void kernel_main(uint32_t initial_stack, int mp)
int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler);
// now we can enable interrupts back again
-// int_enable();
-
- while(1) {
- cpu1_counter++;
- /*
- static uint16_t c=0;
- PutString("cpu1: A",20,560,0xffffff,0);
- for(int c2=0;c2<0xffff;c2++);
- PutString("cpu1: B",20,560,0xffffff,0);
- for(int c2=0;c2<0xffff;c2++);
- //PutString("cpu1: %03d", 20,560,0b1111100000000000, (c++)/100);
- */
- }
+ int_enable();
//
// Scan the PCI Bus
@@ -187,7 +163,12 @@ void kernel_main(uint32_t initial_stack, int mp)
// Just hang here.
//
- while(1);
+ while(1)
+ {
+ static uint32_t cpu1_counter=0;
+ PutString("cpu1counter: %d", 10,560,0b1111100000000000, (cpu1_counter++));
+ cpu1_counter++;
+ }
}
diff --git a/kernel/mp.c b/kernel/mp.c
index dd9fbd5..dece903 100644
--- a/kernel/mp.c
+++ b/kernel/mp.c
@@ -113,6 +113,8 @@ void show_mp_conf(mp_config *addr)
local_apic=addr->local_apic;
+
+
//bsp (boot processor) enables its local apic
uint32_t *reg=addr->local_apic+FOOLOS_APIC_SPUR_INT;
*reg=0xffffffff; // all bits 1 and interrupt 255
diff --git a/kernel/vesa.c b/kernel/vesa.c
index a3fc76c..e8b6269 100644
--- a/kernel/vesa.c
+++ b/kernel/vesa.c
@@ -37,7 +37,7 @@ typedef struct ModeInfoBlock {
uint8_t rsv_mask, rsv_position;
uint8_t directcolor_attributes;
- uint32_t physbase; // your LFB (Linear Framebuffer) address ;)
+ volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;)
uint32_t reserved1;
uint16_t reserved2;
}vbemodeinfo;
diff --git a/kernel/vmem.c b/kernel/vmem.c
index 741a1e8..cd6bc93 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -232,15 +232,15 @@ void vmem_init(uint32_t vesa_physbase)
//! create a new page
pt_entry page=0;
pt_entry_add_attrib (&page, I86_PTE_PRESENT);
+ pt_entry_add_attrib (&page, I86_PTE_WRITABLE);
pt_entry_set_frame (&page, frame);
//! ...and add it to the page table
table2->m_entries [PAGE_TABLE_INDEX (virt) ] = page;
}
- //! map 1mb to 3gb (where we are at)
-
- uint32_t vesa_mapped=0x1000*1024;
+ //uint32_t vesa_mapped=0x1000*1024;
+ uint32_t vesa_mapped=vesa_physbase;
for (int i=0, frame=vesa_physbase, virt=vesa_mapped; i<1024; i++, frame+=4096, virt+=4096)
{
@@ -248,7 +248,7 @@ void vmem_init(uint32_t vesa_physbase)
//! create a new page
pt_entry page=0;
pt_entry_add_attrib (&page, I86_PTE_PRESENT);
-// pt_entry_add_attrib (&page, I86_PTE_WRITABLE);
+ pt_entry_add_attrib (&page, I86_PTE_WRITABLE);
pt_entry_set_frame (&page, frame);
//! ...and add it to the page table
@@ -275,16 +275,10 @@ void vmem_init(uint32_t vesa_physbase)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"enabling paging...");
show_cr();
-
- // while(1);
x86_paging_enable();
- x86_paging_disable();
- x86_paging_enable();
- vesa_set_physbase(vesa_mapped);
- // x86_flush_tlb(0);
- // x86_flush_tlb(vesa_physbase);
+ vesa_set_physbase(vesa_mapped);
show_cr();
diff --git a/kernel/x86.c b/kernel/x86.c
index c1113bf..5e44424 100644
--- a/kernel/x86.c
+++ b/kernel/x86.c
@@ -88,11 +88,6 @@ void x86_paging_enable()
{
uint32_t cr0=x86_get_cr0();
cr0 |= 0x80000000; // enable paging
-
-// cr0 |= 0x40000000; // cahce disable
-// cr0 |= 0x20000000; // not-write-through
-// cr0 |= 0x10000; // write to read-only pages
-
asm volatile("mov %0, %%cr0":: "b"(cr0));
}
@@ -107,7 +102,7 @@ void x86_paging_disable()
void x86_flush_tlb(uint32_t addr)
{
- asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
}