mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: arch/vspace: kmem: exclude initrd
This commit is contained in:
parent
d53fa7b93e
commit
95713e2af4
@ -1,6 +1,6 @@
|
|||||||
use super::{alloc_page, install_pagetable, map_range, RAM_ALLOCATOR};
|
use super::{alloc_page, install_pagetable, map_range, RAM_ALLOCATOR};
|
||||||
use crate::{arch::layout::*, vspace::*};
|
use crate::{arch::layout::*, vspace::*};
|
||||||
use log::{debug, info};
|
use log::{debug, info, trace};
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use utils::{addr::*, size::*};
|
use utils::{addr::*, size::*};
|
||||||
|
|
||||||
@ -65,8 +65,32 @@ pub unsafe fn setup_memory(fdt_addr: usize) {
|
|||||||
// Exclude FDT table
|
// Exclude FDT table
|
||||||
let fdt_addr = PhysAddr::from(fdt_addr);
|
let fdt_addr = PhysAddr::from(fdt_addr);
|
||||||
let fdt_size = align_up(fdt.total_size(), PAGE_SIZE);
|
let fdt_size = align_up(fdt.total_size(), PAGE_SIZE);
|
||||||
debug!("Reserving FDT memory:\tstart: {:x?}, size: {:x?}", fdt_addr, fdt_size);
|
debug!("Reserving FDT table memory:\tstart: {:x?}, size: {:#x?}", fdt_addr, fdt_size);
|
||||||
mem.reserve(fdt_addr, fdt_size);
|
mem.reserve(fdt_addr, fdt_size);
|
||||||
|
|
||||||
|
// Exclude memory for initrd
|
||||||
|
if let Some(chosen) = fdt.find_node("/chosen") {
|
||||||
|
let initrd_start = chosen
|
||||||
|
.properties()
|
||||||
|
.find(|n| n.name == "linux,initrd-start")
|
||||||
|
.map(|prop| prop.as_usize())
|
||||||
|
.flatten();
|
||||||
|
let initrd_end = chosen
|
||||||
|
.properties()
|
||||||
|
.find(|n| n.name == "linux,initrd-end")
|
||||||
|
.map(|prop| prop.as_usize())
|
||||||
|
.flatten();
|
||||||
|
|
||||||
|
if let (Some(initrd_start), Some(initrd_end)) = (initrd_start, initrd_end) {
|
||||||
|
let start = PhysAddr::from(initrd_start);
|
||||||
|
let size = align_up(initrd_end - initrd_start, PAGE_SIZE);
|
||||||
|
|
||||||
|
debug!("Reserving initrd memory:\tstart: {:x?}, size: {:#x?}", start, size);
|
||||||
|
mem.reserve(start, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trace!("Memory setup complete, memory info:\n{:#x?}", mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn setup_kernel_paging() {
|
pub unsafe fn setup_kernel_paging() {
|
||||||
@ -107,7 +131,7 @@ pub unsafe fn setup_kernel_paging() {
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
let count = ALLOC_COUNT.load(core::sync::atomic::Ordering::Acquire);
|
let count = ALLOC_COUNT.load(core::sync::atomic::Ordering::Acquire);
|
||||||
log::trace!("Kernel page table size: {:?}", count);
|
trace!("Kernel page table size: {:?}", count);
|
||||||
assert!(KERNEL_PAGETABLE_SIZE == count, "Kernel page table size mismatch");
|
assert!(KERNEL_PAGETABLE_SIZE == count, "Kernel page table size mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user