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.
7 #include "types.h" // u8
8 #include "farptr.h" // SET_SEG
11 /****************************************************************
12 * Bios Data Area (BDA)
13 ****************************************************************/
20 struct bios_data_area_s {
22 struct ivec ivecs[256];
26 u16 port_com1, port_com2, port_com3, port_com4;
27 u16 port_lpt1, port_lpt2, port_lpt3;
30 u16 equipment_list_flags;
42 u8 floppy_recalibration_status;
43 u8 floppy_motor_status;
45 u8 floppy_motor_counter;
46 u8 floppy_last_status;
47 u8 floppy_return_status[7];
57 u16 kbd_buf_start_offset;
58 u16 kbd_buf_end_offset;
60 u8 floppy_last_data_rate;
62 u8 floppy_harddisk_info;
64 u8 floppy_media_state[4];
69 u32 ptr_user_wait_complete_flag;
70 u32 user_wait_timeout;
73 } __attribute__((packed));
75 // BDA floppy_recalibration_status bitdefs
76 #define FRS_TIMEOUT (1<<7)
78 // BDA rtc_wait_flag bitdefs
79 #define RWS_WAIT_PENDING (1<<0)
80 #define RWS_WAIT_ELAPSED (1<<7)
82 // BDA floppy_media_state bitdefs
83 #define FMS_DRIVE_STATE_MASK (0x07)
84 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
85 #define FMS_DOUBLE_STEPPING (1<<5)
86 #define FMS_DATA_RATE_MASK (0xc0)
89 #define GET_BDA(var) \
90 GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
91 #define SET_BDA(var, val) \
92 SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
93 #define CLEARBITS_BDA(var, val) do { \
94 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
95 SET_BDA(var, (__val & ~(val))); \
97 #define SETBITS_BDA(var, val) do { \
98 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
99 SET_BDA(var, (__val | (val))); \
103 /****************************************************************
104 * Extended Bios Data Area (EBDA)
105 ****************************************************************/
107 struct extended_bios_data_area_s {
111 // FDPT - Can be splitted in data members if needed
121 // El Torito Emulation data
123 #endif // BX_ELTORITO_BOOT
127 /****************************************************************
128 * Extended Bios Data Area (EBDA)
129 ****************************************************************/
131 #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; }; }
136 UREG(edi, di, di_hi, di_lo);
137 UREG(esi, si, si_hi, si_lo);
138 UREG(ebp, bp, bp_hi, bp_lo);
139 UREG(esp, sp, sp_hi, sp_lo);
140 UREG(ebx, bx, bh, bl);
141 UREG(edx, dx, dh, dl);
142 UREG(ecx, cx, ch, cl);
143 UREG(eax, ax, ah, al);
147 } __attribute__((packed));
149 // bregs flags bitdefs
154 set_cf(struct bregs *regs, int cond)
159 regs->flags &= ~F_CF;
163 /****************************************************************
165 ****************************************************************/
167 struct bios_config_table_s {
172 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
175 /****************************************************************
177 ****************************************************************/
179 #define SEG_BIOS 0xf000
181 #define EBDA_SEG 0x9FC0
182 #define EBDA_SIZE 1 // In KiB
183 #define BASE_MEM_IN_K (640 - EBDA_SIZE)