some changes
This commit is contained in:
parent
3041cec87d
commit
1f5a361870
8 changed files with 43 additions and 24 deletions
|
|
@ -34,7 +34,7 @@ MONITOR := sleep 0.5;\
|
|||
kill \`ps -x | grep \"[g]db\" | cut -d \ -f 1 \`;\
|
||||
kill \`ps -x | grep \"[g]db\" | cut -d \ -f 2 \`
|
||||
GDB := gdb -q\
|
||||
-ex \"set arch i386:x86-64\"\
|
||||
-ex \"set arch i386:x64-32\"\
|
||||
-ex \"file $(kernel)\"\
|
||||
-ex \"target remote localhost:$(PORTG)\" \
|
||||
-ex \"continue\"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ start:
|
|||
call check_multiboot
|
||||
|
||||
call set_up_page_tables
|
||||
; call enable_paging
|
||||
call enable_paging
|
||||
|
||||
lgdt [GDTR.ptr] ; load the new gdt
|
||||
jmp GDTR.gdt_cs:x86_start
|
||||
|
|
@ -29,7 +29,7 @@ set_up_page_tables:
|
|||
; map P2 table recursively
|
||||
mov eax, p2_table
|
||||
or eax, 0b11 ; present + writable
|
||||
mov [p2_table + 1023 * 8], eax
|
||||
mov [p2_table + 1023 * 4], eax
|
||||
|
||||
; map each P2 entry to a huge 2MiB page
|
||||
mov ecx, 0 ; counter variable
|
||||
|
|
@ -37,22 +37,21 @@ set_up_page_tables:
|
|||
.map_p2_table:
|
||||
; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx
|
||||
mov eax, 0x200000 ; 2MiB
|
||||
; mov eax, 0x2 ; WRITABLE, not PRESENT
|
||||
mul ecx ; start address of ecx-th page
|
||||
or eax, 0b10000011 ; present + writable + huge
|
||||
mov [p2_table + ecx * 8], eax ; map ecx-th entry
|
||||
mov [p2_table + ecx * 4], eax ; map ecx-th entry
|
||||
|
||||
inc ecx ; increase counter
|
||||
cmp ecx, 1023 ; if counter == 1023, the whole P2 table is mapped
|
||||
jne .map_p2_table ; else map the next entry
|
||||
|
||||
ret
|
||||
|
||||
enable_paging:
|
||||
; load P2 to cr3 register (cpu uses this to access the P2 table)
|
||||
mov eax, p2_table
|
||||
mov cr3, eax
|
||||
|
||||
ret
|
||||
|
||||
enable_paging:
|
||||
; enable paging in the cr0 register
|
||||
mov eax, cr0
|
||||
or eax, 1 << 31
|
||||
|
|
@ -70,6 +69,16 @@ HALT:
|
|||
hlt
|
||||
jmp HALT
|
||||
|
||||
section .bss
|
||||
align 4096
|
||||
p2_table:
|
||||
resb 4096
|
||||
p1_table:
|
||||
resb 4096
|
||||
stack_bottom:
|
||||
resb 4096 * 4
|
||||
stack_top:
|
||||
|
||||
section .gdt
|
||||
GDTR:
|
||||
; http://tuttlem.github.io/2014/07/11/a-gdt-primer.html
|
||||
|
|
@ -128,13 +137,3 @@ GDTR:
|
|||
DW .gdt_bottom - .gdt_top - 1 ; length of the structure minus 1
|
||||
DD .gdt_top ; pointer to top of gdt
|
||||
|
||||
section .bss
|
||||
align 4096
|
||||
p2_table:
|
||||
resb 4096
|
||||
p1_table:
|
||||
resb 4096
|
||||
stack_bottom:
|
||||
resb 4096 * 4
|
||||
stack_top:
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use acpi;
|
|||
use cpuio;
|
||||
use context;
|
||||
use memory;
|
||||
// use multiboot2;
|
||||
use x86;
|
||||
use core::char;
|
||||
use vga::*;
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ fn dispatch(command: &str) -> Result <(), &'static str> {
|
|||
"shutdown" | "halt" | "q" => self::shutdown(),
|
||||
"stack" => self::print_stack(),
|
||||
"test" => self::test(),
|
||||
"regs" => self::regs(),
|
||||
_ => Err("Command unknown. (h|help for help)"),
|
||||
}
|
||||
}
|
||||
|
|
@ -176,3 +177,11 @@ pub fn acpi_info() -> Result <(), &'static str> {
|
|||
acpi::info()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn regs() -> Result <(), &'static str> {
|
||||
println!("cr0={:#b}", x86::cr0());
|
||||
println!("cr3={:#x}", x86::cr3());
|
||||
println!("cr4={:#b}", x86::cr4());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ pub fn kbd_callback() {
|
|||
static mut SHIFT: bool = false;
|
||||
static mut CTRL: bool = false;
|
||||
static mut ALT: bool = false;
|
||||
// let terminal_two: vga::terminal::Terminal = vga::Screen::new();
|
||||
let control = cpuio::inb(0x64);
|
||||
if (control & 1) == 1 {
|
||||
let scancode = cpuio::inb(0x60);
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ impl Mapper {
|
|||
where A: FrameAllocator
|
||||
{
|
||||
let p2 = self.p2_mut();
|
||||
let mut p1 = p2.next_table_create(page.p2_index(), allocator);
|
||||
let p1 = p2.next_table_create(page.p2_index(), allocator);
|
||||
|
||||
assert!(p1[page.p1_index()].is_unused());
|
||||
p1[page.p1_index()].set(frame, flags | EntryFlags::PRESENT);
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ impl Page {
|
|||
}
|
||||
|
||||
fn p2_index(&self) -> usize {
|
||||
(self.number >> 9) & 0o777
|
||||
(self.number >> 10) & 0x3ff
|
||||
}
|
||||
|
||||
fn p1_index(&self) -> usize {
|
||||
(self.number >> 0) & 0o777
|
||||
(self.number >> 0) & 0x3ff
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ impl<L> Table<L> where L: HierarchicalLevel
|
|||
let entry_flags = self[index].flags();
|
||||
if entry_flags.contains(EntryFlags::PRESENT) && !entry_flags.contains(EntryFlags::HUGE_PAGE) {
|
||||
let table_address = self as *const _ as usize;
|
||||
Some((table_address << 9) | (index << 12))
|
||||
Some((table_address << 10) | (index << 12))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
//! x86 (32 bit) only
|
||||
|
||||
pub fn cr0() -> usize {
|
||||
let ret: usize;
|
||||
unsafe { asm!("mov %cr0, $0" : "=r" (ret)) };
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cr3() -> usize {
|
||||
let ret: usize;
|
||||
unsafe { asm!("mov %cr3, $0" : "=r" (ret)) };
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn cr4() -> usize {
|
||||
let ret: usize;
|
||||
unsafe { asm!("mov %cr4, $0" : "=r" (ret)) };
|
||||
ret
|
||||
}
|
||||
|
||||
pub unsafe fn cr3_write(val: usize) {
|
||||
asm!("mov $0, %cr3" :: "r" (val) : "memory");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue