Implement random number generation with x86 rdrand

This commit is contained in:
2025-10-11 21:36:33 +02:00
parent 02a5d8b418
commit b717387adb
2 changed files with 14 additions and 0 deletions

View File

@ -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"

View 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