From f6fa894f6bbd0466365337eb6d2b1aaf5cd2fa76 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 8 Mar 2026 23:57:54 -0400 Subject: [PATCH] test with no NOPs and panic printing --- firmware/design/src/main.rs | 5 +- firmware/design_macros/src/lib.rs | 84 +++++++++++++++---------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/firmware/design/src/main.rs b/firmware/design/src/main.rs index 523767f..f55011f 100644 --- a/firmware/design/src/main.rs +++ b/firmware/design/src/main.rs @@ -3,7 +3,7 @@ use core::panic::PanicInfo; use cortex_m_rt::entry; -use design::sensitive; +use design::{eprintln, sensitive}; use design_macros::rand_ops; use mspm0l222x_hal::{CorePeripherals, Peripherals, Trng, trng}; @@ -16,8 +16,9 @@ use design::{ /// On panic, inform the host with the information associated with the panic and reboot the board. #[panic_handler] -fn handle_panics(_info: &PanicInfo) -> ! { +fn handle_panics(info: &PanicInfo) -> ! { // if salt page is missing on reboot, error gets sent then + eprintln!("{:?}", info); cortex_m::peripheral::SCB::sys_reset(); } diff --git a/firmware/design_macros/src/lib.rs b/firmware/design_macros/src/lib.rs index 3c457f4..4279162 100644 --- a/firmware/design_macros/src/lib.rs +++ b/firmware/design_macros/src/lib.rs @@ -128,48 +128,48 @@ pub fn rand_ops(input: TokenStream) -> TokenStream { let loop_body = generate_rand_ops_body(&mut build_rng); quote! {{ - let mut rng = #rng; - let mut state = core::hint::black_box(rng.word()); - // 16..1040 iterations - let iteration_count = core::hint::black_box((rng.word() & 0x2ff) + 16); - let mut check = core::hint::black_box(#base_check_val); - let mut i = core::hint::black_box(0u32); - - // TODO: idk if keeping init nops is needed, no branches until after randomized loop body which could be glitched - // maybe it is still good ot have random nops ran one iteration, may be hard to measure exactly what they are - #init_nops - - loop { - #loop_body - - if core::hint::black_box(i == iteration_count) { - break; - } - - i = core::hint::black_box(i.wrapping_add(1)); - check = core::hint::black_box(check.wrapping_add(#check_inc_val)); - } - - #post_check_1_nops - if core::hint::black_box(i != iteration_count || check != core::hint::black_box( - (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), - )) { - panic!(); - } - - #post_check_2_nops - if core::hint::black_box(check != core::hint::black_box( - (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), - ) || i != iteration_count) { - panic!(); - } - - #post_check_3_nops - if core::hint::black_box((i != iteration_count) | (check != core::hint::black_box( - (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), - ))) { - panic!(); - } + // let mut rng = #rng; + // let mut state = core::hint::black_box(rng.word()); + // // 16..1040 iterations + // let iteration_count = core::hint::black_box((rng.word() & 0x2ff) + 16); + // let mut check = core::hint::black_box(#base_check_val); + // let mut i = core::hint::black_box(0u32); + + // // TODO: idk if keeping init nops is needed, no branches until after randomized loop body which could be glitched + // // maybe it is still good ot have random nops ran one iteration, may be hard to measure exactly what they are + // #init_nops + + // loop { + // #loop_body + + // if core::hint::black_box(i == iteration_count) { + // break; + // } + + // i = core::hint::black_box(i.wrapping_add(1)); + // check = core::hint::black_box(check.wrapping_add(#check_inc_val)); + // } + + // #post_check_1_nops + // if core::hint::black_box(i != iteration_count || check != core::hint::black_box( + // (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), + // )) { + // panic!(); + // } + + // #post_check_2_nops + // if core::hint::black_box(check != core::hint::black_box( + // (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), + // ) || i != iteration_count) { + // panic!(); + // } + + // #post_check_3_nops + // if core::hint::black_box((i != iteration_count) | (check != core::hint::black_box( + // (#base_check_val).wrapping_add(iteration_count.wrapping_mul(#check_inc_val)), + // ))) { + // panic!(); + // } }} .into() }