Move most of ATA and CDEMU from ebda to global variables.
[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  * Initial Program Load (IPL)
133  ****************************************************************/
134
135 struct ipl_entry_s {
136     u16 type;
137     u16 flags;
138     u32 vector;
139     char *description;
140 };
141
142 struct ipl_s {
143     struct ipl_entry_s table[8];
144     u16 count;
145     u16 sequence;
146     u32 bootorder;
147     u8 checkfloppysig;
148 };
149
150 #define IPL_TYPE_FLOPPY      0x01
151 #define IPL_TYPE_HARDDISK    0x02
152 #define IPL_TYPE_CDROM       0x03
153 #define IPL_TYPE_BEV         0x80
154
155
156 /****************************************************************
157  * Extended Bios Data Area (EBDA)
158  ****************************************************************/
159
160 // DPTE definition
161 struct dpte_s {
162     u16 iobase1;
163     u16 iobase2;
164     u8  prefix;
165     u8  unused;
166     u8  irq;
167     u8  blkcount;
168     u8  dma;
169     u8  pio;
170     u16 options;
171     u16 reserved;
172     u8  revision;
173     u8  checksum;
174 };
175
176 struct fdpt_s {
177     u16 cylinders;
178     u8 heads;
179     u8 a0h_signature;
180     u8 phys_sectors;
181     u16 precompensation;
182     u8 reserved;
183     u8 drive_control_byte;
184     u16 phys_cylinders;
185     u8 phys_heads;
186     u16 landing_zone;
187     u8 sectors;
188     u8 checksum;
189 } PACKED;
190
191 struct extended_bios_data_area_s {
192     u8 size;
193     u8 reserved1[0x21];
194     u32 far_call_pointer;
195     u8 mouse_flag1;
196     u8 mouse_flag2;
197     u8 mouse_data[0x08];
198     // 0x30
199     u8 other1[0x0d];
200
201     // 0x3d
202     struct fdpt_s fdpt[2];
203
204     // 0x5d
205     u8 other2[0xC4];
206
207     // 0x121 - Begin custom storage.
208     u8 ps2ctr;
209
210     u8 cdemu_active;
211
212     // Count of transferred sectors and bytes to/from disk
213     u16 sector_count;
214
215     // Buffer for disk DPTE table
216     struct dpte_s dpte;
217
218     // Locks for removable devices
219     u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
220
221     // Initial program load
222     struct ipl_s ipl;
223
224     // Resume stack
225     u8 resume_stack[128] __aligned(8);
226 } PACKED;
227
228 // Accessor functions
229 #define GET_EBDA(var) \
230     GET_FARVAR(GET_BDA(ebda_seg), ((struct extended_bios_data_area_s *)0)->var)
231 #define SET_EBDA(var, val) \
232     SET_FARVAR(GET_BDA(ebda_seg), ((struct extended_bios_data_area_s *)0)->var, (val))
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 (void*)MAKE_FARPTR(GET_BDA(ebda_seg), 0);
240 }
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