git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
A Total Overhaul on the Lunaix's Virtual Memory Model (#26)
[lunaix-os.git]
/
lunaix-os
/
hal
/
rng
/
rngx86.c
diff --git
a/lunaix-os/hal/rng/rngx86.c
b/lunaix-os/hal/rng/rngx86.c
index 3035f314dc6b238ca3f56afc0c20d791667845ae..b1087406fb3fb49446cfaa3543d5a24ee3e70aa1 100644
(file)
--- a/
lunaix-os/hal/rng/rngx86.c
+++ b/
lunaix-os/hal/rng/rngx86.c
@@
-1,5
+1,7
@@
#include <lunaix/device.h>
#include <lunaix/device.h>
-#include <lunaix/mm/page.h>
+#include <lunaix/mm/pagetable.h>
+
+#include <klibc/string.h>
static inline void
rng_fill(void* data, size_t len)
static inline void
rng_fill(void* data, size_t len)
@@
-17,25
+19,32
@@
rng_fill(void* data, size_t len)
static int
__rand_rd_pg(struct device* dev, void* buf, size_t offset)
{
static int
__rand_rd_pg(struct device* dev, void* buf, size_t offset)
{
- rng_fill(buf, P
G
_SIZE);
- return P
G
_SIZE;
+ rng_fill(buf, P
AGE
_SIZE);
+ return P
AGE
_SIZE;
}
static int
__rand_rd(struct device* dev, void* buf, size_t offset, size_t len)
{
}
static int
__rand_rd(struct device* dev, void* buf, size_t offset, size_t len)
{
- rng_fill(buf, len);
+ if (unlikely(len < 4)) {
+ int tmp_buf = 0;
+ rng_fill(&tmp_buf, 4);
+ memcpy(buf, &tmp_buf, len);
+ } else {
+ rng_fill(buf, len);
+ }
return len;
}
int
pdev_randdev_init(struct device_def* devdef)
{
return len;
}
int
pdev_randdev_init(struct device_def* devdef)
{
+ // FIXME add check on cpuid for presence of rdrand
struct device* devrand = device_allocseq(NULL, NULL);
devrand->ops.read = __rand_rd;
devrand->ops.read_page = __rand_rd_pg;
struct device* devrand = device_allocseq(NULL, NULL);
devrand->ops.read = __rand_rd;
devrand->ops.read_page = __rand_rd_pg;
-
device_register
(devrand, &devdef->class, "rand");
+
register_device
(devrand, &devdef->class, "rand");
return 0;
}
return 0;
}
@@
-43,6
+52,5
@@
pdev_randdev_init(struct device_def* devdef)
static struct device_def devrandx86_def = {
.name = "x86 On-Chip RNG",
.class = DEVCLASS(DEVIF_SOC, DEVFN_CHAR, DEV_RNG),
static struct device_def devrandx86_def = {
.name = "x86 On-Chip RNG",
.class = DEVCLASS(DEVIF_SOC, DEVFN_CHAR, DEV_RNG),
- .init = pdev_randdev_init
-};
-EXPORT_DEVICE(randdev, &devrandx86_def, load_earlystage);
\ No newline at end of file
+ .init = pdev_randdev_init};
+EXPORT_DEVICE(randdev, &devrandx86_def, load_onboot);
\ No newline at end of file