|
|
1.1 root 1: // Variable layouts of bios.
2: //
1.1.1.4 root 3: // Copyright (C) 2008-2010 Kevin O'Connor <[email protected]>
1.1 root 4: //
5: // This file may be distributed under the terms of the GNU LGPLv3 license.
6: #ifndef __BIOSVAR_H
7: #define __BIOSVAR_H
8:
9: #include "types.h" // u8
10: #include "farptr.h" // GET_FARVAR
11: #include "config.h" // CONFIG_*
12: #include "disk.h" // struct chs_s
13:
14:
15: /****************************************************************
16: * Interupt vector table
17: ****************************************************************/
18:
19: struct rmode_IVT {
20: struct segoff_s ivec[256];
21: };
22:
23: #define GET_IVT(vector) \
24: GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
25: #define SET_IVT(vector, segoff) \
26: SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
27:
1.1.1.4 root 28: #define FUNC16(func) ({ \
29: ASSERT32FLAT(); \
30: extern void func (void); \
31: SEGOFF(SEG_BIOS, (u32)func - BUILD_BIOS_ADDR); \
32: })
33:
1.1 root 34:
35: /****************************************************************
36: * Bios Data Area (BDA)
37: ****************************************************************/
38:
39: struct bios_data_area_s {
40: // 40:00
41: u16 port_com[4];
42: u16 port_lpt[3];
43: 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;
50: u8 kbd_flag0;
51: u8 kbd_flag1;
52: 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];
63: u8 video_mode;
64: u16 video_cols;
65: u16 video_pagesize;
66: u16 video_pagestart;
67: // 40:50
68: u16 cursor_pos[8];
69: // 40:60
70: u16 cursor_type;
71: u8 video_page;
72: u16 crtc_address;
73: u8 video_msr;
74: u8 video_pal;
75: struct segoff_s jump;
76: u8 other_6b;
77: u32 timer_counter;
78: // 40:70
79: u8 timer_rollover;
80: u8 break_flag;
81: u16 soft_reset_flag;
82: u8 disk_last_status;
83: u8 hdcount;
84: u8 disk_control_byte;
85: u8 port_disk;
86: u8 lpt_timeout[4];
87: u8 com_timeout[4];
88: // 40:80
89: u16 kbd_buf_start_offset;
90: u16 kbd_buf_end_offset;
91: u8 video_rows;
92: u16 char_height;
93: u8 video_ctl;
94: u8 video_switches;
95: u8 modeset_ctl;
96: u8 dcc_index;
97: u8 floppy_last_data_rate;
98: u8 disk_status_controller;
99: u8 disk_error_controller;
100: u8 disk_interrupt_flag;
101: u8 floppy_harddisk_info;
102: // 40:90
103: u8 floppy_media_state[4];
104: u8 floppy_track[2];
105: u8 kbd_flag2;
106: u8 kbd_led;
107: struct segoff_s user_wait_complete_flag;
108: u32 user_wait_timeout;
109: // 40:A0
110: u8 rtc_wait_flag;
111: u8 other_a1[7];
112: struct segoff_s video_savetable;
113: u8 other_ac[4];
114: // 40:B0
1.1.1.5 ! root 115: u8 other_b0[9];
! 116: u8 vbe_flag;
1.1 root 117: u16 vbe_mode;
118: } PACKED;
119:
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
134: #define GET_BDA(var) \
135: GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
136: #define SET_BDA(var, val) \
137: SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
138: #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:
152: // DPTE definition
153: struct 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:
168: // ElTorito Device Emulation data
169: struct cdemu_s {
1.1.1.3 root 170: struct drive_s *emulated_drive_gf;
1.1 root 171: u32 ilba;
172: u16 buffer_segment;
173: u16 load_segment;
174: u16 sector_count;
175: u8 active;
176: u8 media;
177: u8 emulated_extdrive;
178:
179: // Virtual device
180: struct chs_s lchs;
181: };
182:
183: struct fdpt_s {
184: u16 cylinders;
185: u8 heads;
186: u8 a0h_signature;
187: u8 phys_sectors;
188: u16 precompensation;
189: u8 reserved;
190: u8 drive_control_byte;
191: u16 phys_cylinders;
192: u8 phys_heads;
193: u16 landing_zone;
194: u8 sectors;
195: u8 checksum;
196: } PACKED;
197:
1.1.1.3 root 198: struct usbkeyinfo {
199: union {
200: struct {
201: u8 modifiers;
202: u8 repeatcount;
203: u8 keys[6];
204: };
205: u64 data;
206: };
207: };
208:
1.1 root 209: struct extended_bios_data_area_s {
210: u8 size;
211: u8 reserved1[0x21];
212: struct segoff_s far_call_pointer;
213: u8 mouse_flag1;
214: u8 mouse_flag2;
215: u8 mouse_data[0x08];
216: // 0x30
217: u8 other1[0x0d];
218:
219: // 0x3d
220: struct fdpt_s fdpt[2];
221:
222: // 0x5d
223: u8 other2[0xC4];
224:
225: // 0x121 - Begin custom storage.
226: u8 ps2ctr;
1.1.1.3 root 227: struct usbkeyinfo usbkey_last;
228:
1.1 root 229: int RTCusers;
230:
231: // El Torito Emulation data
232: struct cdemu_s cdemu;
233:
234: // Buffer for disk DPTE table
235: struct dpte_s dpte;
236:
237: // Locks for removable devices
238: u8 cdrom_locks[CONFIG_MAX_EXTDRIVE];
239:
240: u16 boot_sequence;
241:
1.1.1.5 ! root 242: /* TSC emulation timekeepers */
! 243: u64 tsc_8254;
! 244: int last_tsc_8254;
! 245:
1.1 root 246: // Stack space available for code that needs it.
247: u8 extra_stack[512] __aligned(8);
248: } PACKED;
249:
250: // The initial size and location of EBDA
251: #define EBDA_SIZE_START \
252: DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
253: #define EBDA_SEGMENT_START \
254: FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
255:
256: // Accessor functions
1.1.1.2 root 257: static inline u16 get_ebda_seg(void) {
1.1 root 258: return GET_BDA(ebda_seg);
259: }
260: static inline struct extended_bios_data_area_s *
1.1.1.2 root 261: get_ebda_ptr(void)
1.1 root 262: {
1.1.1.2 root 263: ASSERT32FLAT();
1.1 root 264: return MAKE_FLATPTR(get_ebda_seg(), 0);
265: }
266: #define GET_EBDA2(eseg, var) \
267: GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
268: #define SET_EBDA2(eseg, var, val) \
269: SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
270: #define GET_EBDA(var) \
271: GET_EBDA2(get_ebda_seg(), var)
272: #define SET_EBDA(var, val) \
273: SET_EBDA2(get_ebda_seg(), var, (val))
274:
275: #define EBDA_OFFSET_TOP_STACK \
276: offsetof(struct extended_bios_data_area_s, extra_stack[ \
277: FIELD_SIZEOF(struct extended_bios_data_area_s \
278: , extra_stack)])
279:
280:
281: /****************************************************************
282: * Global variables
283: ****************************************************************/
284:
1.1.1.2 root 285: #if MODE16 == 0 && MODESEGMENT == 1
286: // In 32bit segmented mode %cs may not be readable and the code may be
287: // relocated. The entry code sets up %gs with a readable segment and
288: // the code offset can be determined by get_global_offset().
289: #define GLOBAL_SEGREG GS
290: static inline u32 __attribute_const get_global_offset(void) {
291: u32 ret;
292: asm(" calll 1f\n"
293: "1:popl %0\n"
294: " subl $1b, %0"
295: : "=r"(ret));
296: return ret;
297: }
298: #else
1.1 root 299: #define GLOBAL_SEGREG CS
1.1.1.2 root 300: static inline u32 __attribute_const get_global_offset(void) {
301: return 0;
302: }
303: #endif
304: static inline u16 get_global_seg(void) {
1.1 root 305: return GET_SEG(GLOBAL_SEGREG);
306: }
1.1.1.2 root 307: #define GET_GLOBAL(var) \
308: GET_VAR(GLOBAL_SEGREG, *(typeof(&(var)))((void*)&(var) \
309: + get_global_offset()))
1.1 root 310: #define SET_GLOBAL(var, val) do { \
1.1.1.2 root 311: ASSERT32FLAT(); \
1.1 root 312: (var) = (val); \
313: } while (0)
1.1.1.2 root 314: #if MODESEGMENT
1.1.1.3 root 315: #define GLOBALFLAT2GLOBAL(var) ((typeof(var))((void*)(var) - BUILD_BIOS_ADDR))
1.1 root 316: #else
1.1.1.3 root 317: #define GLOBALFLAT2GLOBAL(var) (var)
1.1 root 318: #endif
1.1.1.3 root 319: // Access a "flat" pointer known to point to the f-segment.
320: #define GET_GLOBALFLAT(var) GET_GLOBAL(*GLOBALFLAT2GLOBAL(&(var)))
1.1 root 321:
322:
323: /****************************************************************
324: * Bios Config Table
325: ****************************************************************/
326:
327: struct bios_config_table_s {
328: u16 size;
329: u8 model;
330: u8 submodel;
331: u8 biosrev;
332: u8 feature1, feature2, feature3, feature4, feature5;
333: } PACKED;
334:
335: extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1);
336:
337: #endif // __BIOSVAR_H
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.