From 9a2a1b00be06e0eaa45a25abc0d60f4ca90ebb82 Mon Sep 17 00:00:00 2001 From: Yaossg Date: Sun, 8 Dec 2024 14:34:58 +0800 Subject: [PATCH] fix overflow indirection --- boot.c | 9 ++++++++- test/overflow.c | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/boot.c b/boot.c index 742cc52..ac401de 100644 --- a/boot.c +++ b/boot.c @@ -799,7 +799,14 @@ char* store_op_of_type(int type) { // address loaders // rd must be one of t0, t1, t2 void load_local_address(int rd, int slot_id) { - asm_addi(reg_name(rd), "sp", slot_id * 8 - 8); + int offset = slot_id * 8 - 8; + char* rd_name = reg_name(rd); + if (check_itype_immediate(offset)) { + printf(" addi %s, sp, %d\n", rd_name, offset); + } else { + printf(" li %s, %d\n", rd_name, offset); + printf(" add %s, sp, %s\n", rd_name, rd_name); + } } // load a non-trivial register into trivial one diff --git a/test/overflow.c b/test/overflow.c index 8bb07f7..a580076 100644 --- a/test/overflow.c +++ b/test/overflow.c @@ -1,5 +1,5 @@ int main() { - // int placeholder[1024]; + int placeholder[1024]; int a = 1; return (a=(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(0)))))))))))))))))))))), (a = a); }