blob: d011966b132adfe369bda60de56ae3326d0a87a3 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Variable layouts of bios.
2//
Kevin O'Connor0bf92702009-08-01 11:45:37 -04003// Copyright (C) 2008,2009 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
28
29/****************************************************************
30 * Bios Data Area (BDA)
31 ****************************************************************/
32
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050033struct bios_data_area_s {
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050034 // 40:00
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050035 u16 port_com[4];
36 u16 port_lpt[3];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050037 u16 ebda_seg;
38 // 40:10
39 u16 equipment_list_flags;
40 u8 pad1;
41 u16 mem_size_kb;
42 u8 pad2;
43 u8 ps2_ctrl_flag;
Kevin O'Connor4b60c002008-02-25 22:29:55 -050044 u8 kbd_flag0;
45 u8 kbd_flag1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050046 u8 alt_keypad;
47 u16 kbd_buf_head;
48 u16 kbd_buf_tail;
49 // 40:1e
50 u8 kbd_buf[32];
51 u8 floppy_recalibration_status;
52 u8 floppy_motor_status;
53 // 40:40
54 u8 floppy_motor_counter;
55 u8 floppy_last_status;
56 u8 floppy_return_status[7];
Kevin O'Connor6723d032008-10-25 14:37:29 -040057 u8 video_mode;
58 u16 video_cols;
59 u16 video_pagesize;
60 u16 video_pagestart;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050061 // 40:50
Kevin O'Connor6723d032008-10-25 14:37:29 -040062 u16 cursor_pos[8];
Kevin O'Connord427a3f2008-03-01 14:02:41 -050063 // 40:60
Kevin O'Connor6723d032008-10-25 14:37:29 -040064 u16 cursor_type;
65 u8 video_page;
66 u16 crtc_address;
67 u8 video_msr;
68 u8 video_pal;
Kevin O'Connor9f985422009-09-09 11:34:39 -040069 struct segoff_s jump;
Kevin O'Connor6723d032008-10-25 14:37:29 -040070 u8 other_6b;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050071 u32 timer_counter;
72 // 40:70
73 u8 timer_rollover;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050074 u8 break_flag;
75 u16 soft_reset_flag;
76 u8 disk_last_status;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -050077 u8 hdcount;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050078 u8 disk_control_byte;
79 u8 port_disk;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050080 u8 lpt_timeout[4];
81 u8 com_timeout[4];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050082 // 40:80
83 u16 kbd_buf_start_offset;
84 u16 kbd_buf_end_offset;
Kevin O'Connor6723d032008-10-25 14:37:29 -040085 u8 video_rows;
86 u16 char_height;
87 u8 video_ctl;
88 u8 video_switches;
89 u8 modeset_ctl;
90 u8 dcc_index;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050091 u8 floppy_last_data_rate;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050092 u8 disk_status_controller;
93 u8 disk_error_controller;
94 u8 disk_interrupt_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050095 u8 floppy_harddisk_info;
96 // 40:90
97 u8 floppy_media_state[4];
Kevin O'Connora3b612e2009-02-07 11:25:29 -050098 u8 floppy_track[2];
Kevin O'Connor40c0e482009-09-11 02:06:02 -040099 u8 kbd_flag2;
Kevin O'Connor6f702dd2010-01-28 20:35:21 -0500100 u8 kbd_flag3;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400101 struct segoff_s user_wait_complete_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500102 u32 user_wait_timeout;
103 // 40:A0
104 u8 rtc_wait_flag;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400105 u8 other_a1[7];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400106 struct segoff_s video_savetable;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400107 u8 other_ac[4];
108 // 40:B0
109 u8 other_b0[10];
110 u16 vbe_mode;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500111} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500112
113// BDA floppy_recalibration_status bitdefs
114#define FRS_TIMEOUT (1<<7)
115
116// BDA rtc_wait_flag bitdefs
117#define RWS_WAIT_PENDING (1<<0)
118#define RWS_WAIT_ELAPSED (1<<7)
119
120// BDA floppy_media_state bitdefs
121#define FMS_DRIVE_STATE_MASK (0x07)
122#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
123#define FMS_DOUBLE_STEPPING (1<<5)
124#define FMS_DATA_RATE_MASK (0xc0)
125
Kevin O'Connor6f702dd2010-01-28 20:35:21 -0500126// Bit definitions for kbd_flag[0123]
127#define KF0_RSHIFT (1<<0)
128#define KF0_LSHIFT (1<<1)
129#define KF0_CTRLACTIVE (1<<2)
130#define KF0_ALTACTIVE (1<<3)
131#define KF0_SCROLLACTIVE (1<<4)
132#define KF0_NUMACTIVE (1<<5)
133#define KF0_CAPSACTIVE (1<<6)
134
135#define KF1_LCTRL (1<<0)
136#define KF1_LALT (1<<1)
137#define KF1_PAUSEACTIVE (1<<3)
138#define KF1_SCROLL (1<<4)
139#define KF1_NUM (1<<5)
140#define KF1_CAPS (1<<6)
141
142#define KF2_LAST_E1 (1<<0)
143#define KF2_LAST_E0 (1<<1)
144#define KF2_RCTRL (1<<2)
145#define KF2_RALT (1<<3)
146#define KF2_101KBD (1<<4)
147
148#define KF3_SCROLL_LED (1<<0)
149#define KF3_NUM_LED (1<<1)
150#define KF3_CAPS_LED (1<<2)
151#define KF3_CMD_PENDING (1<<6)
152
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500153// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500154#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400155 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500156#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400157 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500158#define CLEARBITS_BDA(var, val) do { \
159 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
160 SET_BDA(var, (__val & ~(val))); \
161 } while (0)
162#define SETBITS_BDA(var, val) do { \
163 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
164 SET_BDA(var, (__val | (val))); \
165 } while (0)
166
167
168/****************************************************************
169 * Extended Bios Data Area (EBDA)
170 ****************************************************************/
171
Kevin O'Connor609da232008-12-28 23:18:57 -0500172// DPTE definition
173struct dpte_s {
174 u16 iobase1;
175 u16 iobase2;
176 u8 prefix;
177 u8 unused;
178 u8 irq;
179 u8 blkcount;
180 u8 dma;
181 u8 pio;
182 u16 options;
183 u16 reserved;
184 u8 revision;
185 u8 checksum;
186};
187
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500188// ElTorito Device Emulation data
189struct cdemu_s {
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400190 struct drive_s *emulated_drive;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500191 u32 ilba;
192 u16 buffer_segment;
193 u16 load_segment;
194 u16 sector_count;
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400195 u8 active;
196 u8 media;
197 u8 emulated_extdrive;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500198
199 // Virtual device
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400200 struct chs_s lchs;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500201};
202
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400203struct fdpt_s {
204 u16 cylinders;
205 u8 heads;
206 u8 a0h_signature;
207 u8 phys_sectors;
208 u16 precompensation;
209 u8 reserved;
210 u8 drive_control_byte;
211 u16 phys_cylinders;
212 u8 phys_heads;
213 u16 landing_zone;
214 u8 sectors;
215 u8 checksum;
216} PACKED;
217
Kevin O'Connor84a4d4b2010-02-11 22:32:12 -0500218struct usbkeyinfo {
219 union {
220 struct {
221 u8 modifiers;
222 u8 repeatcount;
223 u8 keys[6];
224 };
225 u64 data;
226 };
227};
228
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500229struct extended_bios_data_area_s {
230 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500231 u8 reserved1[0x21];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400232 struct segoff_s far_call_pointer;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500233 u8 mouse_flag1;
234 u8 mouse_flag2;
235 u8 mouse_data[0x08];
236 // 0x30
237 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500238
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500239 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400240 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500241
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400242 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500243 u8 other2[0xC4];
244
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500245 // 0x121 - Begin custom storage.
Kevin O'Connor84a4d4b2010-02-11 22:32:12 -0500246 struct usbkeyinfo usbkey_last;
247
Kevin O'Connorad901592009-12-13 11:25:25 -0500248 int RTCusers;
Kevin O'Connor3b897192008-07-20 10:08:59 -0400249
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500250 // El Torito Emulation data
251 struct cdemu_s cdemu;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500252
Kevin O'Connor609da232008-12-28 23:18:57 -0500253 // Buffer for disk DPTE table
254 struct dpte_s dpte;
255
256 // Locks for removable devices
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400257 u8 cdrom_locks[CONFIG_MAX_EXTDRIVE];
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400258
Kevin O'Connorc659fde2008-12-28 23:43:20 -0500259 u16 boot_sequence;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500260
Kevin O'Connor7f343092009-01-01 18:31:11 -0500261 // Stack space available for code that needs it.
262 u8 extra_stack[512] __aligned(8);
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400263
264 u8 cdemu_buf[2048 * !!CONFIG_CDROM_EMU];
Kevin O'Connored128492008-03-11 11:14:59 -0400265} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500266
Kevin O'Connor49553a42009-05-17 10:31:34 -0400267// The initial size and location of EBDA
268#define EBDA_SIZE_START \
269 DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
270#define EBDA_SEGMENT_START \
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400271 FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
Kevin O'Connor49553a42009-05-17 10:31:34 -0400272
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500273// Accessor functions
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500274static inline u16 get_ebda_seg(void) {
Kevin O'Connor08815372008-12-29 21:16:31 -0500275 return GET_BDA(ebda_seg);
276}
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500277static inline struct extended_bios_data_area_s *
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500278get_ebda_ptr(void)
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500279{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500280 ASSERT32FLAT();
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500281 return MAKE_FLATPTR(get_ebda_seg(), 0);
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500282}
Kevin O'Connor08815372008-12-29 21:16:31 -0500283#define GET_EBDA2(eseg, var) \
284 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
285#define SET_EBDA2(eseg, var, val) \
286 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor7f343092009-01-01 18:31:11 -0500287#define GET_EBDA(var) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500288 GET_EBDA2(get_ebda_seg(), var)
Kevin O'Connor7f343092009-01-01 18:31:11 -0500289#define SET_EBDA(var, val) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500290 SET_EBDA2(get_ebda_seg(), var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500291
Kevin O'Connor7f343092009-01-01 18:31:11 -0500292#define EBDA_OFFSET_TOP_STACK \
293 offsetof(struct extended_bios_data_area_s, extra_stack[ \
294 FIELD_SIZEOF(struct extended_bios_data_area_s \
295 , extra_stack)])
296
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500297
298/****************************************************************
Kevin O'Connor15157a32008-12-13 11:10:37 -0500299 * Global variables
300 ****************************************************************/
301
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500302#if MODE16 == 0 && MODESEGMENT == 1
303// In 32bit segmented mode %cs may not be readable and the code may be
304// relocated. The entry code sets up %gs with a readable segment and
305// the code offset can be determined by get_global_offset().
306#define GLOBAL_SEGREG GS
307static inline u32 __attribute_const get_global_offset(void) {
308 u32 ret;
309 asm(" calll 1f\n"
310 "1:popl %0\n"
311 " subl $1b, %0"
312 : "=r"(ret));
313 return ret;
314}
315#else
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500316#define GLOBAL_SEGREG CS
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500317static inline u32 __attribute_const get_global_offset(void) {
318 return 0;
319}
320#endif
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500321static inline u16 get_global_seg(void) {
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500322 return GET_SEG(GLOBAL_SEGREG);
323}
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500324#define GET_GLOBAL(var) \
325 GET_VAR(GLOBAL_SEGREG, *(typeof(&(var)))((void*)&(var) \
326 + get_global_offset()))
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400327#define SET_GLOBAL(var, val) do { \
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500328 ASSERT32FLAT(); \
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400329 (var) = (val); \
Kevin O'Connor609da232008-12-28 23:18:57 -0500330 } while (0)
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500331#if MODESEGMENT
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400332#define ADJUST_GLOBAL_PTR(var) (var)
333#else
334#define ADJUST_GLOBAL_PTR(var) ((typeof(var))((void*)var - BUILD_BIOS_ADDR))
335#endif
Kevin O'Connor15157a32008-12-13 11:10:37 -0500336
337
338/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500339 * Bios Config Table
340 ****************************************************************/
341
342struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500343 u16 size;
344 u8 model;
345 u8 submodel;
346 u8 biosrev;
347 u8 feature1, feature2, feature3, feature4, feature5;
348} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500349
Kevin O'Connor30853762009-01-17 18:49:20 -0500350extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500351
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500352#endif // __BIOSVAR_H