Implement random number generation with x86 rdrand
This commit is contained in:
@ -19,6 +19,7 @@ size_t hal_strspn(const char *s, const char *accept);
|
|||||||
char *hal_strcpy(char *dest, const char *src);
|
char *hal_strcpy(char *dest, const char *src);
|
||||||
char *hal_strchr(const char *s, int c);
|
char *hal_strchr(const char *s, int c);
|
||||||
void hal_wait(uint32_t ms);
|
void hal_wait(uint32_t ms);
|
||||||
|
int32_t hal_randnum(void);
|
||||||
|
|
||||||
#define HAL_PAGE_SIZE 0x1000
|
#define HAL_PAGE_SIZE 0x1000
|
||||||
#include "x86_64/vmm.h"
|
#include "x86_64/vmm.h"
|
||||||
|
|||||||
13
kernel/hal/x86_64/randnum.S
Normal file
13
kernel/hal/x86_64/randnum.S
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.global hal_randnum
|
||||||
|
hal_randnum:
|
||||||
|
mov $100, %ecx
|
||||||
|
xor %eax, %eax
|
||||||
|
|
||||||
|
.retry:
|
||||||
|
rdrand %eax
|
||||||
|
jc .done
|
||||||
|
loop .retry
|
||||||
|
.fail:
|
||||||
|
mov $-1, %eax
|
||||||
|
.done:
|
||||||
|
ret
|
||||||
Reference in New Issue
Block a user