Add JTAG helpers

This commit is contained in:
Berkus Decker 2020-11-02 20:39:21 +02:00
parent c378250aba
commit 3415ccd68c
5 changed files with 30 additions and 0 deletions
.github/workflows
nucleus

View File

@ -119,6 +119,9 @@ jobs:
"noserial",
"qemu",
"noserial,qemu",
"jtag",
"noserial,jtag",
# jtag and qemu together don't make much sense
]
runs-on: ubuntu-latest
timeout-minutes: 10

View File

@ -17,6 +17,9 @@ maintenance = { status = "experimental" }
[features]
noserial = []
# Enable JTAG debugging of kernel - enable jtag helpers and
# block waiting for JTAG probe attach at the start of kernel main.
jtag = []
# Build for running under QEMU with semihosting, so various halt/reboot options would for example quit QEMU instead.
qemu = ["qemu-exit"]

View File

@ -0,0 +1,19 @@
//! JTAG helper functions.
use cortex_a::asm;
#[no_mangle]
static mut WAIT_FLAG: bool = true;
/// Wait for debugger to attach.
/// Then in gdb issue `> set var *(&WAIT_FLAG) = 0`
/// from inside this function's frame to contiue running.
pub fn wait_debugger() {
use core::ptr::{read_volatile, write_volatile};
while unsafe { read_volatile(&WAIT_FLAG) } {
asm::nop();
}
// Reset the flag so that next jtag::wait_debugger() would block again.
unsafe { write_volatile(&mut WAIT_FLAG, true) }
}

View File

@ -8,6 +8,8 @@
use cortex_a::asm;
mod boot;
#[cfg(feature = "jtag")]
pub mod jtag;
pub mod memory;
pub mod traps;

View File

@ -111,6 +111,9 @@ fn init_uart_serial() {
/// `arch` crate is responsible for calling it.
#[inline]
pub fn kmain() -> ! {
#[cfg(feature = "jtag")]
jtag::wait_debugger();
#[cfg(not(feature = "noserial"))]
init_uart_serial();