mirror of
https://github.com/realmicrosoft/windows.git
synced 2024-08-14 22:46:44 +00:00
page table something idk i'm tired
This commit is contained in:
parent
3bb18ee8f7
commit
1d810657ff
6 changed files with 62 additions and 27 deletions
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ clean:
|
||||||
run: $(final) $(iso)
|
run: $(final) $(iso)
|
||||||
@qemu-system-$(arch) -bios $(efi_bios) -cdrom $(iso) \
|
@qemu-system-$(arch) -bios $(efi_bios) -cdrom $(iso) \
|
||||||
-chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off \
|
-chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off \
|
||||||
-serial chardev:char0 -mon chardev=char0
|
-serial chardev:char0 -mon chardev=char0 -m 512M
|
||||||
|
|
||||||
quick_invalidate:
|
quick_invalidate:
|
||||||
@echo "quick invalidation"
|
@echo "quick invalidation"
|
||||||
|
|
|
@ -11,6 +11,16 @@ SECTIONS {
|
||||||
|
|
||||||
.text :
|
.text :
|
||||||
{
|
{
|
||||||
*(.text)
|
*(.text .text.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.rodata :
|
||||||
|
{
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.data.rel.ro :
|
||||||
|
{
|
||||||
|
*(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*)
|
||||||
}
|
}
|
||||||
}
|
}
|
14
serial.log
14
serial.log
|
@ -6,19 +6,11 @@ BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1
|
||||||
|
|
||||||
WARNING: no console will be available to OS
|
WARNING: no console will be available to OS
|
||||||
error: no suitable video mode found.
|
error: no suitable video mode found.
|
||||||
hello from wukkOS!
|
using serial port 0 as console
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
welcome to wukkOS!
|
welcome to wukkOS!
|
||||||
(c) 2022 Real Microsoft, LLC
|
(c) 2022 Real Microsoft, LLC
|
||||||
initialising memory maps...[OK]
|
initialising memory maps...[OK]
|
||||||
memory map:
|
L4 entry 0: PageTableEntry { addr: PhysAddr(0x128000), flags: PRESENT | WRITABLE | ACCESSED }
|
||||||
0 - a0000 : available
|
|
||||||
100000 - 800000 : available
|
|
||||||
800000 - 808000 : reserved for hibernation
|
|
||||||
808000 - 80b000 : available
|
|
||||||
80b000 - 80c000 : reserved for hibernation
|
|
||||||
80c000 - 810000 : available
|
|
||||||
810000 - 900000 : reserved for hibernation
|
|
||||||
900000 - 78ef000 : available
|
|
||||||
78ef000 - 79ef000 : reserved
|
|
||||||
|
|
|
@ -5,17 +5,31 @@ use crate::KernelArgs;
|
||||||
use multiboot2::{load, MemoryMapTag, BootInformation};
|
use multiboot2::{load, MemoryMapTag, BootInformation};
|
||||||
|
|
||||||
pub struct KernelInfo {
|
pub struct KernelInfo {
|
||||||
|
kernel_start: u64,
|
||||||
|
kernel_end: u64,
|
||||||
|
safe_mem_start: u64,
|
||||||
#[cfg(feature = "f_multiboot2")]
|
#[cfg(feature = "f_multiboot2")]
|
||||||
boot_info: BootInformation,
|
boot_info: BootInformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KernelInfo {
|
impl KernelInfo {
|
||||||
pub fn init_from_kernel_args(args: KernelArgs) -> Self {
|
pub fn init_from_kernel_args(args: KernelArgs) -> Self {
|
||||||
let mut kernel_info = KernelInfo {
|
#[cfg(feature = "f_multiboot2")]
|
||||||
#[cfg(feature = "f_multiboot2")]
|
{
|
||||||
boot_info: unsafe { load(args.multiboot_information_address).expect("ERR ARGS BAD!") },
|
let boot_info = unsafe { load(args.multiboot_information_address) }.expect("failed to load multiboot2 information");
|
||||||
};
|
let elf_sections = boot_info.elf_sections_tag().expect("no elf sections tag");
|
||||||
kernel_info
|
let kernel_start = elf_sections.sections().map(|s| s.start_address()).min().unwrap();
|
||||||
|
let kernel_end = elf_sections.sections().map(|s| s.end_address()).max().unwrap();
|
||||||
|
// get end of multiboot for safe memory
|
||||||
|
let safe_mem_start = boot_info.start_address() + boot_info.total_size();
|
||||||
|
let kernel_info = KernelInfo {
|
||||||
|
kernel_start,
|
||||||
|
kernel_end,
|
||||||
|
safe_mem_start: safe_mem_start as u64,
|
||||||
|
boot_info,
|
||||||
|
};
|
||||||
|
kernel_info
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "f_multiboot2")]
|
#[cfg(feature = "f_multiboot2")]
|
||||||
|
@ -23,4 +37,8 @@ impl KernelInfo {
|
||||||
let mm_tag = self.boot_info.memory_map_tag().expect("ERR NO MEM MAP TAG!");
|
let mm_tag = self.boot_info.memory_map_tag().expect("ERR NO MEM MAP TAG!");
|
||||||
mm_tag.all_memory_areas()
|
mm_tag.all_memory_areas()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_safe_memory(&self, addr: u64) -> bool {
|
||||||
|
addr >= self.safe_mem_start && addr >= self.kernel_end
|
||||||
|
}
|
||||||
}
|
}
|
18
src/lib.rs
18
src/lib.rs
|
@ -11,8 +11,10 @@ use lazy_static::lazy_static;
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use multiboot2::MemoryAreaType;
|
use multiboot2::MemoryAreaType;
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
|
use x86_64::VirtAddr;
|
||||||
use crate::boot::KernelInfo;
|
use crate::boot::KernelInfo;
|
||||||
use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*;
|
use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*;
|
||||||
|
use crate::memory::active_level_4_table;
|
||||||
use crate::serial::terminal::ST;
|
use crate::serial::terminal::ST;
|
||||||
|
|
||||||
mod font;
|
mod font;
|
||||||
|
@ -78,6 +80,7 @@ pub extern fn kernel_main(args: KernelArgs) -> ! {
|
||||||
if let Some(i) = console_port {
|
if let Some(i) = console_port {
|
||||||
let port = &serial_ports.ports[i];
|
let port = &serial_ports.ports[i];
|
||||||
ST.init_from_port(*port);
|
ST.init_from_port(*port);
|
||||||
|
println!("using serial port {} as console", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,15 +93,12 @@ pub extern fn kernel_main(args: KernelArgs) -> ! {
|
||||||
let kern_info = KernelInfo::init_from_kernel_args(args);
|
let kern_info = KernelInfo::init_from_kernel_args(args);
|
||||||
let mut mem_areas = kern_info.memory_areas();
|
let mut mem_areas = kern_info.memory_areas();
|
||||||
println!("[OK]");
|
println!("[OK]");
|
||||||
println!("memory map:");
|
let l4_table = active_level_4_table(VirtAddr::new(0));
|
||||||
while let Some(area) = mem_areas.next() {
|
|
||||||
println!("{:x} - {:x} : {}", area.start_address(), area.end_address(), match area.typ() {
|
for (i, entry) in l4_table.iter().enumerate() {
|
||||||
MemoryAreaType::Available => "available",
|
if !entry.is_unused() {
|
||||||
MemoryAreaType::Reserved => "reserved",
|
println!("L4 entry {}: {:?}", i, entry);
|
||||||
MemoryAreaType::AcpiAvailable => "ACPI available",
|
}
|
||||||
MemoryAreaType::ReservedHibernate => "reserved for hibernation",
|
|
||||||
MemoryAreaType::Defective => "defective",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
use x86_64::registers::control::Cr3;
|
||||||
|
use x86_64::structures::paging::PageTable;
|
||||||
|
use x86_64::VirtAddr;
|
||||||
|
|
||||||
|
pub fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
|
||||||
|
use x86_64::registers::control::Cr3;
|
||||||
|
|
||||||
|
let (level_4_table_frame, _) = Cr3::read();
|
||||||
|
|
||||||
|
let phys = level_4_table_frame.start_address();
|
||||||
|
let virt = physical_memory_offset + phys.as_u64();
|
||||||
|
let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
|
||||||
|
|
||||||
|
unsafe { &mut *page_table_ptr } // unsafe
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue