aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2013-05-23 15:42:14 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2013-05-23 15:42:14 -0700
commit9cff987563c7873a5471b4a195fd32d75d3217e0 (patch)
tree1b3c9b9dcfd4a5272fc367ef1e470f8db5935d97 /pk
parent8bad38e1a9321631de6ece0e150f0124e8c824b8 (diff)
downloadpk-9cff987563c7873a5471b4a195fd32d75d3217e0.zip
pk-9cff987563c7873a5471b4a195fd32d75d3217e0.tar.gz
pk-9cff987563c7873a5471b4a195fd32d75d3217e0.tar.bz2
add block device read/write example
Diffstat (limited to 'pk')
-rw-r--r--pk/device.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/pk/device.c b/pk/device.c
index e0019f8..52f0610 100644
--- a/pk/device.c
+++ b/pk/device.c
@@ -1,5 +1,7 @@
#include "pk.h"
#include "pcr.h"
+#include <string.h>
+#include <stdlib.h>
static uint64_t tohost_sync(unsigned dev, unsigned cmd, uint64_t payload)
{
@@ -16,13 +18,14 @@ void enumerate_devices()
{
char buf[64] __attribute__((aligned(64)));
- for (uint64_t dev = 0; dev < 256; dev++)
+ for (int dev = 0; dev < 256; dev++)
{
tohost_sync(dev, 0xFF, (uintptr_t)buf << 8 | 0xFF);
if (buf[0])
{
printk("device %d: %s\n", dev, buf);
- for (uint64_t cmd = 0; cmd < 255; cmd++)
+
+ for (int cmd = 0; cmd < 255; cmd++)
{
tohost_sync(dev, 0xFF, (uintptr_t)buf << 8 | cmd);
if (buf[0])
@@ -31,3 +34,39 @@ void enumerate_devices()
}
}
}
+
+void disk_test()
+{
+ struct disk_req {
+ uint64_t addr;
+ uint64_t offset;
+ uint64_t size;
+ uint64_t tag;
+ };
+
+ // find disk
+ const char* disk_str = "disk size=";
+ char buf[64] __attribute__((aligned(64)));
+
+ for (int dev = 0; dev < 256; dev++)
+ {
+ tohost_sync(dev, 0xFF, (uintptr_t)buf << 8 | 0xFF);
+ if (strncmp(buf, disk_str, strlen(disk_str)) == 0)
+ {
+ long size = atol(buf + strlen(disk_str));
+ printk("found disk device %d, size %ld\n", dev, size);
+
+ long sec_size = 512;
+ char buf[sec_size] __attribute__((aligned(64)));
+
+ // read block 3
+ struct disk_req req = { (uintptr_t)buf, 3*sec_size, sec_size, 0 };
+ tohost_sync(dev, 0, (uintptr_t)&req);
+ // copy block 3 to block 5
+ req.offset = 5*sec_size;
+ tohost_sync(dev, 1, (uintptr_t)&req);
+
+ printk("copied block 3 to block 5\n");
+ }
+ }
+}