Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


IDE hard drive works past grub
[palacios.git] / palacios / src / devices / ram_hd.c
index 86554d6..3129ec5 100644 (file)
@@ -34,29 +34,28 @@ struct hd_state {
 
 
 // HDs always read 2048 byte blocks... ?
-static int hd_read(uint8_t * buf, int count, int lba,  void * private_data) {
+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 = ((offset + count) > hd->capacity) ? (hd->capacity - offset) : count;
+    int length = sector_count * IDE_SECTOR_SIZE;
 
-    PrintDebug("Reading RAM HD at (LBA=%d) offset %d (length=%d)\n", 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);
 
-    // Pad out the rest of the buffer with 0's
-    //    memset(buf + length, 0, IDE_SECTOR_SIZE - length);
+
 
     return 0;
 }
 
 
-static uint32_t hd_get_capacity(void * private_data) {
+static uint64_t hd_get_capacity(void * private_data) {
     struct vm_device * hd_dev = (struct vm_device *)private_data;
     struct hd_state * hd = (struct hd_state *)(hd_dev->private_data);
     PrintDebug("Querying RAM HD capacity (bytes=%d) (ret = %d)\n", 
-              hd->capacity, (hd->capacity + IDE_SECTOR_SIZE - 1) / IDE_SECTOR_SIZE);
-    return (hd->capacity + IDE_SECTOR_SIZE - 1) / IDE_SECTOR_SIZE;
+              hd->capacity, hd->capacity  / IDE_SECTOR_SIZE);
+    return hd->capacity / IDE_SECTOR_SIZE;
 }
 
 static struct v3_ide_hd_ops hd_ops = {
@@ -91,7 +90,14 @@ static struct vm_device_ops dev_ops = {
 struct vm_device * v3_create_ram_hd(struct vm_device * ide, 
                                    uint_t bus, uint_t drive, 
                                    addr_t ramdisk, uint32_t size) {
-    struct hd_state * hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state));
+    struct hd_state * hd = NULL;
+
+    if (size % IDE_SECTOR_SIZE) {
+       PrintError("HD image must be an integral of sector size (IDE_SECTOR_SIZE=%d)\n", IDE_SECTOR_SIZE);
+       return NULL;
+    }
+
+    hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state));
 
     PrintDebug("Registering Ram HDD at %p (size=%d)\n", (void *)ramdisk, size);