Skip to content

Commit

Permalink
Paging test: identity map first 16MiB
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgian committed Jun 20, 2023
1 parent 35dead3 commit e0d425e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
27 changes: 25 additions & 2 deletions kernel/src/main.rs
Expand Up @@ -9,6 +9,7 @@ mod interrupts;
mod shell;
mod syscalls;
mod task;
mod paging;

use core::arch::asm;
use core::panic::PanicInfo;
Expand All @@ -18,6 +19,8 @@ use filesystem::fat::FAT;
use interrupts::idt::IDT;
use shell::SHELL;
use syscalls::print::PRINTER;
use paging::PAGING;
use paging::PageTable;

use libfelix;

Expand All @@ -42,6 +45,26 @@ pub extern "C" fn _start() -> ! {
asm!("mov esp, {}", in(reg) STACK_START);
}

//setup paging
unsafe {
let table0 = PageTable::new(0x0);
let table1 = PageTable::new(0x0040_0000);
let table2 = PageTable::new(0x0080_0000);
let table3 = PageTable::new(0x00C0_0000);
//let table2 = PageTable::test();
PAGING.set_table(0, &table0);
PAGING.set_table(1, &table1);
PAGING.set_table(2, &table2);
PAGING.set_table(3, &table3);
//PAGING.set_table(15, &table2);

PAGING.enable();
}

unsafe {
asm!("xchg bx, bx");
}

unsafe {
//init idt
IDT.init();
Expand Down Expand Up @@ -96,9 +119,9 @@ pub extern "C" fn _start() -> ! {
}

//bochs magic breakpoint
/*unsafe {
unsafe {
asm!("xchg bx, bx");
}*/
}

//enable hardware interrupts
unsafe {
Expand Down
9 changes: 4 additions & 5 deletions kernel/src/paging.rs
Expand Up @@ -34,23 +34,22 @@ pub struct PageTable {
}

impl PageTable {
pub fn new() -> Self {
pub fn new(from: u32) -> Self {
let mut table = Self { entries: [0; 1024] };

for i in 0..1024 {
//0b011 (supervisor, write, present)
table.entries[i] = ((i * 0x1000) | 0b011) as u32;
table.entries[i] = (((i * 0x1000) + from as usize) | 0b011) as u32;
}

table
}

pub fn test() -> Self {
let mut table = Self { entries: [0; 1024] };

for i in 0..1024 {
for i in 0..4 {
//0b011 (supervisor, write, present)
table.entries[i] = (((1024 + i) * 0x1000) | 0b011) as u32;
table.entries[i] = (((i * 0x1000) + 0x0050_0000) | 0b011) as u32;
}

table
Expand Down

0 comments on commit e0d425e

Please sign in to comment.