Supply vga register names for BDA.
[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     u32 jump_cs_ip;
64     u8 other_6b;
65     u32 timer_counter;
66     // 40:70
67     u8 timer_rollover;
68     u8 break_flag;
69     u16 soft_reset_flag;
70     u8 disk_last_status;
71     u8 disk_count;
72     u8 disk_control_byte;
73     u8 port_disk;
74     u8 lpt_timeout[4];
75     u8 com_timeout[4];
76     // 40:80
77     u16 kbd_buf_start_offset;
78     u16 kbd_buf_end_offset;
79     u8 video_rows;
80     u16 char_height;
81     u8 video_ctl;
82     u8 video_switches;
83     u8 modeset_ctl;
84     u8 dcc_index;
85     u8 floppy_last_data_rate;
86     u8 disk_status_controller;
87     u8 disk_error_controller;
88     u8 disk_interrupt_flag;
89     u8 floppy_harddisk_info;
90     // 40:90
91     u8 floppy_media_state[4];
92     u8 floppy_track0;
93     u8 floppy_track1;
94     u8 kbd_mode;
95     u8 kbd_led;
96     u32 ptr_user_wait_complete_flag;
97     u32 user_wait_timeout;
98     // 40:A0
99     u8 rtc_wait_flag;
100 } PACKED;
101
102 // BDA floppy_recalibration_status bitdefs
103 #define FRS_TIMEOUT (1<<7)
104
105 // BDA rtc_wait_flag bitdefs
106 #define RWS_WAIT_PENDING (1<<0)
107 #define RWS_WAIT_ELAPSED (1<<7)
108
109 // BDA floppy_media_state bitdefs
110 #define FMS_DRIVE_STATE_MASK        (0x07)
111 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
112 #define FMS_DOUBLE_STEPPING         (1<<5)
113 #define FMS_DATA_RATE_MASK          (0xc0)
114
115 // Accessor functions
116 #define GET_BDA(var) \
117     GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
118 #define SET_BDA(var, val) \
119     SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
120 #define CLEARBITS_BDA(var, val) do {                                    \
121         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
122         SET_BDA(var, (__val & ~(val)));                                 \
123     } while (0)
124 #define SETBITS_BDA(var, val) do {                                      \
125         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
126         SET_BDA(var, (__val | (val)));                                  \
127     } while (0)
128
129
130 /****************************************************************
131  * Hard drive info
132  ****************************************************************/
133
134 struct chs_s {
135     u16 heads;      // # heads
136     u16 cylinders;  // # cylinders
137     u16 spt;        // # sectors / track
138 };
139
140 // DPTE definition
141 struct dpte_s {
142     u16 iobase1;
143     u16 iobase2;
144     u8  prefix;
145     u8  unused;
146     u8  irq;
147     u8  blkcount;
148     u8  dma;
149     u8  pio;
150     u16 options;
151     u16 reserved;
152     u8  revision;
153     u8  checksum;
154 };
155
156 struct ata_channel_s {
157     u16 iobase1;      // IO Base 1
158     u16 iobase2;      // IO Base 2
159     u16 pci_bdf;
160     u8  irq;          // IRQ
161 };
162
163 struct ata_device_s {
164     u8  type;         // Detected type of ata (ata/atapi/none/unknown)
165     u8  device;       // Detected type of attached devices (hd/cd/none)
166     u8  removable;    // Removable device flag
167     u8  lock;         // Locks for removable devices
168     u8  mode;         // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
169     u16 blksize;      // block size
170
171     u8  translation;  // type of translation
172     struct chs_s  lchs;         // Logical CHS
173     struct chs_s  pchs;         // Physical CHS
174
175     u64 sectors;      // Total sectors count
176 };
177
178 struct ata_s {
179     // ATA channels info
180     struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
181
182     // ATA devices info
183     struct ata_device_s  devices[CONFIG_MAX_ATA_DEVICES];
184     //
185     // map between bios hd/cd id and ata channels
186     u8 hdcount, cdcount;
187     u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
188
189     // Buffer for DPTE table
190     struct dpte_s dpte;
191
192     // Count of transferred sectors and bytes
193     u16 trsfsectors;
194 };
195
196 // ElTorito Device Emulation data
197 struct cdemu_s {
198     u8  active;
199     u8  media;
200     u8  emulated_drive;
201     u8  controller_index;
202     u16 device_spec;
203     u32 ilba;
204     u16 buffer_segment;
205     u16 load_segment;
206     u16 sector_count;
207
208     // Virtual device
209     struct chs_s  vdevice;
210 };
211
212
213 /****************************************************************
214  * Initial Program Load (IPL)
215  ****************************************************************/
216
217 struct ipl_entry_s {
218     u16 type;
219     u16 flags;
220     u32 vector;
221     u32 description;
222 };
223
224 struct ipl_s {
225     struct ipl_entry_s table[8];
226     u16 count;
227     u16 sequence;
228     u32 bootorder;
229     u8 checkfloppysig;
230 };
231
232 #define IPL_TYPE_FLOPPY      0x01
233 #define IPL_TYPE_HARDDISK    0x02
234 #define IPL_TYPE_CDROM       0x03
235 #define IPL_TYPE_BEV         0x80
236
237
238 /****************************************************************
239  * Extended Bios Data Area (EBDA)
240  ****************************************************************/
241
242 struct fdpt_s {
243     u16 cylinders;
244     u8 heads;
245     u8 a0h_signature;
246     u8 phys_sectors;
247     u16 precompensation;
248     u8 reserved;
249     u8 drive_control_byte;
250     u16 phys_cylinders;
251     u8 phys_heads;
252     u16 landing_zone;
253     u8 sectors;
254     u8 checksum;
255 } PACKED;
256
257 struct extended_bios_data_area_s {
258     u8 size;
259     u8 reserved1[0x21];
260     u32 far_call_pointer;
261     u8 mouse_flag1;
262     u8 mouse_flag2;
263     u8 mouse_data[0x08];
264     // 0x30
265     u8 other1[0x0d];
266
267     // 0x3d
268     struct fdpt_s fdpt[2];
269
270     // 0x5d
271     u8 other2[0xC4];
272
273     u8 ps2ctr;
274
275     // Physical memory available.
276     u32 ram_size;
277     u16 e820_count;
278     u32 e820_loc;
279     u32 pir_loc;
280
281     // ATA Driver data
282     struct ata_s   ata;
283
284     // El Torito Emulation data
285     struct cdemu_s cdemu;
286
287     // Initial program load
288     struct ipl_s ipl;
289 } PACKED;
290
291 #define EBDA_SIZE DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
292 #define BASE_MEM_IN_K (640 - EBDA_SIZE)
293
294 // Accessor functions
295 #define GET_EBDA(var) \
296     GET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var)
297 #define SET_EBDA(var, val) \
298     SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
299
300
301 /****************************************************************
302  * Bios Config Table
303  ****************************************************************/
304
305 struct bios_config_table_s {
306     u16 size;
307     u8 model;
308     u8 submodel;
309     u8 biosrev;
310     u8 feature1, feature2, feature3, feature4, feature5;
311 } PACKED;
312
313 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
314
315 #endif // __BIOSVAR_H