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];
67 u16 kbd_buf_start_offset;
68 u16 kbd_buf_end_offset;
70 u8 floppy_last_data_rate;
72 u8 floppy_harddisk_info;
74 u8 floppy_media_state[4];
79 u32 ptr_user_wait_complete_flag;
80 u32 user_wait_timeout;
85 // BDA floppy_recalibration_status bitdefs
86 #define FRS_TIMEOUT (1<<7)
88 // BDA rtc_wait_flag bitdefs
89 #define RWS_WAIT_PENDING (1<<0)
90 #define RWS_WAIT_ELAPSED (1<<7)
92 // BDA floppy_media_state bitdefs
93 #define FMS_DRIVE_STATE_MASK (0x07)
94 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
95 #define FMS_DOUBLE_STEPPING (1<<5)
96 #define FMS_DATA_RATE_MASK (0xc0)
99 #define GET_BDA(var) \
100 GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
101 #define SET_BDA(var, val) \
102 SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
103 #define CLEARBITS_BDA(var, val) do { \
104 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
105 SET_BDA(var, (__val & ~(val))); \
107 #define SETBITS_BDA(var, val) do { \
108 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
109 SET_BDA(var, (__val | (val))); \
113 /****************************************************************
115 ****************************************************************/
124 u8 drive_control_byte;
133 u16 heads; // # heads
134 u16 cylinders; // # cylinders
135 u16 spt; // # sectors / track
154 struct ata_channel_s {
155 u8 iface; // ISA or PCI
156 u16 iobase1; // IO Base 1
157 u16 iobase2; // IO Base 2
161 struct ata_device_s {
162 u8 type; // Detected type of ata (ata/atapi/none/unknown)
163 u8 device; // Detected type of attached devices (hd/cd/none)
164 u8 removable; // Removable device flag
165 u8 lock; // Locks for removable devices
166 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
167 u16 blksize; // block size
169 u8 translation; // type of translation
170 struct chs_s lchs; // Logical CHS
171 struct chs_s pchs; // Physical CHS
173 u32 sectors; // Total sectors count
178 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
181 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
183 // map between (bios hd id - 0x80) and ata channels
184 u8 hdcount, hdidmap[CONFIG_MAX_ATA_DEVICES];
186 // map between (bios cd id - 0xE0) and ata channels
187 u8 cdcount, cdidmap[CONFIG_MAX_ATA_DEVICES];
189 // Buffer for DPTE table
192 // Count of transferred sectors and bytes
197 // ElTorito Device Emulation data
210 struct chs_s vdevice;
214 /****************************************************************
215 * Extended Bios Data Area (EBDA)
216 ****************************************************************/
218 struct extended_bios_data_area_s {
230 // El Torito Emulation data
231 struct cdemu_s cdemu;
234 // Accessor functions
235 #define GET_EBDA(var) \
236 GET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var)
237 #define SET_EBDA(var, val) \
238 SET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var, (val))
241 /****************************************************************
242 * Initial Program Load (IPL)
243 ****************************************************************/
245 // XXX - is this a standard, or just a bochs bios thing?
256 struct ipl_entry_s table[8];
262 #define IPL_TYPE_FLOPPY 0x01
263 #define IPL_TYPE_HARDDISK 0x02
264 #define IPL_TYPE_CDROM 0x03
265 #define IPL_TYPE_BEV 0x80
267 // Accessor functions
268 #define GET_IPL(var) \
269 GET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var)
270 #define SET_IPL(var, val) \
271 SET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var, (val))
274 /****************************************************************
275 * Registers saved/restored in romlayout.S
276 ****************************************************************/
278 #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; }; }
283 UREG(edi, di, di_hi, di_lo);
284 UREG(esi, si, si_hi, si_lo);
285 UREG(ebp, bp, bp_hi, bp_lo);
286 UREG(esp, sp, sp_hi, sp_lo);
287 UREG(ebx, bx, bh, bl);
288 UREG(edx, dx, dh, dl);
289 UREG(ecx, cx, ch, cl);
290 UREG(eax, ax, ah, al);
294 } __attribute__((packed));
296 // bregs flags bitdefs
301 set_cf(struct bregs *regs, int cond)
306 regs->flags &= ~F_CF;
310 /****************************************************************
312 ****************************************************************/
314 struct bios_config_table_s {
319 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
322 /****************************************************************
324 ****************************************************************/
326 #define SEG_BIOS 0xf000
328 #define EBDA_SEG 0x9FC0
329 #define IPL_SEG 0x9FF0
330 #define EBDA_SIZE 1 // In KiB
331 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
333 #endif // __BIOSVAR_H