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