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
13 /****************************************************************
14 * Bios Data Area (BDA)
15 ****************************************************************/
22 struct bios_data_area_s {
24 struct ivec ivecs[256];
32 u16 equipment_list_flags;
44 u8 floppy_recalibration_status;
45 u8 floppy_motor_status;
47 u8 floppy_motor_counter;
48 u8 floppy_last_status;
49 u8 floppy_return_status[7];
61 u16 kbd_buf_start_offset;
62 u16 kbd_buf_end_offset;
64 u8 floppy_last_data_rate;
66 u8 floppy_harddisk_info;
68 u8 floppy_media_state[4];
73 u32 ptr_user_wait_complete_flag;
74 u32 user_wait_timeout;
77 } __attribute__((packed));
79 // BDA floppy_recalibration_status bitdefs
80 #define FRS_TIMEOUT (1<<7)
82 // BDA rtc_wait_flag bitdefs
83 #define RWS_WAIT_PENDING (1<<0)
84 #define RWS_WAIT_ELAPSED (1<<7)
86 // BDA floppy_media_state bitdefs
87 #define FMS_DRIVE_STATE_MASK (0x07)
88 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
89 #define FMS_DOUBLE_STEPPING (1<<5)
90 #define FMS_DATA_RATE_MASK (0xc0)
93 #define GET_BDA(var) \
94 GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
95 #define SET_BDA(var, val) \
96 SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
97 #define CLEARBITS_BDA(var, val) do { \
98 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
99 SET_BDA(var, (__val & ~(val))); \
101 #define SETBITS_BDA(var, val) do { \
102 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
103 SET_BDA(var, (__val | (val))); \
107 /****************************************************************
108 * Extended Bios Data Area (EBDA)
109 ****************************************************************/
111 struct extended_bios_data_area_s {
115 // FDPT - Can be splitted in data members if needed
125 // El Torito Emulation data
127 #endif // BX_ELTORITO_BOOT
130 // Accessor functions
131 #define GET_EBDA(var) \
132 GET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var)
133 #define SET_EBDA(var, val) \
134 SET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var, (val))
137 /****************************************************************
138 * Initial Program Load (IPL)
139 ****************************************************************/
141 // XXX - is this a standard, or just a bochs bios thing?
152 struct ipl_entry_s table[8];
158 #define IPL_TYPE_FLOPPY 0x01
159 #define IPL_TYPE_HARDDISK 0x02
160 #define IPL_TYPE_CDROM 0x03
161 #define IPL_TYPE_BEV 0x80
163 // Accessor functions
164 #define GET_IPL(var) \
165 GET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var)
166 #define SET_IPL(var, val) \
167 SET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var, (val))
170 /****************************************************************
171 * Registers saved/restored in romlayout.S
172 ****************************************************************/
174 #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; }; }
179 UREG(edi, di, di_hi, di_lo);
180 UREG(esi, si, si_hi, si_lo);
181 UREG(ebp, bp, bp_hi, bp_lo);
182 UREG(esp, sp, sp_hi, sp_lo);
183 UREG(ebx, bx, bh, bl);
184 UREG(edx, dx, dh, dl);
185 UREG(ecx, cx, ch, cl);
186 UREG(eax, ax, ah, al);
190 } __attribute__((packed));
192 // bregs flags bitdefs
197 set_cf(struct bregs *regs, int cond)
202 regs->flags &= ~F_CF;
206 /****************************************************************
208 ****************************************************************/
210 struct bios_config_table_s {
215 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
218 /****************************************************************
220 ****************************************************************/
222 #define SEG_BIOS 0xf000
224 #define EBDA_SEG 0x9FC0
225 #define IPL_SEG 0x9FF0
226 #define EBDA_SIZE 1 // In KiB
227 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
229 #endif // __BIOSVAR_H