Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / seabios / src / biosvar.h
1 // Memory access to BIOS variables.
2 //
3 // Copyright (C) 2008-2013  Kevin O'Connor <kevin@koconnor.net>
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 "config.h" // SEG_BDA
10 #include "farptr.h" // GET_FARVAR
11 #include "std/bda.h" // struct bios_data_area_s
12
13
14 /****************************************************************
15  * Interupt vector table
16  ****************************************************************/
17
18 #define GET_IVT(vector)                                         \
19     GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector])
20 #define SET_IVT(vector, segoff)                                         \
21     SET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector], segoff)
22
23 #define FUNC16(func) ({                                 \
24         ASSERT32FLAT();                                 \
25         extern void func (void);                        \
26         SEGOFF(SEG_BIOS, (u32)func - BUILD_BIOS_ADDR);  \
27     })
28
29
30 /****************************************************************
31  * Bios Data Area (BDA)
32  ****************************************************************/
33
34 // Accessor functions
35 #define GET_BDA(var) \
36     GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var)
37 #define SET_BDA(var, val) \
38     SET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var, (val))
39
40 // Helper function to set the bits of the equipment_list_flags variable.
41 static inline void set_equipment_flags(u16 clear, u16 set) {
42     u16 eqf = GET_BDA(equipment_list_flags);
43     SET_BDA(equipment_list_flags, (eqf & ~clear) | set);
44 }
45
46
47 /****************************************************************
48  * Extended Bios Data Area (EBDA)
49  ****************************************************************/
50
51 // The initial size and location of EBDA
52 #define EBDA_SIZE_START \
53     DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
54 #define EBDA_SEGMENT_START \
55     FLATPTR_TO_SEG(BUILD_LOWRAM_END - EBDA_SIZE_START*1024)
56
57 // Accessor functions
58 static inline u16 get_ebda_seg(void) {
59     return GET_BDA(ebda_seg);
60 }
61 static inline struct extended_bios_data_area_s *
62 get_ebda_ptr(void)
63 {
64     ASSERT32FLAT();
65     return MAKE_FLATPTR(get_ebda_seg(), 0);
66 }
67 #define GET_EBDA(eseg, var)                                             \
68     GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var)
69 #define SET_EBDA(eseg, var, val)                                        \
70     SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val))
71
72
73 /****************************************************************
74  * Global variables
75  ****************************************************************/
76
77 #if MODE16 == 0 && MODESEGMENT == 1
78 // In 32bit segmented mode %cs may not be readable and the code may be
79 // relocated.  The entry code sets up %gs with a readable segment and
80 // the code offset can be determined by get_global_offset().
81 #define GLOBAL_SEGREG GS
82 static inline u32 __attribute_const get_global_offset(void) {
83     u32 ret;
84     asm("  calll 1f\n"
85         "1:popl %0\n"
86         "  subl $1b, %0"
87         : "=r"(ret));
88     return ret;
89 }
90 #else
91 #define GLOBAL_SEGREG CS
92 static inline u32 __attribute_const get_global_offset(void) {
93     return 0;
94 }
95 #endif
96 static inline u16 get_global_seg(void) {
97     return GET_SEG(GLOBAL_SEGREG);
98 }
99 #define GET_GLOBAL(var)                                                 \
100     GET_VAR(GLOBAL_SEGREG, *(typeof(&(var)))((void*)&(var)              \
101                                              + get_global_offset()))
102 #if MODESEGMENT
103 #define GLOBALFLAT2GLOBAL(var) ((typeof(var))((void*)(var) - BUILD_BIOS_ADDR))
104 #else
105 #define GLOBALFLAT2GLOBAL(var) (var)
106 #endif
107 // Access a "flat" pointer known to point to the f-segment.
108 #define GET_GLOBALFLAT(var) GET_GLOBAL(*GLOBALFLAT2GLOBAL(&(var)))
109
110
111 /****************************************************************
112  * "Low" memory variables
113  ****************************************************************/
114
115 extern u8 _zonelow_seg, zonelow_base[];
116 #define SEG_LOW ((u32)&_zonelow_seg)
117
118 #if MODESEGMENT
119 #define GET_LOW(var)            GET_FARVAR(SEG_LOW, (var))
120 #define SET_LOW(var, val)       SET_FARVAR(SEG_LOW, (var), (val))
121 #define LOWFLAT2LOW(var) ((typeof(var))((void*)(var) - (u32)zonelow_base))
122 #else
123 #define GET_LOW(var)            (var)
124 #define SET_LOW(var, val)       do { (var) = (val); } while (0)
125 #define LOWFLAT2LOW(var) (var)
126 #endif
127 #define GET_LOWFLAT(var) GET_LOW(*LOWFLAT2LOW(&(var)))
128 #define SET_LOWFLAT(var, val) SET_LOW(*LOWFLAT2LOW(&(var)), (val))
129
130 #endif // __BIOSVAR_H