summaryrefslogtreecommitdiff
path: root/core/riscv-rv32i/math.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2020-12-29 15:10:43 +0800
committerCommit Bot <commit-bot@chromium.org>2020-12-30 04:31:47 +0000
commitc4aacf4e039d5e797e39988486c1c22180918706 (patch)
tree4d1faa246f3e6fc4e209ff7c64fce4f436eb735a /core/riscv-rv32i/math.c
parentb3584dd1ea0b11c269424ab7693cb9609b15e568 (diff)
downloadchrome-ec-c4aacf4e039d5e797e39988486c1c22180918706.tar.gz
core/riscv-rv32i: Enable integer division by zero UBSAN
Allows us to trap divisions by zero. It might be better to add a new compiler flag for this (e.g. -mcheck-zero-division that is only only available on MIPS currently). BRANCH=none BUG=b:173969773 TEST=crash divzero actually crashes the system, failing address available in RA register. Change-Id: Id82e035b16e05ba2970779367dd6dc8d10f4955a Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2605039 Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Diffstat (limited to 'core/riscv-rv32i/math.c')
-rw-r--r--core/riscv-rv32i/math.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/core/riscv-rv32i/math.c b/core/riscv-rv32i/math.c
index 591a67eb8f..2a637c8bcc 100644
--- a/core/riscv-rv32i/math.c
+++ b/core/riscv-rv32i/math.c
@@ -4,6 +4,8 @@
*/
#include "common.h"
+#include "cpu.h"
+#include "panic.h"
#ifdef CONFIG_FPU
/* Single precision floating point square root. */
@@ -17,3 +19,9 @@ float sqrtf(float x)
return x;
}
#endif
+
+void __ubsan_handle_divrem_overflow(void *data,
+ void *lhs, void *rhs)
+{
+ exception_panic(PANIC_SW_DIV_ZERO, 0);
+}