blob: fceb8762c1568517d695ba9994160cd8c65b9959 [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//
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_*
12
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050013
14/****************************************************************
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050015 * Interupt vector table
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050016 ****************************************************************/
17
Kevin O'Connor30853762009-01-17 18:49:20 -050018struct rmode_IVT {
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050019 union {
20 struct {
21 u16 offset;
22 u16 seg;
23 };
24 u32 segoff;
Kevin O'Connor30853762009-01-17 18:49:20 -050025 } ivec[256];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050026};
27
Kevin O'Connor3d292132009-05-06 23:20:03 -040028#define GET_IVT(vector) \
29 GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050030#define SET_IVT(vector, seg, off) \
Kevin O'Connor30853762009-01-17 18:49:20 -050031 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector].segoff, ((seg) << 16) | (off))
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050032
33
34/****************************************************************
35 * Bios Data Area (BDA)
36 ****************************************************************/
37
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050038struct bios_data_area_s {
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050039 // 40:00
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050040 u16 port_com[4];
41 u16 port_lpt[3];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050042 u16 ebda_seg;
43 // 40:10
44 u16 equipment_list_flags;
45 u8 pad1;
46 u16 mem_size_kb;
47 u8 pad2;
48 u8 ps2_ctrl_flag;
Kevin O'Connor4b60c002008-02-25 22:29:55 -050049 u8 kbd_flag0;
50 u8 kbd_flag1;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050051 u8 alt_keypad;
52 u16 kbd_buf_head;
53 u16 kbd_buf_tail;
54 // 40:1e
55 u8 kbd_buf[32];
56 u8 floppy_recalibration_status;
57 u8 floppy_motor_status;
58 // 40:40
59 u8 floppy_motor_counter;
60 u8 floppy_last_status;
61 u8 floppy_return_status[7];
Kevin O'Connor6723d032008-10-25 14:37:29 -040062 u8 video_mode;
63 u16 video_cols;
64 u16 video_pagesize;
65 u16 video_pagestart;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050066 // 40:50
Kevin O'Connor6723d032008-10-25 14:37:29 -040067 u16 cursor_pos[8];
Kevin O'Connord427a3f2008-03-01 14:02:41 -050068 // 40:60
Kevin O'Connor6723d032008-10-25 14:37:29 -040069 u16 cursor_type;
70 u8 video_page;
71 u16 crtc_address;
72 u8 video_msr;
73 u8 video_pal;
Kevin O'Connor18e38b22008-12-10 20:40:13 -050074 u16 jump_ip;
75 u16 jump_cs;
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'Connorf076a3e2008-02-25 22:25:15 -0500105 u8 kbd_mode;
106 u8 kbd_led;
107 u32 ptr_user_wait_complete_flag;
108 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];
112 u16 video_savetable_ptr;
113 u16 video_savetable_seg;
114 u8 other_ac[4];
115 // 40:B0
116 u8 other_b0[10];
117 u16 vbe_mode;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500118} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500119
120// BDA floppy_recalibration_status bitdefs
121#define FRS_TIMEOUT (1<<7)
122
123// BDA rtc_wait_flag bitdefs
124#define RWS_WAIT_PENDING (1<<0)
125#define RWS_WAIT_ELAPSED (1<<7)
126
127// BDA floppy_media_state bitdefs
128#define FMS_DRIVE_STATE_MASK (0x07)
129#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
130#define FMS_DOUBLE_STEPPING (1<<5)
131#define FMS_DATA_RATE_MASK (0xc0)
132
133// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500134#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400135 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500136#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400137 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500138#define CLEARBITS_BDA(var, val) do { \
139 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
140 SET_BDA(var, (__val & ~(val))); \
141 } while (0)
142#define SETBITS_BDA(var, val) do { \
143 typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
144 SET_BDA(var, (__val | (val))); \
145 } while (0)
146
147
148/****************************************************************
149 * Extended Bios Data Area (EBDA)
150 ****************************************************************/
151
Kevin O'Connor609da232008-12-28 23:18:57 -0500152// DPTE definition
153struct dpte_s {
154 u16 iobase1;
155 u16 iobase2;
156 u8 prefix;
157 u8 unused;
158 u8 irq;
159 u8 blkcount;
160 u8 dma;
161 u8 pio;
162 u16 options;
163 u16 reserved;
164 u8 revision;
165 u8 checksum;
166};
167
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500168// ElTorito Device Emulation data
169struct cdemu_s {
170 u8 active;
171 u8 media;
172 u8 emulated_drive;
173 u8 controller_index;
174 u16 device_spec;
175 u32 ilba;
176 u16 buffer_segment;
177 u16 load_segment;
178 u16 sector_count;
179
180 // Virtual device
181 u16 heads;
182 u16 cylinders;
183 u16 spt;
184};
185
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400186struct fdpt_s {
187 u16 cylinders;
188 u8 heads;
189 u8 a0h_signature;
190 u8 phys_sectors;
191 u16 precompensation;
192 u8 reserved;
193 u8 drive_control_byte;
194 u16 phys_cylinders;
195 u8 phys_heads;
196 u16 landing_zone;
197 u8 sectors;
198 u8 checksum;
199} PACKED;
200
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500201struct extended_bios_data_area_s {
202 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500203 u8 reserved1[0x21];
204 u32 far_call_pointer;
205 u8 mouse_flag1;
206 u8 mouse_flag2;
207 u8 mouse_data[0x08];
208 // 0x30
209 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500210
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500211 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400212 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500213
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400214 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500215 u8 other2[0xC4];
216
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500217 // 0x121 - Begin custom storage.
Kevin O'Connor3b897192008-07-20 10:08:59 -0400218 u8 ps2ctr;
219
Kevin O'Connor4a16ef62008-12-31 00:09:28 -0500220 // El Torito Emulation data
221 struct cdemu_s cdemu;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500222
Kevin O'Connor609da232008-12-28 23:18:57 -0500223 // Count of transferred sectors and bytes to/from disk
224 u16 sector_count;
225
226 // Buffer for disk DPTE table
227 struct dpte_s dpte;
228
229 // Locks for removable devices
230 u8 cdrom_locks[CONFIG_MAX_ATA_DEVICES];
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400231
Kevin O'Connorc659fde2008-12-28 23:43:20 -0500232 u16 boot_sequence;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500233
Kevin O'Connor7f343092009-01-01 18:31:11 -0500234 // Stack space available for code that needs it.
235 u8 extra_stack[512] __aligned(8);
Kevin O'Connored128492008-03-11 11:14:59 -0400236} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500237
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500238// Accessor functions
Kevin O'Connor08815372008-12-29 21:16:31 -0500239static inline u16 get_ebda_seg() {
240 return GET_BDA(ebda_seg);
241}
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500242static inline struct extended_bios_data_area_s *
243get_ebda_ptr()
244{
245 extern void *__force_link_error__get_ebda_ptr_only_in_32bit();
246 if (MODE16)
247 return __force_link_error__get_ebda_ptr_only_in_32bit();
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500248 return MAKE_FLATPTR(get_ebda_seg(), 0);
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500249}
Kevin O'Connor08815372008-12-29 21:16:31 -0500250#define GET_EBDA2(eseg, var) \
251 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
252#define SET_EBDA2(eseg, var, val) \
253 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor7f343092009-01-01 18:31:11 -0500254#define GET_EBDA(var) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500255 GET_EBDA2(get_ebda_seg(), var)
Kevin O'Connor7f343092009-01-01 18:31:11 -0500256#define SET_EBDA(var, val) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500257 SET_EBDA2(get_ebda_seg(), var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500258
Kevin O'Connor7f343092009-01-01 18:31:11 -0500259#define EBDA_OFFSET_TOP_STACK \
260 offsetof(struct extended_bios_data_area_s, extra_stack[ \
261 FIELD_SIZEOF(struct extended_bios_data_area_s \
262 , extra_stack)])
263
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500264
265/****************************************************************
Kevin O'Connor15157a32008-12-13 11:10:37 -0500266 * Global variables
267 ****************************************************************/
268
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500269#define GLOBAL_SEGREG CS
270static inline u16 get_global_seg() {
271 return GET_SEG(GLOBAL_SEGREG);
272}
273#define GET_GLOBAL(var) \
274 GET_VAR(GLOBAL_SEGREG, (var))
Kevin O'Connora9e286d2009-01-19 15:33:49 -0500275#define SET_GLOBAL(var, val) do { \
276 extern void __force_link_error__set_global_only_in_32bit(); \
277 if (MODE16) \
278 __force_link_error__set_global_only_in_32bit(); \
279 (var) = (val); \
Kevin O'Connor609da232008-12-28 23:18:57 -0500280 } while (0)
Kevin O'Connor15157a32008-12-13 11:10:37 -0500281
282
283/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500284 * Bios Config Table
285 ****************************************************************/
286
287struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500288 u16 size;
289 u8 model;
290 u8 submodel;
291 u8 biosrev;
292 u8 feature1, feature2, feature3, feature4, feature5;
293} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500294
Kevin O'Connor30853762009-01-17 18:49:20 -0500295extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500296
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500297#endif // __BIOSVAR_H