Unify mode16/32 compiler checks.
[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 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 hi, lo; };
21     u64 val;
22 };
23
24 #ifdef MANUAL_NO_JUMP_TABLE
25 # define default case 775324556: asm(""); default
26 #endif
27
28 #ifdef WHOLE_PROGRAM
29 # define __VISIBLE __attribute__((externally_visible))
30 #else
31 # define __VISIBLE
32 #endif
33
34 #define UNIQSEC __FILE__ "." __stringify(__LINE__)
35
36 #define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code)
37
38 #if MODE16 == 1
39 // Notes a function as externally visible in the 16bit code chunk.
40 # define VISIBLE16 __VISIBLE
41 // Notes a function as externally visible in the 32bit code chunk.
42 # define VISIBLE32
43 // Designate a variable as (only) visible to 16bit code.
44 # define VAR16 __section(".data16." UNIQSEC)
45 // Designate a variable as visible to both 32bit and 16bit code.
46 # define VAR16_32 VAR16 __VISIBLE
47 // Designate a variable visible externally.
48 # define VAR16EXPORT __section(".data16.export." UNIQSEC) __VISIBLE
49 // Designate a variable at a specific 16bit address
50 # define VAR16FIXED(addr) __aligned(1) __VISIBLE __section(".fixedaddr." __stringify(addr))
51 // Designate top-level assembler as 16bit only.
52 # define ASM16(code) __ASM(code)
53 // Designate top-level assembler as 32bit only.
54 # define ASM32(code)
55 #else
56 # define VISIBLE16
57 # define VISIBLE32 __VISIBLE
58 # define VAR16 __section(".discard.var16." UNIQSEC)
59 # define VAR16_32 VAR16 __VISIBLE __weak
60 # define VAR16EXPORT VAR16_32
61 # define VAR16FIXED(addr) VAR16_32
62 # define ASM16(code)
63 # define ASM32(code) __ASM(code)
64 #endif
65
66 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
67 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
68 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
69 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
70 #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
71 #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
72
73 #define NULL ((void *)0)
74
75 #define __weak __attribute__((weak))
76 #define __section(S) __attribute__((section(S)))
77
78 #define PACKED __attribute__((packed))
79 #define __aligned(x) __attribute__((aligned(x)))
80
81 #define barrier() __asm__ __volatile__("": : :"memory")
82
83 #define noinline __attribute__((noinline))
84 #define __always_inline inline __attribute__((always_inline))
85
86 #define __stringify_1(x)        #x
87 #define __stringify(x)          __stringify_1(x)
88
89 #endif // types.h