2008-02-26 04:25:15 +01:00
|
|
|
// Basic type definitions for X86 cpus.
|
|
|
|
//
|
2010-09-16 03:38:16 +02:00
|
|
|
// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
|
2008-02-26 04:25:15 +01:00
|
|
|
//
|
2009-01-16 02:52:58 +01:00
|
|
|
// This file may be distributed under the terms of the GNU LGPLv3 license.
|
2008-02-26 04:25:15 +01:00
|
|
|
#ifndef __TYPES_H
|
|
|
|
#define __TYPES_H
|
|
|
|
|
|
|
|
typedef unsigned char u8;
|
|
|
|
typedef signed char s8;
|
|
|
|
typedef unsigned short u16;
|
|
|
|
typedef signed short s16;
|
|
|
|
typedef unsigned int u32;
|
|
|
|
typedef signed int s32;
|
2008-03-13 02:19:34 +01:00
|
|
|
typedef unsigned long long u64;
|
2008-04-05 16:47:13 +02:00
|
|
|
typedef signed long long s64;
|
|
|
|
typedef u32 size_t;
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-05-14 06:43:13 +02:00
|
|
|
union u64_u32_u {
|
2012-09-15 18:17:37 +02:00
|
|
|
struct { u32 lo, hi; };
|
2008-05-14 06:43:13 +02:00
|
|
|
u64 val;
|
|
|
|
};
|
|
|
|
|
2013-09-15 04:03:57 +02:00
|
|
|
// Definition for common 16bit segment/offset pointers.
|
|
|
|
struct segoff_s {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
u16 offset;
|
|
|
|
u16 seg;
|
|
|
|
};
|
|
|
|
u32 segoff;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-06-11 04:44:06 +02:00
|
|
|
#ifdef MANUAL_NO_JUMP_TABLE
|
|
|
|
# define default case 775324556: asm(""); default
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WHOLE_PROGRAM
|
|
|
|
# define __VISIBLE __attribute__((externally_visible))
|
|
|
|
#else
|
|
|
|
# define __VISIBLE
|
|
|
|
#endif
|
2008-12-29 03:37:27 +01:00
|
|
|
|
2009-06-11 03:56:01 +02:00
|
|
|
#define UNIQSEC __FILE__ "." __stringify(__LINE__)
|
|
|
|
|
2010-01-01 09:04:19 +01:00
|
|
|
#define __noreturn __attribute__((noreturn))
|
2010-01-03 23:43:37 +01:00
|
|
|
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;
|
2009-12-30 18:14:53 +01:00
|
|
|
|
2009-06-11 03:56:01 +02:00
|
|
|
#define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code)
|
|
|
|
|
2008-07-13 17:08:36 +02:00
|
|
|
#if MODE16 == 1
|
2008-03-06 03:09:59 +01:00
|
|
|
// Notes a function as externally visible in the 16bit code chunk.
|
2008-12-29 03:37:27 +01:00
|
|
|
# define VISIBLE16 __VISIBLE
|
2009-12-27 05:32:57 +01:00
|
|
|
// Notes a function as externally visible in the 32bit flat code chunk.
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE32FLAT
|
2010-09-16 03:38:16 +02:00
|
|
|
// Notes a 32bit flat function that will only be called during init.
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE32INIT
|
2009-12-30 18:14:53 +01:00
|
|
|
// Notes a function as externally visible in the 32bit segmented code chunk.
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE32SEG
|
2008-12-30 02:42:40 +01:00
|
|
|
// Designate a variable as (only) visible to 16bit code.
|
2009-06-11 03:56:01 +02:00
|
|
|
# define VAR16 __section(".data16." UNIQSEC)
|
2009-12-30 18:14:53 +01:00
|
|
|
// Designate a variable as (only) visible to 32bit segmented code.
|
|
|
|
# define VAR32SEG __section(".discard.var32seg." UNIQSEC)
|
2012-05-13 18:10:30 +02:00
|
|
|
// Designate a variable as visible and located in the e-segment.
|
|
|
|
# define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak
|
2013-02-19 05:09:01 +01:00
|
|
|
// Designate a variable as visible and located in the f-segment.
|
|
|
|
# define VARFSEG __section(".discard.varfseg." UNIQSEC) __VISIBLE __weak
|
2014-06-11 20:00:21 +02:00
|
|
|
// Designate a variable at a specific address in the f-segment.
|
|
|
|
# define VARFSEGFIXED(addr) __section(".discard.varfixed." UNIQSEC) __VISIBLE __weak
|
2015-10-02 08:46:40 +02:00
|
|
|
// Verify a variable is only accessible via 32bit "init" functions
|
2013-03-09 01:36:28 +01:00
|
|
|
# define VARVERIFY32INIT __section(".discard.varinit." UNIQSEC)
|
2008-12-29 03:37:27 +01:00
|
|
|
// Designate top-level assembler as 16bit only.
|
2009-06-11 03:56:01 +02:00
|
|
|
# define ASM16(code) __ASM(code)
|
2009-12-27 05:32:57 +01:00
|
|
|
// Designate top-level assembler as 32bit flat only.
|
|
|
|
# define ASM32FLAT(code)
|
|
|
|
// Compile time check for a given mode.
|
2010-01-01 18:46:54 +01:00
|
|
|
# define ASSERT16() do { } while (0)
|
|
|
|
# define ASSERT32SEG() __force_link_error__only_in_32bit_segmented()
|
|
|
|
# define ASSERT32FLAT() __force_link_error__only_in_32bit_flat()
|
2009-12-30 18:14:53 +01:00
|
|
|
#elif MODESEGMENT == 1
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE16
|
|
|
|
# define VISIBLE32FLAT
|
|
|
|
# define VISIBLE32INIT
|
2009-12-30 18:14:53 +01:00
|
|
|
# define VISIBLE32SEG __VISIBLE
|
|
|
|
# define VAR16 __section(".discard.var16." UNIQSEC)
|
|
|
|
# define VAR32SEG __section(".data32seg." UNIQSEC)
|
2012-05-13 18:10:30 +02:00
|
|
|
# define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak
|
2013-02-19 05:09:01 +01:00
|
|
|
# define VARFSEG __section(".discard.varfseg." UNIQSEC) __VISIBLE __weak
|
2014-06-11 20:00:21 +02:00
|
|
|
# define VARFSEGFIXED(addr) __section(".discard.varfixed." UNIQSEC) __VISIBLE __weak
|
2013-03-09 01:36:28 +01:00
|
|
|
# define VARVERIFY32INIT __section(".discard.varinit." UNIQSEC)
|
2009-12-30 18:14:53 +01:00
|
|
|
# define ASM16(code)
|
|
|
|
# define ASM32FLAT(code)
|
2010-01-01 18:46:54 +01:00
|
|
|
# define ASSERT16() __force_link_error__only_in_16bit()
|
|
|
|
# define ASSERT32SEG() do { } while (0)
|
|
|
|
# define ASSERT32FLAT() __force_link_error__only_in_32bit_flat()
|
2008-03-06 03:09:59 +01:00
|
|
|
#else
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE16
|
2010-09-16 03:38:16 +02:00
|
|
|
# define VISIBLE32FLAT __section(".text.runtime." UNIQSEC) __VISIBLE
|
|
|
|
# define VISIBLE32INIT __section(".text.init." UNIQSEC) __VISIBLE
|
2012-05-28 17:37:53 +02:00
|
|
|
# define VISIBLE32SEG
|
2009-06-11 03:56:01 +02:00
|
|
|
# define VAR16 __section(".discard.var16." UNIQSEC)
|
2009-12-30 18:14:53 +01:00
|
|
|
# define VAR32SEG __section(".discard.var32seg." UNIQSEC)
|
2013-02-19 07:02:50 +01:00
|
|
|
# define VARLOW __section(".data.varlow." UNIQSEC) __VISIBLE __weak
|
2013-02-19 05:09:01 +01:00
|
|
|
# define VARFSEG __section(".data.varfseg." UNIQSEC) __VISIBLE
|
2014-06-11 20:00:21 +02:00
|
|
|
# define VARFSEGFIXED(addr) __section(".fixedaddr." __stringify(addr)) __VISIBLE __aligned(1)
|
2013-03-09 01:36:28 +01:00
|
|
|
# define VARVERIFY32INIT __section(".data.varinit." UNIQSEC)
|
2008-12-29 03:37:27 +01:00
|
|
|
# define ASM16(code)
|
2009-12-27 05:32:57 +01:00
|
|
|
# define ASM32FLAT(code) __ASM(code)
|
2010-01-01 18:46:54 +01:00
|
|
|
# define ASSERT16() __force_link_error__only_in_16bit()
|
|
|
|
# define ASSERT32SEG() __force_link_error__only_in_32bit_segmented()
|
|
|
|
# define ASSERT32FLAT() do { } while (0)
|
2008-03-06 03:09:59 +01:00
|
|
|
#endif
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
2008-02-26 04:30:47 +01:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
2008-03-12 03:14:15 +01:00
|
|
|
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
|
2008-05-18 06:03:32 +02:00
|
|
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
2009-09-28 02:07:40 +02:00
|
|
|
#define DIV_ROUND_CLOSEST(x, divisor)({ \
|
|
|
|
typeof(divisor) __divisor = divisor; \
|
|
|
|
(((x) + ((__divisor) / 2)) / (__divisor)); \
|
|
|
|
})
|
2008-06-12 04:47:01 +02:00
|
|
|
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
|
|
|
|
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
2009-08-31 01:19:31 +02:00
|
|
|
#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1))
|
2009-08-01 17:45:37 +02:00
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
2013-06-09 03:49:12 +02:00
|
|
|
#define container_of_or_null(ptr, type, member) ({ \
|
|
|
|
const typeof( ((type *)0)->member ) *___mptr = (ptr); \
|
|
|
|
___mptr ? container_of(___mptr, type, member) : NULL; })
|
2008-02-26 04:30:47 +01:00
|
|
|
|
2010-03-20 23:17:19 +01:00
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
|
2009-08-31 01:19:31 +02:00
|
|
|
#define NULL ((void*)0)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-06-11 03:56:01 +02:00
|
|
|
#define __weak __attribute__((weak))
|
|
|
|
#define __section(S) __attribute__((section(S)))
|
|
|
|
|
2008-03-04 02:14:12 +01:00
|
|
|
#define PACKED __attribute__((packed))
|
2008-12-11 02:40:13 +01:00
|
|
|
#define __aligned(x) __attribute__((aligned(x)))
|
2008-03-04 02:14:12 +01:00
|
|
|
|
2008-03-08 21:43:03 +01:00
|
|
|
#define barrier() __asm__ __volatile__("": : :"memory")
|
|
|
|
|
2008-05-13 06:18:20 +02:00
|
|
|
#define noinline __attribute__((noinline))
|
2008-04-13 22:57:16 +02:00
|
|
|
#define __always_inline inline __attribute__((always_inline))
|
2010-04-17 22:58:32 +02:00
|
|
|
#define __malloc __attribute__((__malloc__))
|
2009-12-30 18:14:53 +01:00
|
|
|
#define __attribute_const __attribute__((__const__))
|
2008-03-12 00:32:38 +01:00
|
|
|
|
2008-03-08 21:43:03 +01:00
|
|
|
#define __stringify_1(x) #x
|
|
|
|
#define __stringify(x) __stringify_1(x)
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
#endif // types.h
|