blob: 9f93e0b22186b512af4dda954e4d65bdfb63bf4a [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Basic type definitions for X86 cpus.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05006#ifndef __TYPES_H
7#define __TYPES_H
8
9typedef unsigned char u8;
10typedef signed char s8;
11typedef unsigned short u16;
12typedef signed short s16;
13typedef unsigned int u32;
14typedef signed int s32;
Kevin O'Connore51313d2008-03-12 21:19:34 -040015typedef unsigned long long u64;
Kevin O'Connor595fb462008-04-05 10:47:13 -040016typedef signed long long s64;
17typedef u32 size_t;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050018
Kevin O'Connor1bb3b5c2008-05-14 00:43:13 -040019union u64_u32_u {
20 struct { u32 hi, lo; };
21 u64 val;
22};
23
Kevin O'Connor942d4952009-06-10 22:44:06 -040024#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
Kevin O'Connor4a754b32008-12-28 21:37:27 -050033
Kevin O'Connorc0693942009-06-10 21:56:01 -040034#define UNIQSEC __FILE__ "." __stringify(__LINE__)
35
36#define __ASM(code) asm(".section .text.asm." UNIQSEC "\n\t" code)
37
Kevin O'Connor7ab798f2008-07-13 11:08:36 -040038#if MODE16 == 1
Kevin O'Connor19786762008-03-05 21:09:59 -050039// Notes a function as externally visible in the 16bit code chunk.
Kevin O'Connor4a754b32008-12-28 21:37:27 -050040# define VISIBLE16 __VISIBLE
Kevin O'Connor19786762008-03-05 21:09:59 -050041// Notes a function as externally visible in the 32bit code chunk.
Kevin O'Connor4a754b32008-12-28 21:37:27 -050042# define VISIBLE32
Kevin O'Connor92f95b02008-12-29 20:42:40 -050043// Designate a variable as (only) visible to 16bit code.
Kevin O'Connorc0693942009-06-10 21:56:01 -040044# define VAR16 __section(".data16." UNIQSEC)
Kevin O'Connor4a754b32008-12-28 21:37:27 -050045// Designate a variable as visible to both 32bit and 16bit code.
Kevin O'Connor92f95b02008-12-29 20:42:40 -050046# define VAR16_32 VAR16 __VISIBLE
Kevin O'Connorc0693942009-06-10 21:56:01 -040047// Designate a variable visible externally.
48# define VAR16EXPORT __section(".data16.export." UNIQSEC) __VISIBLE
Kevin O'Connor30853762009-01-17 18:49:20 -050049// Designate a variable at a specific 16bit address
Kevin O'Connorc0693942009-06-10 21:56:01 -040050# define VAR16FIXED(addr) __aligned(1) __VISIBLE __section(".fixedaddr." __stringify(addr))
Kevin O'Connor4a754b32008-12-28 21:37:27 -050051// Designate top-level assembler as 16bit only.
Kevin O'Connorc0693942009-06-10 21:56:01 -040052# define ASM16(code) __ASM(code)
Kevin O'Connor0b60a062009-06-15 23:03:05 -040053// Designate top-level assembler as 32bit only.
Kevin O'Connorc0693942009-06-10 21:56:01 -040054# define ASM32(code)
Kevin O'Connor19786762008-03-05 21:09:59 -050055#else
Kevin O'Connor4a754b32008-12-28 21:37:27 -050056# define VISIBLE16
57# define VISIBLE32 __VISIBLE
Kevin O'Connorc0693942009-06-10 21:56:01 -040058# define VAR16 __section(".discard.var16." UNIQSEC)
59# define VAR16_32 VAR16 __VISIBLE __weak
60# define VAR16EXPORT VAR16_32
Kevin O'Connor30853762009-01-17 18:49:20 -050061# define VAR16FIXED(addr) VAR16_32
Kevin O'Connor4a754b32008-12-28 21:37:27 -050062# define ASM16(code)
Kevin O'Connorc0693942009-06-10 21:56:01 -040063# define ASM32(code) __ASM(code)
Kevin O'Connor19786762008-03-05 21:09:59 -050064#endif
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050065
66#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050067#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
Kevin O'Connor28fe1bd2008-03-11 22:14:15 -040068#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
Kevin O'Connor9dd0dd12008-05-18 00:03:32 -040069#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
Kevin O'Connor276d4a92008-06-11 22:47:01 -040070#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
71#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050072
73#define NULL ((void *)0)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050074
Kevin O'Connorc0693942009-06-10 21:56:01 -040075#define __weak __attribute__((weak))
76#define __section(S) __attribute__((section(S)))
77
Kevin O'Connor6eee8ca2008-03-03 20:14:12 -050078#define PACKED __attribute__((packed))
Kevin O'Connor18e38b22008-12-10 20:40:13 -050079#define __aligned(x) __attribute__((aligned(x)))
Kevin O'Connor6eee8ca2008-03-03 20:14:12 -050080
Kevin O'Connora4d35762008-03-08 15:43:03 -050081#define barrier() __asm__ __volatile__("": : :"memory")
82
Kevin O'Connoree55c762008-05-13 00:18:20 -040083#define noinline __attribute__((noinline))
Kevin O'Connor74f9c082008-04-13 16:57:16 -040084#define __always_inline inline __attribute__((always_inline))
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040085
Kevin O'Connora4d35762008-03-08 15:43:03 -050086#define __stringify_1(x) #x
87#define __stringify(x) __stringify_1(x)
88
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089#endif // types.h