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 LGPLv3 license.
9 #include "types.h" // u8
10 #include "farptr.h" // GET_FARVAR
11 #include "config.h" // CONFIG_*
14 /****************************************************************
15 * Interupt vector table
16 ****************************************************************/
28 #define GET_IVT(vector) \
29 GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
30 #define SET_IVT(vector, seg, off) \
31 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
34 /****************************************************************
35 * Bios Data Area (BDA)
36 ****************************************************************/
38 struct bios_data_area_s {
44 u16 equipment_list_flags;
56 u8 floppy_recalibration_status;
57 u8 floppy_motor_status;
59 u8 floppy_motor_counter;
60 u8 floppy_last_status;
61 u8 floppy_return_status[7];
89 u16 kbd_buf_start_offset;
90 u16 kbd_buf_end_offset;
97 u8 floppy_last_data_rate;
98 u8 disk_status_controller;
99 u8 disk_error_controller;
100 u8 disk_interrupt_flag;
101 u8 floppy_harddisk_info;
103 u8 floppy_media_state[4];
107 u32 ptr_user_wait_complete_flag;
108 u32 user_wait_timeout;
112 u16 video_savetable_ptr;
113 u16 video_savetable_seg;
120 // BDA floppy_recalibration_status bitdefs
121 #define FRS_TIMEOUT (1<<7)
123 // BDA rtc_wait_flag bitdefs
124 #define RWS_WAIT_PENDING (1<<0)
125 #define RWS_WAIT_ELAPSED (1<<7)
127 // BDA floppy_media_state bitdefs
128 #define FMS_DRIVE_STATE_MASK (0x07)
129 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
130 #define FMS_DOUBLE_STEPPING (1<<5)
131 #define FMS_DATA_RATE_MASK (0xc0)
133 // Accessor functions
134 #define GET_BDA(var) \
135 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
136 #define SET_BDA(var, val) \
137 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
138 #define CLEARBITS_BDA(var, val) do { \
139 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
140 SET_BDA(var, (__val & ~(val))); \
142 #define SETBITS_BDA(var, val) do { \
143 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
144 SET_BDA(var, (__val | (val))); \
148 /****************************************************************
149 * Extended Bios Data Area (EBDA)
150 ****************************************************************/
168 // ElTorito Device Emulation data
193 u8 drive_control_byte;
201 struct extended_bios_data_area_s {
204 u32 far_call_pointer;
212 struct fdpt_s fdpt[2];
217 // 0x121 - Begin custom storage.
220 // El Torito Emulation data
221 struct cdemu_s cdemu;
223 // Count of transferred sectors and bytes to/from disk
226 // Buffer for disk DPTE table
229 // Locks for removable devices
230 u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
234 // Stack space available for code that needs it.
235 u8 extra_stack[512] __aligned(8);
238 // Accessor functions
239 static inline u16 get_ebda_seg() {
240 return GET_BDA(ebda_seg);
242 static inline struct extended_bios_data_area_s *
245 extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
247 return __force_link_error__get_ebda_ptr_only_in_32bit();
248 return MAKE_FLATPTR(get_ebda_seg(), 0);
250 #define GET_EBDA2(eseg, var) \
251 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
252 #define SET_EBDA2(eseg, var, val) \
253 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
254 #define GET_EBDA(var) \
255 GET_EBDA2(get_ebda_seg(), var)
256 #define SET_EBDA(var, val) \
257 SET_EBDA2(get_ebda_seg(), var, (val))
259 #define EBDA_OFFSET_TOP_STACK \
260 offsetof(struct extended_bios_data_area_s, extra_stack[ \
261 FIELD_SIZEOF(struct extended_bios_data_area_s \
265 /****************************************************************
267 ****************************************************************/
269 #define GLOBAL_SEGREG CS
270 static inline u16 get_global_seg() {
271 return GET_SEG(GLOBAL_SEGREG);
273 #define GET_GLOBAL(var) \
274 GET_VAR(GLOBAL_SEGREG, (var))
275 #define SET_GLOBAL(var, val) do { \
276 extern void __force_link_error__set_global_only_in_32bit(); \
278 __force_link_error__set_global_only_in_32bit(); \
283 /****************************************************************
285 ****************************************************************/
287 struct bios_config_table_s {
292 u8 feature1, feature2, feature3, feature4, feature5;
295 extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
297 #endif // __BIOSVAR_H