Introduce GET/SET_EBDA2() macros - they take a cached ebda seg.
[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 GPLv3 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  * Bios Data Area (BDA)
16  ****************************************************************/
17
18 struct ivec {
19     u16 offset;
20     u16 seg;
21 };
22
23 struct bios_data_area_s {
24     // 00:00
25     struct ivec ivecs[256];
26     // 30:00
27 //    u8 stack[256];
28     // 40:00
29     u16 port_com[4];
30     u16 port_lpt[3];
31     u16 ebda_seg;
32     // 40:10
33     u16 equipment_list_flags;
34     u8 pad1;
35     u16 mem_size_kb;
36     u8 pad2;
37     u8 ps2_ctrl_flag;
38     u8 kbd_flag0;
39     u8 kbd_flag1;
40     u8 alt_keypad;
41     u16 kbd_buf_head;
42     u16 kbd_buf_tail;
43     // 40:1e
44     u8 kbd_buf[32];
45     u8 floppy_recalibration_status;
46     u8 floppy_motor_status;
47     // 40:40
48     u8 floppy_motor_counter;
49     u8 floppy_last_status;
50     u8 floppy_return_status[7];
51     u8 video_mode;
52     u16 video_cols;
53     u16 video_pagesize;
54     u16 video_pagestart;
55     // 40:50
56     u16 cursor_pos[8];
57     // 40:60
58     u16 cursor_type;
59     u8 video_page;
60     u16 crtc_address;
61     u8 video_msr;
62     u8 video_pal;
63     u16 jump_ip;
64     u16 jump_cs;
65     u8 other_6b;
66     u32 timer_counter;
67     // 40:70
68     u8 timer_rollover;
69     u8 break_flag;
70     u16 soft_reset_flag;
71     u8 disk_last_status;
72     u8 disk_count;
73     u8 disk_control_byte;
74     u8 port_disk;
75     u8 lpt_timeout[4];
76     u8 com_timeout[4];
77     // 40:80
78     u16 kbd_buf_start_offset;
79     u16 kbd_buf_end_offset;
80     u8 video_rows;
81     u16 char_height;
82     u8 video_ctl;
83     u8 video_switches;
84     u8 modeset_ctl;
85     u8 dcc_index;
86     u8 floppy_last_data_rate;
87     u8 disk_status_controller;
88     u8 disk_error_controller;
89     u8 disk_interrupt_flag;
90     u8 floppy_harddisk_info;
91     // 40:90
92     u8 floppy_media_state[4];
93     u8 floppy_track0;
94     u8 floppy_track1;
95     u8 kbd_mode;
96     u8 kbd_led;
97     u32 ptr_user_wait_complete_flag;
98     u32 user_wait_timeout;
99     // 40:A0
100     u8 rtc_wait_flag;
101 } PACKED;
102
103 // BDA floppy_recalibration_status bitdefs
104 #define FRS_TIMEOUT (1<<7)
105
106 // BDA rtc_wait_flag bitdefs
107 #define RWS_WAIT_PENDING (1<<0)
108 #define RWS_WAIT_ELAPSED (1<<7)
109
110 // BDA floppy_media_state bitdefs
111 #define FMS_DRIVE_STATE_MASK        (0x07)
112 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
113 #define FMS_DOUBLE_STEPPING         (1<<5)
114 #define FMS_DATA_RATE_MASK          (0xc0)
115
116 // Accessor functions
117 #define GET_BDA(var) \
118     GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
119 #define SET_BDA(var, val) \
120     SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
121 #define CLEARBITS_BDA(var, val) do {                                    \
122         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
123         SET_BDA(var, (__val & ~(val)));                                 \
124     } while (0)
125 #define SETBITS_BDA(var, val) do {                                      \
126         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
127         SET_BDA(var, (__val | (val)));                                  \
128     } while (0)
129
130
131 /****************************************************************
132  * Extended Bios Data Area (EBDA)
133  ****************************************************************/
134
135 // DPTE definition
136 struct dpte_s {
137     u16 iobase1;
138     u16 iobase2;
139     u8  prefix;
140     u8  unused;
141     u8  irq;
142     u8  blkcount;
143     u8  dma;
144     u8  pio;
145     u16 options;
146     u16 reserved;
147     u8  revision;
148     u8  checksum;
149 };
150
151 struct fdpt_s {
152     u16 cylinders;
153     u8 heads;
154     u8 a0h_signature;
155     u8 phys_sectors;
156     u16 precompensation;
157     u8 reserved;
158     u8 drive_control_byte;
159     u16 phys_cylinders;
160     u8 phys_heads;
161     u16 landing_zone;
162     u8 sectors;
163     u8 checksum;
164 } PACKED;
165
166 struct extended_bios_data_area_s {
167     u8 size;
168     u8 reserved1[0x21];
169     u32 far_call_pointer;
170     u8 mouse_flag1;
171     u8 mouse_flag2;
172     u8 mouse_data[0x08];
173     // 0x30
174     u8 other1[0x0d];
175
176     // 0x3d
177     struct fdpt_s fdpt[2];
178
179     // 0x5d
180     u8 other2[0xC4];
181
182     // 0x121 - Begin custom storage.
183     u8 ps2ctr;
184
185     u8 cdemu_active;
186
187     // Count of transferred sectors and bytes to/from disk
188     u16 sector_count;
189
190     // Buffer for disk DPTE table
191     struct dpte_s dpte;
192
193     // Locks for removable devices
194     u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
195
196     u16 boot_sequence;
197
198     // Resume stack
199     u8 resume_stack[128] __aligned(8);
200 } PACKED;
201
202 // Accessor functions
203 static inline u16 get_ebda_seg() {
204     return GET_BDA(ebda_seg);
205 }
206 static inline struct extended_bios_data_area_s *
207 get_ebda_ptr()
208 {
209     extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
210     if (MODE16)
211         return __force_link_error__get_ebda_ptr_only_in_32bit();
212     return (void*)MAKE_FARPTR(get_ebda_seg(), 0);
213 }
214 #define GET_EBDA2(eseg, var)                                            \
215     GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
216 #define SET_EBDA2(eseg, var, val)                                       \
217     SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
218 #define GET_EBDA(var)                                            \
219     GET_EBDA2(get_ebda_seg(), var)
220 #define SET_EBDA(var, val)                                       \
221     SET_EBDA2(get_ebda_seg(), var, (val))
222
223
224 /****************************************************************
225  * Global variables
226  ****************************************************************/
227
228 #define GET_GLOBAL(var) \
229     GET_VAR(CS, (var))
230 #if MODE16
231 extern void __force_link_error__set_global_only_in_32bit();
232 #define SET_GLOBAL(var, val) do {                       \
233     (void)(val);                                        \
234     __force_link_error__set_global_only_in_32bit();     \
235     } while (0)
236 #else
237 #define SET_GLOBAL(var, val)                    \
238     do { (var) = (val); } while (0)
239 #endif
240
241
242 /****************************************************************
243  * Bios Config Table
244  ****************************************************************/
245
246 struct bios_config_table_s {
247     u16 size;
248     u8 model;
249     u8 submodel;
250     u8 biosrev;
251     u8 feature1, feature2, feature3, feature4, feature5;
252 } PACKED;
253
254 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
255
256 #endif // __BIOSVAR_H