blob: 2b755e3f419c8a8f3ae9b0e5fc772c073a73db27 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Variable layouts of bios.
2//
Kevin O'Connorcadaf0e2010-07-26 23:47:26 -04003// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 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_*
Kevin O'Connorb68ac712009-08-09 17:25:19 -040012#include "disk.h" // struct chs_s
13
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050014
15/****************************************************************
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050016 * Interupt vector table
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050017 ****************************************************************/
18
Kevin O'Connor30853762009-01-17 18:49:20 -050019struct rmode_IVT {
Kevin O'Connorb68ac712009-08-09 17:25:19 -040020 struct segoff_s ivec[256];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050021};
22
Kevin O'Connor3d292132009-05-06 23:20:03 -040023#define GET_IVT(vector) \
24 GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
Kevin O'Connor9f985422009-09-09 11:34:39 -040025#define SET_IVT(vector, segoff) \
26 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050027
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040028#define FUNC16(func) ({ \
29 ASSERT32FLAT(); \
30 extern void func (void); \
31 SEGOFF(SEG_BIOS, (u32)func - BUILD_BIOS_ADDR); \
32 })
33
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050034
35/****************************************************************
36 * Bios Data Area (BDA)
37 ****************************************************************/
38
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050039struct bios_data_area_s {
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050040 // 40:00
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050041 u16 port_com[4];
42 u16 port_lpt[3];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050043 u16 ebda_seg;
44 // 40:10
45 u16 equipment_list_flags;
46 u8 pad1;
47 u16 mem_size_kb;
48 u8 pad2;
49 u8 ps2_ctrl_flag;
Kevin O'Connor4b60c002008-02-25 22:29:55 -050050 u8 kbd_flag0;
51 u8 kbd_flag1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050052 u8 alt_keypad;
53 u16 kbd_buf_head;
54 u16 kbd_buf_tail;
55 // 40:1e
56 u8 kbd_buf[32];
57 u8 floppy_recalibration_status;
58 u8 floppy_motor_status;
59 // 40:40
60 u8 floppy_motor_counter;
61 u8 floppy_last_status;
62 u8 floppy_return_status[7];
Kevin O'Connor6723d032008-10-25 14:37:29 -040063 u8 video_mode;
64 u16 video_cols;
65 u16 video_pagesize;
66 u16 video_pagestart;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050067 // 40:50
Kevin O'Connor6723d032008-10-25 14:37:29 -040068 u16 cursor_pos[8];
Kevin O'Connord427a3f2008-03-01 14:02:41 -050069 // 40:60
Kevin O'Connor6723d032008-10-25 14:37:29 -040070 u16 cursor_type;
71 u8 video_page;
72 u16 crtc_address;
73 u8 video_msr;
74 u8 video_pal;
Kevin O'Connor9f985422009-09-09 11:34:39 -040075 struct segoff_s jump;
Kevin O'Connor6723d032008-10-25 14:37:29 -040076 u8 other_6b;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050077 u32 timer_counter;
78 // 40:70
79 u8 timer_rollover;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050080 u8 break_flag;
81 u16 soft_reset_flag;
82 u8 disk_last_status;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -050083 u8 hdcount;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050084 u8 disk_control_byte;
85 u8 port_disk;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050086 u8 lpt_timeout[4];
87 u8 com_timeout[4];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050088 // 40:80
89 u16 kbd_buf_start_offset;
90 u16 kbd_buf_end_offset;
Kevin O'Connor6723d032008-10-25 14:37:29 -040091 u8 video_rows;
92 u16 char_height;
93 u8 video_ctl;
94 u8 video_switches;
95 u8 modeset_ctl;
96 u8 dcc_index;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050097 u8 floppy_last_data_rate;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050098 u8 disk_status_controller;
99 u8 disk_error_controller;
100 u8 disk_interrupt_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500101 u8 floppy_harddisk_info;
102 // 40:90
103 u8 floppy_media_state[4];
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500104 u8 floppy_track[2];
Kevin O'Connor40c0e482009-09-11 02:06:02 -0400105 u8 kbd_flag2;
Kevin O'Connor6704cf92010-03-13 18:51:46 -0500106 u8 kbd_led;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400107 struct segoff_s user_wait_complete_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500108 u32 user_wait_timeout;
109 // 40:A0
110 u8 rtc_wait_flag;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400111 u8 other_a1[7];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400112 struct segoff_s video_savetable;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400113 u8 other_ac[4];
114 // 40:B0
115 u8 other_b0[10];
116 u16 vbe_mode;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500117} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500118
119// BDA floppy_recalibration_status bitdefs
120#define FRS_TIMEOUT (1<<7)
121
122// BDA rtc_wait_flag bitdefs
123#define RWS_WAIT_PENDING (1<<0)
124#define RWS_WAIT_ELAPSED (1<<7)
125
126// BDA floppy_media_state bitdefs
127#define FMS_DRIVE_STATE_MASK (0x07)
128#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
129#define FMS_DOUBLE_STEPPING (1<<5)
130#define FMS_DATA_RATE_MASK (0xc0)
131
132// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500133#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400134 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500135#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400136 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500137#define CLEARBITS_BDA(var, val) do { \
138 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
139 SET_BDA(var, (__val & ~(val))); \
140 } while (0)
141#define SETBITS_BDA(var, val) do { \
142 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
143 SET_BDA(var, (__val | (val))); \
144 } while (0)
145
146
147/****************************************************************
148 * Extended Bios Data Area (EBDA)
149 ****************************************************************/
150
Kevin O'Connor609da232008-12-28 23:18:57 -0500151// DPTE definition
152struct dpte_s {
153 u16 iobase1;
154 u16 iobase2;
155 u8 prefix;
156 u8 unused;
157 u8 irq;
158 u8 blkcount;
159 u8 dma;
160 u8 pio;
161 u16 options;
162 u16 reserved;
163 u8 revision;
164 u8 checksum;
165};
166
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500167// ElTorito Device Emulation data
168struct cdemu_s {
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500169 struct drive_s *emulated_drive_gf;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500170 u32 ilba;
171 u16 buffer_segment;
172 u16 load_segment;
173 u16 sector_count;
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400174 u8 active;
175 u8 media;
176 u8 emulated_extdrive;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500177
178 // Virtual device
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400179 struct chs_s lchs;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500180};
181
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400182struct fdpt_s {
183 u16 cylinders;
184 u8 heads;
185 u8 a0h_signature;
186 u8 phys_sectors;
187 u16 precompensation;
188 u8 reserved;
189 u8 drive_control_byte;
190 u16 phys_cylinders;
191 u8 phys_heads;
192 u16 landing_zone;
193 u8 sectors;
194 u8 checksum;
195} PACKED;
196
Kevin O'Connor84a4d4b2010-02-11 22:32:12 -0500197struct usbkeyinfo {
198 union {
199 struct {
200 u8 modifiers;
201 u8 repeatcount;
202 u8 keys[6];
203 };
204 u64 data;
205 };
206};
207
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500208struct extended_bios_data_area_s {
209 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500210 u8 reserved1[0x21];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400211 struct segoff_s far_call_pointer;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500212 u8 mouse_flag1;
213 u8 mouse_flag2;
214 u8 mouse_data[0x08];
215 // 0x30
216 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500217
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500218 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400219 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500220
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400221 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500222 u8 other2[0xC4];
223
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500224 // 0x121 - Begin custom storage.
Kevin O'Connor6704cf92010-03-13 18:51:46 -0500225 u8 ps2ctr;
Kevin O'Connor84a4d4b2010-02-11 22:32:12 -0500226 struct usbkeyinfo usbkey_last;
227
Kevin O'Connorad901592009-12-13 11:25:25 -0500228 int RTCusers;
Kevin O'Connor3b897192008-07-20 10:08:59 -0400229
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500230 // El Torito Emulation data
231 struct cdemu_s cdemu;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500232
Kevin O'Connor609da232008-12-28 23:18:57 -0500233 // Buffer for disk DPTE table
234 struct dpte_s dpte;
235
236 // Locks for removable devices
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400237 u8 cdrom_locks[CONFIG_MAX_EXTDRIVE];
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400238
Kevin O'Connorc659fde2008-12-28 23:43:20 -0500239 u16 boot_sequence;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500240
Kevin O'Connor7f343092009-01-01 18:31:11 -0500241 // Stack space available for code that needs it.
242 u8 extra_stack[512] __aligned(8);
Kevin O'Connored128492008-03-11 11:14:59 -0400243} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500244
Kevin O'Connor49553a42009-05-17 10:31:34 -0400245// The initial size and location of EBDA
246#define EBDA_SIZE_START \
247 DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
248#define EBDA_SEGMENT_START \
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400249 FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
Kevin O'Connor49553a42009-05-17 10:31:34 -0400250
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500251// Accessor functions
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500252static inline u16 get_ebda_seg(void) {
Kevin O'Connor08815372008-12-29 21:16:31 -0500253 return GET_BDA(ebda_seg);
254}
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500255static inline struct extended_bios_data_area_s *
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500256get_ebda_ptr(void)
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500257{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500258 ASSERT32FLAT();
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500259 return MAKE_FLATPTR(get_ebda_seg(), 0);
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500260}
Kevin O'Connor08815372008-12-29 21:16:31 -0500261#define GET_EBDA2(eseg, var) \
262 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
263#define SET_EBDA2(eseg, var, val) \
264 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor7f343092009-01-01 18:31:11 -0500265#define GET_EBDA(var) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500266 GET_EBDA2(get_ebda_seg(), var)
Kevin O'Connor7f343092009-01-01 18:31:11 -0500267#define SET_EBDA(var, val) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500268 SET_EBDA2(get_ebda_seg(), var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500269
Kevin O'Connor7f343092009-01-01 18:31:11 -0500270#define EBDA_OFFSET_TOP_STACK \
271 offsetof(struct extended_bios_data_area_s, extra_stack[ \
272 FIELD_SIZEOF(struct extended_bios_data_area_s \
273 , extra_stack)])
274
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500275
276/****************************************************************
Kevin O'Connor15157a32008-12-13 11:10:37 -0500277 * Global variables
278 ****************************************************************/
279
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500280#if MODE16 == 0 && MODESEGMENT == 1
281// In 32bit segmented mode %cs may not be readable and the code may be
282// relocated. The entry code sets up %gs with a readable segment and
283// the code offset can be determined by get_global_offset().
284#define GLOBAL_SEGREG GS
285static inline u32 __attribute_const get_global_offset(void) {
286 u32 ret;
287 asm(" calll 1f\n"
288 "1:popl %0\n"
289 " subl $1b, %0"
290 : "=r"(ret));
291 return ret;
292}
293#else
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500294#define GLOBAL_SEGREG CS
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500295static inline u32 __attribute_const get_global_offset(void) {
296 return 0;
297}
298#endif
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500299static inline u16 get_global_seg(void) {
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500300 return GET_SEG(GLOBAL_SEGREG);
301}
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500302#define GET_GLOBAL(var) \
303 GET_VAR(GLOBAL_SEGREG, *(typeof(&(var)))((void*)&(var) \
304 + get_global_offset()))
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400305#define SET_GLOBAL(var, val) do { \
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500306 ASSERT32FLAT(); \
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400307 (var) = (val); \
Kevin O'Connor609da232008-12-28 23:18:57 -0500308 } while (0)
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500309#if MODESEGMENT
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500310#define GLOBALFLAT2GLOBAL(var) ((typeof(var))((void*)(var) - BUILD_BIOS_ADDR))
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400311#else
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500312#define GLOBALFLAT2GLOBAL(var) (var)
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400313#endif
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500314// Access a "flat" pointer known to point to the f-segment.
315#define GET_GLOBALFLAT(var) GET_GLOBAL(*GLOBALFLAT2GLOBAL(&(var)))
Kevin O'Connor15157a32008-12-13 11:10:37 -0500316
317
318/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500319 * Bios Config Table
320 ****************************************************************/
321
322struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500323 u16 size;
324 u8 model;
325 u8 submodel;
326 u8 biosrev;
327 u8 feature1, feature2, feature3, feature4, feature5;
328} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500329
Kevin O'Connor30853762009-01-17 18:49:20 -0500330extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500331
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500332#endif // __BIOSVAR_H