X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Ftypes.h;h=c0c6d26ca24358d3405fb97050ce24c09b2a9f20;hb=refs%2Fheads%2Fcoreboot;hp=f7a0e9a6b72830a555d3e5ca7cd0d51ae004fdc7;hpb=4a754b38ee5f8fa9539e49033063b1854d32ae3e;p=seabios.git diff --git a/src/types.h b/src/types.h index f7a0e9a..c0c6d26 100644 --- a/src/types.h +++ b/src/types.h @@ -1,8 +1,8 @@ // Basic type definitions for X86 cpus. // -// Copyright (C) 2008 Kevin O'Connor +// Copyright (C) 2008-2010 Kevin O'Connor // -// This file may be distributed under the terms of the GNU GPLv3 license. +// This file may be distributed under the terms of the GNU LGPLv3 license. #ifndef __TYPES_H #define __TYPES_H @@ -21,32 +21,110 @@ union u64_u32_u { u64 val; }; -#define __VISIBLE __attribute__((externally_visible)) +#ifdef MANUAL_NO_JUMP_TABLE +# define default case 775324556: asm(""); default +#endif + +#ifdef WHOLE_PROGRAM +# define __VISIBLE __attribute__((externally_visible)) +#else +# define __VISIBLE +#endif + +#define UNIQSEC __FILE__ "." __stringify(__LINE__) + +#define __noreturn __attribute__((noreturn)) +extern void __force_link_error__only_in_32bit_flat(void) __noreturn; +extern void __force_link_error__only_in_32bit_segmented(void) __noreturn; +extern void __force_link_error__only_in_16bit(void) __noreturn; + +#define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code) #if MODE16 == 1 // Notes a function as externally visible in the 16bit code chunk. # define VISIBLE16 __VISIBLE -// Notes a function as externally visible in the 32bit code chunk. -# define VISIBLE32 -// Designate a variable as visible to both 32bit and 16bit code. -# define VAR16 __VISIBLE +// Notes a function as externally visible in the 32bit flat code chunk. +# define VISIBLE32FLAT __section(".discard.func32flat." UNIQSEC) noinline +// Notes a 32bit flat function that will only be called during init. +# define VISIBLE32INIT VISIBLE32FLAT +// Notes a function as externally visible in the 32bit segmented code chunk. +# define VISIBLE32SEG __section(".discard.func32seg." UNIQSEC) noinline +// Designate a variable as (only) visible to 16bit code. +# define VAR16 __section(".data16." UNIQSEC) +// Designate a variable as visible to 16bit, 32bit, and assembler code. +# define VAR16VISIBLE VAR16 __VISIBLE +// Designate a variable as externally visible (in addition to all internal code). +# define VAR16EXPORT __section(".data16.export." UNIQSEC) __VISIBLE +// Designate a variable at a specific 16bit address +# define VAR16FIXED(addr) __aligned(1) __VISIBLE __section(".fixedaddr." __stringify(addr)) +// Designate a variable as (only) visible to 32bit segmented code. +# define VAR32SEG __section(".discard.var32seg." UNIQSEC) +// Designate a 32bit variable also available in 16bit "big real" mode. +# define VAR32FLATVISIBLE __section(".discard.var32flat." UNIQSEC) __VISIBLE __weak // Designate top-level assembler as 16bit only. -# define ASM16(code) asm(code) +# define ASM16(code) __ASM(code) +// Designate top-level assembler as 32bit flat only. +# define ASM32FLAT(code) +// Compile time check for a given mode. +# define ASSERT16() do { } while (0) +# define ASSERT32SEG() __force_link_error__only_in_32bit_segmented() +# define ASSERT32FLAT() __force_link_error__only_in_32bit_flat() +#elif MODESEGMENT == 1 +# define VISIBLE16 __section(".discard.func16." UNIQSEC) noinline +# define VISIBLE32FLAT __section(".discard.func32flat." UNIQSEC) noinline +# define VISIBLE32INIT VISIBLE32FLAT +# define VISIBLE32SEG __VISIBLE +# define VAR16 __section(".discard.var16." UNIQSEC) +# define VAR16VISIBLE VAR16 __VISIBLE __weak +# define VAR16EXPORT VAR16VISIBLE +# define VAR16FIXED(addr) VAR16VISIBLE +# define VAR32SEG __section(".data32seg." UNIQSEC) +# define VAR32FLATVISIBLE __section(".discard.var32flat." UNIQSEC) __VISIBLE __weak +# define ASM16(code) +# define ASM32FLAT(code) +# define ASSERT16() __force_link_error__only_in_16bit() +# define ASSERT32SEG() do { } while (0) +# define ASSERT32FLAT() __force_link_error__only_in_32bit_flat() #else -# define VISIBLE16 -# define VISIBLE32 __VISIBLE -# define VAR16 __VISIBLE __attribute__((section(".discard.var16"))) __attribute__((weak)) +# define VISIBLE16 __section(".discard.func16." UNIQSEC) noinline +# define VISIBLE32FLAT __section(".text.runtime." UNIQSEC) __VISIBLE +# define VISIBLE32INIT __section(".text.init." UNIQSEC) __VISIBLE +# define VISIBLE32SEG __section(".discard.func32seg." UNIQSEC) noinline +# define VAR16 __section(".discard.var16." UNIQSEC) +# define VAR16VISIBLE VAR16 __VISIBLE __weak +# define VAR16EXPORT VAR16VISIBLE +# define VAR16FIXED(addr) VAR16VISIBLE +# define VAR32SEG __section(".discard.var32seg." UNIQSEC) +# define VAR32FLATVISIBLE __section(".data.runtime." UNIQSEC) __VISIBLE # define ASM16(code) +# define ASM32FLAT(code) __ASM(code) +# define ASSERT16() __force_link_error__only_in_16bit() +# define ASSERT32SEG() __force_link_error__only_in_32bit_segmented() +# define ASSERT32FLAT() do { } while (0) #endif #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define DIV_ROUND_CLOSEST(x, divisor)({ \ + typeof(divisor) __divisor = divisor; \ + (((x) + ((__divisor) / 2)) / (__divisor)); \ + }) #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) +#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1)) +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) + +#define NULL ((void*)0) -#define NULL ((void *)0) +#define __weak __attribute__((weak)) +#define __section(S) __attribute__((section(S))) #define PACKED __attribute__((packed)) #define __aligned(x) __attribute__((aligned(x))) @@ -55,6 +133,8 @@ union u64_u32_u { #define noinline __attribute__((noinline)) #define __always_inline inline __attribute__((always_inline)) +#define __malloc __attribute__((__malloc__)) +#define __attribute_const __attribute__((__const__)) #define __stringify_1(x) #x #define __stringify(x) __stringify_1(x)