blob: 983d28fb9803e49ad6c44f30abe47bf0ce0bbd99 [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'Connorf076a3e2008-02-25 22:25:15 -0500100 u8 kbd_led;
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
126// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500127#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400128 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500129#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400130 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500131#define CLEARBITS_BDA(var, val) do { \
132 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
133 SET_BDA(var, (__val & ~(val))); \
134 } while (0)
135#define SETBITS_BDA(var, val) do { \
136 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
137 SET_BDA(var, (__val | (val))); \
138 } while (0)
139
140
141/****************************************************************
142 * Extended Bios Data Area (EBDA)
143 ****************************************************************/
144
Kevin O'Connor609da232008-12-28 23:18:57 -0500145// 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
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500161// ElTorito Device Emulation data
162struct cdemu_s {
163 u8 active;
164 u8 media;
Kevin O'Connor669e6442009-08-11 22:36:30 -0400165 u8 emulated_extdrive;
166 u8 emulated_driveid;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500167 u32 ilba;
168 u16 buffer_segment;
169 u16 load_segment;
170 u16 sector_count;
171
172 // Virtual device
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400173 struct chs_s lchs;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500174};
175
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400176struct fdpt_s {
177 u16 cylinders;
178 u8 heads;
179 u8 a0h_signature;
180 u8 phys_sectors;
181 u16 precompensation;
182 u8 reserved;
183 u8 drive_control_byte;
184 u16 phys_cylinders;
185 u8 phys_heads;
186 u16 landing_zone;
187 u8 sectors;
188 u8 checksum;
189} PACKED;
190
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500191struct extended_bios_data_area_s {
192 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500193 u8 reserved1[0x21];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400194 struct segoff_s far_call_pointer;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500195 u8 mouse_flag1;
196 u8 mouse_flag2;
197 u8 mouse_data[0x08];
198 // 0x30
199 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500200
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500201 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400202 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500203
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400204 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500205 u8 other2[0xC4];
206
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500207 // 0x121 - Begin custom storage.
Kevin O'Connor3b897192008-07-20 10:08:59 -0400208 u8 ps2ctr;
209
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500210 // El Torito Emulation data
211 struct cdemu_s cdemu;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500212
Kevin O'Connor609da232008-12-28 23:18:57 -0500213 // Buffer for disk DPTE table
214 struct dpte_s dpte;
215
216 // Locks for removable devices
Kevin O'Connorc892b132009-08-11 21:59:37 -0400217 u8 cdrom_locks[CONFIG_MAX_DRIVES];
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400218
Kevin O'Connorc659fde2008-12-28 23:43:20 -0500219 u16 boot_sequence;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500220
Kevin O'Connor7f343092009-01-01 18:31:11 -0500221 // Stack space available for code that needs it.
222 u8 extra_stack[512] __aligned(8);
Kevin O'Connorb68ac712009-08-09 17:25:19 -0400223
224 u8 cdemu_buf[2048 * !!CONFIG_CDROM_EMU];
Kevin O'Connored128492008-03-11 11:14:59 -0400225} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500226
Kevin O'Connor49553a42009-05-17 10:31:34 -0400227// The initial size and location of EBDA
228#define EBDA_SIZE_START \
229 DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
230#define EBDA_SEGMENT_START \
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400231 FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
Kevin O'Connor49553a42009-05-17 10:31:34 -0400232
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500233// Accessor functions
Kevin O'Connor08815372008-12-29 21:16:31 -0500234static inline u16 get_ebda_seg() {
235 return GET_BDA(ebda_seg);
236}
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500237static inline struct extended_bios_data_area_s *
238get_ebda_ptr()
239{
Kevin O'Connor0b60a062009-06-15 23:03:05 -0400240 ASSERT32();
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500241 return MAKE_FLATPTR(get_ebda_seg(), 0);
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500242}
Kevin O'Connor08815372008-12-29 21:16:31 -0500243#define GET_EBDA2(eseg, var) \
244 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
245#define SET_EBDA2(eseg, var, val) \
246 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor7f343092009-01-01 18:31:11 -0500247#define GET_EBDA(var) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500248 GET_EBDA2(get_ebda_seg(), var)
Kevin O'Connor7f343092009-01-01 18:31:11 -0500249#define SET_EBDA(var, val) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500250 SET_EBDA2(get_ebda_seg(), var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500251
Kevin O'Connor7f343092009-01-01 18:31:11 -0500252#define EBDA_OFFSET_TOP_STACK \
253 offsetof(struct extended_bios_data_area_s, extra_stack[ \
254 FIELD_SIZEOF(struct extended_bios_data_area_s \
255 , extra_stack)])
256
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500257
258/****************************************************************
Kevin O'Connor15157a32008-12-13 11:10:37 -0500259 * Global variables
260 ****************************************************************/
261
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500262#define GLOBAL_SEGREG CS
263static inline u16 get_global_seg() {
264 return GET_SEG(GLOBAL_SEGREG);
265}
266#define GET_GLOBAL(var) \
267 GET_VAR(GLOBAL_SEGREG, (var))
Kevin O'Connora9e286d2009-01-19 15:33:49 -0500268#define SET_GLOBAL(var, val) do { \
Kevin O'Connor0b60a062009-06-15 23:03:05 -0400269 ASSERT32(); \
Kevin O'Connora9e286d2009-01-19 15:33:49 -0500270 (var) = (val); \
Kevin O'Connor609da232008-12-28 23:18:57 -0500271 } while (0)
Kevin O'Connor15157a32008-12-13 11:10:37 -0500272
273
274/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500275 * Bios Config Table
276 ****************************************************************/
277
278struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500279 u16 size;
280 u8 model;
281 u8 submodel;
282 u8 biosrev;
283 u8 feature1, feature2, feature3, feature4, feature5;
284} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500285
Kevin O'Connor30853762009-01-17 18:49:20 -0500286extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500287
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500288#endif // __BIOSVAR_H