[PATCH v3 01/19] add detection of native platform

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The underlying type of most builtin types (size_t, int32_t, ...), as
well as their size, the endianness and other parameters are platform
dependent. The minimal is to have these parameters correct on the
native machine.

Use the diffrent predefined macros to detect the native machine.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 machine.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 machine.h

diff --git a/machine.h b/machine.h
new file mode 100644
index 000000000..a01cdc207
--- /dev/null
+++ b/machine.h
@@ -0,0 +1,54 @@
+#ifndef MACHINE_H
+#define MACHINE_H
+
+enum machine {
+	MACH_ARM,
+	MACH_ARM64,
+	MACH_I386,
+	MACH_X86_64,
+	MACH_MIPS32,
+	MACH_MIPS64,
+	MACH_PPC32,
+	MACH_PPC64,
+	MACH_RISCV32,
+	MACH_RISCV64,
+	MACH_SPARC32,
+	MACH_SPARC64,
+	MACH_M68K,
+	MACH_S390X,
+	MACH_UNKNOWN
+};
+
+#if defined(__aarch64__)
+#define MACH_NATIVE	MACH_ARM64
+#elif defined(__arm__)
+#define	MACH_NATIVE	MACH_ARM
+#elif defined(__x86_64__) || defined(__x86_64)
+#define	MACH_NATIVE	MACH_X86_64
+#elif defined(__i386__) || defined(__i386)
+#define	MACH_NATIVE	MACH_I386
+#elif defined(__mips64__) || (defined(__mips) && __mips == 64)
+#define	MACH_NATIVE	MACH_MIPS64
+#elif defined(__mips__) || defined(__mips)
+#define	MACH_NATIVE	MACH_MIPS32
+#elif defined(__powerpc64__) || defined(__ppc64__)
+#define	MACH_NATIVE	MACH_PPC64
+#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__)
+#define	MACH_NATIVE	MACH_PPC32
+#elif defined(__riscv) && (__riscv_xlen == 64)
+#define	MACH_NATIVE	MACH_RISCV64
+#elif defined(__riscv) && (__riscv_xlen == 32)
+#define	MACH_NATIVE	MACH_RISCV32
+#elif defined(__sparc_v9__)
+#define	MACH_NATIVE	MACH_SPARC64
+#elif defined(__sparc__) || defined(__sparc)
+#define	MACH_NATIVE	MACH_SPARC32
+#elif defined(__m68k__)
+#define MACH_NATIVE	MACH_68K
+#elif defined(__s390x__) || defined(__zarch__)
+#define MACH_NATIVE	MACH_S390X
+#else
+#define MACH_NATIVE	MACH_UNKNOWN
+#endif
+
+#endif
-- 
2.19.2




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux