Paging debug stuff
Some checks failed
Continuous Integration / Check (push) Failing after 53s
Continuous Integration / Clippy (push) Failing after 49s

This commit is contained in:
August 2026-06-30 07:45:54 +00:00
parent f438a722f6
commit eb0c4b7997
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
6 changed files with 47 additions and 19 deletions

View File

@ -128,6 +128,11 @@ script = '''
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]
dependencies = ["iso"]
command = "${QEMUCOMMAND}"

View File

@ -61,7 +61,7 @@ pub fn dump_gdt() {
let flags = x86_64::structures::gdt::DescriptorFlags::from_bits_retain(entry.raw());
let seg_type = SegmentType::try_from(entry);
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(),
entry.access().bits(5..=6),
if flags.contains(gdt::DescriptorFlags::DEFAULT_SIZE) {
@ -71,6 +71,7 @@ pub fn dump_gdt() {
} else {
"16-bit"
},
entry.limit(),
entry.raw().bits(52..=55),
entry.access(),
);

View File

@ -15,6 +15,10 @@ pub static FILE_REQUEST: ExecutableFileRequest = limine::request::ExecutableFile
#[unsafe(link_section = ".requests")]
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! {
pub static ref MODULE_RESPONSE: Option<&'static ModulesResponse> = MODULE_REQUEST.response();
}

View File

@ -38,7 +38,7 @@ use crate::{
gdt::dump_gdt,
},
},
memory::HHDM_RESPONSE,
memory::{paging, phys_to_virt},
};
lazy_static! {
@ -151,7 +151,7 @@ unsafe extern "C" fn main() -> ! {
None => log_info!("RDSP response not received"),
Some(resp) => {
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!(
"Virtual address of current L4 table: 0x{:x}",
l4_start.as_u64() + HHDM_RESPONSE.offset
phys_to_virt(l4_start)
);
//iter_table(4, &PML4);
paging::walk_tables();
log_info!("Long mode: {}", asm::long_mode());
dump_gdt();

View File

@ -9,15 +9,19 @@ use crate::{LOGGER, LogLevel, format};
use alloc::string::String;
use lazy_static::lazy_static;
use limine::memmap::*;
use limine::request::{ExecutableAddressRequest, HhdmRepsonse, HhdmRequest};
use limine::request::{MemmapRequest, MemmapResponse};
use talc::*;
use x86_64::{PhysAddr, VirtAddr};
pub extern crate alloc;
pub mod paging;
pub fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
VirtAddr::new(phys.as_u64() + HHDM_RESPONSE.offset)
}
lazy_static! {
pub static ref MEMMAP_RESPONSE: &'static MemmapResponse = MEMMAP_REQUEST
.response()
@ -38,35 +42,35 @@ pub fn log_memory() {
entry.length as usize / PAGE_SIZE,
entry.base,
match entry.type_ {
MEMMAP_ACPI_NVS => {
limine::memmap::MEMMAP_ACPI_NVS => {
hardware += entry.length;
"ACPI (reserved)"
}
MEMMAP_ACPI_RECLAIMABLE => {
limine::memmap::MEMMAP_ACPI_RECLAIMABLE => {
reclaimable += entry.length;
"ACPI (reclaimable)"
}
MEMMAP_BAD_MEMORY => {
limine::memmap::MEMMAP_BAD_MEMORY => {
unusable += entry.length;
"damaged/unusable"
}
MEMMAP_BOOTLOADER_RECLAIMABLE => {
limine::memmap::MEMMAP_BOOTLOADER_RECLAIMABLE => {
reclaimable += entry.length;
"bootloader (reclaimable)"
}
MEMMAP_EXECUTABLE_AND_MODULES => {
limine::memmap::MEMMAP_EXECUTABLE_AND_MODULES => {
unusable += entry.length;
"executable & modules"
}
MEMMAP_FRAMEBUFFER => {
limine::memmap::MEMMAP_FRAMEBUFFER => {
hardware += entry.length;
"framebuffer"
}
MEMMAP_RESERVED => {
limine::memmap::MEMMAP_RESERVED => {
unusable += entry.length;
"reserved"
}
MEMMAP_USABLE => {
limine::memmap::MEMMAP_USABLE => {
usable += entry.length;
"usable"
}
@ -89,10 +93,6 @@ pub fn log_address() {
if let Some(resp) = ADDRESS_REQUEST.response() {
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 physical start address (calculated): 0x{:x}",
0i64 - resp.virtual_base as i64 + resp.physical_base as i64
);
} else {
log_warning!("No kernel address response provided.");
}

View File

@ -1,4 +1,5 @@
use lazy_static::lazy_static;
use x86_64::PhysAddr;
use x86_64::VirtAddr;
use x86_64::structures::paging::PageTable;
use x86_64::structures::paging::PageTableFlags;
@ -7,6 +8,20 @@ use crate::log::*;
use crate::memory::HHDM_RESPONSE;
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)]
pub unsafe fn active_level_4_table() -> &'static mut PageTable {
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 fn walk_tables() {
iter_table(4, &PML4);
}
// Not used right now, helpful for debugging
#[allow(dead_code)]
pub fn iter_table(level: usize, table: &PageTable) {