1 | /*
|
---|
2 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
3 | *
|
---|
4 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
5 | * available from http://www.virtualbox.org. This file is free software;
|
---|
6 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
7 | * General Public License (GPL) as published by the Free Software
|
---|
8 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
9 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
10 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
11 | * --------------------------------------------------------------------
|
---|
12 | *
|
---|
13 | * This code is based on:
|
---|
14 | *
|
---|
15 | * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
|
---|
16 | *
|
---|
17 | * Copyright (C) 2002 MandrakeSoft S.A.
|
---|
18 | *
|
---|
19 | * MandrakeSoft S.A.
|
---|
20 | * 43, rue d'Aboukir
|
---|
21 | * 75002 Paris - France
|
---|
22 | * http://www.linux-mandrake.com/
|
---|
23 | * http://www.mandrakesoft.com/
|
---|
24 | *
|
---|
25 | * This library is free software; you can redistribute it and/or
|
---|
26 | * modify it under the terms of the GNU Lesser General Public
|
---|
27 | * License as published by the Free Software Foundation; either
|
---|
28 | * version 2 of the License, or (at your option) any later version.
|
---|
29 | *
|
---|
30 | * This library is distributed in the hope that it will be useful,
|
---|
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
33 | * Lesser General Public License for more details.
|
---|
34 | *
|
---|
35 | * You should have received a copy of the GNU Lesser General Public
|
---|
36 | * License along with this library; if not, write to the Free Software
|
---|
37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
38 | *
|
---|
39 | */
|
---|
40 |
|
---|
41 |
|
---|
42 | #include <stdint.h>
|
---|
43 |
|
---|
44 | /* Must be defined here (EBDA structures depend on these). */
|
---|
45 | #define BX_MAX_ATA_INTERFACES 4
|
---|
46 | #define BX_MAX_ATA_DEVICES (BX_MAX_ATA_INTERFACES*2)
|
---|
47 |
|
---|
48 | #define BX_USE_ATADRV 1
|
---|
49 | #define BX_ELTORITO_BOOT 1
|
---|
50 | #define BX_APM 1
|
---|
51 |
|
---|
52 | #ifdef VBOX_WITH_SCSI
|
---|
53 | /* Enough for now */
|
---|
54 | # define BX_MAX_SCSI_DEVICES 4
|
---|
55 | # define BX_MAX_STORAGE_DEVICES (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES)
|
---|
56 |
|
---|
57 | /* A SCSI device starts always at BX_MAX_ATA_DEVICES. */
|
---|
58 | # define VBOX_IS_SCSI_DEVICE(device_id) (device_id >= BX_MAX_ATA_DEVICES)
|
---|
59 | # define VBOX_GET_SCSI_DEVICE(device_id) (device_id - BX_MAX_ATA_DEVICES)
|
---|
60 | #else
|
---|
61 | # define BX_MAX_STORAGE_DEVICES BX_MAX_ATA_DEVICES
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | /* Generic storage device types. Bit of a misnomer! */
|
---|
65 | #define ATA_TYPE_NONE 0x00
|
---|
66 | #define ATA_TYPE_UNKNOWN 0x01
|
---|
67 | #define ATA_TYPE_ATA 0x02
|
---|
68 | #define ATA_TYPE_ATAPI 0x03
|
---|
69 | #define ATA_TYPE_SCSI 0x04 // SCSI disk
|
---|
70 |
|
---|
71 | #define ATA_DEVICE_NONE 0x00
|
---|
72 | #define ATA_DEVICE_HD 0xFF
|
---|
73 | #define ATA_DEVICE_CDROM 0x05
|
---|
74 |
|
---|
75 |
|
---|
76 | #if 1 //BX_USE_ATADRV
|
---|
77 |
|
---|
78 | /* Note: The DPTE and FDPT structures are industry standards and
|
---|
79 | * may not be modified. The other disk-related structures are
|
---|
80 | * internal to the BIOS.
|
---|
81 | */
|
---|
82 |
|
---|
83 | /* Translated DPT (Device Parameter Table). */
|
---|
84 | typedef struct {
|
---|
85 | uint16_t iobase1;
|
---|
86 | uint16_t iobase2;
|
---|
87 | uint8_t prefix;
|
---|
88 | uint8_t unused;
|
---|
89 | uint8_t irq;
|
---|
90 | uint8_t blkcount;
|
---|
91 | uint8_t dma;
|
---|
92 | uint8_t pio;
|
---|
93 | uint16_t options;
|
---|
94 | uint16_t reserved;
|
---|
95 | uint8_t revision;
|
---|
96 | uint8_t checksum;
|
---|
97 | } dpte_t;
|
---|
98 |
|
---|
99 | ct_assert(sizeof(dpte_t) == 16); /* Ensure correct size. */
|
---|
100 |
|
---|
101 | #pragma pack(0)
|
---|
102 |
|
---|
103 | /* FDPT - Fixed Disk Parameter Table. PC/AT compatible; note
|
---|
104 | * that this structure is slightly misaligned.
|
---|
105 | */
|
---|
106 | typedef struct {
|
---|
107 | uint16_t lcyl;
|
---|
108 | uint8_t lhead;
|
---|
109 | uint8_t sig;
|
---|
110 | uint8_t spt;
|
---|
111 | uint8_t resvd1[4];
|
---|
112 | uint16_t cyl;
|
---|
113 | uint8_t head;
|
---|
114 | uint8_t resvd2[2];
|
---|
115 | uint8_t lspt;
|
---|
116 | uint8_t csum;
|
---|
117 | } fdpt_t;
|
---|
118 |
|
---|
119 | #pragma pack()
|
---|
120 |
|
---|
121 | ct_assert(sizeof(fdpt_t) == 16); /* Ensure correct size. */
|
---|
122 |
|
---|
123 |
|
---|
124 | /* C/H/S geometry information. */
|
---|
125 | typedef struct {
|
---|
126 | uint16_t heads; /* Number of heads. */
|
---|
127 | uint16_t cylinders; /* Number of cylinders. */
|
---|
128 | uint16_t spt; /* Number of sectors per track. */
|
---|
129 | } chs_t;
|
---|
130 |
|
---|
131 | typedef struct {
|
---|
132 | uint8_t iface; // ISA or PCI
|
---|
133 | uint8_t irq; // IRQ
|
---|
134 | uint16_t iobase1; // IO Base 1
|
---|
135 | uint16_t iobase2; // IO Base 2
|
---|
136 | } ata_chan_t;
|
---|
137 |
|
---|
138 | typedef struct {
|
---|
139 | uint8_t type; // Detected type of disk (ata/atapi/none/unknown/scsi)
|
---|
140 | uint8_t device; // Detected type of attached devices (hd/cd/none)
|
---|
141 | uint8_t removable; // Removable device flag
|
---|
142 | uint8_t lock; // Locks for removable devices
|
---|
143 | uint8_t mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
|
---|
144 | uint8_t translation; // type of translation
|
---|
145 | uint16_t blksize; // block size
|
---|
146 | chs_t lchs; // Logical CHS
|
---|
147 | chs_t pchs; // Physical CHS
|
---|
148 | uint32_t sectors; // Total sectors count
|
---|
149 | } ata_dev_t;
|
---|
150 |
|
---|
151 | typedef struct {
|
---|
152 | // ATA channels info
|
---|
153 | ata_chan_t channels[BX_MAX_ATA_INTERFACES];
|
---|
154 |
|
---|
155 | // ATA devices info
|
---|
156 | ata_dev_t devices[BX_MAX_ATA_DEVICES];
|
---|
157 | //
|
---|
158 | // map between (bios hd id - 0x80) and ata channels and scsi disks.
|
---|
159 | uint8_t hdcount, hdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
160 |
|
---|
161 | // map between (bios cd id - 0xE0) and ata channels
|
---|
162 | uint8_t cdcount, cdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
163 |
|
---|
164 | // Buffer for DPTE table
|
---|
165 | dpte_t dpte;
|
---|
166 |
|
---|
167 | // Count of transferred sectors and bytes
|
---|
168 | uint16_t trsfsectors;
|
---|
169 | uint32_t trsfbytes;
|
---|
170 | } bio_dsk_t;
|
---|
171 |
|
---|
172 | #if BX_ELTORITO_BOOT
|
---|
173 | // ElTorito Device Emulation data
|
---|
174 | typedef struct {
|
---|
175 | uint8_t active;
|
---|
176 | uint8_t media;
|
---|
177 | uint8_t emulated_drive;
|
---|
178 | uint8_t controller_index;
|
---|
179 | uint16_t device_spec;
|
---|
180 | uint16_t buffer_segment;
|
---|
181 | uint32_t ilba;
|
---|
182 | uint16_t load_segment;
|
---|
183 | uint16_t sector_count;
|
---|
184 | chs_t vdevice; /* Virtual device geometry. */
|
---|
185 | } cdemu_t;
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | #ifdef VBOX_WITH_SCSI
|
---|
189 | typedef struct {
|
---|
190 | // I/O port this device is attached to.
|
---|
191 | uint16_t io_base;
|
---|
192 | // Target Id.
|
---|
193 | uint8_t target_id;
|
---|
194 | // SCSI devices info
|
---|
195 | ata_dev_t device_info;
|
---|
196 | } scsi_dev_t;
|
---|
197 |
|
---|
198 | typedef struct {
|
---|
199 | // SCSI device info
|
---|
200 | scsi_dev_t devices[BX_MAX_SCSI_DEVICES];
|
---|
201 | // Number of scsi disks.
|
---|
202 | uint8_t hdcount;
|
---|
203 | } scsi_t;
|
---|
204 | #endif
|
---|
205 |
|
---|
206 | // for access to EBDA area
|
---|
207 | // The EBDA structure should conform to
|
---|
208 | // http://www.frontiernet.net/~fys/rombios.htm document
|
---|
209 | // I made the ata and cdemu structs begin at 0x121 in the EBDA seg
|
---|
210 | /* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA
|
---|
211 | * which contains the keyboard ID for PS/2 BIOSes.
|
---|
212 | */
|
---|
213 | typedef struct {
|
---|
214 | unsigned char filler1[0x3D];
|
---|
215 |
|
---|
216 | // FDPT - Can be split into data members if needed
|
---|
217 | fdpt_t fdpt0;
|
---|
218 | fdpt_t fdpt1;
|
---|
219 |
|
---|
220 | #if 0
|
---|
221 | unsigned char filler2[0xC4];
|
---|
222 | #else
|
---|
223 | unsigned char filler2[0xC2];
|
---|
224 | uint16_t ahci_seg;
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | bio_dsk_t bdisk; /* Disk driver data (ATA/SCSI/AHCI). */
|
---|
228 |
|
---|
229 | #if BX_ELTORITO_BOOT
|
---|
230 | cdemu_t cdemu; /* El Torito floppy/HD emulation data. */
|
---|
231 | #endif
|
---|
232 |
|
---|
233 | #ifdef VBOX_WITH_SCSI
|
---|
234 | // SCSI Driver data
|
---|
235 | scsi_t scsi;
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | #ifdef VBOX_WITH_BIOS_AHCI
|
---|
239 | // ahci_t ahci;
|
---|
240 | // uint16_t ahci_seg; //@todo: Someone is trashing the data here!?!
|
---|
241 | #endif
|
---|
242 |
|
---|
243 | unsigned char uForceBootDrive;
|
---|
244 | unsigned char uForceBootDevice;
|
---|
245 | } ebda_data_t;
|
---|
246 |
|
---|
247 | ct_assert(sizeof(ebda_data_t) < 0x400); /* Must be under 1K in size. */
|
---|
248 |
|
---|
249 | // the last 16 bytes of the EBDA segment are used for the MPS floating
|
---|
250 | // pointer structure (though only if an I/O APIC is present)
|
---|
251 |
|
---|
252 | #define EbdaData ((ebda_data_t *) 0)
|
---|
253 |
|
---|
254 | // @todo: put this elsewhere (and change/eliminate?)
|
---|
255 | #define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
|
---|
256 |
|
---|
257 | #endif
|
---|