Patchwork [v3,10/25] ide/core: support CHS

login
register
mail settings
Submitter 武田 =?ISO-2022-JP?B?IBskQj1TTGkbKEI=?=
Date Oct. 28, 2009, 4:33 p.m.
Message ID <200910281633.AA00147@YOUR-BD18D6DD63.m1.interq.or.jp>
Download mbox | patch
Permalink /patch/37160/
State New
Headers show

Comments


Patch

diff --git a/qemu/hw/ide/core.c b/qemu/hw/ide/core.c
index fffcd00..6ccab35 100644
--- a/qemu/hw/ide/core.c
+++ b/qemu/hw/ide/core.c
@@ -1770,8 +1770,10 @@  void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         break;
     case 6:
 	/* FIXME: HOB readback uses bit 7 */
-        bus->ifs[0].select = (val & ~0x10) | 0xa0;
-        bus->ifs[1].select = (val | 0x10) | 0xa0;
+        bus->ifs[0].select = (val & ~0x10) |
+                             (bus->ifs[0].support_chs ? 0x80 : 0xa0);
+        bus->ifs[1].select = (val | 0x10) |
+                             (bus->ifs[1].support_chs ? 0x80 : 0xa0);
         /* select drive */
         bus->unit = (val >> 4) & 1;
         break;
@@ -1808,6 +1810,13 @@  void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
             ide_set_irq(s->bus);
             break;
         case WIN_SPECIFY:
+            if (s->support_chs && !(s->select & 0x40)) {
+                uint64_t sectors;
+                bdrv_get_geometry(s->bs, &sectors);
+                s->heads = (s->select & 0xf) + 1;
+                s->sectors = s->nsector;
+                s->cylinders = sectors / (s->heads * s->sectors);
+            }
         case WIN_RECAL:
             s->error = 0;
             s->status = READY_STAT | SEEK_STAT;
diff --git a/qemu/hw/ide/internal.h b/qemu/hw/ide/internal.h
index cfae4c2..c6b6d9f 100644
--- a/qemu/hw/ide/internal.h
+++ b/qemu/hw/ide/internal.h
@@ -396,6 +396,7 @@  struct IDEState {
 
     /* set for lba48 access */
     uint8_t lba48;
+    uint8_t support_chs;
     BlockDriverState *bs;
     /* ATAPI specific */
     uint8_t sense_key;