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;
41 u8 floppy_recalibration_status;
42 u8 floppy_motor_status;
44 u8 floppy_motor_counter;
45 u8 floppy_last_status;
46 u8 floppy_return_status[7];
56 u16 kbd_buf_start_offset;
57 u16 kbd_buf_end_offset;
59 u8 floppy_last_data_rate;
61 u8 floppy_harddisk_info;
63 u8 floppy_media_state[4];
68 u32 ptr_user_wait_complete_flag;
69 u32 user_wait_timeout;
72 } __attribute__((packed));
74 // BDA floppy_recalibration_status bitdefs
75 #define FRS_TIMEOUT (1<<7)
77 // BDA rtc_wait_flag bitdefs
78 #define RWS_WAIT_PENDING (1<<0)
79 #define RWS_WAIT_ELAPSED (1<<7)
81 // BDA floppy_media_state bitdefs
82 #define FMS_DRIVE_STATE_MASK (0x07)
83 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
84 #define FMS_DOUBLE_STEPPING (1<<5)
85 #define FMS_DATA_RATE_MASK (0xc0)
88 #define GET_BDA(var) ({ \
89 SET_SEG(ES, 0x0000); \
90 GET_VAR(ES, ((struct bios_data_area_s *)0)->var); })
91 #define SET_BDA(var, val) do { \
92 SET_SEG(ES, 0x0000); \
93 SET_VAR(ES, ((struct bios_data_area_s *)0)->var, val); \
95 #define CLEARBITS_BDA(var, val) do { \
96 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
97 SET_BDA(var, (__val & ~(val))); \
99 #define SETBITS_BDA(var, val) do { \
100 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
101 SET_BDA(var, (__val | (val))); \
105 /****************************************************************
106 * Extended Bios Data Area (EBDA)
107 ****************************************************************/
109 struct extended_bios_data_area_s {
113 // FDPT - Can be splitted in data members if needed
123 // El Torito Emulation data
125 #endif // BX_ELTORITO_BOOT
129 /****************************************************************
130 * Extended Bios Data Area (EBDA)
131 ****************************************************************/
133 #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; }; }
138 UREG(edi, di, di_hi, di_lo);
139 UREG(esi, si, si_hi, si_lo);
140 UREG(ebp, bp, bp_hi, bp_lo);
141 UREG(esp, sp, sp_hi, sp_lo);
142 UREG(ebx, bx, bh, bl);
143 UREG(edx, dx, dh, dl);
144 UREG(ecx, cx, ch, cl);
145 UREG(eax, ax, ah, al);
149 } __attribute__((packed));
151 // bregs flags bitdefs
155 set_cf(struct bregs *regs, int cond)
160 regs->flags &= ~F_CF;
164 /****************************************************************
166 ****************************************************************/
168 struct bios_config_table_s {
173 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
176 /****************************************************************
178 ****************************************************************/
180 #define SEG_BIOS 0xf000
182 #define EBDA_SEG 0x9FC0
183 #define EBDA_SIZE 1 // In KiB
184 #define BASE_MEM_IN_K (640 - EBDA_SIZE)