From 8c5beeb55f51ec023f4e8e43303e62a619a0a9d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 May 2021 17:06:37 +1000 Subject: [PATCH 1/2] Add support for kernel info --- .vscode/settings.json | 3 ++- src/binary/mod.rs | 16 ++++++++++++++-- src/boot_info.rs | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 309b3c40..f0f83163 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,6 @@ "rust-analyzer.checkOnSave.allTargets": false, "rust-analyzer.checkOnSave.extraArgs": [ "-Zbuild-std=core,alloc" - ] + ], + "rust-analyzer.cargo.allFeatures": true, } \ No newline at end of file diff --git a/src/binary/mod.rs b/src/binary/mod.rs index caa56748..6036cf22 100644 --- a/src/binary/mod.rs +++ b/src/binary/mod.rs @@ -1,6 +1,6 @@ use crate::{ binary::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion}, - boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate}, + boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, KernelInfo, MemoryRegion, TlsTemplate}, }; use core::{ mem::{self, MaybeUninit}, @@ -138,8 +138,9 @@ where // create a stack let stack_start_addr = kernel_stack_start_location(&mut used_entries); let stack_start: Page = Page::containing_address(stack_start_addr); + let stack_size = CONFIG.kernel_stack_size.unwrap_or(20 * PAGE_SIZE); let stack_end = { - let end_addr = stack_start_addr + CONFIG.kernel_stack_size.unwrap_or(20 * PAGE_SIZE); + let end_addr = stack_start_addr + stack_size; Page::containing_address(end_addr - 1u64) }; for page in Page::range_inclusive(stack_start, stack_end) { @@ -246,6 +247,13 @@ where None }; + let kernel_info = KernelInfo { + kernel_base: kernel_bytes.as_ptr() as u64, + kernel_size: kernel_bytes.len() as u64, + stack_top: stack_end.start_address().as_u64(), + stack_size, + }; + Mappings { framebuffer: framebuffer_virt_addr, entry_point, @@ -254,6 +262,7 @@ where physical_memory_offset, recursive_index, tls_template, + kernel_info, } } @@ -274,6 +283,8 @@ pub struct Mappings { pub recursive_index: Option, /// The thread local storage template of the kernel executable, if it contains one. pub tls_template: Option, + /// The information about kernel specific mappings. + pub kernel_info: KernelInfo, } /// Allocates and initializes the boot info struct and the memory map. @@ -359,6 +370,7 @@ where info: system_info.framebuffer_info, }) .into(), + kernel_info: mappings.kernel_info, physical_memory_offset: mappings.physical_memory_offset.map(VirtAddr::as_u64).into(), recursive_index: mappings.recursive_index.map(Into::into).into(), rsdp_addr: system_info.rsdp_addr.map(|addr| addr.as_u64()).into(), diff --git a/src/boot_info.rs b/src/boot_info.rs index adb97bc6..2778973f 100644 --- a/src/boot_info.rs +++ b/src/boot_info.rs @@ -36,6 +36,9 @@ pub struct BootInfo { /// the memory map before passing it to the kernel. Regions marked as usable can be freely /// used by the kernel. pub memory_regions: MemoryRegions, + /// Information about the kernel specific allocations that the bootloader provided + /// for the kernel. + pub kernel_info: KernelInfo, /// Information about the framebuffer for screen output if available. pub framebuffer: Optional, /// The virtual address at which the mapping of the physical memory starts. @@ -149,6 +152,25 @@ pub enum MemoryRegionKind { UnknownBios(u32), } +/// Information about the kernel specific allocations that the bootloader provided +/// for the kernel. +#[derive(Debug, Copy, Clone)] +#[repr(C)] +pub struct KernelInfo { + /// The base address of the kernel. The kernel base is helpful + /// for stack unwinding during kernel panics. + pub kernel_base: u64, + /// The size of the kernel, required to calculate the end of the + /// kernel base. + pub kernel_size: u64, + + /// The start address of the stack allocated for the kernel. + pub stack_top: u64, + /// The size of the stack allocated for the kernel, required to calculate + /// the end of the kernel stack. + pub stack_size: u64, +} + /// A pixel-based framebuffer that controls the screen output. #[derive(Debug)] #[repr(C)] From 0c18981619accfde7d038b9880f6740c1848d6fb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 May 2021 17:06:37 +1000 Subject: [PATCH 2/2] Add support for kernel info --- .vscode/settings.json | 3 ++- src/binary/mod.rs | 16 ++++++++++++++-- src/boot_info.rs | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 309b3c40..f0f83163 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,6 @@ "rust-analyzer.checkOnSave.allTargets": false, "rust-analyzer.checkOnSave.extraArgs": [ "-Zbuild-std=core,alloc" - ] + ], + "rust-analyzer.cargo.allFeatures": true, } \ No newline at end of file diff --git a/src/binary/mod.rs b/src/binary/mod.rs index 59e494b4..b5fe5a37 100644 --- a/src/binary/mod.rs +++ b/src/binary/mod.rs @@ -1,6 +1,6 @@ use crate::{ binary::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion}, - boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate}, + boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, KernelInfo, MemoryRegion, TlsTemplate}, }; use core::{ mem::{self, MaybeUninit}, @@ -139,8 +139,9 @@ where // create a stack let stack_start_addr = kernel_stack_start_location(&mut used_entries); let stack_start: Page = Page::containing_address(stack_start_addr); + let stack_size = CONFIG.kernel_stack_size.unwrap_or(20 * PAGE_SIZE); let stack_end = { - let end_addr = stack_start_addr + CONFIG.kernel_stack_size.unwrap_or(20 * PAGE_SIZE); + let end_addr = stack_start_addr + stack_size; Page::containing_address(end_addr - 1u64) }; for page in Page::range_inclusive(stack_start, stack_end) { @@ -259,6 +260,13 @@ where None }; + let kernel_info = KernelInfo { + kernel_base: kernel_bytes.as_ptr() as u64, + kernel_size: kernel_bytes.len() as u64, + stack_top: stack_end.start_address().as_u64(), + stack_size, + }; + Mappings { framebuffer: framebuffer_virt_addr, entry_point, @@ -267,6 +275,7 @@ where physical_memory_offset, recursive_index, tls_template, + kernel_info, } } @@ -287,6 +296,8 @@ pub struct Mappings { pub recursive_index: Option, /// The thread local storage template of the kernel executable, if it contains one. pub tls_template: Option, + /// The information about kernel specific mappings. + pub kernel_info: KernelInfo, } /// Allocates and initializes the boot info struct and the memory map. @@ -372,6 +383,7 @@ where info: system_info.framebuffer_info, }) .into(), + kernel_info: mappings.kernel_info, physical_memory_offset: mappings.physical_memory_offset.map(VirtAddr::as_u64).into(), recursive_index: mappings.recursive_index.map(Into::into).into(), rsdp_addr: system_info.rsdp_addr.map(|addr| addr.as_u64()).into(), diff --git a/src/boot_info.rs b/src/boot_info.rs index adb97bc6..2778973f 100644 --- a/src/boot_info.rs +++ b/src/boot_info.rs @@ -36,6 +36,9 @@ pub struct BootInfo { /// the memory map before passing it to the kernel. Regions marked as usable can be freely /// used by the kernel. pub memory_regions: MemoryRegions, + /// Information about the kernel specific allocations that the bootloader provided + /// for the kernel. + pub kernel_info: KernelInfo, /// Information about the framebuffer for screen output if available. pub framebuffer: Optional, /// The virtual address at which the mapping of the physical memory starts. @@ -149,6 +152,25 @@ pub enum MemoryRegionKind { UnknownBios(u32), } +/// Information about the kernel specific allocations that the bootloader provided +/// for the kernel. +#[derive(Debug, Copy, Clone)] +#[repr(C)] +pub struct KernelInfo { + /// The base address of the kernel. The kernel base is helpful + /// for stack unwinding during kernel panics. + pub kernel_base: u64, + /// The size of the kernel, required to calculate the end of the + /// kernel base. + pub kernel_size: u64, + + /// The start address of the stack allocated for the kernel. + pub stack_top: u64, + /// The size of the stack allocated for the kernel, required to calculate + /// the end of the kernel stack. + pub stack_size: u64, +} + /// A pixel-based framebuffer that controls the screen output. #[derive(Debug)] #[repr(C)]