mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
loader/arm: allocate separate IRQ stack
This commit is contained in:
parent
90df83f885
commit
6ac2713f0a
6 changed files with 63 additions and 24 deletions
|
|
@ -1,14 +1,18 @@
|
||||||
use core::{mem, slice};
|
use core::{mem, slice};
|
||||||
|
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
|
use armv7::structures::paging::TranslationTableMemory;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "atsama5d27", feature = "debug-print"))]
|
||||||
use armv7::{
|
use armv7::{
|
||||||
VirtualAddress,
|
VirtualAddress,
|
||||||
structures::paging::{
|
structures::paging::{
|
||||||
InMemoryRegister, PageTableDescriptor,
|
InMemoryRegister, PageTableDescriptor,
|
||||||
Readable, TranslationTableDescriptor, TranslationTableMemory,
|
Readable, TranslationTableDescriptor, TranslationTableType,
|
||||||
TranslationTableType, SMALL_PAGE_FLAGS,
|
SMALL_PAGE_FLAGS,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub const FLG_VALID: usize = 0x1;
|
pub const FLG_VALID: usize = 0x1;
|
||||||
|
|
@ -109,7 +113,7 @@ impl MiniElf {
|
||||||
|
|
||||||
// Allocate a page to handle the top-level memory translation
|
// Allocate a page to handle the top-level memory translation
|
||||||
#[cfg(not(feature = "atsama5d27"))]
|
#[cfg(not(feature = "atsama5d27"))]
|
||||||
let (tt, tt_address) = {
|
let (tt, _tt_address) = {
|
||||||
let tt_address = allocator.alloc() as usize;
|
let tt_address = allocator.alloc() as usize;
|
||||||
let tt = unsafe { &mut *(tt_address as *mut PageTable) };
|
let tt = unsafe { &mut *(tt_address as *mut PageTable) };
|
||||||
|
|
||||||
|
|
@ -119,7 +123,7 @@ impl MiniElf {
|
||||||
(tt, tt_address)
|
(tt, tt_address)
|
||||||
};
|
};
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
let (tt, tt_address) = {
|
let (tt, _tt_address) = {
|
||||||
let pid_idx = pid as usize - 1;
|
let pid_idx = pid as usize - 1;
|
||||||
|
|
||||||
// Allocate a page to handle the top-level memory translation
|
// Allocate a page to handle the top-level memory translation
|
||||||
|
|
@ -142,7 +146,7 @@ impl MiniElf {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Turn the satp address into a pointer
|
// Turn the satp address into a pointer
|
||||||
println!(" Pagetable @ {:08x}", tt_address);
|
println!(" Pagetable @ {:08x}", _tt_address);
|
||||||
|
|
||||||
// Allocate thread 1 for this process
|
// Allocate thread 1 for this process
|
||||||
let thread_address = allocator.alloc() as usize;
|
let thread_address = allocator.alloc() as usize;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
||||||
let mut kdata_size = 0;
|
let mut kdata_size = 0;
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
let mut kernel_exception_sp = 0;
|
let mut kernel_exception_sp = 0;
|
||||||
|
#[cfg(feature = "atsama5d27")]
|
||||||
|
let mut kernel_irq_sp = 0;
|
||||||
for tag in args.iter() {
|
for tag in args.iter() {
|
||||||
if tag.name == u32::from_le_bytes(*b"IniE") {
|
if tag.name == u32::from_le_bytes(*b"IniE") {
|
||||||
let inie = MiniElf::new(&tag);
|
let inie = MiniElf::new(&tag);
|
||||||
|
|
@ -54,7 +56,7 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
||||||
}
|
}
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
{
|
{
|
||||||
(ktext_offset, kdata_offset, kernel_exception_sp) = xkrn.load(cfg, process_offset - load_size_rounded, 1);
|
(ktext_offset, kdata_offset, kernel_exception_sp, kernel_irq_sp) = xkrn.load(cfg, process_offset - load_size_rounded, 1);
|
||||||
(ktext_size, kdata_size, ktext_virt_offset, kdata_virt_offset) = (
|
(ktext_size, kdata_size, ktext_virt_offset, kdata_virt_offset) = (
|
||||||
(xkrn.text_size as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1),
|
(xkrn.text_size as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1),
|
||||||
(((xkrn.data_size + xkrn.bss_size) as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)),
|
(((xkrn.data_size + xkrn.bss_size) as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)),
|
||||||
|
|
@ -117,6 +119,7 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
||||||
kdata_size,
|
kdata_size,
|
||||||
kdata_virt_offset,
|
kdata_virt_offset,
|
||||||
kernel_exception_sp,
|
kernel_exception_sp,
|
||||||
|
kernel_irq_sp,
|
||||||
krn_struct_start,
|
krn_struct_start,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,7 @@ use armv7::structures::paging::{
|
||||||
PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS,
|
PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS,
|
||||||
};
|
};
|
||||||
use armv7::{PhysicalAddress, VirtualAddress};
|
use armv7::{PhysicalAddress, VirtualAddress};
|
||||||
use crate::consts::{
|
use crate::consts::{FLG_R, FLG_U, FLG_VALID, FLG_W, FLG_X, GUARD_MEMORY_BYTES, KERNEL_ARGUMENT_OFFSET, LOADER_CODE_ADDRESS, PAGE_TABLE_OFFSET, KERNEL_STACK_PAGE_COUNT, EXCEPTION_STACK_TOP, IRQ_STACK_TOP};
|
||||||
FLG_R, FLG_U, FLG_VALID, FLG_W, FLG_X, GUARD_MEMORY_BYTES, KERNEL_ARGUMENT_OFFSET,
|
|
||||||
LOADER_CODE_ADDRESS, PAGE_TABLE_OFFSET, KERNEL_STACK_PAGE_COUNT,
|
|
||||||
EXCEPTION_STACK_TOP,
|
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bzero, println, BootConfig, XousPid, PAGE_SIZE, WORD_SIZE,
|
bzero, println, BootConfig, XousPid, PAGE_SIZE, WORD_SIZE,
|
||||||
};
|
};
|
||||||
|
|
@ -394,6 +390,7 @@ pub fn map_kernel_to_processes(
|
||||||
kdata_size: usize,
|
kdata_size: usize,
|
||||||
kdata_virt_offset: usize,
|
kdata_virt_offset: usize,
|
||||||
kernel_exception_sp: usize,
|
kernel_exception_sp: usize,
|
||||||
|
kernel_irq_sp: usize,
|
||||||
krn_struct_start: usize,
|
krn_struct_start: usize,
|
||||||
) {
|
) {
|
||||||
let processes = unsafe { core::mem::transmute::<_, &[InitialProcess]>( &*cfg.processes) };
|
let processes = unsafe { core::mem::transmute::<_, &[InitialProcess]>( &*cfg.processes) };
|
||||||
|
|
@ -444,6 +441,17 @@ pub fn map_kernel_to_processes(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Mapping irq stack page to the process PID{}", process.asid);
|
||||||
|
let virt = IRQ_STACK_TOP;
|
||||||
|
let phys = kernel_irq_sp;
|
||||||
|
println!("MAP ({:08x}): {:08x} -> {:08x}", translation_table as usize, virt, phys);
|
||||||
|
cfg.map_page(
|
||||||
|
translation_table,
|
||||||
|
phys,
|
||||||
|
virt,
|
||||||
|
FLG_VALID | FLG_R | FLG_W,
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: For now, make the UART visible for all the processes.
|
// TODO: For now, make the UART visible for all the processes.
|
||||||
// Later on we may reuse the mapping made by the kernel.
|
// Later on we may reuse the mapping made by the kernel.
|
||||||
println!("Mapping UART registers to the process PID{}", process.asid);
|
println!("Mapping UART registers to the process PID{}", process.asid);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ pub const PAGE_TABLE_ROOT_OFFSET: usize = 0xff80_0000;
|
||||||
pub const CONTEXT_OFFSET: usize = 0xff80_4000;
|
pub const CONTEXT_OFFSET: usize = 0xff80_4000;
|
||||||
pub const USER_AREA_END: usize = 0xfe00_0000;
|
pub const USER_AREA_END: usize = 0xfe00_0000;
|
||||||
pub const EXCEPTION_STACK_TOP: usize = 0xffff_0000;
|
pub const EXCEPTION_STACK_TOP: usize = 0xffff_0000;
|
||||||
|
pub const IRQ_STACK_TOP: usize = 0xfffd_0000;
|
||||||
pub const KERNEL_LOAD_OFFSET: usize = 0xffd0_0000;
|
pub const KERNEL_LOAD_OFFSET: usize = 0xffd0_0000;
|
||||||
pub const KERNEL_STACK_TOP: usize = 0xfff8_0000;
|
pub const KERNEL_STACK_TOP: usize = 0xfff8_0000;
|
||||||
pub const KERNEL_ARGUMENT_OFFSET: usize = 0xffc0_0000;
|
pub const KERNEL_ARGUMENT_OFFSET: usize = 0xffc0_0000;
|
||||||
|
|
@ -21,6 +22,7 @@ pub const GUARD_MEMORY_BYTES: usize = 2 * PAGE_SIZE;
|
||||||
|
|
||||||
// Allocate more pages for the kernel stacks
|
// Allocate more pages for the kernel stacks
|
||||||
pub const KERNEL_STACK_PAGE_COUNT: usize = 4;
|
pub const KERNEL_STACK_PAGE_COUNT: usize = 4;
|
||||||
|
pub const IRQ_STACK_PAGE_COUNT: usize = 1;
|
||||||
|
|
||||||
pub const FLG_VALID: usize = 0x1;
|
pub const FLG_VALID: usize = 0x1;
|
||||||
pub const FLG_X: usize = 0x8;
|
pub const FLG_X: usize = 0x8;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub struct Uart {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: UartType::new(),
|
inner: UartType::new(),
|
||||||
|
|
@ -89,7 +90,7 @@ fn print_l2_pagetable(vpn1: usize, phys_addr: PhysicalAddress) {
|
||||||
|
|
||||||
let mut no_valid_items = true;
|
let mut no_valid_items = true;
|
||||||
for (i, pt_desc) in l2_pt.iter().enumerate() {
|
for (i, pt_desc) in l2_pt.iter().enumerate() {
|
||||||
let virt_addr = (vpn1 << 20) | (i << 12);
|
let _virt_addr = (vpn1 << 20) | (i << 12);
|
||||||
|
|
||||||
if let PageTableType::Invalid = pt_desc.get_type() {
|
if let PageTableType::Invalid = pt_desc.get_type() {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -97,16 +98,16 @@ fn print_l2_pagetable(vpn1: usize, phys_addr: PhysicalAddress) {
|
||||||
|
|
||||||
no_valid_items = false;
|
no_valid_items = false;
|
||||||
|
|
||||||
let phys_addr = pt_desc.get_addr().expect("addr");
|
let _phys_addr = pt_desc.get_addr().expect("addr");
|
||||||
|
|
||||||
match pt_desc.get_type() {
|
match pt_desc.get_type() {
|
||||||
PageTableType::LargePage => println!(
|
PageTableType::LargePage => println!(
|
||||||
" - {:02x} (64K) Large Page {:08x} -> {:08x}",
|
" - {:02x} (64K) Large Page {:08x} -> {:08x}",
|
||||||
i, virt_addr, phys_addr
|
i, _virt_addr, _phys_addr
|
||||||
),
|
),
|
||||||
PageTableType::SmallPage => println!(
|
PageTableType::SmallPage => println!(
|
||||||
" - {:02x} (4K) Small Page {:08x} -> {:08x}",
|
" - {:02x} (4K) Small Page {:08x} -> {:08x}",
|
||||||
i, virt_addr, phys_addr
|
i, _virt_addr, _phys_addr
|
||||||
),
|
),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
@ -132,25 +133,25 @@ pub fn print_pagetable(root: usize) {
|
||||||
|
|
||||||
match tt_desc.get_type() {
|
match tt_desc.get_type() {
|
||||||
TranslationTableType::Page => {
|
TranslationTableType::Page => {
|
||||||
let virt_addr = i << 20;
|
let _virt_addr = i << 20;
|
||||||
println!(
|
println!(
|
||||||
" - {:03x} (1MB) {:08x} L2 page table @ {:08x}",
|
" - {:03x} (1MB) {:08x} L2 page table @ {:08x}",
|
||||||
i, virt_addr, phys_addr
|
i, _virt_addr, phys_addr
|
||||||
);
|
);
|
||||||
print_l2_pagetable(i, phys_addr);
|
print_l2_pagetable(i, phys_addr);
|
||||||
}
|
}
|
||||||
TranslationTableType::Section => {
|
TranslationTableType::Section => {
|
||||||
let virt_addr = i * 1024; // 1 MB
|
let _virt_addr = i * 1024; // 1 MB
|
||||||
println!(
|
println!(
|
||||||
" - {:03x} (1MB) section {:08x} -> {:08x}",
|
" - {:03x} (1MB) section {:08x} -> {:08x}",
|
||||||
i, virt_addr, phys_addr
|
i, _virt_addr, phys_addr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
TranslationTableType::Supersection => {
|
TranslationTableType::Supersection => {
|
||||||
let virt_addr = i * (1024 * 16); // 16 MB
|
let _virt_addr = i * (1024 * 16); // 16 MB
|
||||||
println!(
|
println!(
|
||||||
" - {:03x} (16MB) supersection {:08x} -> {:08x}",
|
" - {:03x} (16MB) supersection {:08x} -> {:08x}",
|
||||||
i, virt_addr, phys_addr
|
i, _virt_addr, phys_addr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Foundation Devices, Inc <hello@foundationdevices.com>
|
// SPDX-FileCopyrightText: 2023 Foundation Devices, Inc <hello@foundationdevices.com>
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::consts::{CONTEXT_OFFSET, EXCEPTION_STACK_TOP, FLG_R, FLG_U, FLG_VALID, FLG_W, FLG_X, KERNEL_LOAD_OFFSET, PAGE_TABLE_ROOT_OFFSET, USER_AREA_END, USER_STACK_TOP, KERNEL_STACK_PAGE_COUNT, KERNEL_STACK_TOP};
|
use crate::consts::{CONTEXT_OFFSET, EXCEPTION_STACK_TOP, FLG_R, FLG_U, FLG_VALID, FLG_W, FLG_X, KERNEL_LOAD_OFFSET, PAGE_TABLE_ROOT_OFFSET, USER_AREA_END, USER_STACK_TOP, KERNEL_STACK_PAGE_COUNT, KERNEL_STACK_TOP, IRQ_STACK_PAGE_COUNT, IRQ_STACK_TOP};
|
||||||
use crate::{
|
use crate::{
|
||||||
println, BootConfig, ProgramDescription,
|
println, BootConfig, ProgramDescription,
|
||||||
XousPid, PAGE_SIZE, STACK_PAGE_COUNT, VDBG,
|
XousPid, PAGE_SIZE, STACK_PAGE_COUNT, VDBG,
|
||||||
|
|
@ -33,7 +33,7 @@ impl ProgramDescription {
|
||||||
/// that is passed in should be used instead of `self.load_offset`
|
/// that is passed in should be used instead of `self.load_offset`
|
||||||
/// for this reason.
|
/// for this reason.
|
||||||
pub fn load(&self, allocator: &mut BootConfig, load_offset: usize, pid: XousPid)
|
pub fn load(&self, allocator: &mut BootConfig, load_offset: usize, pid: XousPid)
|
||||||
-> (usize, usize, usize) {
|
-> (usize, usize, usize, usize) {
|
||||||
assert_ne!(pid, 0, "PID must not be 0");
|
assert_ne!(pid, 0, "PID must not be 0");
|
||||||
|
|
||||||
println!("Mapping PID {} into offset {:08x}", pid, load_offset);
|
println!("Mapping PID {} into offset {:08x}", pid, load_offset);
|
||||||
|
|
@ -151,6 +151,27 @@ impl ProgramDescription {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate IRQ stack pages
|
||||||
|
let mut irq_sp = 0;
|
||||||
|
for i in 0..IRQ_STACK_PAGE_COUNT {
|
||||||
|
// If it's the kernel, also allocate an exception page
|
||||||
|
if is_kernel {
|
||||||
|
let sp_page = allocator.alloc() as usize;
|
||||||
|
// Remember only the first (top) exception stack page
|
||||||
|
if irq_sp == 0 {
|
||||||
|
irq_sp = sp_page;
|
||||||
|
}
|
||||||
|
println!("Allocated IRQ stack page: {:08x}", sp_page);
|
||||||
|
allocator.map_page(
|
||||||
|
translation_table,
|
||||||
|
sp_page,
|
||||||
|
(IRQ_STACK_TOP - 16 - PAGE_SIZE * i) & !(PAGE_SIZE - 1),
|
||||||
|
flag_defaults,
|
||||||
|
);
|
||||||
|
allocator.change_owner(pid as XousPid, sp_page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!((self.text_offset as usize & (PAGE_SIZE - 1)), 0);
|
assert_eq!((self.text_offset as usize & (PAGE_SIZE - 1)), 0);
|
||||||
assert_eq!((self.data_offset as usize & (PAGE_SIZE - 1)), 0);
|
assert_eq!((self.data_offset as usize & (PAGE_SIZE - 1)), 0);
|
||||||
if allocator.no_copy {
|
if allocator.no_copy {
|
||||||
|
|
@ -207,6 +228,6 @@ impl ProgramDescription {
|
||||||
allocator.processes[pid_idx].sp = stack_addr;
|
allocator.processes[pid_idx].sp = stack_addr;
|
||||||
allocator.processes[pid_idx].asid = pid;
|
allocator.processes[pid_idx].asid = pid;
|
||||||
|
|
||||||
(text_phys_offset, data_phys_offset, exception_sp)
|
(text_phys_offset, data_phys_offset, exception_sp, irq_sp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue