diff --git a/03_hacky_hello_world/README.md b/03_hacky_hello_world/README.md index dffbbb8a..1e764e65 100644 --- a/03_hacky_hello_world/README.md +++ b/03_hacky_hello_world/README.md @@ -24,9 +24,14 @@ QEMU is no longer running in assembly mode. It will from now on show the output ```console $ make qemu [...] + Hello from Rust! +Kernel panic! + +Panic location: + File 'src/main.rs', line 126, column 5 -Kernel panic: Stopping here. +Stopping here. ``` ## Diff to previous @@ -230,7 +235,7 @@ diff -uNr 02_runtime_init/src/main.rs 03_hacky_hello_world/src/main.rs /// - Only a single core must be active and running this function. unsafe fn kernel_init() -> ! { - panic!() -+ println!("[0] Hello from Rust!"); ++ println!("Hello from Rust!"); + + panic!("Stopping here.") } @@ -238,7 +243,7 @@ diff -uNr 02_runtime_init/src/main.rs 03_hacky_hello_world/src/main.rs diff -uNr 02_runtime_init/src/panic_wait.rs 03_hacky_hello_world/src/panic_wait.rs --- 02_runtime_init/src/panic_wait.rs +++ 03_hacky_hello_world/src/panic_wait.rs -@@ -4,14 +4,52 @@ +@@ -4,14 +4,61 @@ //! A panic handler that infinitely waits. @@ -285,11 +290,20 @@ diff -uNr 02_runtime_init/src/panic_wait.rs 03_hacky_hello_world/src/panic_wait. + // Protect against panic infinite loops if any of the following code panics itself. + panic_prevent_reenter(); + -+ if let Some(args) = info.message() { -+ println!("\nKernel panic: {}", args); -+ } else { -+ println!("\nKernel panic!"); -+ } ++ let (location, line, column) = match info.location() { ++ Some(loc) => (loc.file(), loc.line(), loc.column()), ++ _ => ("???", 0, 0), ++ }; ++ ++ println!( ++ "Kernel panic!\n\n\ ++ Panic location:\n File '{}', line {}, column {}\n\n\ ++ {}", ++ location, ++ line, ++ column, ++ info.message().unwrap_or(&format_args!("")), ++ ); + cpu::wait_forever() } diff --git a/03_hacky_hello_world/src/main.rs b/03_hacky_hello_world/src/main.rs index 7a3957dd..da450139 100644 --- a/03_hacky_hello_world/src/main.rs +++ b/03_hacky_hello_world/src/main.rs @@ -121,7 +121,7 @@ mod print; /// /// - Only a single core must be active and running this function. unsafe fn kernel_init() -> ! { - println!("[0] Hello from Rust!"); + println!("Hello from Rust!"); panic!("Stopping here.") } diff --git a/03_hacky_hello_world/src/panic_wait.rs b/03_hacky_hello_world/src/panic_wait.rs index e37724a4..fb30e8d4 100644 --- a/03_hacky_hello_world/src/panic_wait.rs +++ b/03_hacky_hello_world/src/panic_wait.rs @@ -45,11 +45,20 @@ fn panic(info: &PanicInfo) -> ! { // Protect against panic infinite loops if any of the following code panics itself. panic_prevent_reenter(); - if let Some(args) = info.message() { - println!("\nKernel panic: {}", args); - } else { - println!("\nKernel panic!"); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + println!( + "Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/04_safe_globals/README.md b/04_safe_globals/README.md index 83e1a45c..b42be642 100644 --- a/04_safe_globals/README.md +++ b/04_safe_globals/README.md @@ -244,11 +244,12 @@ diff -uNr 03_hacky_hello_world/src/main.rs 04_safe_globals/src/main.rs /// /// - Only a single core must be active and running this function. unsafe fn kernel_init() -> ! { +- println!("Hello from Rust!"); + use console::interface::Statistics; -+ - println!("[0] Hello from Rust!"); - panic!("Stopping here.") ++ println!("[0] Hello from Rust!"); ++ + println!( + "[1] Chars written: {}", + bsp::console::console().chars_written() diff --git a/04_safe_globals/src/panic_wait.rs b/04_safe_globals/src/panic_wait.rs index e37724a4..fb30e8d4 100644 --- a/04_safe_globals/src/panic_wait.rs +++ b/04_safe_globals/src/panic_wait.rs @@ -45,11 +45,20 @@ fn panic(info: &PanicInfo) -> ! { // Protect against panic infinite loops if any of the following code panics itself. panic_prevent_reenter(); - if let Some(args) = info.message() { - println!("\nKernel panic: {}", args); - } else { - println!("\nKernel panic!"); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + println!( + "Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/05_drivers_gpio_uart/README.md b/05_drivers_gpio_uart/README.md index 44e5aadf..aa39cbaa 100644 --- a/05_drivers_gpio_uart/README.md +++ b/05_drivers_gpio_uart/README.md @@ -1446,18 +1446,15 @@ diff -uNr 04_safe_globals/src/panic_wait.rs 05_drivers_gpio_uart/src/panic_wait. /// Stop immediately if called a second time. /// /// # Note -@@ -46,9 +62,9 @@ - panic_prevent_reenter(); - - if let Some(args) = info.message() { -- println!("\nKernel panic: {}", args); -+ panic_println!("\nKernel panic: {}", args); - } else { -- println!("\nKernel panic!"); -+ panic_println!("\nKernel panic!"); - } - - cpu::wait_forever() +@@ -50,7 +66,7 @@ + _ => ("???", 0, 0), + }; + +- println!( ++ panic_println!( + "Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", diff -uNr 04_safe_globals/tests/boot_test_string.rb 05_drivers_gpio_uart/tests/boot_test_string.rb --- 04_safe_globals/tests/boot_test_string.rb diff --git a/05_drivers_gpio_uart/src/panic_wait.rs b/05_drivers_gpio_uart/src/panic_wait.rs index e879b5b3..e546b06d 100644 --- a/05_drivers_gpio_uart/src/panic_wait.rs +++ b/05_drivers_gpio_uart/src/panic_wait.rs @@ -61,11 +61,20 @@ fn panic(info: &PanicInfo) -> ! { // Protect against panic infinite loops if any of the following code panics itself. panic_prevent_reenter(); - if let Some(args) = info.message() { - panic_println!("\nKernel panic: {}", args); - } else { - panic_println!("\nKernel panic!"); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/06_uart_chainloader/demo_payload_rpi3.img b/06_uart_chainloader/demo_payload_rpi3.img index b95058e4..1997951a 100755 Binary files a/06_uart_chainloader/demo_payload_rpi3.img and b/06_uart_chainloader/demo_payload_rpi3.img differ diff --git a/06_uart_chainloader/demo_payload_rpi4.img b/06_uart_chainloader/demo_payload_rpi4.img index 33debd90..9f463d32 100755 Binary files a/06_uart_chainloader/demo_payload_rpi4.img and b/06_uart_chainloader/demo_payload_rpi4.img differ diff --git a/06_uart_chainloader/src/panic_wait.rs b/06_uart_chainloader/src/panic_wait.rs index e879b5b3..e546b06d 100644 --- a/06_uart_chainloader/src/panic_wait.rs +++ b/06_uart_chainloader/src/panic_wait.rs @@ -61,11 +61,20 @@ fn panic(info: &PanicInfo) -> ! { // Protect against panic infinite loops if any of the following code panics itself. panic_prevent_reenter(); - if let Some(args) = info.message() { - panic_println!("\nKernel panic: {}", args); - } else { - panic_println!("\nKernel panic!"); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/07_timestamps/README.md b/07_timestamps/README.md index bfd2ee14..0af0b046 100644 --- a/07_timestamps/README.md +++ b/07_timestamps/README.md @@ -635,7 +635,7 @@ diff -uNr 06_uart_chainloader/src/main.rs 07_timestamps/src/main.rs diff -uNr 06_uart_chainloader/src/panic_wait.rs 07_timestamps/src/panic_wait.rs --- 06_uart_chainloader/src/panic_wait.rs +++ 07_timestamps/src/panic_wait.rs -@@ -58,13 +58,26 @@ +@@ -58,18 +58,23 @@ #[panic_handler] fn panic(info: &PanicInfo) -> ! { @@ -645,25 +645,21 @@ diff -uNr 06_uart_chainloader/src/panic_wait.rs 07_timestamps/src/panic_wait.rs panic_prevent_reenter(); + let timestamp = crate::time::time_manager().uptime(); -+ - if let Some(args) = info.message() { -- panic_println!("\nKernel panic: {}", args); -+ panic_println!( -+ "[ {:>3}.{:06}] Kernel panic: {}", -+ timestamp.as_secs(), -+ timestamp.subsec_micros(), -+ args, -+ ); - } else { -- panic_println!("\nKernel panic!"); -+ panic_println!( -+ "[ {:>3}.{:06}] Kernel panic!", -+ timestamp.as_secs(), -+ timestamp.subsec_micros(), -+ ); - } - - cpu::wait_forever() + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( +- "Kernel panic!\n\n\ ++ "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", ++ timestamp.as_secs(), ++ timestamp.subsec_micros(), + location, + line, + column, diff -uNr 06_uart_chainloader/src/print.rs 07_timestamps/src/print.rs --- 06_uart_chainloader/src/print.rs diff --git a/07_timestamps/src/panic_wait.rs b/07_timestamps/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/07_timestamps/src/panic_wait.rs +++ b/07_timestamps/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/08_hw_debug_JTAG/src/panic_wait.rs b/08_hw_debug_JTAG/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/08_hw_debug_JTAG/src/panic_wait.rs +++ b/08_hw_debug_JTAG/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/09_privilege_level/src/panic_wait.rs b/09_privilege_level/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/09_privilege_level/src/panic_wait.rs +++ b/09_privilege_level/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/10_virtual_mem_part1_identity_mapping/src/panic_wait.rs b/10_virtual_mem_part1_identity_mapping/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/10_virtual_mem_part1_identity_mapping/src/panic_wait.rs +++ b/10_virtual_mem_part1_identity_mapping/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/11_exceptions_part1_groundwork/README.md b/11_exceptions_part1_groundwork/README.md index 8d18d616..4df5c939 100644 --- a/11_exceptions_part1_groundwork/README.md +++ b/11_exceptions_part1_groundwork/README.md @@ -313,7 +313,7 @@ for each exception yet, a default handler is provided: /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); @@ -413,33 +413,37 @@ Minipush 1.0 [MP] ⏩ Pushing 64 KiB =========================================🦀 100% 0 KiB/s Time: 00:00:00 [ML] Loaded! Executing the payload now -[ 0.789853] mingo version 0.11.0 -[ 0.790060] Booting on: Raspberry Pi 3 -[ 0.790515] MMU online. Special regions: -[ 0.790992] 0x00080000 - 0x0008ffff | 64 KiB | C RO PX | Kernel code and RO data -[ 0.792010] 0x3f000000 - 0x4000ffff | 16 MiB | Dev RW PXN | Device MMIO -[ 0.792899] Current privilege level: EL1 -[ 0.793375] Exception handling state: -[ 0.793819] Debug: Masked -[ 0.794209] SError: Masked -[ 0.794599] IRQ: Masked -[ 0.794989] FIQ: Masked -[ 0.795379] Architectural timer resolution: 52 ns -[ 0.795954] Drivers loaded: -[ 0.796289] 1. BCM GPIO -[ 0.796647] 2. BCM PL011 UART -[ 0.797070] Timer test, spinning for 1 second -[ 1.797600] -[ 1.797604] Trying to read from address 8 GiB... -[ 1.798154] ************************************************ -[ 1.798846] Whoa! We recovered from a synchronous exception! -[ 1.799539] ************************************************ -[ 1.800233] -[ 1.800406] Let's try again -[ 1.800742] Trying to read from address 9 GiB... -[ 1.801306] Kernel panic: +[ 0.787414] mingo version 0.11.0 +[ 0.787621] Booting on: Raspberry Pi 3 +[ 0.788076] MMU online. Special regions: +[ 0.788553] 0x00080000 - 0x0008ffff | 64 KiB | C RO PX | Kernel code and RO data +[ 0.789571] 0x3f000000 - 0x4000ffff | 16 MiB | Dev RW PXN | Device MMIO +[ 0.790460] Current privilege level: EL1 +[ 0.790936] Exception handling state: +[ 0.791380] Debug: Masked +[ 0.791770] SError: Masked +[ 0.792160] IRQ: Masked +[ 0.792550] FIQ: Masked +[ 0.792940] Architectural timer resolution: 52 ns +[ 0.793514] Drivers loaded: +[ 0.793850] 1. BCM GPIO +[ 0.794208] 2. BCM PL011 UART +[ 0.794630] Timer test, spinning for 1 second +[ 1.795161] +[ 1.795165] Trying to read from address 8 GiB... +[ 1.795715] ************************************************ +[ 1.796407] Whoa! We recovered from a synchronous exception! +[ 1.797100] ************************************************ +[ 1.797794] +[ 1.797967] Let's try again +[ 1.798303] Trying to read from address 9 GiB... +[ 1.798867] Kernel panic! + +Panic location: + File 'src/_arch/aarch64/exception.rs', line 58, column 5 CPU Exception! + ESR_EL1: 0x96000004 Exception Class (EC) : 0x25 - Data Abort, current EL Instr Specific Syndrome (ISS): 0x4 @@ -459,21 +463,21 @@ SPSR_EL1: 0x600003c5 ELR_EL1: 0x0000000000082194 General purpose register: - x0 : 0x0000000000000000 x1 : 0x000000000008555f - x2 : 0x0000000000000027 x3 : 0x000000000008435c - x4 : 0x0000000000000006 x5 : 0x3f27329c00000000 - x6 : 0x0000000000000000 x7 : 0xd3d1b900228f0241 - x8 : 0x0000000240000000 x9 : 0x000000000008555f + x0 : 0x0000000000000000 x1 : 0x0000000000085517 + x2 : 0x0000000000000027 x3 : 0x0000000000084380 + x4 : 0x0000000000000006 x5 : 0xfb5f341800000000 + x6 : 0x0000000000000000 x7 : 0x7f91bc012b2b0209 + x8 : 0x0000000240000000 x9 : 0x0000000000085517 x10: 0x0000000000000443 x11: 0x000000003f201000 x12: 0x0000000000000019 x13: 0x00000000ffffd8f0 x14: 0x000000000000147b x15: 0x00000000ffffff9c x16: 0x000000000007fd38 x17: 0x0000000005f5e0ff - x18: 0x0000000000000034 x19: 0x0000000000090008 - x20: 0x0000000000085398 x21: 0x000000003b9aca00 - x22: 0x0000000000082e30 x23: 0x0000000000082308 + x18: 0x0000000000000030 x19: 0x0000000000090008 + x20: 0x0000000000085350 x21: 0x000000003b9aca00 + x22: 0x0000000000082e4c x23: 0x0000000000082308 x24: 0x0000000010624dd3 x25: 0xffffffffc4653600 - x26: 0x00000000000866b8 x27: 0x0000000000085458 - x28: 0x0000000000084fe0 x29: 0x0000000000086770 + x26: 0x0000000000086638 x27: 0x0000000000085410 + x28: 0x0000000000084f90 x29: 0x0000000000086538 lr : 0x0000000000082188 ``` @@ -546,7 +550,7 @@ diff -uNr 10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/exception.rs 1 +/// Prints verbose information about the exception and then panics. +fn default_exception_handler(exc: &ExceptionContext) { + panic!( -+ "\n\nCPU Exception!\n\ ++ "CPU Exception!\n\n\ + {}", + exc + ); diff --git a/11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs b/11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs index f8178210..e8484938 100644 --- a/11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs +++ b/11_exceptions_part1_groundwork/src/_arch/aarch64/exception.rs @@ -56,7 +56,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/11_exceptions_part1_groundwork/src/panic_wait.rs b/11_exceptions_part1_groundwork/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/11_exceptions_part1_groundwork/src/panic_wait.rs +++ b/11_exceptions_part1_groundwork/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() } diff --git a/12_integrated_testing/README.md b/12_integrated_testing/README.md index 5de7c0ef..8a20a0d5 100644 --- a/12_integrated_testing/README.md +++ b/12_integrated_testing/README.md @@ -856,10 +856,14 @@ Compiling integration test(s) - rpi3 🦀 Testing synchronous exception handling by causing a page fault ------------------------------------------------------------------- - [ 0.163030] Writing beyond mapped area to address 9 GiB... - [ 0.164791] Kernel panic: + [ 0.132792] Writing beyond mapped area to address 9 GiB... + [ 0.134563] Kernel panic! + + Panic location: + File 'src/_arch/aarch64/exception.rs', line 58, column 5 CPU Exception! + ESR_EL1: 0x96000004 Exception Class (EC) : 0x25 - Data Abort, current EL [...] @@ -1753,9 +1757,9 @@ diff -uNr 11_exceptions_part1_groundwork/src/panic_wait.rs 12_integrated_testing } #[panic_handler] -@@ -80,5 +97,5 @@ - ); - } +@@ -81,5 +98,5 @@ + info.message().unwrap_or(&format_args!("")), + ); - cpu::wait_forever() + _panic_exit() diff --git a/12_integrated_testing/src/_arch/aarch64/exception.rs b/12_integrated_testing/src/_arch/aarch64/exception.rs index e15dc7a0..e84699e1 100644 --- a/12_integrated_testing/src/_arch/aarch64/exception.rs +++ b/12_integrated_testing/src/_arch/aarch64/exception.rs @@ -56,7 +56,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/12_integrated_testing/src/panic_wait.rs b/12_integrated_testing/src/panic_wait.rs index a1b090d7..6f09f11c 100644 --- a/12_integrated_testing/src/panic_wait.rs +++ b/12_integrated_testing/src/panic_wait.rs @@ -81,21 +81,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); _panic_exit() } diff --git a/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/exception.rs b/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/exception.rs index 18441018..495dba34 100644 --- a/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/exception.rs +++ b/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/exception.rs @@ -57,7 +57,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/13_exceptions_part2_peripheral_IRQs/src/panic_wait.rs b/13_exceptions_part2_peripheral_IRQs/src/panic_wait.rs index 787bc7dc..08d7d453 100644 --- a/13_exceptions_part2_peripheral_IRQs/src/panic_wait.rs +++ b/13_exceptions_part2_peripheral_IRQs/src/panic_wait.rs @@ -83,21 +83,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); _panic_exit() } diff --git a/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/exception.rs b/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/exception.rs index 18441018..495dba34 100644 --- a/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/exception.rs +++ b/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/exception.rs @@ -57,7 +57,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/14_virtual_mem_part2_mmio_remap/src/panic_wait.rs b/14_virtual_mem_part2_mmio_remap/src/panic_wait.rs index 787bc7dc..08d7d453 100644 --- a/14_virtual_mem_part2_mmio_remap/src/panic_wait.rs +++ b/14_virtual_mem_part2_mmio_remap/src/panic_wait.rs @@ -83,21 +83,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); _panic_exit() } diff --git a/15_virtual_mem_part3_precomputed_tables/src/_arch/aarch64/exception.rs b/15_virtual_mem_part3_precomputed_tables/src/_arch/aarch64/exception.rs index 18441018..495dba34 100644 --- a/15_virtual_mem_part3_precomputed_tables/src/_arch/aarch64/exception.rs +++ b/15_virtual_mem_part3_precomputed_tables/src/_arch/aarch64/exception.rs @@ -57,7 +57,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/15_virtual_mem_part3_precomputed_tables/src/panic_wait.rs b/15_virtual_mem_part3_precomputed_tables/src/panic_wait.rs index 787bc7dc..08d7d453 100644 --- a/15_virtual_mem_part3_precomputed_tables/src/panic_wait.rs +++ b/15_virtual_mem_part3_precomputed_tables/src/panic_wait.rs @@ -83,21 +83,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); _panic_exit() } diff --git a/16_virtual_mem_part4_higher_half_kernel/src/_arch/aarch64/exception.rs b/16_virtual_mem_part4_higher_half_kernel/src/_arch/aarch64/exception.rs index 18441018..495dba34 100644 --- a/16_virtual_mem_part4_higher_half_kernel/src/_arch/aarch64/exception.rs +++ b/16_virtual_mem_part4_higher_half_kernel/src/_arch/aarch64/exception.rs @@ -57,7 +57,7 @@ struct ExceptionContext { /// Prints verbose information about the exception and then panics. fn default_exception_handler(exc: &ExceptionContext) { panic!( - "\n\nCPU Exception!\n\ + "CPU Exception!\n\n\ {}", exc ); diff --git a/16_virtual_mem_part4_higher_half_kernel/src/panic_wait.rs b/16_virtual_mem_part4_higher_half_kernel/src/panic_wait.rs index 787bc7dc..08d7d453 100644 --- a/16_virtual_mem_part4_higher_half_kernel/src/panic_wait.rs +++ b/16_virtual_mem_part4_higher_half_kernel/src/panic_wait.rs @@ -83,21 +83,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); _panic_exit() } diff --git a/X1_JTAG_boot/jtag_boot_rpi3.img b/X1_JTAG_boot/jtag_boot_rpi3.img index 9fcd693e..14b22a47 100755 Binary files a/X1_JTAG_boot/jtag_boot_rpi3.img and b/X1_JTAG_boot/jtag_boot_rpi3.img differ diff --git a/X1_JTAG_boot/jtag_boot_rpi4.img b/X1_JTAG_boot/jtag_boot_rpi4.img index fb16a02b..8622b9be 100755 Binary files a/X1_JTAG_boot/jtag_boot_rpi4.img and b/X1_JTAG_boot/jtag_boot_rpi4.img differ diff --git a/X1_JTAG_boot/src/panic_wait.rs b/X1_JTAG_boot/src/panic_wait.rs index 3c57f562..f851e0d8 100644 --- a/X1_JTAG_boot/src/panic_wait.rs +++ b/X1_JTAG_boot/src/panic_wait.rs @@ -64,21 +64,22 @@ fn panic(info: &PanicInfo) -> ! { panic_prevent_reenter(); let timestamp = crate::time::time_manager().uptime(); - - if let Some(args) = info.message() { - panic_println!( - "[ {:>3}.{:06}] Kernel panic: {}", - timestamp.as_secs(), - timestamp.subsec_micros(), - args, - ); - } else { - panic_println!( - "[ {:>3}.{:06}] Kernel panic!", - timestamp.as_secs(), - timestamp.subsec_micros(), - ); - } + let (location, line, column) = match info.location() { + Some(loc) => (loc.file(), loc.line(), loc.column()), + _ => ("???", 0, 0), + }; + + panic_println!( + "[ {:>3}.{:06}] Kernel panic!\n\n\ + Panic location:\n File '{}', line {}, column {}\n\n\ + {}", + timestamp.as_secs(), + timestamp.subsec_micros(), + location, + line, + column, + info.message().unwrap_or(&format_args!("")), + ); cpu::wait_forever() }