X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fram_hd.c;h=3bce4fcfdb32926b21a54a392aeacb121024f7a0;hb=c62141df299854f534f7ff255693db5f4b7bac4b;hp=3129ec537082d9df439a74538cc6954fd822dd48;hpb=6661dd1d2aa547ae248e816dcd4201bcbcb7fee0;p=palacios.git diff --git a/palacios/src/devices/ram_hd.c b/palacios/src/devices/ram_hd.c index 3129ec5..3bce4fc 100644 --- a/palacios/src/devices/ram_hd.c +++ b/palacios/src/devices/ram_hd.c @@ -22,6 +22,12 @@ #include + +#ifndef DEBUG_IDE +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + struct hd_state { addr_t disk_image; uint32_t capacity; // in bytes @@ -33,18 +39,28 @@ struct hd_state { }; -// HDs always read 2048 byte blocks... ? +// HDs always read 512 byte blocks... ? static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); int offset = lba * IDE_SECTOR_SIZE; int length = sector_count * IDE_SECTOR_SIZE; - PrintDebug("Reading RAM HD at (LBA=%d) offset %d (length=%d)\n", (uint32_t)lba, offset, length); + // PrintDebug("Reading RAM HD at (LBA=%d) offset %d (length=%d)\n", (uint32_t)lba, offset, length); memcpy(buf, (uint8_t *)(hd->disk_image + offset), length); + return 0; +} + + +static int hd_write(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { + struct vm_device * hd_dev = (struct vm_device *)private_data; + struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); + int offset = lba * IDE_SECTOR_SIZE; + int length = sector_count * IDE_SECTOR_SIZE; + memcpy((uint8_t *)(hd->disk_image + offset), buf, length); return 0; } @@ -60,6 +76,7 @@ static uint64_t hd_get_capacity(void * private_data) { static struct v3_ide_hd_ops hd_ops = { .read = hd_read, + .write = hd_write, .get_capacity = hd_get_capacity, };