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];
106 u32 ptr_user_wait_complete_flag;
107 u32 user_wait_timeout;
112 // BDA floppy_recalibration_status bitdefs
113 #define FRS_TIMEOUT (1<<7)
115 // BDA rtc_wait_flag bitdefs
116 #define RWS_WAIT_PENDING (1<<0)
117 #define RWS_WAIT_ELAPSED (1<<7)
119 // BDA floppy_media_state bitdefs
120 #define FMS_DRIVE_STATE_MASK (0x07)
121 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
122 #define FMS_DOUBLE_STEPPING (1<<5)
123 #define FMS_DATA_RATE_MASK (0xc0)
125 // Accessor functions
126 #define GET_BDA(var) \
127 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
128 #define SET_BDA(var, val) \
129 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
130 #define CLEARBITS_BDA(var, val) do { \
131 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
132 SET_BDA(var, (__val & ~(val))); \
134 #define SETBITS_BDA(var, val) do { \
135 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
136 SET_BDA(var, (__val | (val))); \
140 /****************************************************************
141 * Extended Bios Data Area (EBDA)
142 ****************************************************************/
160 // ElTorito Device Emulation data
185 u8 drive_control_byte;
193 struct extended_bios_data_area_s {
196 u32 far_call_pointer;
204 struct fdpt_s fdpt[2];
209 // 0x121 - Begin custom storage.
212 // El Torito Emulation data
213 struct cdemu_s cdemu;
215 // Count of transferred sectors and bytes to/from disk
218 // Buffer for disk DPTE table
221 // Locks for removable devices
222 u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
226 // Stack space available for code that needs it.
227 u8 extra_stack[512] __aligned(8);
230 // Accessor functions
231 static inline u16 get_ebda_seg() {
232 return GET_BDA(ebda_seg);
234 static inline struct extended_bios_data_area_s *
237 extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
239 return __force_link_error__get_ebda_ptr_only_in_32bit();
240 return MAKE_FLATPTR(get_ebda_seg(), 0);
242 #define GET_EBDA2(eseg, var) \
243 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
244 #define SET_EBDA2(eseg, var, val) \
245 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
246 #define GET_EBDA(var) \
247 GET_EBDA2(get_ebda_seg(), var)
248 #define SET_EBDA(var, val) \
249 SET_EBDA2(get_ebda_seg(), var, (val))
251 #define EBDA_OFFSET_TOP_STACK \
252 offsetof(struct extended_bios_data_area_s, extra_stack[ \
253 FIELD_SIZEOF(struct extended_bios_data_area_s \
257 /****************************************************************
259 ****************************************************************/
261 #define GET_GLOBAL(var) \
263 #define SET_GLOBAL(var, val) do { \
264 extern void __force_link_error__set_global_only_in_32bit(); \
266 __force_link_error__set_global_only_in_32bit(); \
271 /****************************************************************
273 ****************************************************************/
275 struct bios_config_table_s {
280 u8 feature1, feature2, feature3, feature4, feature5;
283 extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
285 #endif // __BIOSVAR_H