Return CDEMU parameters to ebda segment (instead of using globals).
[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 hdcount;
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 // ElTorito Device Emulation data
152 struct cdemu_s {
153     u8  active;
154     u8  media;
155     u8  emulated_drive;
156     u8  controller_index;
157     u16 device_spec;
158     u32 ilba;
159     u16 buffer_segment;
160     u16 load_segment;
161     u16 sector_count;
162
163     // Virtual device
164     u16 heads;
165     u16 cylinders;
166     u16 spt;
167 };
168
169 struct fdpt_s {
170     u16 cylinders;
171     u8 heads;
172     u8 a0h_signature;
173     u8 phys_sectors;
174     u16 precompensation;
175     u8 reserved;
176     u8 drive_control_byte;
177     u16 phys_cylinders;
178     u8 phys_heads;
179     u16 landing_zone;
180     u8 sectors;
181     u8 checksum;
182 } PACKED;
183
184 struct extended_bios_data_area_s {
185     u8 size;
186     u8 reserved1[0x21];
187     u32 far_call_pointer;
188     u8 mouse_flag1;
189     u8 mouse_flag2;
190     u8 mouse_data[0x08];
191     // 0x30
192     u8 other1[0x0d];
193
194     // 0x3d
195     struct fdpt_s fdpt[2];
196
197     // 0x5d
198     u8 other2[0xC4];
199
200     // 0x121 - Begin custom storage.
201     u8 ps2ctr;
202
203     // El Torito Emulation data
204     struct cdemu_s cdemu;
205
206     // Count of transferred sectors and bytes to/from disk
207     u16 sector_count;
208
209     // Buffer for disk DPTE table
210     struct dpte_s dpte;
211
212     // Locks for removable devices
213     u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
214
215     u16 boot_sequence;
216
217     // Resume stack
218     u8 resume_stack[128] __aligned(8);
219 } PACKED;
220
221 // Accessor functions
222 static inline u16 get_ebda_seg() {
223     return GET_BDA(ebda_seg);
224 }
225 static inline struct extended_bios_data_area_s *
226 get_ebda_ptr()
227 {
228     extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
229     if (MODE16)
230         return __force_link_error__get_ebda_ptr_only_in_32bit();
231     return (void*)MAKE_FARPTR(get_ebda_seg(), 0);
232 }
233 #define GET_EBDA2(eseg, var)                                            \
234     GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
235 #define SET_EBDA2(eseg, var, val)                                       \
236     SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
237 #define GET_EBDA(var)                                            \
238     GET_EBDA2(get_ebda_seg(), var)
239 #define SET_EBDA(var, val)                                       \
240     SET_EBDA2(get_ebda_seg(), var, (val))
241
242
243 /****************************************************************
244  * Global variables
245  ****************************************************************/
246
247 #define GET_GLOBAL(var) \
248     GET_VAR(CS, (var))
249 #if MODE16
250 extern void __force_link_error__set_global_only_in_32bit();
251 #define SET_GLOBAL(var, val) do {                       \
252     (void)(val);                                        \
253     __force_link_error__set_global_only_in_32bit();     \
254     } while (0)
255 #else
256 #define SET_GLOBAL(var, val)                    \
257     do { (var) = (val); } while (0)
258 #endif
259
260
261 /****************************************************************
262  * Bios Config Table
263  ****************************************************************/
264
265 struct bios_config_table_s {
266     u16 size;
267     u8 model;
268     u8 submodel;
269     u8 biosrev;
270     u8 feature1, feature2, feature3, feature4, feature5;
271 } PACKED;
272
273 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
274
275 #endif // __BIOSVAR_H