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 | //@todo: does the struct really have to be misaligned?
|
---|
79 | #pragma pack(0)
|
---|
80 |
|
---|
81 | typedef struct {
|
---|
82 | uint16_t heads; // # heads
|
---|
83 | uint16_t cylinders; // # cylinders
|
---|
84 | uint16_t spt; // # sectors / track
|
---|
85 | } chs_t;
|
---|
86 |
|
---|
87 | // DPTE definition
|
---|
88 | typedef struct {
|
---|
89 | uint16_t iobase1;
|
---|
90 | uint16_t iobase2;
|
---|
91 | uint8_t prefix;
|
---|
92 | uint8_t unused;
|
---|
93 | uint8_t irq;
|
---|
94 | uint8_t blkcount;
|
---|
95 | uint8_t dma;
|
---|
96 | uint8_t pio;
|
---|
97 | uint16_t options;
|
---|
98 | uint16_t reserved;
|
---|
99 | uint8_t revision;
|
---|
100 | uint8_t checksum;
|
---|
101 | } dpte_t;
|
---|
102 |
|
---|
103 | typedef struct {
|
---|
104 | uint8_t iface; // ISA or PCI
|
---|
105 | uint16_t iobase1; // IO Base 1
|
---|
106 | uint16_t iobase2; // IO Base 2
|
---|
107 | uint8_t irq; // IRQ
|
---|
108 | } ata_channel_t;
|
---|
109 |
|
---|
110 | typedef struct {
|
---|
111 | uint8_t type; // Detected type of ata (ata/atapi/none/unknown/scsi)
|
---|
112 | uint8_t device; // Detected type of attached devices (hd/cd/none)
|
---|
113 | uint8_t removable; // Removable device flag
|
---|
114 | uint8_t lock; // Locks for removable devices
|
---|
115 | uint8_t mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
|
---|
116 | uint16_t blksize; // block size
|
---|
117 |
|
---|
118 | uint8_t translation; // type of translation
|
---|
119 | chs_t lchs; // Logical CHS
|
---|
120 | chs_t pchs; // Physical CHS
|
---|
121 |
|
---|
122 | uint32_t sectors; // Total sectors count
|
---|
123 | } ata_device_t;
|
---|
124 |
|
---|
125 | typedef struct {
|
---|
126 | // ATA channels info
|
---|
127 | ata_channel_t channels[BX_MAX_ATA_INTERFACES];
|
---|
128 |
|
---|
129 | // ATA devices info
|
---|
130 | ata_device_t devices[BX_MAX_ATA_DEVICES];
|
---|
131 | //
|
---|
132 | // map between (bios hd id - 0x80) and ata channels and scsi disks.
|
---|
133 | uint8_t hdcount, hdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
134 |
|
---|
135 | // map between (bios cd id - 0xE0) and ata channels
|
---|
136 | uint8_t cdcount, cdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
137 |
|
---|
138 | // Buffer for DPTE table
|
---|
139 | dpte_t dpte;
|
---|
140 |
|
---|
141 | // Count of transferred sectors and bytes
|
---|
142 | uint16_t trsfsectors;
|
---|
143 | uint32_t trsfbytes;
|
---|
144 | } ata_t;
|
---|
145 |
|
---|
146 | #if BX_ELTORITO_BOOT
|
---|
147 | // ElTorito Device Emulation data
|
---|
148 | typedef struct {
|
---|
149 | uint8_t active;
|
---|
150 | uint8_t media;
|
---|
151 | uint8_t emulated_drive;
|
---|
152 | uint8_t controller_index;
|
---|
153 | uint16_t device_spec;
|
---|
154 | uint32_t ilba;
|
---|
155 | uint16_t buffer_segment;
|
---|
156 | uint16_t load_segment;
|
---|
157 | uint16_t sector_count;
|
---|
158 |
|
---|
159 | // Virtual device
|
---|
160 | chs_t vdevice;
|
---|
161 | } cdemu_t;
|
---|
162 | #endif // BX_ELTORITO_BOOT
|
---|
163 |
|
---|
164 | #ifdef VBOX_WITH_SCSI
|
---|
165 | typedef struct {
|
---|
166 | // I/O port this device is attached to.
|
---|
167 | uint16_t io_base;
|
---|
168 | // Target Id.
|
---|
169 | uint8_t target_id;
|
---|
170 | // SCSI devices info
|
---|
171 | ata_device_t device_info;
|
---|
172 | } scsi_device_t;
|
---|
173 |
|
---|
174 | typedef struct {
|
---|
175 | // SCSI device info
|
---|
176 | scsi_device_t devices[BX_MAX_SCSI_DEVICES];
|
---|
177 | // Number of scsi disks.
|
---|
178 | uint8_t hdcount;
|
---|
179 | } scsi_t;
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | #ifdef VBOX_WITH_BIOS_AHCI
|
---|
183 | //typedef struct {
|
---|
184 | // uint16_t iobase;
|
---|
185 | //} ahci_t;
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | typedef struct {
|
---|
189 | uint16_t lcyl;
|
---|
190 | uint8_t lhead;
|
---|
191 | uint8_t sig;
|
---|
192 | uint8_t spt;
|
---|
193 | uint8_t resvd1[4];
|
---|
194 | uint16_t cyl;
|
---|
195 | uint8_t head;
|
---|
196 | uint8_t resvd2[2];
|
---|
197 | uint8_t lspt;
|
---|
198 | uint8_t csum;
|
---|
199 | } fdpt_t;
|
---|
200 |
|
---|
201 | // for access to EBDA area
|
---|
202 | // The EBDA structure should conform to
|
---|
203 | // http://www.frontiernet.net/~fys/rombios.htm document
|
---|
204 | // I made the ata and cdemu structs begin at 0x121 in the EBDA seg
|
---|
205 | /* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA. */
|
---|
206 | typedef struct {
|
---|
207 | unsigned char filler1[0x3D];
|
---|
208 |
|
---|
209 | // FDPT - Can be split into data members if needed
|
---|
210 | fdpt_t fdpt0;
|
---|
211 | fdpt_t fdpt1;
|
---|
212 |
|
---|
213 | #if 0
|
---|
214 | unsigned char filler2[0xC4];
|
---|
215 | #else
|
---|
216 | unsigned char filler2[0xC2];
|
---|
217 | uint16_t ahci_seg;
|
---|
218 | #endif
|
---|
219 |
|
---|
220 | // ATA Driver data
|
---|
221 | ata_t ata;
|
---|
222 |
|
---|
223 | #if BX_ELTORITO_BOOT
|
---|
224 | // El Torito Emulation data
|
---|
225 | cdemu_t cdemu;
|
---|
226 | #endif // BX_ELTORITO_BOOT
|
---|
227 |
|
---|
228 | #ifdef VBOX_WITH_SCSI
|
---|
229 | // SCSI Driver data
|
---|
230 | scsi_t scsi;
|
---|
231 | # endif
|
---|
232 |
|
---|
233 | #ifdef VBOX_WITH_BIOS_AHCI
|
---|
234 | // ahci_t ahci;
|
---|
235 | // uint16_t ahci_seg; //@todo: Someone is trashing the data here!?!
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | unsigned char uForceBootDrive;
|
---|
239 | unsigned char uForceBootDevice;
|
---|
240 | } ebda_data_t;
|
---|
241 |
|
---|
242 | #pragma pack()
|
---|
243 |
|
---|
244 | // the last 16 bytes of the EBDA segment are used for the MPS floating
|
---|
245 | // pointer structure (though only if an I/O APIC is present)
|
---|
246 |
|
---|
247 | #define EbdaData ((ebda_data_t *) 0)
|
---|
248 |
|
---|
249 | // @todo: put this elsewhere (and change/eliminate?)
|
---|
250 | #define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
|
---|
251 |
|
---|
252 | #endif
|
---|