summaryrefslogtreecommitdiffstats
path: root/libfat/ulint.h
diff options
context:
space:
mode:
authorhpa <hpa>2004-12-15 10:14:39 +0000
committerhpa <hpa>2004-12-15 10:14:39 +0000
commit7be70022dd3ae138998fc7185351b9b49ad9a9b2 (patch)
tree2599a8ede407eec131228fb607a52e22145ba1f9 /libfat/ulint.h
parent4912df96419eff85394da1160bcb19a4dd2c1c59 (diff)
downloadsyslinux-7be70022dd3ae138998fc7185351b9b49ad9a9b2.tar.gz
syslinux-7be70022dd3ae138998fc7185351b9b49ad9a9b2.tar.xz
syslinux-7be70022dd3ae138998fc7185351b9b49ad9a9b2.zip
Prepping for new 2.20 version: rewrite main syslinux program to support
FAT32 and EDD, and a new cleaner installer infrastructure.
Diffstat (limited to 'libfat/ulint.h')
-rw-r--r--libfat/ulint.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/libfat/ulint.h b/libfat/ulint.h
new file mode 100644
index 00000000..0b200ea8
--- /dev/null
+++ b/libfat/ulint.h
@@ -0,0 +1,115 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2001-2004 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ * USA; either version 2 of the License, or (at your option) any later
+ * version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * ulint.h
+ *
+ * Basic operations on unaligned, littleendian integers
+ */
+
+#ifndef ULINT_H
+#define ULINT_H
+
+#include <inttypes.h>
+
+/* These are unaligned, littleendian integer types */
+
+typedef uint8_t le8_t; /* 8-bit byte */
+typedef uint8_t le16_t[2]; /* 16-bit word */
+typedef uint8_t le32_t[4]; /* 32-bit dword */
+
+/* Read/write these quantities */
+
+static inline unsigned char
+read8(le8_t *_p)
+{
+ return *_p;
+}
+
+static inline void
+write8(le8_t *_p, unsigned char _v)
+{
+ *_p = _v;
+}
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/* Littleendian architectures which support unaligned memory accesses */
+
+static inline unsigned short
+read16(le16_t *_p)
+{
+ return *((unsigned short *)_p);
+}
+
+static inline void
+write16(le16_t *_p, unsigned short _v)
+{
+ *((unsigned short *)_p) = _v;
+}
+
+static inline unsigned int
+read32(le32_t *_p)
+{
+ return *((unsigned int *)_p);
+}
+
+static inline void
+write32(le32_t *_p, unsigned int _v)
+{
+ *((unsigned int *)_p) = _v;
+}
+
+#else
+
+/* Generic, mostly portable versions */
+
+static inline unsigned short
+read16(le16_t *_p)
+{
+ unsigned short _v;
+
+ _v = p[0];
+ _v |= p[1] << 8;
+ return _v;
+}
+
+static inline void
+write16(le16_t *_p, unsigned short _v)
+{
+ _p[0] = _v & 0xFF;
+ _p[1] = (_v >> 8) & 0xFF;
+}
+
+static inline unsigned int
+read32(le32_t *_p)
+{
+ _v = _p[0];
+ _v |= _p[1] << 8;
+ _v |= _p[2] << 16;
+ _v |= _p[3] << 24;
+ return _v;
+}
+
+static inline void
+write32(le32_t *_p, unsigned int _v)
+{
+ _p[0] = _v & 0xFF;
+ _p[1] = (_v >> 8) & 0xFF;
+ _p[2] = (_v >> 16) & 0xFF;
+ _p[3] = (_v >> 24) & 0xFF;
+}
+
+#endif
+
+#endif /* ULINT_H */