blob: 6dfcbc71518e51e0a2380cc60964d89aad89b00f [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// 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.
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -05006#ifndef __BIOSVAR_H
7#define __BIOSVAR_H
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05008
9#include "types.h" // u8
Kevin O'Connor9521e262008-07-04 13:04:29 -040010#include "farptr.h" // GET_FARVAR
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050011#include "config.h" // CONFIG_*
12
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050013
14/****************************************************************
15 * Bios Data Area (BDA)
16 ****************************************************************/
17
18struct ivec {
19 u16 offset;
20 u16 seg;
21};
22
23struct bios_data_area_s {
24 // 00:00
25 struct ivec ivecs[256];
26 // 30:00
27// u8 stack[256];
28 // 40:00
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050029 u16 port_com[4];
30 u16 port_lpt[3];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050031 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;
Kevin O'Connor4b60c002008-02-25 22:29:55 -050038 u8 kbd_flag0;
39 u8 kbd_flag1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050040 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];
Kevin O'Connor6723d032008-10-25 14:37:29 -040051 u8 video_mode;
52 u16 video_cols;
53 u16 video_pagesize;
54 u16 video_pagestart;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050055 // 40:50
Kevin O'Connor6723d032008-10-25 14:37:29 -040056 u16 cursor_pos[8];
Kevin O'Connord427a3f2008-03-01 14:02:41 -050057 // 40:60
Kevin O'Connor6723d032008-10-25 14:37:29 -040058 u16 cursor_type;
59 u8 video_page;
60 u16 crtc_address;
61 u8 video_msr;
62 u8 video_pal;
Kevin O'Connord427a3f2008-03-01 14:02:41 -050063 u32 jump_cs_ip;
Kevin O'Connor6723d032008-10-25 14:37:29 -040064 u8 other_6b;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050065 u32 timer_counter;
66 // 40:70
67 u8 timer_rollover;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050068 u8 break_flag;
69 u16 soft_reset_flag;
70 u8 disk_last_status;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050071 u8 disk_count;
72 u8 disk_control_byte;
73 u8 port_disk;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050074 u8 lpt_timeout[4];
75 u8 com_timeout[4];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050076 // 40:80
77 u16 kbd_buf_start_offset;
78 u16 kbd_buf_end_offset;
Kevin O'Connor6723d032008-10-25 14:37:29 -040079 u8 video_rows;
80 u16 char_height;
81 u8 video_ctl;
82 u8 video_switches;
83 u8 modeset_ctl;
84 u8 dcc_index;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050085 u8 floppy_last_data_rate;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050086 u8 disk_status_controller;
87 u8 disk_error_controller;
88 u8 disk_interrupt_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089 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;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500100} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500101
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
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500116#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400117 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500118#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400119 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500120#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/****************************************************************
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500131 * Hard drive info
132 ****************************************************************/
133
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500134struct chs_s {
135 u16 heads; // # heads
136 u16 cylinders; // # cylinders
137 u16 spt; // # sectors / track
138};
139
140// DPTE definition
141struct 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
156struct ata_channel_s {
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500157 u16 iobase1; // IO Base 1
158 u16 iobase2; // IO Base 2
Kevin O'Connor53236cc2008-08-31 11:16:33 -0400159 u16 pci_bdf;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500160 u8 irq; // IRQ
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400161};
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500162
163struct 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
Kevin O'Connor1bb3b5c2008-05-14 00:43:13 -0400175 u64 sectors; // Total sectors count
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400176};
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500177
178struct 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 //
Kevin O'Connor180a9592008-03-04 22:50:53 -0500185 // map between bios hd/cd id and ata channels
186 u8 hdcount, cdcount;
187 u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500188
189 // Buffer for DPTE table
190 struct dpte_s dpte;
191
192 // Count of transferred sectors and bytes
193 u16 trsfsectors;
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400194};
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500195
196// ElTorito Device Emulation data
197struct 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;
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400210};
211
212
213/****************************************************************
214 * Initial Program Load (IPL)
215 ****************************************************************/
216
217struct ipl_entry_s {
218 u16 type;
219 u16 flags;
220 u32 vector;
221 u32 description;
222};
223
224struct ipl_s {
225 struct ipl_entry_s table[8];
226 u16 count;
227 u16 sequence;
Kevin O'Connorabc75972008-05-18 00:20:53 -0400228 u32 bootorder;
229 u8 checkfloppysig;
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400230};
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
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500236
237
238/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500239 * Extended Bios Data Area (EBDA)
240 ****************************************************************/
241
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400242struct 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
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500257struct extended_bios_data_area_s {
258 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500259 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];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500266
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500267 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400268 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500269
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400270 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500271 u8 other2[0xC4];
272
Kevin O'Connor3b897192008-07-20 10:08:59 -0400273 u8 ps2ctr;
274
Kevin O'Connor9571ac22008-05-17 22:20:27 -0400275 // Physical memory available.
Kevin O'Connor59c35f22008-10-25 23:05:42 -0400276 u32 ram_size; // Amount of continuous ram under 4Gig
277 u64 ram_size_over4G; // Amount of continuous ram >4Gig
Kevin O'Connord25810a2008-06-12 22:16:35 -0400278 u32 pir_loc;
Kevin O'Connor9571ac22008-05-17 22:20:27 -0400279
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500280 // ATA Driver data
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500281 struct ata_s ata;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500282
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500283 // El Torito Emulation data
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500284 struct cdemu_s cdemu;
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400285
286 // Initial program load
287 struct ipl_s ipl;
Kevin O'Connored128492008-03-11 11:14:59 -0400288} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500289
Kevin O'Connor9521e262008-07-04 13:04:29 -0400290#define EBDA_SIZE DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
291#define BASE_MEM_IN_K (640 - EBDA_SIZE)
292
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500293// Accessor functions
294#define GET_EBDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400295 GET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500296#define SET_EBDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400297 SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500298
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500299
300/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500301 * Bios Config Table
302 ****************************************************************/
303
304struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500305 u16 size;
306 u8 model;
307 u8 submodel;
308 u8 biosrev;
309 u8 feature1, feature2, feature3, feature4, feature5;
310} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500311
312extern struct bios_config_table_s BIOS_CONFIG_TABLE;
313
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500314#endif // __BIOSVAR_H