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" // SET_SEG
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];
70 u16 kbd_buf_start_offset;
71 u16 kbd_buf_end_offset;
73 u8 floppy_last_data_rate;
74 u8 disk_status_controller;
75 u8 disk_error_controller;
76 u8 disk_interrupt_flag;
77 u8 floppy_harddisk_info;
79 u8 floppy_media_state[4];
84 u32 ptr_user_wait_complete_flag;
85 u32 user_wait_timeout;
90 // BDA floppy_recalibration_status bitdefs
91 #define FRS_TIMEOUT (1<<7)
93 // BDA rtc_wait_flag bitdefs
94 #define RWS_WAIT_PENDING (1<<0)
95 #define RWS_WAIT_ELAPSED (1<<7)
97 // BDA floppy_media_state bitdefs
98 #define FMS_DRIVE_STATE_MASK (0x07)
99 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
100 #define FMS_DOUBLE_STEPPING (1<<5)
101 #define FMS_DATA_RATE_MASK (0xc0)
103 // Accessor functions
104 #define GET_BDA(var) \
105 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
106 #define SET_BDA(var, val) \
107 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
108 #define CLEARBITS_BDA(var, val) do { \
109 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
110 SET_BDA(var, (__val & ~(val))); \
112 #define SETBITS_BDA(var, val) do { \
113 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
114 SET_BDA(var, (__val | (val))); \
118 /****************************************************************
120 ****************************************************************/
123 u16 heads; // # heads
124 u16 cylinders; // # cylinders
125 u16 spt; // # sectors / track
144 struct ata_channel_s {
145 u8 iface; // ISA or PCI
146 u16 iobase1; // IO Base 1
147 u16 iobase2; // IO Base 2
151 struct ata_device_s {
152 u8 type; // Detected type of ata (ata/atapi/none/unknown)
153 u8 device; // Detected type of attached devices (hd/cd/none)
154 u8 removable; // Removable device flag
155 u8 lock; // Locks for removable devices
156 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
157 u16 blksize; // block size
159 u8 translation; // type of translation
160 struct chs_s lchs; // Logical CHS
161 struct chs_s pchs; // Physical CHS
163 u32 sectors; // Total sectors count
168 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
171 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
173 // map between bios hd/cd id and ata channels
175 u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
177 // Buffer for DPTE table
180 // Count of transferred sectors and bytes
184 // ElTorito Device Emulation data
197 struct chs_s vdevice;
201 /****************************************************************
202 * Initial Program Load (IPL)
203 ****************************************************************/
213 struct ipl_entry_s table[8];
219 #define IPL_TYPE_FLOPPY 0x01
220 #define IPL_TYPE_HARDDISK 0x02
221 #define IPL_TYPE_CDROM 0x03
222 #define IPL_TYPE_BEV 0x80
225 /****************************************************************
226 * Extended Bios Data Area (EBDA)
227 ****************************************************************/
236 u8 drive_control_byte;
244 struct extended_bios_data_area_s {
247 u32 far_call_pointer;
264 // El Torito Emulation data
265 struct cdemu_s cdemu;
267 // Initial program load
271 // Accessor functions
272 #define GET_EBDA(var) \
273 GET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var)
274 #define SET_EBDA(var, val) \
275 SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
278 /****************************************************************
279 * Registers saved/restored in romlayout.S
280 ****************************************************************/
282 #define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
284 // Layout of registers passed in to irq handlers. Note that this
285 // layout corresponds to code in romlayout.S - don't change it here
286 // without also updating the assembler code.
290 UREG(edi, di, di_hi, di_lo);
291 UREG(esi, si, si_hi, si_lo);
292 UREG(ebx, bx, bh, bl);
293 UREG(edx, dx, dh, dl);
294 UREG(ecx, cx, ch, cl);
295 UREG(eax, ax, ah, al);
301 // bregs flags bitdefs
306 set_cf(struct bregs *regs, int cond)
311 regs->flags &= ~F_CF;
315 /****************************************************************
317 ****************************************************************/
319 struct bios_config_table_s {
324 u8 feature1, feature2, feature3, feature4, feature5;
327 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
330 /****************************************************************
332 ****************************************************************/
334 #define SEG_BIOS 0xf000
335 #define SEG_EBDA 0x9fc0
336 #define SEG_BDA 0x0000
338 #define EBDA_SIZE 1 // In KiB
339 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
341 #endif // __BIOSVAR_H