VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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