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