mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
refactor loader to use a single function to swap MAC offset in swap
also pre-map some pages to handle offset increment in swapper
This commit is contained in:
parent
933a9a342d
commit
95c27c765e
6 changed files with 45 additions and 8 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#[cfg(feature = "swap")]
|
||||
pub mod swap;
|
||||
|
||||
pub const PAGE_SIZE: usize = 4096;
|
||||
|
||||
// Locate the hard-wired IFRAM allocations for UDMA
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "cramium-soc")]
|
||||
|
|
|
|||
|
|
@ -30,14 +30,13 @@ use core::{mem, ptr, slice};
|
|||
use asm::*;
|
||||
use bootconfig::BootConfig;
|
||||
use consts::*;
|
||||
pub use loader::PAGE_SIZE;
|
||||
use minielf::*;
|
||||
use phase1::{phase_1, InitialProcess};
|
||||
use phase2::{phase_2, ProgramDescription};
|
||||
#[cfg(feature = "swap")]
|
||||
use platform::SwapHal;
|
||||
|
||||
pub type XousPid = u8;
|
||||
pub const PAGE_SIZE: usize = 4096;
|
||||
const WORD_SIZE: usize = mem::size_of::<usize>();
|
||||
pub const SIGBLOCK_SIZE: usize = 0x1000;
|
||||
const STACK_PAGE_COUNT: usize = 8;
|
||||
|
|
|
|||
|
|
@ -291,6 +291,22 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) {
|
|||
}
|
||||
}
|
||||
|
||||
// allocate swap offset tracker
|
||||
{
|
||||
// note that this computation is mirrored in xous-swapper
|
||||
let swap_size_usable = crate::swap::derive_usable_swap(swap_spec.swap_len as usize);
|
||||
for offset in (0..(swap_size_usable / PAGE_SIZE) * core::mem::size_of::<u32>()).step_by(4096) {
|
||||
let offset_page = cfg.alloc() as usize; // this also zeroes the page
|
||||
cfg.map_page(
|
||||
root,
|
||||
offset_page,
|
||||
SWAP_OFFSET_VADDR + offset,
|
||||
FLG_R | FLG_W | FLG_U | FLG_VALID,
|
||||
SWAPPER_PID,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// map any hardware-specific pages into the userspace swapper
|
||||
crate::platform::userspace_maps(cfg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,9 +270,8 @@ impl SwapHal {
|
|||
flash_spim.mem_read(SWAP_IMG_START as u32, &mut buf.data, false);
|
||||
|
||||
// compute offsets for swap
|
||||
let mac_size = (swap.ram_size as usize / 4096) * size_of::<Tag>();
|
||||
let mac_size_to_page = (mac_size + (PAGE_SIZE - 1)) & !(PAGE_SIZE - 1);
|
||||
let ram_size_actual = (swap.ram_size as usize & !(PAGE_SIZE - 1)) - mac_size_to_page;
|
||||
let ram_size_actual = crate::swap::derive_usable_swap(swap.ram_size as usize);
|
||||
let mac_size = crate::swap::derive_mac_size(swap.ram_size as usize);
|
||||
if SDBG {
|
||||
println!(
|
||||
"mac area size: {:x}, ram_size_actual: {:x}, swap.ram_size: {:x}, mac offset: {:x}",
|
||||
|
|
|
|||
|
|
@ -34,9 +34,8 @@ impl SwapHal {
|
|||
|
||||
// compute the MAC area needed for the total RAM size. This is a slight over-estimate
|
||||
// because once we remove the MAC area, we need even less storage, but it's a small error.
|
||||
let mac_size = (swap.ram_size as usize / 4096) * size_of::<Tag>();
|
||||
let mac_size_to_page = (mac_size + (PAGE_SIZE - 1)) & !(PAGE_SIZE - 1);
|
||||
let ram_size_actual = (swap.ram_size as usize & !(PAGE_SIZE - 1)) - mac_size_to_page;
|
||||
let ram_size_actual = crate::swap::derive_usable_swap(swap.ram_size as usize);
|
||||
let mac_size = crate::swap::derive_mac_size(swap.ram_size as usize);
|
||||
if SDBG {
|
||||
println!(
|
||||
"mac area size: {:x}, ram_size_actual: {:x}, swap.ram_size: {:x}, mac offset: {:x}",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
use core::mem::size_of;
|
||||
|
||||
use aes_gcm_siv::Tag;
|
||||
|
||||
use crate::PAGE_SIZE;
|
||||
|
||||
/// Virtual address fields:
|
||||
/// 31 22 21 12 11 0
|
||||
/// | L1 index | L2 index | LSB of addr |
|
||||
|
|
@ -42,6 +48,7 @@ pub const SWAP_PT_VADDR: usize = 0xE000_0000;
|
|||
// E000_0000 - E100_0000 => 16 MiB of vaddr space for page tables; should be more than enough
|
||||
pub const SWAP_CFG_VADDR: usize = 0xE100_0000;
|
||||
pub const SWAP_RPT_VADDR: usize = 0xE100_1000;
|
||||
pub const SWAP_OFFSET_VADDR: usize = 0xE110_0000;
|
||||
pub const SWAP_APP_UART_VADDR: usize = 0xE180_0000;
|
||||
#[cfg(feature = "cramium-soc")]
|
||||
pub const SWAP_APP_UART_IFRAM_VADDR: usize = 0xE180_1000;
|
||||
|
|
@ -82,3 +89,18 @@ pub const SPIM_RAM_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRA
|
|||
#[allow(dead_code)]
|
||||
#[cfg(feature = "cramium-soc")]
|
||||
pub const SPIM_FLASH_IFRAM_ADDR: usize = utralib::HW_IFRAM0_MEM + utralib::HW_IFRAM0_MEM_LEN - 5 * 4096;
|
||||
|
||||
/// Function that derives the usable amount of swap space from the total length of swap memory available.
|
||||
/// This is used repeatedly in the initialization process to define the boundary between the swap page
|
||||
/// storage and the message authentication code (MAC) tables.
|
||||
///
|
||||
/// This is a slight over-estimate because once we remove the MAC area, we need even less storage,
|
||||
/// but it's a small error.
|
||||
pub fn derive_usable_swap(swap_len: usize) -> usize {
|
||||
let mac_size = (swap_len as usize / 4096) * size_of::<Tag>();
|
||||
let mac_size_to_page = (mac_size + (PAGE_SIZE - 1)) & !(PAGE_SIZE - 1);
|
||||
let swap_size_usable = (swap_len as usize & !(PAGE_SIZE - 1)) - mac_size_to_page;
|
||||
swap_size_usable
|
||||
}
|
||||
|
||||
pub fn derive_mac_size(swap_len: usize) -> usize { (swap_len / 4096) * size_of::<Tag>() }
|
||||
|
|
|
|||
Loading…
Reference in a new issue