1 // Basic type definitions for X86 cpus.
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
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;
20 struct { u32 hi, lo; };
24 #ifdef MANUAL_NO_JUMP_TABLE
25 # define default case 775324556: asm(""); default
29 # define __VISIBLE __attribute__((externally_visible))
34 #define UNIQSEC __FILE__ "." __stringify(__LINE__)
36 #define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code)
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.
43 // Designate a variable as (only) visible to 16bit code.
44 # define VAR16 __section(".data16." UNIQSEC)
45 // Designate a variable as visible to 16bit, 32bit, and assembler code.
46 # define VAR16VISIBLE VAR16 __VISIBLE
47 // Designate a variable as externally visible (in addition to all internal code).
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 a 32bit variable also available in 16bit "big real" mode.
52 # define VAR32VISIBLE __section(".discard.var32." UNIQSEC) __VISIBLE __weak
53 // Designate top-level assembler as 16bit only.
54 # define ASM16(code) __ASM(code)
55 // Designate top-level assembler as 32bit only.
59 # define VISIBLE32 __VISIBLE
60 # define VAR16 __section(".discard.var16." UNIQSEC)
61 # define VAR16VISIBLE VAR16 __VISIBLE __weak
62 # define VAR16EXPORT VAR16VISIBLE
63 # define VAR16FIXED(addr) VAR16VISIBLE
64 # define VAR32VISIBLE __VISIBLE
66 # define ASM32(code) __ASM(code)
69 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
70 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
71 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
72 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
73 #define DIV_ROUND_CLOSEST(x, divisor)({ \
74 typeof(divisor) __divisor = divisor; \
75 (((x) + ((__divisor) / 2)) / (__divisor)); \
77 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
78 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
79 #define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1))
80 #define container_of(ptr, type, member) ({ \
81 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
82 (type *)( (char *)__mptr - offsetof(type,member) );})
84 #define NULL ((void*)0)
86 #define __weak __attribute__((weak))
87 #define __section(S) __attribute__((section(S)))
89 #define PACKED __attribute__((packed))
90 #define __aligned(x) __attribute__((aligned(x)))
92 #define barrier() __asm__ __volatile__("": : :"memory")
94 #define noinline __attribute__((noinline))
95 #define __always_inline inline __attribute__((always_inline))
97 #define __stringify_1(x) #x
98 #define __stringify(x) __stringify_1(x)