blob: 5f362a0b0a5aeca7bc15e8b4af2e7ce82707610f [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
10#include "farptr.h" // SET_SEG
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050011#include "config.h" // CONFIG_*
12
13#define PACKED __attribute__((packed))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050014
15
16/****************************************************************
17 * Bios Data Area (BDA)
18 ****************************************************************/
19
20struct ivec {
21 u16 offset;
22 u16 seg;
23};
24
25struct bios_data_area_s {
26 // 00:00
27 struct ivec ivecs[256];
28 // 30:00
29// u8 stack[256];
30 // 40:00
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050031 u16 port_com[4];
32 u16 port_lpt[3];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050033 u16 ebda_seg;
34 // 40:10
35 u16 equipment_list_flags;
36 u8 pad1;
37 u16 mem_size_kb;
38 u8 pad2;
39 u8 ps2_ctrl_flag;
Kevin O'Connor4b60c002008-02-25 22:29:55 -050040 u8 kbd_flag0;
41 u8 kbd_flag1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050042 u8 alt_keypad;
43 u16 kbd_buf_head;
44 u16 kbd_buf_tail;
45 // 40:1e
46 u8 kbd_buf[32];
47 u8 floppy_recalibration_status;
48 u8 floppy_motor_status;
49 // 40:40
50 u8 floppy_motor_counter;
51 u8 floppy_last_status;
52 u8 floppy_return_status[7];
53 u8 other1[0x7];
54 // 40:50
Kevin O'Connord427a3f2008-03-01 14:02:41 -050055 u8 other2[0x10];
56 // 40:60
57 u8 other3[0x7];
58 u32 jump_cs_ip;
59 u8 dummy;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050060 u32 timer_counter;
61 // 40:70
62 u8 timer_rollover;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050063 u8 break_flag;
64 u16 soft_reset_flag;
65 u8 disk_last_status;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050066 u8 disk_count;
67 u8 disk_control_byte;
68 u8 port_disk;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050069 u8 lpt_timeout[4];
70 u8 com_timeout[4];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050071 // 40:80
72 u16 kbd_buf_start_offset;
73 u16 kbd_buf_end_offset;
74 u8 other5[7];
75 u8 floppy_last_data_rate;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050076 u8 disk_status_controller;
77 u8 disk_error_controller;
78 u8 disk_interrupt_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050079 u8 floppy_harddisk_info;
80 // 40:90
81 u8 floppy_media_state[4];
82 u8 floppy_track0;
83 u8 floppy_track1;
84 u8 kbd_mode;
85 u8 kbd_led;
86 u32 ptr_user_wait_complete_flag;
87 u32 user_wait_timeout;
88 // 40:A0
89 u8 rtc_wait_flag;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050090} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050091
92// BDA floppy_recalibration_status bitdefs
93#define FRS_TIMEOUT (1<<7)
94
95// BDA rtc_wait_flag bitdefs
96#define RWS_WAIT_PENDING (1<<0)
97#define RWS_WAIT_ELAPSED (1<<7)
98
99// BDA floppy_media_state bitdefs
100#define FMS_DRIVE_STATE_MASK (0x07)
101#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
102#define FMS_DOUBLE_STEPPING (1<<5)
103#define FMS_DATA_RATE_MASK (0xc0)
104
105// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500106#define GET_BDA(var) \
107 GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
108#define SET_BDA(var, val) \
109 SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500110#define CLEARBITS_BDA(var, val) do { \
111 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
112 SET_BDA(var, (__val & ~(val))); \
113 } while (0)
114#define SETBITS_BDA(var, val) do { \
115 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
116 SET_BDA(var, (__val | (val))); \
117 } while (0)
118
119
120/****************************************************************
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500121 * Hard drive info
122 ****************************************************************/
123
124struct fdpt_s {
125 u16 cylinders;
126 u8 heads;
127 u8 a0h_signature;
128 u8 phys_sectors;
129 u16 precompensation;
130 u8 reserved;
131 u8 drive_control_byte;
132 u16 phys_cylinders;
133 u8 phys_heads;
134 u16 landing_zone;
135 u8 sectors;
136 u8 checksum;
137} PACKED;
138
139struct chs_s {
140 u16 heads; // # heads
141 u16 cylinders; // # cylinders
142 u16 spt; // # sectors / track
143};
144
145// DPTE definition
146struct dpte_s {
147 u16 iobase1;
148 u16 iobase2;
149 u8 prefix;
150 u8 unused;
151 u8 irq;
152 u8 blkcount;
153 u8 dma;
154 u8 pio;
155 u16 options;
156 u16 reserved;
157 u8 revision;
158 u8 checksum;
159};
160
161struct ata_channel_s {
162 u8 iface; // ISA or PCI
163 u16 iobase1; // IO Base 1
164 u16 iobase2; // IO Base 2
165 u8 irq; // IRQ
166} PACKED;
167
168struct ata_device_s {
169 u8 type; // Detected type of ata (ata/atapi/none/unknown)
170 u8 device; // Detected type of attached devices (hd/cd/none)
171 u8 removable; // Removable device flag
172 u8 lock; // Locks for removable devices
173 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
174 u16 blksize; // block size
175
176 u8 translation; // type of translation
177 struct chs_s lchs; // Logical CHS
178 struct chs_s pchs; // Physical CHS
179
180 u32 sectors; // Total sectors count
181} PACKED;
182
183struct ata_s {
184 // ATA channels info
185 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
186
187 // ATA devices info
188 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
189 //
190 // map between (bios hd id - 0x80) and ata channels
191 u8 hdcount, hdidmap[CONFIG_MAX_ATA_DEVICES];
192
193 // map between (bios cd id - 0xE0) and ata channels
194 u8 cdcount, cdidmap[CONFIG_MAX_ATA_DEVICES];
195
196 // Buffer for DPTE table
197 struct dpte_s dpte;
198
199 // Count of transferred sectors and bytes
200 u16 trsfsectors;
201 u32 trsfbytes;
202} PACKED;
203
204// ElTorito Device Emulation data
205struct cdemu_s {
206 u8 active;
207 u8 media;
208 u8 emulated_drive;
209 u8 controller_index;
210 u16 device_spec;
211 u32 ilba;
212 u16 buffer_segment;
213 u16 load_segment;
214 u16 sector_count;
215
216 // Virtual device
217 struct chs_s vdevice;
218} PACKED;
219
220
221/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500222 * Extended Bios Data Area (EBDA)
223 ****************************************************************/
224
225struct extended_bios_data_area_s {
226 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500227 u8 reserved1[0x21];
228 u32 far_call_pointer;
229 u8 mouse_flag1;
230 u8 mouse_flag2;
231 u8 mouse_data[0x08];
232 // 0x30
233 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500234
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500235 // 0x3d
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500236 struct fdpt_s fdpt0;
237 struct fdpt_s fdpt1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500238
239 u8 other2[0xC4];
240
241 // ATA Driver data
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500242 struct ata_s ata;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500243
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500244 // El Torito Emulation data
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500245 struct cdemu_s cdemu;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500246};
247
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500248// Accessor functions
249#define GET_EBDA(var) \
250 GET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var)
251#define SET_EBDA(var, val) \
252 SET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var, (val))
253
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500254
255/****************************************************************
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500256 * Initial Program Load (IPL)
257 ****************************************************************/
258
259// XXX - is this a standard, or just a bochs bios thing?
260
261struct ipl_entry_s {
262 u16 type;
263 u16 flags;
264 u32 vector;
265 u32 description;
266 u32 reserved;
267};
268
269struct ipl_s {
270 struct ipl_entry_s table[8];
271 u16 count;
272 u16 sequence;
273 u8 pad[124];
274};
275
276#define IPL_TYPE_FLOPPY 0x01
277#define IPL_TYPE_HARDDISK 0x02
278#define IPL_TYPE_CDROM 0x03
279#define IPL_TYPE_BEV 0x80
280
281// Accessor functions
282#define GET_IPL(var) \
283 GET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var)
284#define SET_IPL(var, val) \
285 SET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var, (val))
286
287
288/****************************************************************
289 * Registers saved/restored in romlayout.S
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500290 ****************************************************************/
291
292#define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
293
294struct bregs {
295 u16 ds;
296 u16 es;
297 UREG(edi, di, di_hi, di_lo);
298 UREG(esi, si, si_hi, si_lo);
299 UREG(ebp, bp, bp_hi, bp_lo);
300 UREG(esp, sp, sp_hi, sp_lo);
301 UREG(ebx, bx, bh, bl);
302 UREG(edx, dx, dh, dl);
303 UREG(ecx, cx, ch, cl);
304 UREG(eax, ax, ah, al);
305 u16 ip;
306 u16 cs;
307 u16 flags;
308} __attribute__((packed));
309
310// bregs flags bitdefs
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500311#define F_ZF (1<<6)
312#define F_CF (1<<0)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500313
314static inline void
315set_cf(struct bregs *regs, int cond)
316{
317 if (cond)
318 regs->flags |= F_CF;
319 else
320 regs->flags &= ~F_CF;
321}
322
323
324/****************************************************************
325 * Bios Config Table
326 ****************************************************************/
327
328struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500329 u16 size;
330 u8 model;
331 u8 submodel;
332 u8 biosrev;
333 u8 feature1, feature2, feature3, feature4, feature5;
334} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500335
336extern struct bios_config_table_s BIOS_CONFIG_TABLE;
337
338
339/****************************************************************
340 * Memory layout info
341 ****************************************************************/
342
343#define SEG_BIOS 0xf000
344
345#define EBDA_SEG 0x9FC0
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500346#define IPL_SEG 0x9FF0
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500347#define EBDA_SIZE 1 // In KiB
348#define BASE_MEM_IN_K (640 - EBDA_SIZE)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500349
350#endif // __BIOSVAR_H