Paging debug stuff
This commit is contained in:
parent
f438a722f6
commit
eb0c4b7997
@ -128,6 +128,11 @@ script = '''
|
|||||||
limine bios-install build/gila.iso
|
limine bios-install build/gila.iso
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
[tasks.gui_run]
|
||||||
|
dependencies = ["iso"]
|
||||||
|
command = "${QEMUCOMMAND}"
|
||||||
|
args = ["-drive", "file=build/gila.iso,format=raw,index=0,media=disk"]
|
||||||
|
|
||||||
[tasks.run]
|
[tasks.run]
|
||||||
dependencies = ["iso"]
|
dependencies = ["iso"]
|
||||||
command = "${QEMUCOMMAND}"
|
command = "${QEMUCOMMAND}"
|
||||||
|
|||||||
@ -61,7 +61,7 @@ pub fn dump_gdt() {
|
|||||||
let flags = x86_64::structures::gdt::DescriptorFlags::from_bits_retain(entry.raw());
|
let flags = x86_64::structures::gdt::DescriptorFlags::from_bits_retain(entry.raw());
|
||||||
let seg_type = SegmentType::try_from(entry);
|
let seg_type = SegmentType::try_from(entry);
|
||||||
log_info!(
|
log_info!(
|
||||||
"GDT entry: type: {:?} (ring {}), size: {}, raw flags: 0b{:04b}, access: 0b{:08b}",
|
"GDT entry: type: {:?} (ring {}), width: {}, length: 0x{:x}, raw flags: 0b{:04b}, access: 0b{:08b}",
|
||||||
seg_type.unwrap(),
|
seg_type.unwrap(),
|
||||||
entry.access().bits(5..=6),
|
entry.access().bits(5..=6),
|
||||||
if flags.contains(gdt::DescriptorFlags::DEFAULT_SIZE) {
|
if flags.contains(gdt::DescriptorFlags::DEFAULT_SIZE) {
|
||||||
@ -71,6 +71,7 @@ pub fn dump_gdt() {
|
|||||||
} else {
|
} else {
|
||||||
"16-bit"
|
"16-bit"
|
||||||
},
|
},
|
||||||
|
entry.limit(),
|
||||||
entry.raw().bits(52..=55),
|
entry.raw().bits(52..=55),
|
||||||
entry.access(),
|
entry.access(),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -15,6 +15,10 @@ pub static FILE_REQUEST: ExecutableFileRequest = limine::request::ExecutableFile
|
|||||||
#[unsafe(link_section = ".requests")]
|
#[unsafe(link_section = ".requests")]
|
||||||
pub static MODULE_REQUEST: ModulesRequest = limine::request::ModulesRequest::new();
|
pub static MODULE_REQUEST: ModulesRequest = limine::request::ModulesRequest::new();
|
||||||
|
|
||||||
|
#[used]
|
||||||
|
#[unsafe(link_section = ".requests")]
|
||||||
|
pub static IOMMU_REQUEST: KeepIommuRequest = limine::request::KeepIommuRequest::new();
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref MODULE_RESPONSE: Option<&'static ModulesResponse> = MODULE_REQUEST.response();
|
pub static ref MODULE_RESPONSE: Option<&'static ModulesResponse> = MODULE_REQUEST.response();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ use crate::{
|
|||||||
gdt::dump_gdt,
|
gdt::dump_gdt,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
memory::HHDM_RESPONSE,
|
memory::{paging, phys_to_virt},
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -151,7 +151,7 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
None => log_info!("RDSP response not received"),
|
None => log_info!("RDSP response not received"),
|
||||||
Some(resp) => {
|
Some(resp) => {
|
||||||
log_info!("RSDP response received");
|
log_info!("RSDP response received");
|
||||||
log_trace!("RSDT address: 0x{:x}", resp.address as usize)
|
log_trace!("RSDP address: 0x{:x}", resp.address as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,10 +175,9 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
log_info!("Physical address of current L4 table: 0x{:x}", l4_start);
|
log_info!("Physical address of current L4 table: 0x{:x}", l4_start);
|
||||||
log_info!(
|
log_info!(
|
||||||
"Virtual address of current L4 table: 0x{:x}",
|
"Virtual address of current L4 table: 0x{:x}",
|
||||||
l4_start.as_u64() + HHDM_RESPONSE.offset
|
phys_to_virt(l4_start)
|
||||||
);
|
);
|
||||||
|
paging::walk_tables();
|
||||||
//iter_table(4, &PML4);
|
|
||||||
log_info!("Long mode: {}", asm::long_mode());
|
log_info!("Long mode: {}", asm::long_mode());
|
||||||
dump_gdt();
|
dump_gdt();
|
||||||
|
|
||||||
|
|||||||
@ -9,15 +9,19 @@ use crate::{LOGGER, LogLevel, format};
|
|||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use limine::memmap::*;
|
|
||||||
use limine::request::{ExecutableAddressRequest, HhdmRepsonse, HhdmRequest};
|
use limine::request::{ExecutableAddressRequest, HhdmRepsonse, HhdmRequest};
|
||||||
use limine::request::{MemmapRequest, MemmapResponse};
|
use limine::request::{MemmapRequest, MemmapResponse};
|
||||||
use talc::*;
|
use talc::*;
|
||||||
|
use x86_64::{PhysAddr, VirtAddr};
|
||||||
|
|
||||||
pub extern crate alloc;
|
pub extern crate alloc;
|
||||||
|
|
||||||
pub mod paging;
|
pub mod paging;
|
||||||
|
|
||||||
|
pub fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
|
||||||
|
VirtAddr::new(phys.as_u64() + HHDM_RESPONSE.offset)
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref MEMMAP_RESPONSE: &'static MemmapResponse = MEMMAP_REQUEST
|
pub static ref MEMMAP_RESPONSE: &'static MemmapResponse = MEMMAP_REQUEST
|
||||||
.response()
|
.response()
|
||||||
@ -38,35 +42,35 @@ pub fn log_memory() {
|
|||||||
entry.length as usize / PAGE_SIZE,
|
entry.length as usize / PAGE_SIZE,
|
||||||
entry.base,
|
entry.base,
|
||||||
match entry.type_ {
|
match entry.type_ {
|
||||||
MEMMAP_ACPI_NVS => {
|
limine::memmap::MEMMAP_ACPI_NVS => {
|
||||||
hardware += entry.length;
|
hardware += entry.length;
|
||||||
"ACPI (reserved)"
|
"ACPI (reserved)"
|
||||||
}
|
}
|
||||||
MEMMAP_ACPI_RECLAIMABLE => {
|
limine::memmap::MEMMAP_ACPI_RECLAIMABLE => {
|
||||||
reclaimable += entry.length;
|
reclaimable += entry.length;
|
||||||
"ACPI (reclaimable)"
|
"ACPI (reclaimable)"
|
||||||
}
|
}
|
||||||
MEMMAP_BAD_MEMORY => {
|
limine::memmap::MEMMAP_BAD_MEMORY => {
|
||||||
unusable += entry.length;
|
unusable += entry.length;
|
||||||
"damaged/unusable"
|
"damaged/unusable"
|
||||||
}
|
}
|
||||||
MEMMAP_BOOTLOADER_RECLAIMABLE => {
|
limine::memmap::MEMMAP_BOOTLOADER_RECLAIMABLE => {
|
||||||
reclaimable += entry.length;
|
reclaimable += entry.length;
|
||||||
"bootloader (reclaimable)"
|
"bootloader (reclaimable)"
|
||||||
}
|
}
|
||||||
MEMMAP_EXECUTABLE_AND_MODULES => {
|
limine::memmap::MEMMAP_EXECUTABLE_AND_MODULES => {
|
||||||
unusable += entry.length;
|
unusable += entry.length;
|
||||||
"executable & modules"
|
"executable & modules"
|
||||||
}
|
}
|
||||||
MEMMAP_FRAMEBUFFER => {
|
limine::memmap::MEMMAP_FRAMEBUFFER => {
|
||||||
hardware += entry.length;
|
hardware += entry.length;
|
||||||
"framebuffer"
|
"framebuffer"
|
||||||
}
|
}
|
||||||
MEMMAP_RESERVED => {
|
limine::memmap::MEMMAP_RESERVED => {
|
||||||
unusable += entry.length;
|
unusable += entry.length;
|
||||||
"reserved"
|
"reserved"
|
||||||
}
|
}
|
||||||
MEMMAP_USABLE => {
|
limine::memmap::MEMMAP_USABLE => {
|
||||||
usable += entry.length;
|
usable += entry.length;
|
||||||
"usable"
|
"usable"
|
||||||
}
|
}
|
||||||
@ -89,10 +93,6 @@ pub fn log_address() {
|
|||||||
if let Some(resp) = ADDRESS_REQUEST.response() {
|
if let Some(resp) = ADDRESS_REQUEST.response() {
|
||||||
log_info!("Kernel physical start address: 0x{:x}", resp.physical_base);
|
log_info!("Kernel physical start address: 0x{:x}", resp.physical_base);
|
||||||
log_info!("Kernel virtual start address: 0x{:x}", resp.virtual_base);
|
log_info!("Kernel virtual start address: 0x{:x}", resp.virtual_base);
|
||||||
log_info!(
|
|
||||||
"Kernel physical start address (calculated): 0x{:x}",
|
|
||||||
0i64 - resp.virtual_base as i64 + resp.physical_base as i64
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
log_warning!("No kernel address response provided.");
|
log_warning!("No kernel address response provided.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use x86_64::PhysAddr;
|
||||||
use x86_64::VirtAddr;
|
use x86_64::VirtAddr;
|
||||||
use x86_64::structures::paging::PageTable;
|
use x86_64::structures::paging::PageTable;
|
||||||
use x86_64::structures::paging::PageTableFlags;
|
use x86_64::structures::paging::PageTableFlags;
|
||||||
@ -7,6 +8,20 @@ use crate::log::*;
|
|||||||
use crate::memory::HHDM_RESPONSE;
|
use crate::memory::HHDM_RESPONSE;
|
||||||
use crate::memory::format;
|
use crate::memory::format;
|
||||||
|
|
||||||
|
pub fn map_page(virt: VirtAddr, phys: PhysAddr) {
|
||||||
|
// TODO:
|
||||||
|
// This function should create necessary page tables until the
|
||||||
|
// supplied virtual address maps to the supplied physical address.
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unmap_page(virt: VirtAddr) -> Result<(), ()> {
|
||||||
|
// TODO:
|
||||||
|
// This funciton should remove any present mappings
|
||||||
|
// corresponding to the supplied virtual address.
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub unsafe fn active_level_4_table() -> &'static mut PageTable {
|
pub unsafe fn active_level_4_table() -> &'static mut PageTable {
|
||||||
use x86_64::registers::control::Cr3;
|
use x86_64::registers::control::Cr3;
|
||||||
@ -24,6 +39,10 @@ lazy_static! {
|
|||||||
pub static ref PML4: &'static mut PageTable = unsafe { active_level_4_table() };
|
pub static ref PML4: &'static mut PageTable = unsafe { active_level_4_table() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn walk_tables() {
|
||||||
|
iter_table(4, &PML4);
|
||||||
|
}
|
||||||
|
|
||||||
// Not used right now, helpful for debugging
|
// Not used right now, helpful for debugging
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn iter_table(level: usize, table: &PageTable) {
|
pub fn iter_table(level: usize, table: &PageTable) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user