mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
add rdrand support
If available, HermitCore supports rdrand to generate random number. LwIP uses this instruction to support DNSSec.
This commit is contained in:
parent
d287184bbe
commit
da4486d93a
3 changed files with 24 additions and 2 deletions
|
@ -76,6 +76,7 @@ extern "C" {
|
|||
#define CPU_FEATURE_XSAVE (1 << 26)
|
||||
#define CPU_FEATURE_OSXSAVE (1 << 27)
|
||||
#define CPU_FEATURE_AVX (1 << 28)
|
||||
#define CPU_FEATURE_RDRAND (1 << 30)
|
||||
#define CPU_FEATURE_HYPERVISOR (1 << 31)
|
||||
|
||||
// CPUID.80000001H:EDX feature list
|
||||
|
@ -389,6 +390,10 @@ inline static uint32_t has_avx(void) {
|
|||
return (cpu_info.feature2 & CPU_FEATURE_AVX);
|
||||
}
|
||||
|
||||
inline static uint32_t has_rdrand(void) {
|
||||
return (cpu_info.feature2 & CPU_FEATURE_RDRAND);
|
||||
}
|
||||
|
||||
inline static uint32_t on_hypervisor(void) {
|
||||
return (cpu_info.feature2 & CPU_FEATURE_HYPERVISOR);
|
||||
}
|
||||
|
@ -452,6 +457,22 @@ static inline void clts(void)
|
|||
asm volatile("clts");
|
||||
}
|
||||
|
||||
/** @brief Read a random number
|
||||
*
|
||||
* Returns a hardware generated random value.
|
||||
*/
|
||||
inline static uint32_t rdrand(void)
|
||||
{
|
||||
uint32_t val;
|
||||
uint8_t rc;
|
||||
|
||||
do {
|
||||
asm volatile("rdrand %0 ; setc %1" : "=r" (val), "=qm" (rc));
|
||||
} while(rc == 0); // rc == 0: underflow
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/** @brief Read out time stamp counter
|
||||
*
|
||||
* The rdtsc instruction puts a 64 bit time stamp value
|
||||
|
|
|
@ -554,7 +554,7 @@ int cpu_detection(void) {
|
|||
a = b = c = d = 0;
|
||||
cpuid(1, &a, &b, &cpu_info.feature2, &cpu_info.feature1);
|
||||
|
||||
LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
||||
LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
||||
has_sse() ? "SSE " : "",
|
||||
has_sse2() ? "SSE2 " : "",
|
||||
has_sse3() ? "SSE3 " : "",
|
||||
|
@ -562,6 +562,7 @@ int cpu_detection(void) {
|
|||
has_sse4_2() ? "SSE4.2 " : "",
|
||||
has_avx() ? "AVX " : "",
|
||||
has_avx2() ? "AVX2 " : "",
|
||||
has_rdrand() ? "RDRAND " : "",
|
||||
has_fma() ? "FMA " : "",
|
||||
has_movbe() ? "MOVBE " : "",
|
||||
has_x2apic() ? "X2APIC " : "",
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 594aea71498c7c11850186f9b7d85e95ee34ac68
|
||||
Subproject commit 3dbc272333882dd02029ef9c45bbcb4c59ee7a6d
|
Loading…
Add table
Reference in a new issue