Skip to content

Commit

Permalink
setjmp, longjmp
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed May 9, 2024
1 parent 5052e77 commit 92ff486
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
21 changes: 21 additions & 0 deletions libsrc/misc/longjmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,26 @@ void longjmp(jmp_buf env, int result) {
"mov w0, #1\n"
".longjmp_0:");
}
#elif defined(__riscv)
void longjmp(jmp_buf env, int result) {
__asm("ld ra, 0(a0)\n"
"ld sp, 8(a0)\n"
"ld fp, 16(a0)\n"
"ld s1, 24(a0)\n"
"ld s2, 32(a0)\n"
"ld s3, 40(a0)\n"
"ld s4, 48(a0)\n"
"ld s5, 56(a0)\n"
"ld s6, 64(a0)\n"
"ld s7, 72(a0)\n"
"ld s8, 80(a0)\n"
"ld s9, 88(a0)\n"
"ld s10, 96(a0)\n"
"ld s11, 104(a0)\n"
"mv a0, a1\n"
"bne a0, zero, .longjmp_0\n"
"li a0, 1\n"
".longjmp_0:");
}
#endif
#endif
18 changes: 18 additions & 0 deletions libsrc/misc/setjmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,23 @@ int setjmp(jmp_buf env) {
"stp d14, d15, [x0, 160]\n"
"mov w0, wzr");
}
#elif defined(__riscv)
int setjmp(jmp_buf env) {
__asm("sd ra, 0(a0)\n"
"sd sp, 8(a0)\n"
"sd fp, 16(a0)\n"
"sd s1, 24(a0)\n"
"sd s2, 32(a0)\n"
"sd s3, 40(a0)\n"
"sd s4, 48(a0)\n"
"sd s5, 56(a0)\n"
"sd s6, 64(a0)\n"
"sd s7, 72(a0)\n"
"sd s8, 80(a0)\n"
"sd s9, 88(a0)\n"
"sd s10, 96(a0)\n"
"sd s11, 104(a0)\n"
"li a0, 0\n");
}
#endif
#endif
5 changes: 4 additions & 1 deletion src/as/arch/riscv64/asm_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ static unsigned char *asm_noop(Inst *inst, Code *code) {
static unsigned char *asm_mv(Inst *inst, Code *code) {
int rd = inst->opr1.reg.no;
int rs = inst->opr2.reg.no;
C_MV(rd, rs);
if (rs != ZERO)
C_MV(rd, rs);
else
C_LI(rd, 0);
return code->buf;
}

Expand Down

0 comments on commit 92ff486

Please sign in to comment.