Unify mode16/32 compiler checks.
[seabios.git] / src / biosvar.h
1 // Variable layouts of bios.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6 #ifndef __BIOSVAR_H
7 #define __BIOSVAR_H
8
9 #include "types.h" // u8
10 #include "farptr.h" // GET_FARVAR
11 #include "config.h" // CONFIG_*
12
13
14 /****************************************************************
15  * Interupt vector table
16  ****************************************************************/
17
18 struct rmode_IVT {
19     union {
20         struct {
21             u16 offset;
22             u16 seg;
23         };
24         u32 segoff;
25     } ivec[256];
26 };
27
28 #define GET_IVT(vector)                                         \
29     GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
30 #define SET_IVT(vector, seg, off)                                       \
31     SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
32
33
34 /****************************************************************
35  * Bios Data Area (BDA)
36  ****************************************************************/
37
38 struct bios_data_area_s {
39     // 40:00
40     u16 port_com[4];
41     u16 port_lpt[3];
42     u16 ebda_seg;
43     // 40:10
44     u16 equipment_list_flags;
45     u8 pad1;
46     u16 mem_size_kb;
47     u8 pad2;
48     u8 ps2_ctrl_flag;
49     u8 kbd_flag0;
50     u8 kbd_flag1;
51     u8 alt_keypad;
52     u16 kbd_buf_head;
53     u16 kbd_buf_tail;
54     // 40:1e
55     u8 kbd_buf[32];
56     u8 floppy_recalibration_status;
57     u8 floppy_motor_status;
58     // 40:40
59     u8 floppy_motor_counter;
60     u8 floppy_last_status;
61     u8 floppy_return_status[7];
62     u8 video_mode;
63     u16 video_cols;
64     u16 video_pagesize;
65     u16 video_pagestart;
66     // 40:50
67     u16 cursor_pos[8];
68     // 40:60
69     u16 cursor_type;
70     u8 video_page;
71     u16 crtc_address;
72     u8 video_msr;
73     u8 video_pal;
74     u16 jump_ip;
75     u16 jump_cs;
76     u8 other_6b;
77     u32 timer_counter;
78     // 40:70
79     u8 timer_rollover;
80     u8 break_flag;
81     u16 soft_reset_flag;
82     u8 disk_last_status;
83     u8 hdcount;
84     u8 disk_control_byte;
85     u8 port_disk;
86     u8 lpt_timeout[4];
87     u8 com_timeout[4];
88     // 40:80
89     u16 kbd_buf_start_offset;
90     u16 kbd_buf_end_offset;
91     u8 video_rows;
92     u16 char_height;
93     u8 video_ctl;
94     u8 video_switches;
95     u8 modeset_ctl;
96     u8 dcc_index;
97     u8 floppy_last_data_rate;
98     u8 disk_status_controller;
99     u8 disk_error_controller;
100     u8 disk_interrupt_flag;
101     u8 floppy_harddisk_info;
102     // 40:90
103     u8 floppy_media_state[4];
104     u8 floppy_track[2];
105     u8 kbd_mode;
106     u8 kbd_led;
107     u32 ptr_user_wait_complete_flag;
108     u32 user_wait_timeout;
109     // 40:A0
110     u8 rtc_wait_flag;
111     u8 other_a1[7];
112     u16 video_savetable_ptr;
113     u16 video_savetable_seg;
114     u8 other_ac[4];
115     // 40:B0
116     u8 other_b0[10];
117     u16 vbe_mode;
118 } PACKED;
119
120 // BDA floppy_recalibration_status bitdefs
121 #define FRS_TIMEOUT (1<<7)
122
123 // BDA rtc_wait_flag bitdefs
124 #define RWS_WAIT_PENDING (1<<0)
125 #define RWS_WAIT_ELAPSED (1<<7)
126
127 // BDA floppy_media_state bitdefs
128 #define FMS_DRIVE_STATE_MASK        (0x07)
129 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
130 #define FMS_DOUBLE_STEPPING         (1<<5)
131 #define FMS_DATA_RATE_MASK          (0xc0)
132
133 // Accessor functions
134 #define GET_BDA(var) \
135     GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
136 #define SET_BDA(var, val) \
137     SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
138 #define CLEARBITS_BDA(var, val) do {                                    \
139         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
140         SET_BDA(var, (__val & ~(val)));                                 \
141     } while (0)
142 #define SETBITS_BDA(var, val) do {                                      \
143         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
144         SET_BDA(var, (__val | (val)));                                  \
145     } while (0)
146
147
148 /****************************************************************
149  * Extended Bios Data Area (EBDA)
150  ****************************************************************/
151
152 // DPTE definition
153 struct dpte_s {
154     u16 iobase1;
155     u16 iobase2;
156     u8  prefix;
157     u8  unused;
158     u8  irq;
159     u8  blkcount;
160     u8  dma;
161     u8  pio;
162     u16 options;
163     u16 reserved;
164     u8  revision;
165     u8  checksum;
166 };
167
168 // ElTorito Device Emulation data
169 struct cdemu_s {
170     u8  active;
171     u8  media;
172     u8  emulated_drive;
173     u8  controller_index;
174     u16 device_spec;
175     u32 ilba;
176     u16 buffer_segment;
177     u16 load_segment;
178     u16 sector_count;
179
180     // Virtual device
181     u16 heads;
182     u16 cylinders;
183     u16 spt;
184 };
185
186 struct fdpt_s {
187     u16 cylinders;
188     u8 heads;
189     u8 a0h_signature;
190     u8 phys_sectors;
191     u16 precompensation;
192     u8 reserved;
193     u8 drive_control_byte;
194     u16 phys_cylinders;
195     u8 phys_heads;
196     u16 landing_zone;
197     u8 sectors;
198     u8 checksum;
199 } PACKED;
200
201 struct extended_bios_data_area_s {
202     u8 size;
203     u8 reserved1[0x21];
204     u32 far_call_pointer;
205     u8 mouse_flag1;
206     u8 mouse_flag2;
207     u8 mouse_data[0x08];
208     // 0x30
209     u8 other1[0x0d];
210
211     // 0x3d
212     struct fdpt_s fdpt[2];
213
214     // 0x5d
215     u8 other2[0xC4];
216
217     // 0x121 - Begin custom storage.
218     u8 ps2ctr;
219
220     // El Torito Emulation data
221     struct cdemu_s cdemu;
222
223     // Count of transferred sectors and bytes to/from disk
224     u16 sector_count;
225
226     // Buffer for disk DPTE table
227     struct dpte_s dpte;
228
229     // Locks for removable devices
230     u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
231
232     u16 boot_sequence;
233
234     // Stack space available for code that needs it.
235     u8 extra_stack[512] __aligned(8);
236 } PACKED;
237
238 // The initial size and location of EBDA
239 #define EBDA_SIZE_START \
240     DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
241 #define EBDA_SEGMENT_START \
242     FLATPTR_TO_SEG((640 - EBDA_SIZE_START) * 1024)
243
244 // Accessor functions
245 static inline u16 get_ebda_seg() {
246     return GET_BDA(ebda_seg);
247 }
248 static inline struct extended_bios_data_area_s *
249 get_ebda_ptr()
250 {
251     ASSERT32();
252     return MAKE_FLATPTR(get_ebda_seg(), 0);
253 }
254 #define GET_EBDA2(eseg, var)                                            \
255     GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
256 #define SET_EBDA2(eseg, var, val)                                       \
257     SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
258 #define GET_EBDA(var)                           \
259     GET_EBDA2(get_ebda_seg(), var)
260 #define SET_EBDA(var, val)                      \
261     SET_EBDA2(get_ebda_seg(), var, (val))
262
263 #define EBDA_OFFSET_TOP_STACK                                   \
264     offsetof(struct extended_bios_data_area_s, extra_stack[     \
265                  FIELD_SIZEOF(struct extended_bios_data_area_s  \
266                               , extra_stack)])
267
268
269 /****************************************************************
270  * Global variables
271  ****************************************************************/
272
273 #define GLOBAL_SEGREG CS
274 static inline u16 get_global_seg() {
275     return GET_SEG(GLOBAL_SEGREG);
276 }
277 #define GET_GLOBAL(var)                         \
278     GET_VAR(GLOBAL_SEGREG, (var))
279 #define SET_GLOBAL(var, val) do {                                       \
280         ASSERT32();                                                     \
281         (var) = (val);                                                  \
282     } while (0)
283
284
285 /****************************************************************
286  * Bios Config Table
287  ****************************************************************/
288
289 struct bios_config_table_s {
290     u16 size;
291     u8 model;
292     u8 submodel;
293     u8 biosrev;
294     u8 feature1, feature2, feature3, feature4, feature5;
295 } PACKED;
296
297 extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
298
299 #endif // __BIOSVAR_H