1 // Variable layouts of bios.
3 // Copyright (C) 2008,2009 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_*
12 #include "disk.h" // struct chs_s
23 #define SEGOFF(s,o) ({struct segoff_s __so; __so.offset=(o); __so.seg=(s); __so;})
26 /****************************************************************
27 * Interupt vector table
28 ****************************************************************/
31 struct segoff_s ivec[256];
34 #define GET_IVT(vector) \
35 GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
36 #define SET_IVT(vector, seg, off) \
37 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
40 /****************************************************************
41 * Bios Data Area (BDA)
42 ****************************************************************/
44 struct bios_data_area_s {
50 u16 equipment_list_flags;
62 u8 floppy_recalibration_status;
63 u8 floppy_motor_status;
65 u8 floppy_motor_counter;
66 u8 floppy_last_status;
67 u8 floppy_return_status[7];
95 u16 kbd_buf_start_offset;
96 u16 kbd_buf_end_offset;
103 u8 floppy_last_data_rate;
104 u8 disk_status_controller;
105 u8 disk_error_controller;
106 u8 disk_interrupt_flag;
107 u8 floppy_harddisk_info;
109 u8 floppy_media_state[4];
113 u32 ptr_user_wait_complete_flag;
114 u32 user_wait_timeout;
118 u16 video_savetable_ptr;
119 u16 video_savetable_seg;
126 // BDA floppy_recalibration_status bitdefs
127 #define FRS_TIMEOUT (1<<7)
129 // BDA rtc_wait_flag bitdefs
130 #define RWS_WAIT_PENDING (1<<0)
131 #define RWS_WAIT_ELAPSED (1<<7)
133 // BDA floppy_media_state bitdefs
134 #define FMS_DRIVE_STATE_MASK (0x07)
135 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
136 #define FMS_DOUBLE_STEPPING (1<<5)
137 #define FMS_DATA_RATE_MASK (0xc0)
139 // Accessor functions
140 #define GET_BDA(var) \
141 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
142 #define SET_BDA(var, val) \
143 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
144 #define CLEARBITS_BDA(var, val) do { \
145 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
146 SET_BDA(var, (__val & ~(val))); \
148 #define SETBITS_BDA(var, val) do { \
149 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
150 SET_BDA(var, (__val | (val))); \
154 /****************************************************************
155 * Extended Bios Data Area (EBDA)
156 ****************************************************************/
174 // ElTorito Device Emulation data
197 u8 drive_control_byte;
205 struct extended_bios_data_area_s {
208 u32 far_call_pointer;
216 struct fdpt_s fdpt[2];
221 // 0x121 - Begin custom storage.
224 // El Torito Emulation data
225 struct cdemu_s cdemu;
227 // Count of transferred sectors and bytes to/from disk
230 // Buffer for disk DPTE table
233 // Locks for removable devices
234 u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
238 // Stack space available for code that needs it.
239 u8 extra_stack[512] __aligned(8);
241 u8 cdemu_buf[2048 * !!CONFIG_CDROM_EMU];
244 // The initial size and location of EBDA
245 #define EBDA_SIZE_START \
246 DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
247 #define EBDA_SEGMENT_START \
248 FLATPTR_TO_SEG((640 - EBDA_SIZE_START) * 1024)
249 #define EBDA_SEGMENT_MINIMUM \
250 FLATPTR_TO_SEG((640 - 256) * 1024)
252 // Accessor functions
253 static inline u16 get_ebda_seg() {
254 return GET_BDA(ebda_seg);
256 static inline struct extended_bios_data_area_s *
260 return MAKE_FLATPTR(get_ebda_seg(), 0);
262 #define GET_EBDA2(eseg, var) \
263 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
264 #define SET_EBDA2(eseg, var, val) \
265 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
266 #define GET_EBDA(var) \
267 GET_EBDA2(get_ebda_seg(), var)
268 #define SET_EBDA(var, val) \
269 SET_EBDA2(get_ebda_seg(), var, (val))
271 #define EBDA_OFFSET_TOP_STACK \
272 offsetof(struct extended_bios_data_area_s, extra_stack[ \
273 FIELD_SIZEOF(struct extended_bios_data_area_s \
277 /****************************************************************
279 ****************************************************************/
281 #define GLOBAL_SEGREG CS
282 static inline u16 get_global_seg() {
283 return GET_SEG(GLOBAL_SEGREG);
285 #define GET_GLOBAL(var) \
286 GET_VAR(GLOBAL_SEGREG, (var))
287 #define SET_GLOBAL(var, val) do { \
293 /****************************************************************
295 ****************************************************************/
297 struct bios_config_table_s {
302 u8 feature1, feature2, feature3, feature4, feature5;
305 extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
307 #endif // __BIOSVAR_H