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 SET_IVT(vector, seg, off) \
29 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
32 /****************************************************************
33 * Bios Data Area (BDA)
34 ****************************************************************/
36 struct bios_data_area_s {
42 u16 equipment_list_flags;
54 u8 floppy_recalibration_status;
55 u8 floppy_motor_status;
57 u8 floppy_motor_counter;
58 u8 floppy_last_status;
59 u8 floppy_return_status[7];
87 u16 kbd_buf_start_offset;
88 u16 kbd_buf_end_offset;
95 u8 floppy_last_data_rate;
96 u8 disk_status_controller;
97 u8 disk_error_controller;
98 u8 disk_interrupt_flag;
99 u8 floppy_harddisk_info;
101 u8 floppy_media_state[4];
105 u32 ptr_user_wait_complete_flag;
106 u32 user_wait_timeout;
111 // BDA floppy_recalibration_status bitdefs
112 #define FRS_TIMEOUT (1<<7)
114 // BDA rtc_wait_flag bitdefs
115 #define RWS_WAIT_PENDING (1<<0)
116 #define RWS_WAIT_ELAPSED (1<<7)
118 // BDA floppy_media_state bitdefs
119 #define FMS_DRIVE_STATE_MASK (0x07)
120 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
121 #define FMS_DOUBLE_STEPPING (1<<5)
122 #define FMS_DATA_RATE_MASK (0xc0)
124 // Accessor functions
125 #define GET_BDA(var) \
126 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
127 #define SET_BDA(var, val) \
128 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
129 #define CLEARBITS_BDA(var, val) do { \
130 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
131 SET_BDA(var, (__val & ~(val))); \
133 #define SETBITS_BDA(var, val) do { \
134 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
135 SET_BDA(var, (__val | (val))); \
139 /****************************************************************
140 * Extended Bios Data Area (EBDA)
141 ****************************************************************/
159 // ElTorito Device Emulation data
184 u8 drive_control_byte;
192 struct extended_bios_data_area_s {
195 u32 far_call_pointer;
203 struct fdpt_s fdpt[2];
208 // 0x121 - Begin custom storage.
211 // El Torito Emulation data
212 struct cdemu_s cdemu;
214 // Count of transferred sectors and bytes to/from disk
217 // Buffer for disk DPTE table
220 // Locks for removable devices
221 u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
225 // Stack space available for code that needs it.
226 u8 extra_stack[512] __aligned(8);
229 // Accessor functions
230 static inline u16 get_ebda_seg() {
231 return GET_BDA(ebda_seg);
233 static inline struct extended_bios_data_area_s *
236 extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
238 return __force_link_error__get_ebda_ptr_only_in_32bit();
239 return MAKE_FLATPTR(get_ebda_seg(), 0);
241 #define GET_EBDA2(eseg, var) \
242 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
243 #define SET_EBDA2(eseg, var, val) \
244 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
245 #define GET_EBDA(var) \
246 GET_EBDA2(get_ebda_seg(), var)
247 #define SET_EBDA(var, val) \
248 SET_EBDA2(get_ebda_seg(), var, (val))
250 #define EBDA_OFFSET_TOP_STACK \
251 offsetof(struct extended_bios_data_area_s, extra_stack[ \
252 FIELD_SIZEOF(struct extended_bios_data_area_s \
256 /****************************************************************
258 ****************************************************************/
260 #define GLOBAL_SEGREG CS
261 static inline u16 get_global_seg() {
262 return GET_SEG(GLOBAL_SEGREG);
264 #define GET_GLOBAL(var) \
265 GET_VAR(GLOBAL_SEGREG, (var))
266 #define SET_GLOBAL(var, val) do { \
267 extern void __force_link_error__set_global_only_in_32bit(); \
269 __force_link_error__set_global_only_in_32bit(); \
274 /****************************************************************
276 ****************************************************************/
278 struct bios_config_table_s {
283 u8 feature1, feature2, feature3, feature4, feature5;
286 extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
288 #endif // __BIOSVAR_H