mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix default flags for swap; add load checking for swap
load checking is aware of all three types of sections, and can natively call the encrypt/decrypt ops to ensure that the encrypted swap is set up correctly.
This commit is contained in:
parent
62f1ad09f0
commit
d318134bdc
1 changed files with 101 additions and 28 deletions
|
|
@ -243,8 +243,7 @@ impl MiniElf {
|
||||||
| FLG_X
|
| FLG_X
|
||||||
| FLG_VALID
|
| FLG_VALID
|
||||||
| if section.flags() & 1 == 1 { FLG_W } else { 0 }
|
| if section.flags() & 1 == 1 { FLG_W } else { 0 }
|
||||||
| if section.flags() & 4 == 4 { FLG_X } else { 0 }
|
| if section.flags() & 4 == 4 { FLG_X } else { 0 };
|
||||||
| if ini_type == IniType::IniS { FLG_P } else { 0 };
|
|
||||||
|
|
||||||
let copy_to_ram = ((section.flags() as u8) & MINIELF_FLG_W) != 0;
|
let copy_to_ram = ((section.flags() as u8) & MINIELF_FLG_W) != 0;
|
||||||
if (section.virt as usize) < previous_addr {
|
if (section.virt as usize) < previous_addr {
|
||||||
|
|
@ -371,8 +370,17 @@ impl MiniElf {
|
||||||
|
|
||||||
// --- map FLASH or swap pages to virtual memory ---
|
// --- map FLASH or swap pages to virtual memory ---
|
||||||
while pages_to_map > 0 {
|
while pages_to_map > 0 {
|
||||||
let map_phys_addr = (image_phys_base + section_map_phys_offset) & !(PAGE_SIZE - 1);
|
let map_phys_addr = if ini_type != IniType::IniS {
|
||||||
allocator.map_page(tt, map_phys_addr, virt_page, flag_defaults, pid as XousPid);
|
(image_phys_base + section_map_phys_offset) & !(PAGE_SIZE - 1)
|
||||||
|
} else {
|
||||||
|
0 // IniS physical addresses are non-existent; make that abundantly clear
|
||||||
|
};
|
||||||
|
let flags = if ini_type == IniType::IniS {
|
||||||
|
flag_defaults & !FLG_VALID | FLG_P
|
||||||
|
} else {
|
||||||
|
flag_defaults
|
||||||
|
};
|
||||||
|
allocator.map_page(tt, map_phys_addr, virt_page, flags, pid as XousPid);
|
||||||
last_mapped_xip = virt_page;
|
last_mapped_xip = virt_page;
|
||||||
|
|
||||||
section_map_phys_offset += PAGE_SIZE;
|
section_map_phys_offset += PAGE_SIZE;
|
||||||
|
|
@ -404,18 +412,28 @@ impl MiniElf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Page through a processes allocated pages and check against the file spec.
|
/// Page through a processes allocated pages and check against the file spec.
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(any(feature = "debug-print", feature = "swap"))]
|
||||||
pub fn check(&self, allocator: &mut BootConfig, load_offset: usize, pid: XousPid, xip: bool) {
|
pub fn check(&self, allocator: &mut BootConfig, load_offset: usize, pid: XousPid, ini_type: IniType) {
|
||||||
println!(
|
println!("Checking {:?} PID {} starting at offset {:08x}", ini_type, pid, load_offset);
|
||||||
"Checking {} PID {} starting at offset {:08x}",
|
let image_phys_base = match ini_type {
|
||||||
if xip { "xip" } else { "ram" },
|
IniType::IniE | IniType::IniF => allocator.base_addr as usize + self.load_offset as usize,
|
||||||
pid,
|
IniType::IniS => load_offset,
|
||||||
load_offset
|
};
|
||||||
);
|
|
||||||
let image_phys_base = allocator.base_addr as usize + self.load_offset as usize;
|
|
||||||
// the process offset is always 1 less than the PID, because that's how we built the table.
|
// the process offset is always 1 less than the PID, because that's how we built the table.
|
||||||
#[cfg(not(feature = "atsama5d27"))]
|
#[cfg(not(feature = "atsama5d27"))]
|
||||||
let tt = { allocator.processes[pid as usize - 1].satp };
|
let tt = match ini_type {
|
||||||
|
IniType::IniE | IniType::IniF => allocator.processes[pid as usize - 1].satp,
|
||||||
|
IniType::IniS => {
|
||||||
|
#[cfg(feature = "swap")]
|
||||||
|
{
|
||||||
|
allocator.processes[pid as usize - 1].swap_root >> 12
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "swap"))]
|
||||||
|
{
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
let tt = { allocator.processes[pid as usize - 1].ttbr0 };
|
let tt = { allocator.processes[pid as usize - 1].ttbr0 };
|
||||||
|
|
||||||
|
|
@ -435,18 +453,63 @@ impl MiniElf {
|
||||||
let dump_pa_src = section_offset + image_phys_base;
|
let dump_pa_src = section_offset + image_phys_base;
|
||||||
let dump_pa_dst = dest_offset;
|
let dump_pa_dst = dest_offset;
|
||||||
let dump_pa_end_dst = pt_walk(tt, section.virt as usize + section.len() - 20);
|
let dump_pa_end_dst = pt_walk(tt, section.virt as usize + section.len() - 20);
|
||||||
dump_addr(dump_pa_src, " Src [:20] ");
|
match ini_type {
|
||||||
dump_addr(dump_pa_dst, " Dst [:20] ");
|
IniType::IniE | IniType::IniF => {
|
||||||
dump_addr(dump_pa_src + section.len() - 20, " Src [-20:] ");
|
dump_addr(dump_pa_src, " Src [:20] ");
|
||||||
// recompute the end section mapping, because PA/VA mappings don't have to be linear (in fact
|
dump_addr(dump_pa_dst, " Dst [:20] ");
|
||||||
// they go in the opposite direction)
|
dump_addr(dump_pa_src + section.len() - 20, " Src [-20:] ");
|
||||||
if let Some(pa_dst_end) = dump_pa_end_dst {
|
// recompute the end section mapping, because PA/VA mappings don't have to be linear
|
||||||
dump_addr(pa_dst_end, " Dst [-20:] ");
|
// (in fact they go in the opposite direction)
|
||||||
} else {
|
if let Some(pa_dst_end) = dump_pa_end_dst {
|
||||||
println!(
|
dump_addr(pa_dst_end, " Dst [-20:] ");
|
||||||
" End of destination VA 0x{:x}, ERR UNMAPPED!",
|
} else {
|
||||||
section.virt as usize + section.len() - 20
|
println!(
|
||||||
);
|
" End of destination VA 0x{:x}, ERR UNMAPPED!",
|
||||||
|
section.virt as usize + section.len() - 20
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IniType::IniS => {
|
||||||
|
#[cfg(feature = "swap")]
|
||||||
|
if let Some(swap) = allocator.swap_hal.as_mut() {
|
||||||
|
let dump_disk = swap.decrypt_src_page_at(dump_pa_src & !(PAGE_SIZE - 1));
|
||||||
|
dump_slice(&dump_disk[dump_pa_src & (PAGE_SIZE - 1)..], " Src [:20] ");
|
||||||
|
let dump_swap = swap.decrypt_swap_from(
|
||||||
|
dest_offset & !(PAGE_SIZE - 1),
|
||||||
|
(section.virt as usize) & !(PAGE_SIZE - 1),
|
||||||
|
pid,
|
||||||
|
);
|
||||||
|
dump_slice(
|
||||||
|
&dump_swap[(section.virt as usize) & (PAGE_SIZE - 1)..],
|
||||||
|
" Dst [:20] ",
|
||||||
|
);
|
||||||
|
let dump_disk = swap
|
||||||
|
.decrypt_src_page_at((dump_pa_src + section.len() - 20) & !(PAGE_SIZE - 1));
|
||||||
|
dump_slice(
|
||||||
|
&dump_disk[(dump_pa_src + section.len() - 20) & (PAGE_SIZE - 1)..],
|
||||||
|
" Src [-20:] ",
|
||||||
|
);
|
||||||
|
// recompute the end section mapping, because PA/VA mappings don't have to be
|
||||||
|
// linear (in fact they go in the opposite direction)
|
||||||
|
if let Some(pa_dst_end) = dump_pa_end_dst {
|
||||||
|
let dump_swap = swap.decrypt_swap_from(
|
||||||
|
pa_dst_end & !(PAGE_SIZE - 1),
|
||||||
|
(section.virt as usize + section.len() - 20) & !(PAGE_SIZE - 1),
|
||||||
|
pid,
|
||||||
|
);
|
||||||
|
dump_slice(
|
||||||
|
&dump_swap
|
||||||
|
[(section.virt as usize + section.len() - 20) & (PAGE_SIZE - 1)..],
|
||||||
|
" Dst [-20:] ",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
" End of destination VA 0x{:x}, ERR UNMAPPED!",
|
||||||
|
section.virt as usize + section.len() - 20
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
|
|
@ -461,7 +524,7 @@ impl MiniElf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(any(feature = "debug-print", feature = "swap"))]
|
||||||
fn dump_addr(addr: usize, label: &str) {
|
fn dump_addr(addr: usize, label: &str) {
|
||||||
print!("{}", label);
|
print!("{}", label);
|
||||||
let slice = unsafe { core::slice::from_raw_parts(addr as *const u8, 20) };
|
let slice = unsafe { core::slice::from_raw_parts(addr as *const u8, 20) };
|
||||||
|
|
@ -470,8 +533,18 @@ fn dump_addr(addr: usize, label: &str) {
|
||||||
}
|
}
|
||||||
print!("\n\r");
|
print!("\n\r");
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "swap")]
|
||||||
|
fn dump_slice(slice: &[u8], label: &str) {
|
||||||
|
print!("{}", label);
|
||||||
|
// handle case that our decrypt region isn't 20 bytes long...
|
||||||
|
let len = slice.len().min(20);
|
||||||
|
for &b in &slice[..len] {
|
||||||
|
print!("{:02x}", b);
|
||||||
|
}
|
||||||
|
print!("\n\r");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "debug-print", not(feature = "atsama5d27")))]
|
#[cfg(all(any(feature = "debug-print", feature = "swap"), not(feature = "atsama5d27")))]
|
||||||
pub fn pt_walk(root: usize, va: usize) -> Option<usize> {
|
pub fn pt_walk(root: usize, va: usize) -> Option<usize> {
|
||||||
let l1_pt = unsafe { &mut (*((root << 12) as *mut PageTable)) };
|
let l1_pt = unsafe { &mut (*((root << 12) as *mut PageTable)) };
|
||||||
let l1_entry = l1_pt.entries[(va & 0xFFC0_0000) >> 22];
|
let l1_entry = l1_pt.entries[(va & 0xFFC0_0000) >> 22];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue