2 * Extended boot option ROM support.
4 * Copyright IBM, Corp. 2007
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
19 /* Extended Boot ROM suport */
40 static void get_translated_chs(BlockDriverState
*bs
, int *c
, int *h
, int *s
)
42 bdrv_get_geometry_hint(bs
, c
, h
, s
);
47 } else if (*c
<= 2048) {
50 } else if (*c
<= 4096) {
53 } else if (*c
<= 8192) {
61 /* what is the correct algorithm for this?? */
68 static uint32_t extboot_read(void *opaque
, uint32_t addr
)
74 static void extboot_write_cmd(void *opaque
, uint32_t addr
, uint32_t value
)
76 union extboot_cmd cmd
;
77 BlockDriverState
*bs
= opaque
;
78 int cylinders
, heads
, sectors
, err
;
80 target_phys_addr_t pa
= 0;
84 cpu_physical_memory_read((value
& 0xFFFF) << 4, (uint8_t *)&cmd
,
87 if (cmd
.type
== 0x01 || cmd
.type
== 0x02) {
88 pa
= cmd
.xfer
.segment
* 16 + cmd
.xfer
.offset
;
89 blen
= cmd
.xfer
.nb_sectors
* 512;
90 buf
= qemu_memalign(512, blen
);
95 get_translated_chs(bs
, &cylinders
, &heads
, §ors
);
96 bdrv_get_geometry(bs
, &nb_sectors
);
97 cmd
.query_geometry
.cylinders
= cylinders
;
98 cmd
.query_geometry
.heads
= heads
;
99 cmd
.query_geometry
.sectors
= sectors
;
100 cmd
.query_geometry
.nb_sectors
= nb_sectors
;
103 err
= bdrv_read(bs
, cmd
.xfer
.sector
, buf
, cmd
.xfer
.nb_sectors
);
105 printf("Read failed\n");
107 cpu_physical_memory_write(pa
, buf
, blen
);
111 cpu_physical_memory_read(pa
, buf
, blen
);
113 err
= bdrv_write(bs
, cmd
.xfer
.sector
, buf
, cmd
.xfer
.nb_sectors
);
115 printf("Write failed\n");
120 cpu_physical_memory_write((value
& 0xFFFF) << 4, (uint8_t *)&cmd
,
126 void extboot_init(BlockDriverState
*bs
, int cmd
)
130 pcmd
= qemu_mallocz(sizeof(int));
133 register_ioport_read(0x404, 1, 1, extboot_read
, pcmd
);
134 register_ioport_write(0x405, 1, 2, extboot_write_cmd
, bs
);