summaryrefslogtreecommitdiffstats
path: root/types.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:19:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:19:39 +0000
commitb3099b4a9cd903bc2c0088e84a4e97d7cc072f1d (patch)
tree4de44db30324d1793a5b7ed6fdf32113fe7135ce /types.h
parentInitial commit. (diff)
downloaddmidecode-b3099b4a9cd903bc2c0088e84a4e97d7cc072f1d.tar.xz
dmidecode-b3099b4a9cd903bc2c0088e84a4e97d7cc072f1d.zip
Adding upstream version 3.5.upstream/3.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'types.h')
-rw-r--r--types.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/types.h b/types.h
new file mode 100644
index 0000000..51c32d7
--- /dev/null
+++ b/types.h
@@ -0,0 +1,59 @@
+#ifndef TYPES_H
+#define TYPES_H
+
+#include "config.h"
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef signed short i16;
+typedef unsigned int u32;
+
+/*
+ * You may use the following defines to adjust the type definitions
+ * depending on the architecture:
+ * - Define BIGENDIAN on big-endian systems.
+ * - Define ALIGNMENT_WORKAROUND if your system doesn't support
+ * non-aligned memory access. In this case, we use a slower, but safer,
+ * memory access method. This should be done automatically in config.h
+ * for architectures which need it.
+ */
+
+#ifdef BIGENDIAN
+typedef struct {
+ u32 h;
+ u32 l;
+} u64;
+#else
+typedef struct {
+ u32 l;
+ u32 h;
+} u64;
+#endif
+
+#if defined(ALIGNMENT_WORKAROUND) || defined(BIGENDIAN)
+static inline u64 U64(u32 low, u32 high)
+{
+ u64 self;
+
+ self.l = low;
+ self.h = high;
+
+ return self;
+}
+#endif
+
+/*
+ * Per SMBIOS v2.8.0 and later, all structures assume a little-endian
+ * ordering convention.
+ */
+#if defined(ALIGNMENT_WORKAROUND) || defined(BIGENDIAN)
+#define WORD(x) (u16)((x)[0] + ((x)[1] << 8))
+#define DWORD(x) (u32)((x)[0] + ((x)[1] << 8) + ((x)[2] << 16) + ((x)[3] << 24))
+#define QWORD(x) (U64(DWORD(x), DWORD(x + 4)))
+#else /* ALIGNMENT_WORKAROUND || BIGENDIAN */
+#define WORD(x) (u16)(*(const u16 *)(x))
+#define DWORD(x) (u32)(*(const u32 *)(x))
+#define QWORD(x) (*(const u64 *)(x))
+#endif /* ALIGNMENT_WORKAROUND || BIGENDIAN */
+
+#endif