blob: e49a10acc6884af0ed35dc7b4bdb4c278a531903 [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'Connord3140832012-05-13 22:46:12 -040011#include "config.h" // SEG_BDA
Kevin O'Connorb68ac712009-08-09 17:25:19 -040012
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'Connorb68ac712009-08-09 17:25:19 -040019 struct segoff_s ivec[256];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050020};
21
Kevin O'Connor3d292132009-05-06 23:20:03 -040022#define GET_IVT(vector) \
23 GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
Kevin O'Connor9f985422009-09-09 11:34:39 -040024#define SET_IVT(vector, segoff) \
25 SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050026
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040027#define FUNC16(func) ({ \
28 ASSERT32FLAT(); \
29 extern void func (void); \
30 SEGOFF(SEG_BIOS, (u32)func - BUILD_BIOS_ADDR); \
31 })
32
Kevin O'Connor8c0e3722009-01-02 14:19:43 -050033
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'Connor9f985422009-09-09 11:34:39 -040074 struct segoff_s jump;
Kevin O'Connor6723d032008-10-25 14:37:29 -040075 u8 other_6b;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050076 u32 timer_counter;
77 // 40:70
78 u8 timer_rollover;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050079 u8 break_flag;
80 u16 soft_reset_flag;
81 u8 disk_last_status;
Kevin O'Connor4a16ef62008-12-31 00:09:28 -050082 u8 hdcount;
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050083 u8 disk_control_byte;
84 u8 port_disk;
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050085 u8 lpt_timeout[4];
86 u8 com_timeout[4];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050087 // 40:80
88 u16 kbd_buf_start_offset;
89 u16 kbd_buf_end_offset;
Kevin O'Connor6723d032008-10-25 14:37:29 -040090 u8 video_rows;
91 u16 char_height;
92 u8 video_ctl;
93 u8 video_switches;
94 u8 modeset_ctl;
95 u8 dcc_index;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050096 u8 floppy_last_data_rate;
Kevin O'Connor3491e8b2008-02-29 00:22:27 -050097 u8 disk_status_controller;
98 u8 disk_error_controller;
99 u8 disk_interrupt_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500100 u8 floppy_harddisk_info;
101 // 40:90
102 u8 floppy_media_state[4];
Kevin O'Connora3b612e2009-02-07 11:25:29 -0500103 u8 floppy_track[2];
Kevin O'Connor40c0e482009-09-11 02:06:02 -0400104 u8 kbd_flag2;
Kevin O'Connor6704cf92010-03-13 18:51:46 -0500105 u8 kbd_led;
Kevin O'Connor9f985422009-09-09 11:34:39 -0400106 struct segoff_s user_wait_complete_flag;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500107 u32 user_wait_timeout;
108 // 40:A0
109 u8 rtc_wait_flag;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400110 u8 other_a1[7];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400111 struct segoff_s video_savetable;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400112 u8 other_ac[4];
113 // 40:B0
Julian Pidanceta6ad7df2011-12-19 05:07:58 +0000114 u8 other_b0[9];
115 u8 vbe_flag;
Kevin O'Connor3d292132009-05-06 23:20:03 -0400116 u16 vbe_mode;
Kevin O'Connor7af133c2012-06-10 09:18:44 -0400117 u8 other_bc[4];
118 // 40:C0
119 u8 other_c0[4*16];
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500120} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500121
122// BDA floppy_recalibration_status bitdefs
Kevin O'Connor6e529bd2013-03-02 20:30:50 -0500123#define FRS_IRQ (1<<7)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500124
125// BDA rtc_wait_flag bitdefs
126#define RWS_WAIT_PENDING (1<<0)
127#define RWS_WAIT_ELAPSED (1<<7)
128
129// BDA floppy_media_state bitdefs
130#define FMS_DRIVE_STATE_MASK (0x07)
131#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
132#define FMS_DOUBLE_STEPPING (1<<5)
133#define FMS_DATA_RATE_MASK (0xc0)
134
Kevin O'Connorb7ab1782013-07-20 13:06:35 -0400135// Limit of BDA timer_counter field
136#define TICKS_PER_DAY 1573040
137
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500138// Accessor functions
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500139#define GET_BDA(var) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400140 GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
Kevin O'Connor4b60c002008-02-25 22:29:55 -0500141#define SET_BDA(var, val) \
Kevin O'Connor438f6352008-03-30 21:46:53 -0400142 SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
Kevin O'Connore51316d2012-06-10 09:09:22 -0400143
144// Helper function to set the bits of the equipment_list_flags variable.
145static inline void set_equipment_flags(u16 clear, u16 set) {
146 u16 eqf = GET_BDA(equipment_list_flags);
147 SET_BDA(equipment_list_flags, (eqf & ~clear) | set);
148}
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500149
150
151/****************************************************************
152 * Extended Bios Data Area (EBDA)
153 ****************************************************************/
154
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400155struct fdpt_s {
156 u16 cylinders;
157 u8 heads;
158 u8 a0h_signature;
159 u8 phys_sectors;
160 u16 precompensation;
161 u8 reserved;
162 u8 drive_control_byte;
163 u16 phys_cylinders;
164 u8 phys_heads;
165 u16 landing_zone;
166 u8 sectors;
167 u8 checksum;
168} PACKED;
169
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500170struct extended_bios_data_area_s {
171 u8 size;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500172 u8 reserved1[0x21];
Kevin O'Connor9f985422009-09-09 11:34:39 -0400173 struct segoff_s far_call_pointer;
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500174 u8 mouse_flag1;
175 u8 mouse_flag2;
176 u8 mouse_data[0x08];
177 // 0x30
178 u8 other1[0x0d];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500179
Kevin O'Connor4d6dbc62008-03-02 08:43:44 -0500180 // 0x3d
Kevin O'Connor9f0d94d2008-04-13 17:25:30 -0400181 struct fdpt_s fdpt[2];
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500182
Kevin O'Connor56a506d2008-03-29 13:15:36 -0400183 // 0x5d
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500184 u8 other2[0xC4];
185
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500186 // 0x121 - Begin custom storage.
Kevin O'Connored128492008-03-11 11:14:59 -0400187} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500188
Kevin O'Connor49553a42009-05-17 10:31:34 -0400189// The initial size and location of EBDA
190#define EBDA_SIZE_START \
191 DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
192#define EBDA_SEGMENT_START \
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400193 FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
Kevin O'Connor49553a42009-05-17 10:31:34 -0400194
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500195// Accessor functions
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500196static inline u16 get_ebda_seg(void) {
Kevin O'Connor08815372008-12-29 21:16:31 -0500197 return GET_BDA(ebda_seg);
198}
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500199static inline struct extended_bios_data_area_s *
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500200get_ebda_ptr(void)
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500201{
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500202 ASSERT32FLAT();
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500203 return MAKE_FLATPTR(get_ebda_seg(), 0);
Kevin O'Connor4d7c37e2008-12-26 23:50:17 -0500204}
Kevin O'Connor4bc49972012-05-13 22:58:08 -0400205#define GET_EBDA(eseg, var) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500206 GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
Kevin O'Connor4bc49972012-05-13 22:58:08 -0400207#define SET_EBDA(eseg, var, val) \
Kevin O'Connor08815372008-12-29 21:16:31 -0500208 SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500209
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500210
211/****************************************************************
Kevin O'Connor15157a32008-12-13 11:10:37 -0500212 * Global variables
213 ****************************************************************/
214
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500215#if MODE16 == 0 && MODESEGMENT == 1
216// In 32bit segmented mode %cs may not be readable and the code may be
217// relocated. The entry code sets up %gs with a readable segment and
218// the code offset can be determined by get_global_offset().
219#define GLOBAL_SEGREG GS
220static inline u32 __attribute_const get_global_offset(void) {
221 u32 ret;
222 asm(" calll 1f\n"
223 "1:popl %0\n"
224 " subl $1b, %0"
225 : "=r"(ret));
226 return ret;
227}
228#else
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500229#define GLOBAL_SEGREG CS
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500230static inline u32 __attribute_const get_global_offset(void) {
231 return 0;
232}
233#endif
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500234static inline u16 get_global_seg(void) {
Kevin O'Connor8b267cb2009-01-19 19:25:21 -0500235 return GET_SEG(GLOBAL_SEGREG);
236}
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500237#define GET_GLOBAL(var) \
238 GET_VAR(GLOBAL_SEGREG, *(typeof(&(var)))((void*)&(var) \
239 + get_global_offset()))
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400240#define SET_GLOBAL(var, val) do { \
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500241 ASSERT32FLAT(); \
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400242 (var) = (val); \
Kevin O'Connor609da232008-12-28 23:18:57 -0500243 } while (0)
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500244#if MODESEGMENT
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500245#define GLOBALFLAT2GLOBAL(var) ((typeof(var))((void*)(var) - BUILD_BIOS_ADDR))
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400246#else
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500247#define GLOBALFLAT2GLOBAL(var) (var)
Kevin O'Connor77d227b2009-10-22 21:48:39 -0400248#endif
Kevin O'Connor8f469b92010-02-28 01:28:11 -0500249// Access a "flat" pointer known to point to the f-segment.
250#define GET_GLOBALFLAT(var) GET_GLOBAL(*GLOBALFLAT2GLOBAL(&(var)))
Kevin O'Connor15157a32008-12-13 11:10:37 -0500251
252
253/****************************************************************
Kevin O'Connor46b82622012-05-13 12:10:30 -0400254 * "Low" memory variables
255 ****************************************************************/
256
Kevin O'Connorc9243442013-02-17 13:58:28 -0500257extern u8 _zonelow_seg, zonelow_base[];
258#define SEG_LOW ((u32)&_zonelow_seg)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400259
260#if MODESEGMENT
261#define GET_LOW(var) GET_FARVAR(SEG_LOW, (var))
262#define SET_LOW(var, val) SET_FARVAR(SEG_LOW, (var), (val))
Kevin O'Connorc9243442013-02-17 13:58:28 -0500263#define LOWFLAT2LOW(var) ((typeof(var))((void*)(var) - (u32)zonelow_base))
Kevin O'Connor46b82622012-05-13 12:10:30 -0400264#else
265#define GET_LOW(var) (var)
266#define SET_LOW(var, val) do { (var) = (val); } while (0)
Kevin O'Connor4f6563e2012-05-19 22:42:51 -0400267#define LOWFLAT2LOW(var) (var)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400268#endif
Kevin O'Connor4f6563e2012-05-19 22:42:51 -0400269#define GET_LOWFLAT(var) GET_LOW(*LOWFLAT2LOW(&(var)))
270#define SET_LOWFLAT(var, val) SET_LOW(*LOWFLAT2LOW(&(var)), (val))
Kevin O'Connor46b82622012-05-13 12:10:30 -0400271
272
273/****************************************************************
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500274 * Bios Config Table
275 ****************************************************************/
276
277struct bios_config_table_s {
Kevin O'Connor44c631d2008-03-02 11:24:36 -0500278 u16 size;
279 u8 model;
280 u8 submodel;
281 u8 biosrev;
282 u8 feature1, feature2, feature3, feature4, feature5;
283} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500284
Kevin O'Connor30853762009-01-17 18:49:20 -0500285extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500286
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500287#endif // __BIOSVAR_H