037cdab8c8d7703519d5ab3d364a9a0ba90cd129
[seabios.git] / src / biosvar.h
1 // Variable layouts of bios.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU GPLv3 license.
6 #ifndef __BIOSVAR_H
7 #define __BIOSVAR_H
8
9 #include "types.h" // u8
10 #include "farptr.h" // SET_SEG
11
12
13 /****************************************************************
14  * Bios Data Area (BDA)
15  ****************************************************************/
16
17 struct ivec {
18     u16 offset;
19     u16 seg;
20 };
21
22 struct bios_data_area_s {
23     // 00:00
24     struct ivec ivecs[256];
25     // 30:00
26 //    u8 stack[256];
27     // 40:00
28     u16 port_com[4];
29     u16 port_lpt[3];
30     u16 ebda_seg;
31     // 40:10
32     u16 equipment_list_flags;
33     u8 pad1;
34     u16 mem_size_kb;
35     u8 pad2;
36     u8 ps2_ctrl_flag;
37     u8 kbd_flag0;
38     u8 kbd_flag1;
39     u8 alt_keypad;
40     u16 kbd_buf_head;
41     u16 kbd_buf_tail;
42     // 40:1e
43     u8 kbd_buf[32];
44     u8 floppy_recalibration_status;
45     u8 floppy_motor_status;
46     // 40:40
47     u8 floppy_motor_counter;
48     u8 floppy_last_status;
49     u8 floppy_return_status[7];
50     u8 other1[0x7];
51     // 40:50
52     u8 other2[0x1c];
53     // 40:6c
54     u32 timer_counter;
55     // 40:70
56     u8 timer_rollover;
57     u8 other4[0x07];
58     u8 lpt_timeout[4];
59     u8 com_timeout[4];
60     // 40:80
61     u16 kbd_buf_start_offset;
62     u16 kbd_buf_end_offset;
63     u8 other5[7];
64     u8 floppy_last_data_rate;
65     u8 other6[3];
66     u8 floppy_harddisk_info;
67     // 40:90
68     u8 floppy_media_state[4];
69     u8 floppy_track0;
70     u8 floppy_track1;
71     u8 kbd_mode;
72     u8 kbd_led;
73     u32 ptr_user_wait_complete_flag;
74     u32 user_wait_timeout;
75     // 40:A0
76     u8 rtc_wait_flag;
77 } __attribute__((packed));
78
79 // BDA floppy_recalibration_status bitdefs
80 #define FRS_TIMEOUT (1<<7)
81
82 // BDA rtc_wait_flag bitdefs
83 #define RWS_WAIT_PENDING (1<<0)
84 #define RWS_WAIT_ELAPSED (1<<7)
85
86 // BDA floppy_media_state bitdefs
87 #define FMS_DRIVE_STATE_MASK        (0x07)
88 #define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4)
89 #define FMS_DOUBLE_STEPPING         (1<<5)
90 #define FMS_DATA_RATE_MASK          (0xc0)
91
92 // Accessor functions
93 #define GET_BDA(var) \
94     GET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var)
95 #define SET_BDA(var, val) \
96     SET_FARVAR(0x0000, ((struct bios_data_area_s *)0)->var, (val))
97 #define CLEARBITS_BDA(var, val) do {                                    \
98         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
99         SET_BDA(var, (__val & ~(val)));                                 \
100     } while (0)
101 #define SETBITS_BDA(var, val) do {                                      \
102         typeof(((struct bios_data_area_s *)0)->var) __val = GET_BDA(var); \
103         SET_BDA(var, (__val | (val)));                                  \
104     } while (0)
105
106
107 /****************************************************************
108  * Extended Bios Data Area (EBDA)
109  ****************************************************************/
110
111 struct extended_bios_data_area_s {
112     u8 size;
113     u8 other1[0x3c];
114
115     // FDPT - Can be splitted in data members if needed
116     u8 fdpt0[0x10];
117     u8 fdpt1[0x10];
118
119     u8 other2[0xC4];
120
121     // ATA Driver data
122     //ata_t   ata;
123
124 #if BX_ELTORITO_BOOT
125     // El Torito Emulation data
126     cdemu_t cdemu;
127 #endif // BX_ELTORITO_BOOT
128 };
129
130 // Accessor functions
131 #define GET_EBDA(var) \
132     GET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var)
133 #define SET_EBDA(var, val) \
134     SET_FARVAR(EBDA_SEG, ((struct extended_bios_data_area_s *)0)->var, (val))
135
136
137 /****************************************************************
138  * Initial Program Load (IPL)
139  ****************************************************************/
140
141 // XXX - is this a standard, or just a bochs bios thing?
142
143 struct ipl_entry_s {
144     u16 type;
145     u16 flags;
146     u32 vector;
147     u32 description;
148     u32 reserved;
149 };
150
151 struct ipl_s {
152     struct ipl_entry_s table[8];
153     u16 count;
154     u16 sequence;
155     u8 pad[124];
156 };
157
158 #define IPL_TYPE_FLOPPY      0x01
159 #define IPL_TYPE_HARDDISK    0x02
160 #define IPL_TYPE_CDROM       0x03
161 #define IPL_TYPE_BEV         0x80
162
163 // Accessor functions
164 #define GET_IPL(var) \
165     GET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var)
166 #define SET_IPL(var, val) \
167     SET_FARVAR(IPL_SEG, ((struct ipl_s *)0)->var, (val))
168
169
170 /****************************************************************
171  * Registers saved/restored in romlayout.S
172  ****************************************************************/
173
174 #define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
175
176 struct bregs {
177     u16 ds;
178     u16 es;
179     UREG(edi, di, di_hi, di_lo);
180     UREG(esi, si, si_hi, si_lo);
181     UREG(ebp, bp, bp_hi, bp_lo);
182     UREG(esp, sp, sp_hi, sp_lo);
183     UREG(ebx, bx, bh, bl);
184     UREG(edx, dx, dh, dl);
185     UREG(ecx, cx, ch, cl);
186     UREG(eax, ax, ah, al);
187     u16 ip;
188     u16 cs;
189     u16 flags;
190 } __attribute__((packed));
191
192 // bregs flags bitdefs
193 #define F_ZF (1<<6)
194 #define F_CF (1<<0)
195
196 static inline void
197 set_cf(struct bregs *regs, int cond)
198 {
199     if (cond)
200         regs->flags |= F_CF;
201     else
202         regs->flags &= ~F_CF;
203 }
204
205
206 /****************************************************************
207  * Bios Config Table
208  ****************************************************************/
209
210 struct bios_config_table_s {
211     // XXX
212     u8 x;
213 };
214
215 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
216
217
218 /****************************************************************
219  * Memory layout info
220  ****************************************************************/
221
222 #define SEG_BIOS     0xf000
223
224 #define EBDA_SEG           0x9FC0
225 #define IPL_SEG            0x9FF0
226 #define EBDA_SIZE          1              // In KiB
227 #define BASE_MEM_IN_K   (640 - EBDA_SIZE)
228
229 #endif // __BIOSVAR_H