VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS-new/ebda.h@ 39597

Last change on this file since 39597 was 39597, checked in by vboxsync, 13 years ago

Throw away unneeded data from CD.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
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
51#ifdef VBOX_WITH_SCSI
52 /* Enough for now */
53 #define BX_MAX_SCSI_DEVICES 4
54 /* A SCSI device starts always at BX_MAX_ATA_DEVICES. */
55 #define VBOX_IS_SCSI_DEVICE(device_id) (device_id >= BX_MAX_ATA_DEVICES)
56 #define VBOX_GET_SCSI_DEVICE(device_id) (device_id - BX_MAX_ATA_DEVICES)
57#else
58 #define BX_MAX_SCSI_DEVICES 0
59#endif
60
61#ifdef VBOX_WITH_AHCI
62 /* Four should be enough for now */
63 #define BX_MAX_AHCI_DEVICES 4
64
65 /* An AHCI device starts always at BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES. */
66 #define VBOX_IS_AHCI_DEVICE(device_id) (device_id >= (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
67 #define VBOX_GET_AHCI_DEVICE(device_id) (device_id - (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
68#else
69 #define BX_MAX_AHCI_DEVICES 0
70#endif
71
72#define BX_MAX_STORAGE_DEVICES (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES)
73
74/* Generic storage device types. Bit of a misnomer! */
75#define ATA_TYPE_NONE 0x00
76#define ATA_TYPE_UNKNOWN 0x01
77#define ATA_TYPE_ATA 0x02
78#define ATA_TYPE_ATAPI 0x03
79#define ATA_TYPE_SCSI 0x04 // SCSI disk
80#define ATA_TYPE_AHCI 0x05 // SATA disk
81
82#define ATA_DEVICE_NONE 0x00
83#define ATA_DEVICE_HD 0xFF
84#define ATA_DEVICE_CDROM 0x05
85
86#define ATA_TRANSLATION_NONE 0
87#define ATA_TRANSLATION_LBA 1
88#define ATA_TRANSLATION_LARGE 2
89#define ATA_TRANSLATION_RECHS 3
90
91#if 1 //BX_USE_ATADRV
92
93/* Note: The DPTE and FDPT structures are industry standards and
94 * may not be modified. The other disk-related structures are
95 * internal to the BIOS.
96 */
97
98/* Translated DPT (Device Parameter Table). */
99typedef struct {
100 uint16_t iobase1;
101 uint16_t iobase2;
102 uint8_t prefix;
103 uint8_t unused;
104 uint8_t irq;
105 uint8_t blkcount;
106 uint8_t dma;
107 uint8_t pio;
108 uint16_t options;
109 uint16_t reserved;
110 uint8_t revision;
111 uint8_t checksum;
112} dpte_t;
113
114ct_assert(sizeof(dpte_t) == 16); /* Ensure correct size. */
115
116#pragma pack(0)
117
118/* FDPT - Fixed Disk Parameter Table. PC/AT compatible; note
119 * that this structure is slightly misaligned.
120 */
121typedef struct {
122 uint16_t lcyl;
123 uint8_t lhead;
124 uint8_t sig;
125 uint8_t spt;
126 uint8_t resvd1[4];
127 uint16_t cyl;
128 uint8_t head;
129 uint8_t resvd2[2];
130 uint8_t lspt;
131 uint8_t csum;
132} fdpt_t;
133
134#pragma pack()
135
136ct_assert(sizeof(fdpt_t) == 16); /* Ensure correct size. */
137
138
139/* C/H/S geometry information. */
140typedef struct {
141 uint16_t heads; /* Number of heads. */
142 uint16_t cylinders; /* Number of cylinders. */
143 uint16_t spt; /* Number of sectors per track. */
144} chs_t;
145
146/* IDE/ATA specific device information. */
147typedef struct {
148 uint8_t iface; /* ISA or PCI. */
149 uint8_t irq; /* IRQ (on the PIC). */
150 uint16_t iobase1; /* I/O base 1. */
151 uint16_t iobase2; /* I/O base 2. */
152} ata_chan_t;
153
154#ifdef VBOX_WITH_SCSI
155
156/* SCSI specific device information. */
157typedef struct {
158 uint16_t io_base; /* Port base for HBA communication. */
159 uint8_t target_id; /* Target ID. */
160} scsi_dev_t;
161
162#endif
163
164#ifdef VBOX_WITH_AHCI
165
166/* AHCI specific device information. */
167typedef struct {
168 uint8_t port; /* SATA port. */
169} ahci_dev_t;
170
171#endif
172
173/* Generic disk information. */
174typedef struct {
175 uint8_t type; /* Device type (ATA/ATAPI/SCSI/none/unknown). */
176 uint8_t device; /* Detected type of attached device (HD/CD/none). */
177 uint8_t removable; /* Removable device flag. */
178 uint8_t lock; /* Lock count for removable devices. */
179 //@todo: ATA specific - move?
180 uint8_t mode; /* Transfer mode: PIO 16/32 bits - IRQ - ISADMA - PCIDMA. */
181 uint8_t translation; /* Type of geometry translation. */
182 uint16_t blksize; /* Disk block size. */
183 chs_t lchs; /* Logical CHS geometry. */
184 chs_t pchs; /* Physical CHS geometry. */
185 uint32_t sectors; /* Total sector count. */
186} disk_dev_t;
187
188/* A structure for passing disk request information around. This structure
189 * is designed for saving stack space. As BIOS requests cannot be overlapped,
190 * one such structure is sufficient.
191 */
192typedef struct {
193 uint32_t lba; /* Starting LBA. */
194 void __far *buffer; /* Read/write data buffer pointer. */
195 uint8_t dev_id; /* Device ID; index into devices array. */
196 uint16_t nsect; /* Number of sectors to be transferred. */
197 uint16_t sect_sz; /* Size of a sector in bytes. */
198 uint16_t cylinder; /* Starting cylinder (CHS only). */
199 uint16_t head; /* Starting head (CHS only). */
200 uint16_t sector; /* Starting sector (CHS only). */
201 uint16_t trsfsectors; /* Actual sectors transferred. */
202 uint32_t trsfbytes; /* Actual bytes transferred. */
203 uint16_t skip_b; /* Bytes to skip before transfer. */
204 uint16_t skip_a; /* Bytes to skip after transfer. */
205} disk_req_t;
206
207/* All BIOS disk information. Disk-related code in the BIOS should not need
208 * anything outside of this structure.
209 */
210typedef struct {
211 disk_req_t drqp; /* Disk request packet. */
212
213 /* Bus-independent disk device information. */
214 disk_dev_t devices[BX_MAX_STORAGE_DEVICES];
215
216 uint8_t hdcount; /* Total number of BIOS disks. */
217 /* Map between (BIOS disk ID - 0x80) and ATA/SCSI/AHCI disks. */
218 uint8_t hdidmap[BX_MAX_STORAGE_DEVICES];
219
220 uint8_t cdcount; /* Number of CD-ROMs. */
221 /* Map between (BIOS CD-ROM ID - 0xE0) and ATA/SCSI/AHCI devices. */
222 uint8_t cdidmap[BX_MAX_STORAGE_DEVICES];
223
224 /* ATA bus-specific device information. */
225 ata_chan_t channels[BX_MAX_ATA_INTERFACES];
226
227#ifdef VBOX_WITH_SCSI
228 /* SCSI bus-specific device information. */
229 scsi_dev_t scsidev[BX_MAX_SCSI_DEVICES];
230 uint8_t scsi_hdcount; /* Number of SCSI disks. */
231#endif
232
233#ifdef VBOX_WITH_AHCI
234 /* SATA (AHCI) bus-specific device information. */
235 ahci_dev_t ahcidev[BX_MAX_AHCI_DEVICES];
236 uint8_t ahci_devcnt; /* Number of SATA devices. */
237 uint16_t ahci_seg; /* Segment of AHCI data block. */
238#endif
239
240 dpte_t dpte; /* Buffer for building a DPTE. */
241} bio_dsk_t;
242
243#if BX_ELTORITO_BOOT
244/* El Torito device emulation state. */
245typedef struct {
246 uint8_t active;
247 uint8_t media;
248 uint8_t emulated_drive;
249 uint8_t controller_index;
250 uint16_t device_spec;
251 uint16_t buffer_segment;
252 uint32_t ilba;
253 uint16_t load_segment;
254 uint16_t sector_count;
255 chs_t vdevice; /* Virtual device geometry. */
256} cdemu_t;
257#endif
258
259// for access to EBDA area
260// The EBDA structure should conform to
261// http://www.frontiernet.net/~fys/rombios.htm document
262// I made the ata and cdemu structs begin at 0x121 in the EBDA seg
263/* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA
264 * which contains the keyboard ID for PS/2 BIOSes.
265 */
266typedef struct {
267 uint8_t filler1[0x3D];
268
269 fdpt_t fdpt0; /* FDPTs for the first two ATA disks. */
270 fdpt_t fdpt1;
271
272 uint8_t filler2[0xC4];
273
274 bio_dsk_t bdisk; /* Disk driver data (ATA/SCSI/AHCI). */
275
276#if BX_ELTORITO_BOOT
277 cdemu_t cdemu; /* El Torito floppy/HD emulation data. */
278#endif
279
280 unsigned char uForceBootDrive;
281 unsigned char uForceBootDevice;
282} ebda_data_t;
283
284ct_assert(sizeof(ebda_data_t) < 0x380); /* Must be under 1K in size. */
285
286// the last 16 bytes of the EBDA segment are used for the MPS floating
287// pointer structure (though only if an I/O APIC is present)
288
289#define EbdaData ((ebda_data_t *) 0)
290
291/* Note: Using fastcall reduces stack usage a little. */
292int __fastcall ata_read_sectors(bio_dsk_t __far *bios_dsk);
293int __fastcall ata_write_sectors(bio_dsk_t __far *bios_dsk);
294
295int __fastcall scsi_read_sectors(bio_dsk_t __far *bios_dsk);
296int __fastcall scsi_write_sectors(bio_dsk_t __far *bios_dsk);
297
298int __fastcall ahci_read_sectors(bio_dsk_t __far *bios_dsk);
299int __fastcall ahci_write_sectors(bio_dsk_t __far *bios_dsk);
300
301
302uint16_t ahci_cmd_packet(uint16_t device_id, uint8_t cmdlen, char __far *cmdbuf,
303 uint16_t header, uint32_t length, uint8_t inout, char __far *buffer);
304
305uint16_t ata_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
306 uint16_t header, uint32_t length, uint8_t inout, char __far *buffer);
307
308// @todo: put this elsewhere (and change/eliminate?)
309#define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
310
311#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette