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 */
39 static void get_translated_chs(BlockDriverState
*bs
, int *c
, int *h
, int *s
)
41 bdrv_get_geometry_hint(bs
, c
, h
, s
);
46 } else if (*c
<= 2048) {
49 } else if (*c
<= 4096) {
52 } else if (*c
<= 8192) {
60 /* what is the correct algorithm for this?? */
67 static uint32_t extboot_read(void *opaque
, uint32_t addr
)
73 static void extboot_write_cmd(void *opaque
, uint32_t addr
, uint32_t value
)
75 union extboot_cmd
*cmd
= (void *)(phys_ram_base
+ ((value
& 0xFFFF) << 4));
76 BlockDriverState
*bs
= opaque
;
77 int cylinders
, heads
, sectors
, err
;
79 get_translated_chs(bs
, &cylinders
, &heads
, §ors
);
81 if (cmd
->type
== 0x01 || cmd
->type
== 0x02) {
82 target_ulong pa
= cmd
->xfer
.segment
* 16 + cmd
->xfer
.segment
;
84 /* possible buffer overflow */
85 if ((pa
+ cmd
->xfer
.nb_sectors
* 512) > phys_ram_size
)
91 cmd
->query_geometry
.cylinders
= cylinders
;
92 cmd
->query_geometry
.heads
= heads
;
93 cmd
->query_geometry
.sectors
= sectors
;
94 cpu_physical_memory_set_dirty((value
& 0xFFFF) << 4);
97 err
= bdrv_read(bs
, cmd
->xfer
.sector
, phys_ram_base
+
98 cmd
->xfer
.segment
* 16 + cmd
->xfer
.offset
,
99 cmd
->xfer
.nb_sectors
);
101 printf("Read failed\n");
104 err
= bdrv_write(bs
, cmd
->xfer
.sector
, phys_ram_base
+
105 cmd
->xfer
.segment
* 16 + cmd
->xfer
.offset
,
106 cmd
->xfer
.nb_sectors
);
108 printf("Write failed\n");
110 cpu_physical_memory_set_dirty(cmd
->xfer
.segment
* 16 + cmd
->xfer
.offset
);
115 void extboot_init(BlockDriverState
*bs
, int cmd
)
119 pcmd
= qemu_mallocz(sizeof(int));
121 fprintf(stderr
, "Error allocating memory\n");
126 register_ioport_read(0x404, 1, 1, extboot_read
, pcmd
);
127 register_ioport_write(0x405, 1, 2, extboot_write_cmd
, bs
);