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