1 // Variable layouts of bios.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU GPLv3 license.
9 #include "types.h" // u8
10 #include "farptr.h" // GET_FARVAR
11 #include "config.h" // CONFIG_*
14 /****************************************************************
15 * Bios Data Area (BDA)
16 ****************************************************************/
23 struct bios_data_area_s {
25 struct ivec ivecs[256];
33 u16 equipment_list_flags;
45 u8 floppy_recalibration_status;
46 u8 floppy_motor_status;
48 u8 floppy_motor_counter;
49 u8 floppy_last_status;
50 u8 floppy_return_status[7];
77 u16 kbd_buf_start_offset;
78 u16 kbd_buf_end_offset;
85 u8 floppy_last_data_rate;
86 u8 disk_status_controller;
87 u8 disk_error_controller;
88 u8 disk_interrupt_flag;
89 u8 floppy_harddisk_info;
91 u8 floppy_media_state[4];
96 u32 ptr_user_wait_complete_flag;
97 u32 user_wait_timeout;
102 // BDA floppy_recalibration_status bitdefs
103 #define FRS_TIMEOUT (1<<7)
105 // BDA rtc_wait_flag bitdefs
106 #define RWS_WAIT_PENDING (1<<0)
107 #define RWS_WAIT_ELAPSED (1<<7)
109 // BDA floppy_media_state bitdefs
110 #define FMS_DRIVE_STATE_MASK (0x07)
111 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
112 #define FMS_DOUBLE_STEPPING (1<<5)
113 #define FMS_DATA_RATE_MASK (0xc0)
115 // Accessor functions
116 #define GET_BDA(var) \
117 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
118 #define SET_BDA(var, val) \
119 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
120 #define CLEARBITS_BDA(var, val) do { \
121 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
122 SET_BDA(var, (__val & ~(val))); \
124 #define SETBITS_BDA(var, val) do { \
125 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
126 SET_BDA(var, (__val | (val))); \
130 /****************************************************************
132 ****************************************************************/
135 u16 heads; // # heads
136 u16 cylinders; // # cylinders
137 u16 spt; // # sectors / track
156 struct ata_channel_s {
157 u16 iobase1; // IO Base 1
158 u16 iobase2; // IO Base 2
163 struct ata_device_s {
164 u8 type; // Detected type of ata (ata/atapi/none/unknown)
165 u8 device; // Detected type of attached devices (hd/cd/none)
166 u8 removable; // Removable device flag
167 u8 lock; // Locks for removable devices
168 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
169 u16 blksize; // block size
171 u8 translation; // type of translation
172 struct chs_s lchs; // Logical CHS
173 struct chs_s pchs; // Physical CHS
175 u64 sectors; // Total sectors count
180 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
183 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
185 // map between bios hd/cd id and ata channels
187 u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
189 // Buffer for DPTE table
192 // Count of transferred sectors and bytes
196 // ElTorito Device Emulation data
209 struct chs_s vdevice;
213 /****************************************************************
214 * Initial Program Load (IPL)
215 ****************************************************************/
225 struct ipl_entry_s table[8];
232 #define IPL_TYPE_FLOPPY 0x01
233 #define IPL_TYPE_HARDDISK 0x02
234 #define IPL_TYPE_CDROM 0x03
235 #define IPL_TYPE_BEV 0x80
238 /****************************************************************
239 * Extended Bios Data Area (EBDA)
240 ****************************************************************/
249 u8 drive_control_byte;
257 struct extended_bios_data_area_s {
260 u32 far_call_pointer;
268 struct fdpt_s fdpt[2];
275 // Physical memory available.
284 // El Torito Emulation data
285 struct cdemu_s cdemu;
287 // Initial program load
291 #define EBDA_SIZE DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
292 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
294 // Accessor functions
295 #define GET_EBDA(var) \
296 GET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var)
297 #define SET_EBDA(var, val) \
298 SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
301 /****************************************************************
303 ****************************************************************/
305 struct bios_config_table_s {
310 u8 feature1, feature2, feature3, feature4, feature5;
313 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
315 #endif // __BIOSVAR_H