Add linker magic to ensure 16bit variables aren't repeated in 32bit code.
[seabios.git] / src / types.h
1 // Basic type definitions for X86 cpus.
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 __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 hi, lo; };
21     u64 val;
22 };
23
24 #define __VISIBLE __attribute__((externally_visible))
25
26 #if MODE16 == 1
27 // Notes a function as externally visible in the 16bit code chunk.
28 # define VISIBLE16 __VISIBLE
29 // Notes a function as externally visible in the 32bit code chunk.
30 # define VISIBLE32
31 // Designate a variable as visible to both 32bit and 16bit code.
32 # define VAR16 __VISIBLE
33 // Designate top-level assembler as 16bit only.
34 # define ASM16(code) asm(code)
35 #else
36 # define VISIBLE16
37 # define VISIBLE32 __VISIBLE
38 # define VAR16 __VISIBLE __attribute__((section(".discard.var16"))) __attribute__((weak))
39 # define ASM16(code)
40 #endif
41
42 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
43 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
44 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
45 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
46 #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
47 #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
48
49 #define NULL ((void *)0)
50
51 #define PACKED __attribute__((packed))
52 #define __aligned(x) __attribute__((aligned(x)))
53
54 #define barrier() __asm__ __volatile__("": : :"memory")
55
56 #define noinline __attribute__((noinline))
57 #define __always_inline inline __attribute__((always_inline))
58
59 #define __stringify_1(x)        #x
60 #define __stringify(x)          __stringify_1(x)
61
62 #endif // types.h