From 55e00cff9917c94389cd7440e114ac4c0bdb2d83 Mon Sep 17 00:00:00 2001 From: Andrew McRae Date: Mon, 9 May 2022 12:12:00 +1000 Subject: zephyr: it81302: Enable divide-by-zero exception check Enable the divide-by-zero exception check in the the compiler for RISCV CPUs. Without this change: ec:~$ crash divzero ffffffffCommand returned error: 1 With this change: ec:~$ crash divzero E: E: mcause: 3, Breakpoint E: mtval: 0 E: a0: 00000001 t0: 8010d988 E: a1: fffffffe t1: 00000020 E: a2: 00000000 t2: 00000000 E: a3: 000000c0 t3: 00000000 E: a4: 00f02700 t4: 00000001 E: a5: 00000008 t5: aaaaaaaa E: a6: 00000011 t6: aaaaaaaa E: a7: 00000000 E: tp: aaaaaaaa E: ra: 80013866 E: mepc: 8001386a E: mstatus: 00001880 E: E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0 E: Current thread: 0x801063f0 (shell_uart) E: Halting system BUG=b:231844211 TEST=crash divzero BRANCH=none Signed-off-by: Andrew McRae Cq-Depend: chromium:3637157 Change-Id: I4edf7d5b33d31a39d2172f3b8b1e4becdd94def4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3631725 Reviewed-by: Dino Li Reviewed-by: Yuval Peress Reviewed-by: Peter Marheine --- zephyr/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index ae3e8413b7..9173c67253 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -65,6 +65,10 @@ endif() # Set extra compiler flags. zephyr_cc_option(-mno-unaligned-access) +if (DEFINED CONFIG_RISCV) + zephyr_cc_option(-fsanitize=integer-divide-by-zero) + zephyr_cc_option(-fsanitize-undefined-trap-on-error) +endif() # The EC application is split into two libraries: # app: contains all the legacy code -- cgit v1.2.1