Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | ** |
| 3 | ** machine.h |
| 4 | ** |
| 5 | ** Copyright (c) Cambridge Electronic Design Limited 1991,1992,2010 |
| 6 | ** |
| 7 | ** This program is free software; you can redistribute it and/or |
| 8 | ** modify it under the terms of the GNU General Public License |
| 9 | ** as published by the Free Software Foundation; either version 2 |
| 10 | ** of the License, or (at your option) any later version. |
| 11 | ** |
| 12 | ** This program is distributed in the hope that it will be useful, |
| 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ** GNU General Public License for more details. |
| 16 | ** |
| 17 | ** You should have received a copy of the GNU General Public License |
| 18 | ** along with this program; if not, write to the Free Software |
| 19 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | ** |
| 21 | ** Contact CED: Cambridge Electronic Design Limited, Science Park, Milton Road |
| 22 | ** Cambridge, CB6 0FE. |
| 23 | ** www.ced.co.uk |
| 24 | ** greg@ced.co.uk |
| 25 | ** |
| 26 | ** This file is included at the start of 'C' or 'C++' source file to define |
| 27 | ** things for cross-platform/compiler interoperability. This used to deal with |
| 28 | ** MSDOS/16-bit stuff, but this was all removed in Decemeber 2010. There are |
| 29 | ** three things to consider: Windows, LINUX, mac OSX (BSD Unix) and 32 vs 64 |
| 30 | ** bit. At the time of writing (DEC 2010) there is a consensus on the following |
| 31 | ** and their unsigned equivalents: |
| 32 | ** |
| 33 | ** type bits |
| 34 | ** char 8 |
| 35 | ** short 16 |
| 36 | ** int 32 |
| 37 | ** long long 64 |
| 38 | ** |
| 39 | ** long is a problem as it is always 64 bits on linux/unix and is always 32 bits |
| 40 | ** on windows. |
| 41 | ** On windows, we define _IS_WINDOWS_ and one of WIN32 or WIN64. |
| 42 | ** On linux we define LINUX |
| 43 | ** On Max OSX we define MACOSX |
| 44 | ** |
| 45 | */ |
| 46 | |
| 47 | #ifndef __MACHINE_H__ |
| 48 | #define __MACHINE_H__ |
| 49 | #ifndef __KERNEL__ |
| 50 | #include <float.h> |
| 51 | #include <limits.h> |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | ** The initial section is to identify the operating system |
| 56 | */ |
| 57 | #if (defined(__linux__) || defined(_linux) || defined(__linux)) && !defined(LINUX) |
| 58 | #define LINUX 1 |
| 59 | #endif |
| 60 | |
| 61 | #if (defined(__WIN32__) || defined(_WIN32)) && !defined(WIN32) |
| 62 | #define WIN32 1 |
| 63 | #endif |
| 64 | |
| 65 | #if defined(__APPLE__) |
| 66 | #define MACOSX |
| 67 | #endif |
| 68 | |
| 69 | #if defined(_WIN64) |
| 70 | #undef WIN32 |
| 71 | #undef WIN64 |
| 72 | #define WIN64 1 |
| 73 | #endif |
| 74 | |
| 75 | #if defined(WIN32) || defined(WIN64) |
| 76 | #define _IS_WINDOWS_ 1 |
| 77 | #endif |
| 78 | |
| 79 | #if defined(LINUX) || defined(MAXOSX) |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 80 | #define FAR |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 81 | |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 82 | typedef int BOOL; /* To match Windows */ |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 83 | typedef unsigned char BYTE; |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 84 | #define __packed __attribute__((packed)) |
Elena Ufimtseva | 4e0825f | 2013-05-16 12:47:05 -0400 | [diff] [blame] | 85 | #define HIWORD(x) (unsigned short)(((x)>>16) & 0xffff) |
| 86 | #define LOWORD(x) (unsigned short)((x) & 0xffff) |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | #ifdef _IS_WINDOWS_ |
| 90 | #include <windows.h> |
| 91 | #define __packed |
| 92 | #endif |
| 93 | |
| 94 | /* |
| 95 | ** Sort out the DllExport and DllImport macros. The GCC compiler has its own |
| 96 | ** syntax for this, though it also supports the MS specific __declspec() as |
| 97 | ** a synonym. |
| 98 | */ |
| 99 | #ifdef GNUC |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 100 | #define DllExport __attribute__((dllexport)) |
| 101 | #define DllImport __attribute__((dllimport)) |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 102 | #endif |
| 103 | |
| 104 | #ifndef DllExport |
| 105 | #ifdef _IS_WINDOWS_ |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 106 | #define DllExport __declspec(dllexport) |
| 107 | #define DllImport __declspec(dllimport) |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 108 | #else |
Elena Ufimtseva | d9f8374 | 2013-05-15 12:57:17 -0400 | [diff] [blame] | 109 | #define DllExport |
| 110 | #define DllImport |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 111 | #endif |
| 112 | #endif /* _IS_WINDOWS_ */ |
| 113 | |
Alois Schlögl | 2eae6bd | 2012-09-17 19:22:52 -0700 | [diff] [blame] | 114 | #ifndef TRUE |
| 115 | #define TRUE 1 |
| 116 | #define FALSE 0 |
| 117 | #endif |
| 118 | |
| 119 | #endif |