Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / seabios / src / types.h
1 // Basic type definitions for X86 cpus.
2 //
3 // Copyright (C) 2008-2010  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6 #ifndef __TYPES_H
7 #define __TYPES_H
8
9 typedef unsigned char u8;
10 typedef signed char s8;
11 typedef unsigned short u16;
12 typedef signed short s16;
13 typedef unsigned int u32;
14 typedef signed int s32;
15 typedef unsigned long long u64;
16 typedef signed long long s64;
17 typedef u32 size_t;
18
19 union u64_u32_u {
20     struct { u32 lo, hi; };
21     u64 val;
22 };
23
24 // Definition for common 16bit segment/offset pointers.
25 struct segoff_s {
26     union {
27         struct {
28             u16 offset;
29             u16 seg;
30         };
31         u32 segoff;
32     };
33 };
34
35 #ifdef MANUAL_NO_JUMP_TABLE
36 # define default case 775324556: asm(""); default
37 #endif
38
39 #ifdef WHOLE_PROGRAM
40 # define __VISIBLE __attribute__((externally_visible))
41 #else
42 # define __VISIBLE
43 #endif
44
45 #define UNIQSEC __FILE__ "." __stringify(__LINE__)
46
47 #define __noreturn __attribute__((noreturn))
48 extern void __force_link_error__only_in_32bit_flat(void) __noreturn;
49 extern void __force_link_error__only_in_32bit_segmented(void) __noreturn;
50 extern void __force_link_error__only_in_16bit(void) __noreturn;
51
52 #define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code)
53
54 #if MODE16 == 1
55 // Notes a function as externally visible in the 16bit code chunk.
56 # define VISIBLE16 __VISIBLE
57 // Notes a function as externally visible in the 32bit flat code chunk.
58 # define VISIBLE32FLAT
59 // Notes a 32bit flat function that will only be called during init.
60 # define VISIBLE32INIT
61 // Notes a function as externally visible in the 32bit segmented code chunk.
62 # define VISIBLE32SEG
63 // Designate a variable as (only) visible to 16bit code.
64 # define VAR16 __section(".data16." UNIQSEC)
65 // Designate a variable as (only) visible to 32bit segmented code.
66 # define VAR32SEG __section(".discard.var32seg." UNIQSEC)
67 // Designate a variable as visible and located in the e-segment.
68 # define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak
69 // Designate a variable as visible and located in the f-segment.
70 # define VARFSEG __section(".discard.varfseg." UNIQSEC) __VISIBLE __weak
71 // Designate a variable at a specific address in the f-segment.
72 # define VARFSEGFIXED(addr) __section(".discard.varfixed." UNIQSEC) __VISIBLE __weak
73 // Verify a variable is only accessable via 32bit "init" functions
74 # define VARVERIFY32INIT __section(".discard.varinit." UNIQSEC)
75 // Designate top-level assembler as 16bit only.
76 # define ASM16(code) __ASM(code)
77 // Designate top-level assembler as 32bit flat only.
78 # define ASM32FLAT(code)
79 // Compile time check for a given mode.
80 # define ASSERT16() do { } while (0)
81 # define ASSERT32SEG() __force_link_error__only_in_32bit_segmented()
82 # define ASSERT32FLAT() __force_link_error__only_in_32bit_flat()
83 #elif MODESEGMENT == 1
84 # define VISIBLE16
85 # define VISIBLE32FLAT
86 # define VISIBLE32INIT
87 # define VISIBLE32SEG __VISIBLE
88 # define VAR16 __section(".discard.var16." UNIQSEC)
89 # define VAR32SEG __section(".data32seg." UNIQSEC)
90 # define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak
91 # define VARFSEG __section(".discard.varfseg." UNIQSEC) __VISIBLE __weak
92 # define VARFSEGFIXED(addr) __section(".discard.varfixed." UNIQSEC) __VISIBLE __weak
93 # define VARVERIFY32INIT __section(".discard.varinit." UNIQSEC)
94 # define ASM16(code)
95 # define ASM32FLAT(code)
96 # define ASSERT16() __force_link_error__only_in_16bit()
97 # define ASSERT32SEG() do { } while (0)
98 # define ASSERT32FLAT() __force_link_error__only_in_32bit_flat()
99 #else
100 # define VISIBLE16
101 # define VISIBLE32FLAT __section(".text.runtime." UNIQSEC) __VISIBLE
102 # define VISIBLE32INIT __section(".text.init." UNIQSEC) __VISIBLE
103 # define VISIBLE32SEG
104 # define VAR16 __section(".discard.var16." UNIQSEC)
105 # define VAR32SEG __section(".discard.var32seg." UNIQSEC)
106 # define VARLOW __section(".data.varlow." UNIQSEC) __VISIBLE __weak
107 # define VARFSEG __section(".data.varfseg." UNIQSEC) __VISIBLE
108 # define VARFSEGFIXED(addr) __section(".fixedaddr." __stringify(addr)) __VISIBLE __aligned(1)
109 # define VARVERIFY32INIT __section(".data.varinit." UNIQSEC)
110 # define ASM16(code)
111 # define ASM32FLAT(code) __ASM(code)
112 # define ASSERT16() __force_link_error__only_in_16bit()
113 # define ASSERT32SEG() __force_link_error__only_in_32bit_segmented()
114 # define ASSERT32FLAT() do { } while (0)
115 #endif
116
117 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
118 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
119 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
120 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
121 #define DIV_ROUND_CLOSEST(x, divisor)({                 \
122             typeof(divisor) __divisor = divisor;        \
123             (((x) + ((__divisor) / 2)) / (__divisor));  \
124         })
125 #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
126 #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
127 #define ALIGN_DOWN(x,a)         ((x) & ~((typeof(x))(a)-1))
128 #define container_of(ptr, type, member) ({                      \
129         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
130         (type *)( (char *)__mptr - offsetof(type,member) );})
131 #define container_of_or_null(ptr, type, member) ({              \
132         const typeof( ((type *)0)->member ) *___mptr = (ptr);   \
133         ___mptr ? container_of(___mptr, type, member) : NULL; })
134
135 #define likely(x)       __builtin_expect(!!(x), 1)
136 #define unlikely(x)     __builtin_expect(!!(x), 0)
137
138 #define NULL ((void*)0)
139
140 #define __weak __attribute__((weak))
141 #define __section(S) __attribute__((section(S)))
142
143 #define PACKED __attribute__((packed))
144 #define __aligned(x) __attribute__((aligned(x)))
145
146 #define barrier() __asm__ __volatile__("": : :"memory")
147
148 #define noinline __attribute__((noinline))
149 #define __always_inline inline __attribute__((always_inline))
150 #define __malloc __attribute__((__malloc__))
151 #define __attribute_const __attribute__((__const__))
152
153 #define __stringify_1(x)        #x
154 #define __stringify(x)          __stringify_1(x)
155
156 #endif // types.h