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_*
13 #define PACKED __attribute__((packed))
16 /****************************************************************
17 * Bios Data Area (BDA)
18 ****************************************************************/
25 struct bios_data_area_s {
27 struct ivec ivecs[256];
35 u16 equipment_list_flags;
47 u8 floppy_recalibration_status;
48 u8 floppy_motor_status;
50 u8 floppy_motor_counter;
51 u8 floppy_last_status;
52 u8 floppy_return_status[7];
72 u16 kbd_buf_start_offset;
73 u16 kbd_buf_end_offset;
75 u8 floppy_last_data_rate;
76 u8 disk_status_controller;
77 u8 disk_error_controller;
78 u8 disk_interrupt_flag;
79 u8 floppy_harddisk_info;
81 u8 floppy_media_state[4];
86 u32 ptr_user_wait_complete_flag;
87 u32 user_wait_timeout;
92 // BDA floppy_recalibration_status bitdefs
93 #define FRS_TIMEOUT (1<<7)
95 // BDA rtc_wait_flag bitdefs
96 #define RWS_WAIT_PENDING (1<<0)
97 #define RWS_WAIT_ELAPSED (1<<7)
99 // BDA floppy_media_state bitdefs
100 #define FMS_DRIVE_STATE_MASK (0x07)
101 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
102 #define FMS_DOUBLE_STEPPING (1<<5)
103 #define FMS_DATA_RATE_MASK (0xc0)
105 // Accessor functions
106 #define GET_BDA(var) \
107 GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
108 #define SET_BDA(var, val) \
109 SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
110 #define CLEARBITS_BDA(var, val) do { \
111 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
112 SET_BDA(var, (__val & ~(val))); \
114 #define SETBITS_BDA(var, val) do { \
115 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
116 SET_BDA(var, (__val | (val))); \
120 /****************************************************************
122 ****************************************************************/
131 u8 drive_control_byte;
140 u16 heads; // # heads
141 u16 cylinders; // # cylinders
142 u16 spt; // # sectors / track
161 struct ata_channel_s {
162 u8 iface; // ISA or PCI
163 u16 iobase1; // IO Base 1
164 u16 iobase2; // IO Base 2
168 struct ata_device_s {
169 u8 type; // Detected type of ata (ata/atapi/none/unknown)
170 u8 device; // Detected type of attached devices (hd/cd/none)
171 u8 removable; // Removable device flag
172 u8 lock; // Locks for removable devices
173 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
174 u16 blksize; // block size
176 u8 translation; // type of translation
177 struct chs_s lchs; // Logical CHS
178 struct chs_s pchs; // Physical CHS
180 u32 sectors; // Total sectors count
185 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
188 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
190 // map between (bios hd id - 0x80) and ata channels
191 u8 hdcount, hdidmap[CONFIG_MAX_ATA_DEVICES];
193 // map between (bios cd id - 0xE0) and ata channels
194 u8 cdcount, cdidmap[CONFIG_MAX_ATA_DEVICES];
196 // Buffer for DPTE table
199 // Count of transferred sectors and bytes
204 // ElTorito Device Emulation data
217 struct chs_s vdevice;
221 /****************************************************************
222 * Extended Bios Data Area (EBDA)
223 ****************************************************************/
225 struct extended_bios_data_area_s {
228 u32 far_call_pointer;
244 // El Torito Emulation data
245 struct cdemu_s cdemu;
248 // Accessor functions
249 #define GET_EBDA(var) \
250 GET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var)
251 #define SET_EBDA(var, val) \
252 SET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var, (val))
255 /****************************************************************
256 * Initial Program Load (IPL)
257 ****************************************************************/
259 // XXX - is this a standard, or just a bochs bios thing?
270 struct ipl_entry_s table[8];
276 #define IPL_TYPE_FLOPPY 0x01
277 #define IPL_TYPE_HARDDISK 0x02
278 #define IPL_TYPE_CDROM 0x03
279 #define IPL_TYPE_BEV 0x80
281 // Accessor functions
282 #define GET_IPL(var) \
283 GET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var)
284 #define SET_IPL(var, val) \
285 SET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var, (val))
288 /****************************************************************
289 * Registers saved/restored in romlayout.S
290 ****************************************************************/
292 #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; }; }
297 UREG(edi, di, di_hi, di_lo);
298 UREG(esi, si, si_hi, si_lo);
299 UREG(ebp, bp, bp_hi, bp_lo);
300 UREG(esp, sp, sp_hi, sp_lo);
301 UREG(ebx, bx, bh, bl);
302 UREG(edx, dx, dh, dl);
303 UREG(ecx, cx, ch, cl);
304 UREG(eax, ax, ah, al);
308 } __attribute__((packed));
310 // bregs flags bitdefs
315 set_cf(struct bregs *regs, int cond)
320 regs->flags &= ~F_CF;
324 /****************************************************************
326 ****************************************************************/
328 struct bios_config_table_s {
333 u8 feature1, feature2, feature3, feature4, feature5;
336 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
339 /****************************************************************
341 ****************************************************************/
343 #define SEG_BIOS 0xf000
345 #define EBDA_SEG 0x9FC0
346 #define IPL_SEG 0x9FF0
347 #define EBDA_SIZE 1 // In KiB
348 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
350 #endif // __BIOSVAR_H