Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
arch-sys.h
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016-2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #ifdef XEMU_COMMON_ARCH_SYS_H_INCLUDED
19 # error "xemu/arch-sys.h cannot be included multiple times (and it's included by C compiler command line)."
20 #endif
21 #define XEMU_COMMON_ARCH_SYS_H_INCLUDED
22 
23 #ifndef _ISOC11_SOURCE
24 # define _ISOC11_SOURCE
25 #endif
26 // We need this otherwise stupid things happen like M_E is not defined by math.h, grrr.
27 #ifndef _DEFAULT_SOURCE
28 # define _DEFAULT_SOURCE
29 #endif
30 //#ifdef __STRICT_ANSI__
31 //# undef __STRICT_ANSI__
32 //#endif
33 
34 // Generic stuff to signal we're inside XEMU build
35 // Useful for multi-purpose sources, can be also compiled out-of-source-tree, and stuff like that ...
36 #define XEMU_BUILD
37 
38 #if defined(__arm64__) || defined(__arm64) || defined(__aarch64__) || defined(__aarch64) || defined(__arm64e__) || defined(__arm64e) || defined(__aarch64e__) || defined(__aarch64e)
39 # define XEMU_CPU_ARM
40 # define XEMU_CPU_ARM64
41 # if defined(__arm64e__) || defined(__arm64e)
42  // thus should be refined later, how Apple M1 is called himself, in terms of __arm* and similar macros to check for it, TODO
43 # define XEMU_CPU_ARM_APPLE
44 # endif
45 #elif defined(__arm__) || defined(__arm32__) || defined(__arm) || defined(__arm32) || defined(__aarch__) || defined(__aarch) || defined(__aarch32__) || defined(__aarch32)
46 # define XEMU_CPU_ARM
47 # define XEMU_CPU_ARM32
48 #endif
49 
50 #ifdef __EMSCRIPTEN__
51 # define XEMU_ARCH_HTML
52 # define XEMU_ARCH_NAME "html"
53 # ifndef DISABLE_DEBUG
54 # define DISABLE_DEBUG
55 # endif
56 //# define XEMU_OLD_TIMING
57 #elif defined(_WIN64)
58 # define XEMU_ARCH_WIN64
59 # define XEMU_ARCH_WIN
60 # define XEMU_ARCH_NAME "win64"
61 # define XEMU_SLEEP_IS_USLEEP
62 #elif defined(_WIN32)
63 # define XEMU_ARCH_WIN32
64 # define XEMU_ARCH_WIN
65 # define XEMU_ARCH_NAME "win32"
66 # define XEMU_SLEEP_IS_USLEEP
67 #elif defined(__APPLE__)
68  // Actually, MacOS / OSX is kinda UNIX, but for some minor reasons we handle it differently here
69 # include <TargetConditionals.h>
70 # ifndef TARGET_OS_MAC
71 # error "Unknown Apple platform (TARGET_OS_MAC is not defined by TargetConditionals.h)"
72 # endif
73 # define XEMU_ARCH_OSX
74 # define XEMU_ARCH_MAC
75 # define XEMU_ARCH_UNIX
76 # define XEMU_ARCH_NAME "osx"
77 # define XEMU_SLEEP_IS_NANOSLEEP
78 # ifdef XEMU_CPU_ARM
79 # define XEMU_ARCH_MAC_ARM
80 # endif
81 #elif defined(__unix__) || defined(__unix) || defined(__linux__) || defined(__linux)
82 # define XEMU_ARCH_UNIX
83 # if defined(__linux__) || defined(__linux)
84 # define XEMU_ARCH_LINUX
85 # define XEMU_ARCH_NAME "linux"
86 # else
87 # define XEMU_ARCH_NAME "unix"
88  // It seems at least on FreeBSD there is some problem hiding definitions by the FreeBSD system headers
89  // when using some other macros like _C11_SOURCE by default. Thus we define this as well, to avoid
90  // the problem. Thanks to @Scott on MEGA65/Xemu Discord for the the hint.
91 # define __BSD_VISIBLE 1
92 # endif
93 # define XEMU_SLEEP_IS_NANOSLEEP
94 #else
95 # error "Unknown target OS architecture."
96 #endif
97 
98 #if defined(XEMU_ARCH_UNIX) && !defined(_XOPEN_SOURCE)
99 # define _XOPEN_SOURCE 700
100 #endif
101 
102 #if defined(XEMU_ARCH_WIN) && !defined(_USE_MATH_DEFINES)
103  // It seems, some (?) versions of Windows requires _USE_MATH_DEFINES to be defined to define some math constants by math.h
104 # define _USE_MATH_DEFINES
105 #endif
106 
107 // It seems Mingw on windows defaults to 32 bit off_t which causes problems, even on win64
108 // In theory this _FILE_OFFSET_BITS should work for UNIX as well (though maybe that's default there since ages?)
109 // Mingw "should" support this since 2011 or so ... Thus in nutshell: use this trick to enable large file support
110 // in general, regardless of the OS, UNIX-like or Windows. Hopefully it will work.
111 #ifdef _FILE_OFFSET_BITS
112 # undef _FILE_OFFSET_BITS
113 #endif
114 #define _FILE_OFFSET_BITS 64
115 
116 #ifdef XEMU_ARCH_OSX
117  // MacOS and/or SDL bug: even if this prototype is in string.h system header in MacOS,
118  // somehow it does not work even if string.h _IS_ included. So I have to create my
119  // own prototype for this function here :-O For the prototype, we also need the stddef.h
120  // though, for the "size_t".
121 # include <stddef.h>
122  void memset_pattern4(void *__b, const void *__pattern4, size_t __len);
123 #endif