diff options
| author | David Rubin <daviru007@icloud.com> | 2024-03-25 03:28:11 -0700 |
|---|---|---|
| committer | David Rubin <daviru007@icloud.com> | 2024-05-11 02:17:11 -0700 |
| commit | 06089fc89a47e6ae84d09e6e21db23b7a57f885e (patch) | |
| tree | 343cb80d558948d9ecc4e2940920c950cb10828b /src | |
| parent | c96989aa4b283c5d386c5f19e2b12a6b13dd521a (diff) | |
| download | zig-06089fc89a47e6ae84d09e6e21db23b7a57f885e.tar.gz zig-06089fc89a47e6ae84d09e6e21db23b7a57f885e.zip | |
riscv: fix how we calculate stack offsets. allows for pass by reference arguments.
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/riscv64/Emit.zig | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/arch/riscv64/Emit.zig b/src/arch/riscv64/Emit.zig index c371f14ec1..b2e97041cb 100644 --- a/src/arch/riscv64/Emit.zig +++ b/src/arch/riscv64/Emit.zig @@ -536,11 +536,18 @@ fn lowerMir(emit: *Emit) !void { const data = mir_datas[inst].i_type; // TODO: probably create a psuedo instruction for s0 loads/stores instead of this. if (data.rs1 == .s0) { - const casted_size = math.cast(i12, emit.stack_size) orelse { - return emit.fail("TODO: support bigger stack sizes lowerMir", .{}); - }; const offset = mir_datas[inst].i_type.imm12; - mir_datas[inst].i_type.imm12 = -(casted_size - 12 - offset); + + // sp + 32 (aka s0) + // ra -- previous ra spilled + // s0 -- previous s0 spilled + // --- this is -16(s0) + + // TODO: this "+ 8" is completely arbiratary as the largest possible store + // we don't want to actually use it. instead we need to calculate the difference + // between the first and second stack store and use it instead. + + mir_datas[inst].i_type.imm12 = -(16 + offset + 8); } } |
