shithub: riscv

ref: f88a55e79b5bf656e7f9578d1318a955b9a4963a
dir: /sys/src/libc/riscv64/setjmp.s/

View raw version
#define LINK	R1
#define RARG	R8

TEXT	setjmp(SB), 1, $-4
	MOV	R2, (RARG)	/* store sp in jmp_buf */
	MOV	LINK, XLEN(RARG) /* store return pc */
	MOV	R0, RARG	/* return 0 */
	RET

TEXT	longjmp(SB), 1, $-4
	MOVW	r+XLEN(FP), R13
	BNE	R13, ok		/* ansi: "longjmp(0) => longjmp(1)" */
	MOV	$1, R13		/* bless their pointed heads */
ok:	MOV	(RARG), R2	/* restore sp */
	MOV	XLEN(RARG), LINK /* restore return pc */
	MOV	R13, RARG
	RET			/* jump to saved pc */