shithub: riscv

Download patch

ref: 052abe1cc8dd6403f4983b1b587f14d3eed1fe8c
parent: 6cbc226351d6c47ace019f6d62e7070deb7b4b5a
author: cinap_lenrek <[email protected]>
date: Wed Dec 14 15:02:07 EST 2016

xen: fix build by adding missing rdrandbuf() function

--- a/sys/src/9/xen/fns.h
+++ b/sys/src/9/xen/fns.h
@@ -102,6 +102,7 @@
 uint	xchgl(uint*, uint);
 uint	xchgw(ushort*, uint);
 uint	xchgb(uchar*, uint);
+void	rdrandbuf(void*, ulong);
 
 #define	waserror()	(up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
 #define KADDR(a)	((void*)((ulong)(a)|KZERO))
--- a/sys/src/9/xen/l.s
+++ b/sys/src/9/xen/l.s
@@ -296,6 +296,38 @@
 	ADCL	BX, 4(CX)			/* r2 += carry */
 	RET
 
+#define RDRANDAX	BYTE $0x0f; BYTE $0xc7; BYTE $0xf0
+
+TEXT rdrand32(SB), $-4
+_rloop32:
+	RDRANDAX
+	JCC	_rloop32
+	RET
+
+TEXT rdrandbuf(SB), $0
+	MOVL	buf+0(FP), DI
+	MOVL	cnt+4(FP), CX
+	CLD
+	MOVL	CX, DX
+	SHRL	$2, CX
+	CMPL	CX, $0
+	JE	_rndleft
+_rnddwords:
+	CALL	rdrand32(SB)
+	STOSL
+	LOOP _rnddwords
+_rndleft:
+	MOVL	DX, CX
+	ANDL	$3, CX
+	CMPL	CX, $0
+	JE	_rnddone
+_rndbytes:
+	CALL rdrand32(SB)
+	STOSB
+	LOOP _rndbytes
+_rnddone:
+	RET
+
 /*
  *  label consists of a stack pointer and a PC
  */