Skip to content

Commit 528476f

Browse files
jakebaileydeadprogram
authored andcommitted
compiler, runtime: support recover on riscv64
1 parent 0c68e12 commit 528476f

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

compiler/defer.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (b *builder) supportsRecover() bool {
3232
// proposal of WebAssembly:
3333
// https://github.com/WebAssembly/exception-handling
3434
return false
35-
case "riscv64", "xtensa":
35+
case "xtensa":
3636
// TODO: add support for these architectures
3737
return false
3838
default:
@@ -217,12 +217,20 @@ sw $$ra, 4($$5)
217217
// So only add them when using hardfloat.
218218
constraints += ",~{$f0},~{$f1},~{$f2},~{$f3},~{$f4},~{$f5},~{$f6},~{$f7},~{$f8},~{$f9},~{$f10},~{$f11},~{$f12},~{$f13},~{$f14},~{$f15},~{$f16},~{$f17},~{$f18},~{$f19},~{$f20},~{$f21},~{$f22},~{$f23},~{$f24},~{$f25},~{$f26},~{$f27},~{$f28},~{$f29},~{$f30},~{$f31}"
219219
}
220-
case "riscv32":
221-
asmString = `
220+
case "riscv32", "riscv64":
221+
if b.archFamily() == "riscv32" {
222+
asmString = `
222223
la a2, 1f
223224
sw a2, 4(a1)
224225
li a0, 0
225226
1:`
227+
} else {
228+
asmString = `
229+
la a2, 1f
230+
sd a2, 8(a1)
231+
li a0, 0
232+
1:`
233+
}
226234
constraints = "={a0},{a1},~{a1},~{a2},~{a3},~{a4},~{a5},~{a6},~{a7},~{s0},~{s1},~{s2},~{s3},~{s4},~{s5},~{s6},~{s7},~{s8},~{s9},~{s10},~{s11},~{t0},~{t1},~{t2},~{t3},~{t4},~{t5},~{t6},~{ra},~{f0},~{f1},~{f2},~{f3},~{f4},~{f5},~{f6},~{f7},~{f8},~{f9},~{f10},~{f11},~{f12},~{f13},~{f14},~{f15},~{f16},~{f17},~{f18},~{f19},~{f20},~{f21},~{f22},~{f23},~{f24},~{f25},~{f26},~{f27},~{f28},~{f29},~{f30},~{f31},~{memory}"
227235
default:
228236
// This case should have been handled by b.supportsRecover().

src/runtime/asm_riscv.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ tinygo_scanCurrentStack:
4747
tinygo_longjmp:
4848
// Note: the code we jump to assumes a0 is non-zero, which is already the
4949
// case because that's the defer frame pointer.
50-
lw sp, 0(a0) // jumpSP
51-
lw a1, REGSIZE(a0) // jumpPC
50+
LREG sp, 0(a0) // jumpSP
51+
LREG a1, REGSIZE(a0) // jumpPC
5252
jr a1
5353

5454
.section .text.tinygo_checkpointJump

0 commit comments

Comments
 (0)