#include "compiler.h"
#include "sections.h"
#include "picorv32.h"
#include "ioregs.h"

	// Debug functions to read and write x-registers from interrupt
	// mode by register number
	.pushsection ".text.hot.rdxreg","ax"
	.globl	rdxreg
	.balign 4
rdxreg:
	la a3,_xreg_smc
	lw a2,8(a3)		// addqxi a0,zero,0
	andi a0,a0,31
	slli a0,a0,15		// rs1
	or a2,a2,a0
	sw a2,(a3)
	jr a3
	.type rdxreg, @function
	.size rdxreg, . - rdxreg
	.popsection

	.pushsection ".text.hot.wrxreg","ax"
	.globl	wrxreg
	.balign 4
wrxreg:
	la a3,_xreg_smc
	lw a2,12(a3)		// addxqi zero,a1,0
	andi a0,a0,31
	slli a0,a0,7		// rd
	or a2,a2,a0
	sw a2,(a3)
	jr a3
	.type wrxreg, @function
	.size wrxreg, . - wrxreg
	.popsection

	__rwtext
	.balign 4
	.option norvc
_xreg_smc:
	nop
	ret
	addqxi a0,zero,0
	addxqi zero,a1,0
	.type _xreg_smc, @function
	.size _xreg_smc, . - _xreg_smc
