VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/ebda.h@ 71963

Last change on this file since 71963 was 71426, checked in by vboxsync, 7 years ago

BIOS: Added disabled code which can place the FDPT outside of conventional memory.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: ebda.h 71426 2018-03-21 11:49:59Z vboxsync $ */
2/** @file
3 * PC BIOS - ???
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on:
19 *
20 * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
21 *
22 * Copyright (C) 2002 MandrakeSoft S.A.
23 *
24 * MandrakeSoft S.A.
25 * 43, rue d'Aboukir
26 * 75002 Paris - France
27 * http://www.linux-mandrake.com/
28 * http://www.mandrakesoft.com/
29 *
30 * This library is free software; you can redistribute it and/or
31 * modify it under the terms of the GNU Lesser General Public
32 * License as published by the Free Software Foundation; either
33 * version 2 of the License, or (at your option) any later version.
34 *
35 * This library is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 * Lesser General Public License for more details.
39 *
40 * You should have received a copy of the GNU Lesser General Public
41 * License along with this library; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
43 *
44 */
45
46/*
47 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
48 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
49 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
50 * a choice of LGPL license versions is made available with the language indicating
51 * that LGPLv2 or any later version may be used, or where a choice of which version
52 * of the LGPL is applied is otherwise unspecified.
53 */
54
55
56#include <stdint.h>
57
58/* Must be defined here (EBDA structures depend on these). */
59#define BX_MAX_ATA_INTERFACES 4
60#define BX_MAX_ATA_DEVICES (BX_MAX_ATA_INTERFACES*2)
61
62#define BX_USE_ATADRV 1
63#define BX_ELTORITO_BOOT 1
64
65#ifdef VBOX_WITH_SCSI
66 /* Enough for now */
67 #define BX_MAX_SCSI_DEVICES 4
68 /* A SCSI device starts always at BX_MAX_ATA_DEVICES. */
69 #define VBOX_IS_SCSI_DEVICE(device_id) (device_id >= BX_MAX_ATA_DEVICES)
70 #define VBOX_GET_SCSI_DEVICE(device_id) (device_id - BX_MAX_ATA_DEVICES)
71#else
72 #define BX_MAX_SCSI_DEVICES 0
73#endif
74
75#ifdef VBOX_WITH_AHCI
76 /* Four should be enough for now */
77 #define BX_MAX_AHCI_DEVICES 4
78
79 /* An AHCI device starts always at BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES. */
80 #define VBOX_IS_AHCI_DEVICE(device_id) (device_id >= (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
81 #define VBOX_GET_AHCI_DEVICE(device_id) (device_id - (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
82#else
83 #define BX_MAX_AHCI_DEVICES 0
84#endif
85
86#define BX_MAX_STORAGE_DEVICES (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES)
87
88/* Generic storage device types. These depend on the controller type and
89 * determine which device access routines should be called.
90 */
91enum dsk_type_enm {
92 DSK_TYPE_NONE, /* Unknown device. */
93 DSK_TYPE_UNKNOWN, /* Unknown ATA device. */
94 DSK_TYPE_ATA, /* ATA disk. */
95 DSK_TYPE_ATAPI, /* ATAPI device. */
96 DSK_TYPE_SCSI, /* SCSI disk. */
97 DSK_TYPE_AHCI, /* SATA disk via AHCI. */
98 DSKTYP_CNT /* Number of disk types. */
99};
100
101/* Disk device types. */
102//@todo: Do we really need these?
103#define DSK_DEVICE_NONE 0x00 /* No device attached. */
104#define DSK_DEVICE_HD 0xFF /* Device is a hard disk. */
105#define DSK_DEVICE_CDROM 0x05 /* Device is a CD-ROM. */
106
107/* Geometry translation modes. */
108enum geo_xlat_enm {
109 GEO_TRANSLATION_NONE, /* No geometry translation. */
110 GEO_TRANSLATION_LBA, /* LBA translation. */
111 GEO_TRANSLATION_LARGE, /* Large CHS translation. */
112 GEO_TRANSLATION_RECHS
113};
114
115#if 1 //BX_USE_ATADRV
116
117/* Note: The DPTE and FDPT structures are industry standards and
118 * may not be modified. The other disk-related structures are
119 * internal to the BIOS.
120 */
121
122/* Translated DPT (Device Parameter Table). */
123typedef struct {
124 uint16_t iobase1;
125 uint16_t iobase2;
126 uint8_t prefix;
127 uint8_t unused;
128 uint8_t irq;
129 uint8_t blkcount;
130 uint8_t dma;
131 uint8_t pio;
132 uint16_t options;
133 uint16_t reserved;
134 uint8_t revision;
135 uint8_t checksum;
136} dpte_t;
137
138ct_assert(sizeof(dpte_t) == 16); /* Ensure correct size. */
139
140#pragma pack(0)
141
142/* FDPT - Fixed Disk Parameter Table. PC/AT compatible; note
143 * that this structure is slightly misaligned.
144 */
145typedef struct {
146 uint16_t lcyl;
147 uint8_t lhead;
148 uint8_t sig;
149 uint8_t spt;
150 uint32_t resvd1;
151 uint16_t cyl;
152 uint8_t head;
153 uint16_t resvd2;
154 uint8_t lspt;
155 uint8_t csum;
156} fdpt_t;
157
158#pragma pack()
159
160ct_assert(sizeof(fdpt_t) == 16); /* Ensure correct size. */
161
162
163/* C/H/S geometry information. */
164typedef struct {
165 uint16_t heads; /* Number of heads. */
166 uint16_t cylinders; /* Number of cylinders. */
167 uint16_t spt; /* Number of sectors per track. */
168} chs_t;
169
170/* IDE/ATA specific device information. */
171typedef struct {
172 uint8_t iface; /* ISA or PCI. */
173 uint8_t irq; /* IRQ (on the PIC). */
174 uint16_t iobase1; /* I/O base 1. */
175 uint16_t iobase2; /* I/O base 2. */
176} ata_chan_t;
177
178#ifdef VBOX_WITH_SCSI
179
180/* SCSI specific device information. */
181typedef struct {
182 uint16_t io_base; /* Port base for HBA communication. */
183 uint8_t target_id; /* Target ID. */
184} scsi_dev_t;
185
186#endif
187
188#ifdef VBOX_WITH_AHCI
189
190/* AHCI specific device information. */
191typedef struct {
192 uint8_t port; /* SATA port. */
193} ahci_dev_t;
194
195#endif
196
197/* Generic disk information. */
198typedef struct {
199 uint8_t type; /* Device type (ATA/ATAPI/SCSI/none/unknown). */
200 uint8_t device; /* Detected type of attached device (HD/CD/none). */
201 uint8_t removable; /* Removable device flag. */
202 uint8_t lock; /* Lock count for removable devices. */
203 //@todo: ATA specific - move?
204 uint8_t mode; /* Transfer mode: PIO 16/32 bits - IRQ - ISADMA - PCIDMA. */
205 uint8_t translation; /* Type of geometry translation. */
206 uint16_t blksize; /* Disk block size. */
207 chs_t lchs; /* Logical CHS geometry. */
208 chs_t pchs; /* Physical CHS geometry. */
209 uint64_t sectors; /* Total sector count. */
210} disk_dev_t;
211
212/* A structure for passing disk request information around. This structure
213 * is designed for saving stack space. As BIOS requests cannot be overlapped,
214 * one such structure is sufficient.
215 */
216typedef struct {
217 uint64_t lba; /* Starting LBA. */
218 void __far *buffer; /* Read/write data buffer pointer. */
219 uint8_t dev_id; /* Device ID; index into devices array. */
220 uint16_t nsect; /* Number of sectors to be transferred. */
221 uint16_t sect_sz; /* Size of a sector in bytes. */
222 uint16_t cylinder; /* Starting cylinder (CHS only). */
223 uint16_t head; /* Starting head (CHS only). */
224 uint16_t sector; /* Starting sector (CHS only). */
225 uint16_t trsfsectors; /* Actual sectors transferred. */
226 uint32_t trsfbytes; /* Actual bytes transferred. */
227 uint16_t skip_b; /* Bytes to skip before transfer. */
228 uint16_t skip_a; /* Bytes to skip after transfer. */
229} disk_req_t;
230
231extern uint16_t ahci_cmd_packet(uint16_t device_id, uint8_t cmdlen, char __far *cmdbuf,
232 uint16_t header, uint32_t length, uint8_t inout, char __far *buffer);
233extern uint16_t scsi_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
234 uint16_t header, uint32_t length, uint8_t inout, char __far *buffer);
235extern uint16_t ata_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
236 uint16_t header, uint32_t length, uint8_t inout, char __far *buffer);
237
238extern uint16_t ata_soft_reset(uint16_t device);
239
240/* All BIOS disk information. Disk-related code in the BIOS should not need
241 * anything outside of this structure.
242 */
243typedef struct {
244 disk_req_t drqp; /* Disk request packet. */
245
246 /* Bus-independent disk device information. */
247 disk_dev_t devices[BX_MAX_STORAGE_DEVICES];
248
249 uint8_t hdcount; /* Total number of BIOS disks. */
250 /* Map between (BIOS disk ID - 0x80) and ATA/SCSI/AHCI disks. */
251 uint8_t hdidmap[BX_MAX_STORAGE_DEVICES];
252
253 uint8_t cdcount; /* Number of CD-ROMs. */
254 /* Map between (BIOS CD-ROM ID - 0xE0) and ATA/SCSI/AHCI devices. */
255 uint8_t cdidmap[BX_MAX_STORAGE_DEVICES];
256
257 /* ATA bus-specific device information. */
258 ata_chan_t channels[BX_MAX_ATA_INTERFACES];
259
260#ifdef VBOX_WITH_SCSI
261 /* SCSI bus-specific device information. */
262 scsi_dev_t scsidev[BX_MAX_SCSI_DEVICES];
263 uint8_t scsi_devcount; /* Number of SCSI devices. */
264#endif
265
266#ifdef VBOX_WITH_AHCI
267 /* SATA (AHCI) bus-specific device information. */
268 ahci_dev_t ahcidev[BX_MAX_AHCI_DEVICES];
269 uint8_t ahci_devcnt; /* Number of SATA devices. */
270 uint16_t ahci_seg; /* Segment of AHCI data block. */
271#endif
272
273 dpte_t dpte; /* Buffer for building a DPTE. */
274} bio_dsk_t;
275
276#if BX_ELTORITO_BOOT
277/* El Torito device emulation state. */
278typedef struct {
279 uint8_t active;
280 uint8_t media;
281 uint8_t emulated_drive;
282 uint8_t controller_index;
283 uint16_t device_spec;
284 uint16_t buffer_segment;
285 uint32_t ilba;
286 uint16_t load_segment;
287 uint16_t sector_count;
288 chs_t vdevice; /* Virtual device geometry. */
289} cdemu_t;
290#endif
291
292// for access to EBDA area
293// The EBDA structure should conform to
294// http://www.frontiernet.net/~fys/rombios.htm document
295// I made the ata and cdemu structs begin at 0x121 in the EBDA seg
296/* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA
297 * which contains the keyboard ID for PS/2 BIOSes.
298 */
299typedef struct {
300 uint8_t filler1[0x3D];
301
302 fdpt_t fdpt0; /* FDPTs for the first two ATA disks. */
303 fdpt_t fdpt1;
304
305 uint8_t filler2[0xC4];
306
307 bio_dsk_t bdisk; /* Disk driver data (ATA/SCSI/AHCI). */
308
309#if BX_ELTORITO_BOOT
310 cdemu_t cdemu; /* El Torito floppy/HD emulation data. */
311#endif
312
313 unsigned char uForceBootDrive;
314 unsigned char uForceBootDevice;
315} ebda_data_t;
316
317ct_assert(sizeof(ebda_data_t) < 0x380); /* Must be under 1K in size. */
318
319// the last 16 bytes of the EBDA segment are used for the MPS floating
320// pointer structure (though only if an I/O APIC is present)
321
322#define EbdaData ((ebda_data_t *) 0)
323
324// for access to the int13ext structure
325typedef struct {
326 uint8_t size;
327 uint8_t reserved;
328 uint16_t count;
329 uint16_t offset;
330 uint16_t segment;
331 uint32_t lba1;
332 uint32_t lba2;
333} int13ext_t;
334
335/* Disk Physical Table structure */
336typedef struct {
337 uint16_t size;
338 uint16_t infos;
339 uint32_t cylinders;
340 uint32_t heads;
341 uint32_t spt;
342 uint32_t sector_count1;
343 uint32_t sector_count2;
344 uint16_t blksize;
345 uint16_t dpte_offset;
346 uint16_t dpte_segment;
347 uint16_t key;
348 uint8_t dpi_length;
349 uint8_t reserved1;
350 uint16_t reserved2;
351 uint8_t host_bus[4];
352 uint8_t iface_type[8];
353 uint8_t iface_path[8];
354 uint8_t device_path[8];
355 uint8_t reserved3;
356 uint8_t checksum;
357} dpt_t;
358
359/* Note: Using fastcall reduces stack usage a little. */
360int __fastcall ata_read_sectors(bio_dsk_t __far *bios_dsk);
361int __fastcall ata_write_sectors(bio_dsk_t __far *bios_dsk);
362
363int __fastcall scsi_read_sectors(bio_dsk_t __far *bios_dsk);
364int __fastcall scsi_write_sectors(bio_dsk_t __far *bios_dsk);
365
366int __fastcall ahci_read_sectors(bio_dsk_t __far *bios_dsk);
367int __fastcall ahci_write_sectors(bio_dsk_t __far *bios_dsk);
368
369extern void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors);
370extern int edd_fill_dpt(dpt_t __far *dpt, bio_dsk_t __far *bios_dsk, uint8_t device);
371
372// @todo: put this elsewhere (and change/eliminate?)
373#define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
374
375#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