mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Merge pull request #359 from Foundation-Devices/arm-revamped-irq
arm: revamp IRQ handling
This commit is contained in:
commit
26c56e2ead
16 changed files with 206 additions and 75 deletions
|
|
@ -44,6 +44,7 @@ members = [
|
|||
"services/com",
|
||||
"services/keyboard",
|
||||
"services/kernel-test",
|
||||
"services/ticktimer-test-client",
|
||||
"services/trng",
|
||||
"services/gam",
|
||||
"services/status",
|
||||
|
|
|
|||
|
|
@ -26,11 +26,12 @@ xous-kernel = { package = "xous", version = "0.9.37", features = [
|
|||
riscv = { version = "0.5.6", package = "xous-riscv" } # source is in "../imports/riscv-0.5.6"
|
||||
|
||||
[target.'cfg(target_arch = "arm")'.dependencies]
|
||||
armv7 = { git = "https://github.com/Foundation-Devices/armv7.git", branch = "update" }
|
||||
armv7 = { git = "https://github.com/Foundation-Devices/armv7.git", branch = "update", features = ["critical-section"] }
|
||||
atsama5d27 = { git = "https://github.com/Foundation-Devices/atsama5d27.git", branch = "master" }
|
||||
xous-kernel = { package = "xous", version = "0.9.37", features = [
|
||||
"v2p",
|
||||
] }
|
||||
critical-section = "1.1.1"
|
||||
|
||||
[features]
|
||||
atsama5d27 = ["utralib/atsama5d27"]
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -22,6 +22,10 @@
|
|||
#define I_BIT 0x80
|
||||
#define F_BIT 0x40
|
||||
|
||||
#define EXCEPTION_STACK_TOP 0xffff0000
|
||||
#define IRQ_STACK_TOP 0xfffd0000
|
||||
#define THREAD_CONTEXT_AREA 0xff804000
|
||||
|
||||
.section .text.reset_vector, "ax"
|
||||
|
||||
.global reset
|
||||
|
|
@ -36,8 +40,8 @@ _exception_vectors_kernel:
|
|||
b trap_handler /* Prefetch Abort */
|
||||
b trap_handler /* Data Abort */
|
||||
.word 0 /* Empty */
|
||||
b trap_handler /* IRQ : read the AIC */
|
||||
b trap_handler /* FIQ */
|
||||
b irq_handler /* IRQ : read the AIC */
|
||||
b fiq_handler /* FIQ */
|
||||
|
||||
undef_vector:
|
||||
bkpt /* Issue debugger breakpoint */
|
||||
|
|
@ -51,6 +55,21 @@ _branch_main:
|
|||
ldr r4, =_exception_vectors_kernel
|
||||
mcr p15, 0, r4, c12, c0, 0
|
||||
|
||||
/* Clear all faults if any */
|
||||
mov ip, #0
|
||||
mcr p15, 0, ip, c6, c0, 0
|
||||
mcr p15, 0, ip, c6, c0, 2
|
||||
mcr p15, 0, ip, c5, c0, 0
|
||||
mcr p15, 0, ip, c5, c0, 1
|
||||
|
||||
/* Configure IRQ/FIQ stack pointers */
|
||||
msr cpsr_c, #ARM_MODE_IRQ
|
||||
ldr sp, =(IRQ_STACK_TOP)
|
||||
msr cpsr_c, #ARM_MODE_FIQ
|
||||
ldr sp, =(IRQ_STACK_TOP)
|
||||
|
||||
msr cpsr_c, #ARM_MODE_SVC
|
||||
|
||||
/* Note that registers r0-r3 still contain the kernel arguments */
|
||||
bl init
|
||||
bl kmain
|
||||
|
|
@ -60,18 +79,18 @@ _branch_main:
|
|||
Syscall/IRQ/Abort trap handler.
|
||||
|
||||
Saves all process context into a structure that is
|
||||
mapped to each thread at 0xff804000 (THREAD_CONTEXT_AREA).
|
||||
mapped to each thread at THREAD_CONTEXT_AREA.
|
||||
Return happens elsewhere.
|
||||
*/
|
||||
trap_handler:
|
||||
ldr ip, =(0xff804000)
|
||||
ldr ip, =(THREAD_CONTEXT_AREA)
|
||||
|
||||
# If this is a syscall, then r0 contains a pointer to the syscall arguments structure
|
||||
# Due to it being clobbered by this routine's code, we have save it into the scratch area for future use
|
||||
str r0, [ip] /* Preserve r0 in the scratch field */
|
||||
ldr r0, [ip, #4] /* Load current context number */
|
||||
lsl r0, #7 /* Multiply by 32 */
|
||||
add ip, ip, r0 /* ip = 0xff804000 + (context_number * 32) */
|
||||
add ip, ip, r0 /* ip = THREAD_CONTEXT_AREA + (context_number * 32) */
|
||||
|
||||
# If the trap has originated in the user/system mode, then we need to store
|
||||
# the user/system mode registers that are currently banked out
|
||||
|
|
@ -82,7 +101,7 @@ trap_handler:
|
|||
cmp r0, #ARM_MODE_USR /* Compare with 'User' mode */
|
||||
beq _store_banked /* Save banked out user registers if coming from User mode */
|
||||
|
||||
ldr r0, =(0xff804000) /* Restore r0 from the scratch field */
|
||||
ldr r0, =(THREAD_CONTEXT_AREA) /* Restore r0 from the scratch field */
|
||||
ldr r0, [r0]
|
||||
|
||||
stm ip, {r0 - r15} /* Save all the registers */
|
||||
|
|
@ -95,7 +114,7 @@ _store_banked:
|
|||
str r0, [ip]
|
||||
sub ip, ip, #(17 * 4)
|
||||
|
||||
ldr r0, =(0xff804000) /* Restore r0 from the scratch field */
|
||||
ldr r0, =(THREAD_CONTEXT_AREA) /* Restore r0 from the scratch field */
|
||||
ldr r0, [r0]
|
||||
|
||||
stm ip, {r0 - r7} /* Save the common registers */
|
||||
|
|
@ -108,8 +127,8 @@ _skip_store_banked:
|
|||
str lr, [ip]
|
||||
sub ip, #(4 * 19)
|
||||
|
||||
# Set a default exception/irq stack pointer (EXCEPTION_STACK_TOP)
|
||||
ldr sp, =(0xffff0000)
|
||||
# Set a default stack pointer
|
||||
ldr sp, =(EXCEPTION_STACK_TOP)
|
||||
|
||||
# Choose where to go next depending on the current mode: SVC (syscall), abort or IRQ
|
||||
mrs ip, cpsr /* Access the current mode register */
|
||||
|
|
@ -118,10 +137,6 @@ _skip_store_banked:
|
|||
bleq _swi_handler_rust /* Jump to SVC handler */
|
||||
cmp ip, #ARM_MODE_ABT /* Compare with 'Abort' mode */
|
||||
bleq _abort_handler_rust /* Jump to abort handler */
|
||||
cmp ip, #ARM_MODE_IRQ /* Compare with 'IRQ' mode */
|
||||
bleq irq_handler /* Jump to IRQ handler */
|
||||
cmp ip, #ARM_MODE_FIQ /* Compare with 'FIQ' mode */
|
||||
bleq fiq_handler /* Jump to FIQ handler */
|
||||
|
||||
# Any other unhandled exception goes here
|
||||
bkpt
|
||||
|
|
@ -129,14 +144,49 @@ _skip_store_banked:
|
|||
|
||||
irq_handler:
|
||||
fiq_handler:
|
||||
# Disable further IRQs
|
||||
mrs ip, cpsr
|
||||
orr ip, ip, #I_BIT | F_BIT /* Disable interrupts */
|
||||
msr cpsr, ip
|
||||
/* Save interrupt context on stack to allow nesting */
|
||||
sub lr, lr, #4
|
||||
stmfd sp!, {lr}
|
||||
stmfd sp, {r0 - r12, sp, lr}^
|
||||
sub sp, sp, #(4 * 15)
|
||||
mrs lr, spsr
|
||||
stmfd sp!, {lr}
|
||||
mrc p15, 0, lr, c13, c0, 2 /* Read hardware thread pointer register */
|
||||
stmfd sp!, {lr}
|
||||
mrc p15, 0, lr, c2, c0, 0 /* Read TTBR0 */
|
||||
stmfd sp!, {lr}
|
||||
mrc p15, 0, lr, c13, c0, 1 /* Read CONTEXTIDR */
|
||||
stmfd sp!, {lr}
|
||||
mrc p15, 0, lr, c13, c0, 3 /* Read thread resume address scratch register */
|
||||
stmfd sp!, {lr}
|
||||
|
||||
bl _irq_handler_rust
|
||||
bkpt
|
||||
b .
|
||||
/* Handle IRQs in supervisor mode (IRQs disabled) */
|
||||
msr cpsr_c, #(ARM_MODE_SVC | I_BIT | F_BIT)
|
||||
# Set a default stack pointer
|
||||
ldr sp, =(EXCEPTION_STACK_TOP)
|
||||
|
||||
b _irq_handler_rust
|
||||
|
||||
.global irq_handler_return
|
||||
irq_handler_return:
|
||||
/* As we're returning from ABORT mode, go back to IRQ mode (but with interrupts disabled) */
|
||||
msr cpsr_c, #(ARM_MODE_IRQ | I_BIT | F_BIT)
|
||||
|
||||
/* Restore interrupt context and branch back to calling code */
|
||||
ldmia sp!, {lr}
|
||||
mcr p15, 0, lr, c13, c0, 3 /* Set thread resume address scratch register */
|
||||
ldmia sp!, {lr}
|
||||
mcr p15, 0, lr, c13, c0, 1 /* Set CONTEXTIDR */
|
||||
ldmia sp!, {lr}
|
||||
mcr p15, 0, lr, c2, c0, 0 /* Set TTBR0 */
|
||||
bl flush_mmu
|
||||
ldmia sp!, {lr}
|
||||
mcr p15, 0, lr, c13, c0, 2 /* Set hardware thread pointer register */
|
||||
ldmia sp!, {lr}
|
||||
msr spsr_cxsf, lr
|
||||
ldmia sp, {r0 - r12, sp, lr}^
|
||||
add sp, sp, #(4 * 15)
|
||||
ldmia sp!, {pc}^
|
||||
|
||||
/*
|
||||
A thread resume routine.
|
||||
|
|
@ -149,11 +199,11 @@ _resume_trampoline:
|
|||
ldm ip, {sp, lr}^
|
||||
|
||||
# Switch privilege modes.
|
||||
# Interrupts have to be disabled if we're in the IRQ mode because the code we're resuming to
|
||||
# will have to service the interrupt source first before allowing more interrupts
|
||||
# Keep interrupts disabled if we're going to switch to the user mode IRQ handler (r2 != 0) to prevent
|
||||
# endless interrupt firing loop
|
||||
mrs ip, cpsr /* Access the current state register */
|
||||
and ip, ip, #0x1f /* Extract the mode field */
|
||||
cmp ip, #ARM_MODE_IRQ
|
||||
cmp r2, #0 /* r2 contains a "keep IRQs enabled" flag */
|
||||
mrs ip, spsr
|
||||
bic ip, ip, #I_BIT | F_BIT /* Allow interrupts. They'll stay enabled unless we're in IRQ mode */
|
||||
blne skip_disabling_interrupts
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use crate::SystemServices;
|
|||
|
||||
extern "Rust" {
|
||||
fn _xous_syscall_return_result(context: &Thread) -> !;
|
||||
fn irq_handler_return() -> !;
|
||||
}
|
||||
|
||||
static mut PREVIOUS_PAIR: Option<(PID, TID)> = None;
|
||||
|
|
@ -240,16 +241,7 @@ pub extern "C" fn abort_handler() {
|
|||
|
||||
// Resume the new thread within the same process.
|
||||
ArchProcess::with_current_mut(|p| {
|
||||
// Adjust the program counter by the amount returned by the exception handler
|
||||
/* FIXME let pc_adjust = a0 as isize;
|
||||
if pc_adjust < 0 {
|
||||
p.current_thread_mut().sepc -= pc_adjust.abs() as usize;
|
||||
} else {
|
||||
p.current_thread_mut().sepc += pc_adjust.abs() as usize;
|
||||
}*/
|
||||
|
||||
clear_fault();
|
||||
|
||||
crate::arch::syscall::resume(pid.get() == 1, p.current_thread())
|
||||
});
|
||||
}
|
||||
|
|
@ -272,7 +264,7 @@ pub extern "C" fn abort_handler() {
|
|||
});
|
||||
}
|
||||
|
||||
RETURN_FROM_ISR if dfar == 0 => {
|
||||
RETURN_FROM_ISR => {
|
||||
// If we hit this address, then an ISR has just returned. Since
|
||||
// we're in an interrupt context, it is safe to access this
|
||||
// global variable.
|
||||
|
|
@ -294,12 +286,9 @@ pub extern "C" fn abort_handler() {
|
|||
|
||||
clear_fault();
|
||||
|
||||
ArchProcess::with_current_mut(|process| {
|
||||
let mut curr_thread = process.current_thread_mut();
|
||||
curr_thread.resume_addr -= 4;
|
||||
curr_thread.ret_addr = 0;
|
||||
crate::arch::syscall::resume(current_pid().get() == 1, curr_thread)
|
||||
});
|
||||
unsafe {
|
||||
irq_handler_return();
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
|
@ -360,15 +349,18 @@ pub extern "C" fn _irq_handler_rust() {
|
|||
});
|
||||
klog!("Pending irqs mask: {:032b}", irqs_pending);
|
||||
|
||||
// Safe to access globals since interrupts are disabled
|
||||
unsafe {
|
||||
if PREVIOUS_PAIR.is_none() {
|
||||
let tid = crate::arch::process::current_tid();
|
||||
set_isr_return_pair(pid, tid);
|
||||
critical_section::with(|_| {
|
||||
// Safe to access globals since interrupts are disabled (critical section)
|
||||
unsafe {
|
||||
if PREVIOUS_PAIR.is_none() {
|
||||
let tid = crate::arch::process::current_tid();
|
||||
set_isr_return_pair(pid, tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
crate::irq::handle(irqs_pending).expect("Couldn't handle IRQ");
|
||||
ArchProcess::with_current_mut(|process| {
|
||||
crate::arch::syscall::resume(current_pid().get() == 1, process.current_thread())
|
||||
crate::arch::syscall::resume_no_irqs(current_pid().get() == 1, process.current_thread())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
use crate::services::Thread;
|
||||
|
||||
extern "C" {
|
||||
fn _resume_trampoline(mode: usize, thread: &Thread) -> !;
|
||||
fn _resume_trampoline(mode: usize, thread: &Thread, enable_irqs: bool) -> !;
|
||||
}
|
||||
|
||||
pub fn invoke(
|
||||
|
|
@ -37,8 +37,16 @@ pub fn invoke(
|
|||
}
|
||||
|
||||
pub fn resume(supervisor: bool, thread: &Thread) -> ! {
|
||||
resume_inner(supervisor, thread, true)
|
||||
}
|
||||
|
||||
pub fn resume_no_irqs(supervisor: bool, thread: &Thread) -> ! {
|
||||
resume_inner(supervisor, thread, false)
|
||||
}
|
||||
|
||||
fn resume_inner(supervisor: bool, thread: &Thread, enable_irqs: bool) -> ! {
|
||||
// Restore thread stack and PC, pass resume arguments via r0-r4
|
||||
klog!("resume: setting sp={:08x}, res_addr={:08x}, lr={:08x} | privileged: {:?} | ret: {:08x}", thread.sp, thread.resume_addr, thread.lr, supervisor, thread.ret_addr);
|
||||
klog!("resume: setting sp={:08x}, res_addr={:08x}, lr={:08x} | privileged: {:?} | irqs: {:?} | ret: {:08x}", thread.sp, thread.resume_addr, thread.lr, supervisor, enable_irqs, thread.ret_addr);
|
||||
|
||||
// See ARM ARM
|
||||
// B1.3.1 ARM processor modes
|
||||
|
|
@ -49,6 +57,6 @@ pub fn resume(supervisor: bool, thread: &Thread) -> ! {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
_resume_trampoline(mode, thread);
|
||||
_resume_trampoline(mode, thread, enable_irqs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
use core::{mem, slice};
|
||||
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
use armv7::structures::paging::TranslationTableMemory;
|
||||
|
||||
#[cfg(all(feature = "atsama5d27", feature = "debug-print"))]
|
||||
use armv7::{
|
||||
VirtualAddress,
|
||||
structures::paging::{
|
||||
InMemoryRegister, PageTableDescriptor,
|
||||
Readable, TranslationTableDescriptor, TranslationTableMemory,
|
||||
TranslationTableType, SMALL_PAGE_FLAGS,
|
||||
Readable, TranslationTableDescriptor, TranslationTableType,
|
||||
SMALL_PAGE_FLAGS,
|
||||
}
|
||||
};
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub const FLG_VALID: usize = 0x1;
|
||||
|
|
@ -109,7 +113,7 @@ impl MiniElf {
|
|||
|
||||
// Allocate a page to handle the top-level memory translation
|
||||
#[cfg(not(feature = "atsama5d27"))]
|
||||
let (tt, tt_address) = {
|
||||
let (tt, _tt_address) = {
|
||||
let tt_address = allocator.alloc() as usize;
|
||||
let tt = unsafe { &mut *(tt_address as *mut PageTable) };
|
||||
|
||||
|
|
@ -119,7 +123,7 @@ impl MiniElf {
|
|||
(tt, tt_address)
|
||||
};
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
let (tt, tt_address) = {
|
||||
let (tt, _tt_address) = {
|
||||
let pid_idx = pid as usize - 1;
|
||||
|
||||
// Allocate a page to handle the top-level memory translation
|
||||
|
|
@ -142,7 +146,7 @@ impl MiniElf {
|
|||
};
|
||||
|
||||
// Turn the satp address into a pointer
|
||||
println!(" Pagetable @ {:08x}", tt_address);
|
||||
println!(" Pagetable @ {:08x}", _tt_address);
|
||||
|
||||
// Allocate thread 1 for this process
|
||||
let thread_address = allocator.alloc() as usize;
|
||||
|
|
@ -329,7 +333,7 @@ impl MiniElf {
|
|||
process.sp = stack_addr;
|
||||
#[cfg(not(feature = "atsama5d27"))]
|
||||
{
|
||||
process.satp = 0x8000_0000 | ((pid as usize) << 22) | (tt_address >> 12);
|
||||
process.satp = 0x8000_0000 | ((pid as usize) << 22) | (_tt_address >> 12);
|
||||
}
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
|||
let mut kdata_size = 0;
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
let mut kernel_exception_sp = 0;
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
let mut kernel_irq_sp = 0;
|
||||
for tag in args.iter() {
|
||||
if tag.name == u32::from_le_bytes(*b"IniE") {
|
||||
let inie = MiniElf::new(&tag);
|
||||
|
|
@ -54,7 +56,7 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
|||
}
|
||||
#[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) = (
|
||||
(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)),
|
||||
|
|
@ -117,6 +119,7 @@ pub fn phase_2(cfg: &mut BootConfig) {
|
|||
kdata_size,
|
||||
kdata_virt_offset,
|
||||
kernel_exception_sp,
|
||||
kernel_irq_sp,
|
||||
krn_struct_start,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,7 @@ use armv7::structures::paging::{
|
|||
PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS,
|
||||
};
|
||||
use armv7::{PhysicalAddress, VirtualAddress};
|
||||
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,
|
||||
};
|
||||
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};
|
||||
use crate::{
|
||||
bzero, println, BootConfig, XousPid, PAGE_SIZE, WORD_SIZE,
|
||||
};
|
||||
|
|
@ -394,6 +390,7 @@ pub fn map_kernel_to_processes(
|
|||
kdata_size: usize,
|
||||
kdata_virt_offset: usize,
|
||||
kernel_exception_sp: usize,
|
||||
kernel_irq_sp: usize,
|
||||
krn_struct_start: usize,
|
||||
) {
|
||||
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.
|
||||
// Later on we may reuse the mapping made by the kernel.
|
||||
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 USER_AREA_END: usize = 0xfe00_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_STACK_TOP: usize = 0xfff8_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
|
||||
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_X: usize = 0x8;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ pub struct Uart {
|
|||
}
|
||||
|
||||
impl Uart {
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: UartType::new(),
|
||||
|
|
@ -89,7 +90,7 @@ fn print_l2_pagetable(vpn1: usize, phys_addr: PhysicalAddress) {
|
|||
|
||||
let mut no_valid_items = true;
|
||||
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() {
|
||||
continue;
|
||||
|
|
@ -97,16 +98,16 @@ fn print_l2_pagetable(vpn1: usize, phys_addr: PhysicalAddress) {
|
|||
|
||||
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() {
|
||||
PageTableType::LargePage => println!(
|
||||
" - {:02x} (64K) Large Page {:08x} -> {:08x}",
|
||||
i, virt_addr, phys_addr
|
||||
i, _virt_addr, _phys_addr
|
||||
),
|
||||
PageTableType::SmallPage => println!(
|
||||
" - {: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() {
|
||||
TranslationTableType::Page => {
|
||||
let virt_addr = i << 20;
|
||||
let _virt_addr = i << 20;
|
||||
println!(
|
||||
" - {:03x} (1MB) {:08x} L2 page table @ {:08x}",
|
||||
i, virt_addr, phys_addr
|
||||
i, _virt_addr, phys_addr
|
||||
);
|
||||
print_l2_pagetable(i, phys_addr);
|
||||
}
|
||||
TranslationTableType::Section => {
|
||||
let virt_addr = i * 1024; // 1 MB
|
||||
let _virt_addr = i * 1024; // 1 MB
|
||||
println!(
|
||||
" - {:03x} (1MB) section {:08x} -> {:08x}",
|
||||
i, virt_addr, phys_addr
|
||||
i, _virt_addr, phys_addr
|
||||
);
|
||||
}
|
||||
TranslationTableType::Supersection => {
|
||||
let virt_addr = i * (1024 * 16); // 16 MB
|
||||
let _virt_addr = i * (1024 * 16); // 16 MB
|
||||
println!(
|
||||
" - {: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-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::{
|
||||
println, BootConfig, ProgramDescription,
|
||||
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`
|
||||
/// for this reason.
|
||||
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");
|
||||
|
||||
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.data_offset as usize & (PAGE_SIZE - 1)), 0);
|
||||
if allocator.no_copy {
|
||||
|
|
@ -207,6 +228,6 @@ impl ProgramDescription {
|
|||
allocator.processes[pid_idx].sp = stack_addr;
|
||||
allocator.processes[pid_idx].asid = pid;
|
||||
|
||||
(text_phys_offset, data_phys_offset, exception_sp)
|
||||
(text_phys_offset, data_phys_offset, exception_sp, irq_sp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
services/ticktimer-test-client/Cargo.toml
Normal file
15
services/ticktimer-test-client/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
authors = ["Sean Cross <sean@xobs.io>"]
|
||||
description = "Program to test the log server"
|
||||
edition = "2021"
|
||||
name = "ticktimer-test-client"
|
||||
version = "0.1.0"
|
||||
|
||||
# Dependency versions enforced by Cargo.lock.
|
||||
[dependencies]
|
||||
xous = "0.9.28"
|
||||
log = "0.4.14"
|
||||
log-server = {package = "xous-api-log", version = "0.1.22"}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
1
services/ticktimer-test-client/README.md
Normal file
1
services/ticktimer-test-client/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# `xous-ticktimer` test client
|
||||
21
services/ticktimer-test-client/src/main.rs
Normal file
21
services/ticktimer-test-client/src/main.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
use log::info;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
const DELAY_MS: u64 = 5000;
|
||||
|
||||
for i in 0.. {
|
||||
info!("Loop #{}, waiting {} ms", i, DELAY_MS);
|
||||
sleep(Duration::from_millis(DELAY_MS));
|
||||
}
|
||||
|
||||
panic!("Finished endless loop");
|
||||
}
|
||||
|
|
@ -359,6 +359,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
builder.target_arm()
|
||||
.add_services(&vec![
|
||||
"xous-log".to_string(),
|
||||
"xous-ticktimer".to_string(),
|
||||
"xous-names".to_string(),
|
||||
"ticktimer-test-client".to_string(),
|
||||
])
|
||||
.add_kernel_feature("v2p") // required to use LCD DMA with lcd-console
|
||||
.add_feature("atsama5d27")
|
||||
|
|
|
|||
Loading…
Reference in a new issue