[syslinux:firmware] Patches here support 32bit and 64bit environment.

syslinux-bot for chandramouli narayanan mouli at linux.intel.com
Fri Nov 9 09:06:18 PST 2012


Commit-ID:  c53187e1adc326c3246917cb936cbab020b4d820
Gitweb:     http://www.syslinux.org/commit/c53187e1adc326c3246917cb936cbab020b4d820
Author:     chandramouli narayanan <mouli at linux.intel.com>
AuthorDate: Mon, 25 Jun 2012 12:32:17 -0700
Committer:  chandramouli narayanan <mouli at linux.intel.com>
CommitDate: Mon, 25 Jun 2012 12:32:17 -0700

Patches here support 32bit and 64bit environment.

Move the standard definitions of constants, variously-sized ints,limits into
respective architecture specific files. com32/include/bitsize holds the standard
header files that in turn include bitsize32 or bitsize64 based on the architecture.
The makefiles should build pick the right ones based on architecture.

Files com32/include/sys/cpu.h, com32/include/sys/bitops.h now have
architecture specific files underneath to define relevant macros definitions.

com32/include/setjmp.h has architecture specific counterparts underneath.

ssize_t in dos/stdlib.h is appropriately defined based on architecture to be able
to support building for 32bit and 64bit environments.

Remanants of the unused old i386-only files, if any, need to be pruned.

---
 com32/include/bitsize/limits.h                     |   12 +-
 com32/include/bitsize/stddef.h                     |   14 ++-
 com32/include/bitsize/stdint.h                     |   46 ++++++
 com32/include/bitsize/stdintconst.h                |   18 +--
 com32/include/bitsize/stdintlimits.h               |   22 +--
 com32/include/{bitsize => bitsize32}/limits.h      |    2 +-
 com32/include/{bitsize => bitsize32}/stddef.h      |    5 -
 com32/include/bitsize32/stdint.h                   |   41 ++++++
 com32/include/{bitsize => bitsize32}/stdintconst.h |    5 -
 .../include/{bitsize => bitsize32}/stdintlimits.h  |    9 +-
 com32/include/bitsize64/limits.h                   |   14 ++
 com32/include/bitsize64/stddef.h                   |   10 ++
 com32/include/bitsize64/stdint.h                   |   41 ++++++
 com32/include/bitsize64/stdintconst.h              |   13 ++
 com32/include/bitsize64/stdintlimits.h             |   23 +++
 com32/include/klibc/{ => i386}/archsetjmp.h        |    0
 com32/include/klibc/x86_64/archsetjmp.h            |   21 +++
 com32/include/netinet/in.h                         |    8 +
 com32/include/setjmp.h                             |    8 +-
 com32/include/stdint.h                             |  130 +++++++++++-------
 com32/include/sys/bitops.h                         |   30 +---
 com32/include/sys/cpu.h                            |  140 +------------------
 com32/include/sys/{ => i386}/bitops.h              |   10 +--
 com32/include/sys/{ => i386}/cpu.h                 |    9 +-
 com32/include/sys/{ => x86_64}/bitops.h            |   13 +--
 com32/include/sys/x86_64/cpu.h                     |  148 ++++++++++++++++++++
 dos/stdlib.h                                       |    7 +
 27 files changed, 522 insertions(+), 277 deletions(-)

diff --git a/com32/include/bitsize/limits.h b/com32/include/bitsize/limits.h
index f90e524..7129c4a 100644
--- a/com32/include/bitsize/limits.h
+++ b/com32/include/bitsize/limits.h
@@ -5,10 +5,12 @@
 #ifndef _BITSIZE_LIMITS_H
 #define _BITSIZE_LIMITS_H
 
-#define LONG_BIT	32
-
-#define LONG_MIN	(-2147483647L-1)
-#define LONG_MAX	2147483647L
-#define ULONG_MAX	4294967295UL
+#if __SIZEOF_POINTER__ == 4
+#include <bitsize32/limits.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <bitsize64/limits.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
 
 #endif /* _BITSIZE_LIMITS_H */
diff --git a/com32/include/bitsize/stddef.h b/com32/include/bitsize/stddef.h
index caa5e72..3d5c3e7 100644
--- a/com32/include/bitsize/stddef.h
+++ b/com32/include/bitsize/stddef.h
@@ -1,11 +1,20 @@
 /*
- * bits32/stddef.h
+ * Include stddef.h as appropriate for architecture
  */
 
 #ifndef _BITSIZE_STDDEF_H
 #define _BITSIZE_STDDEF_H
 
 #define _SIZE_T
+#if __SIZEOF_POINTER__ == 4
+#include <bitsize32/stddef.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <bitsize64/stddef.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
+/* Original definitions below */
+/*
 #if defined(__s390__) || defined(__hppa__) || defined(__cris__)
 typedef unsigned long size_t;
 #else
@@ -14,5 +23,8 @@ typedef unsigned int size_t;
 
 #define _PTRDIFF_T
 typedef signed int ptrdiff_t;
+*/
 
+#else
+#error "BITSIZE_STDDEF already defined"
 #endif /* _BITSIZE_STDDEF_H */
diff --git a/com32/include/bitsize/stdint.h b/com32/include/bitsize/stdint.h
index 8cbfc5d..854c543 100644
--- a/com32/include/bitsize/stdint.h
+++ b/com32/include/bitsize/stdint.h
@@ -5,6 +5,7 @@
 #ifndef _BITSIZE_STDINT_H
 #define _BITSIZE_STDINT_H
 
+/*
 typedef signed char int8_t;
 typedef short int int16_t;
 typedef int int32_t;
@@ -30,5 +31,50 @@ typedef unsigned int uintptr_t;
 #define __PRI64_RANK   "ll"
 #define __PRIFAST_RANK ""
 #define __PRIPTR_RANK  ""
+*/
+
+/* Exact types */
+
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+/* Small types */
+
+typedef signed char int_least8_t;
+typedef signed short int_least16_t;
+typedef signed int int_least32_t;
+typedef signed long long int_least64_t;
+
+typedef unsigned char uint_least8_t;
+typedef unsigned short uint_least16_t;
+typedef unsigned int uint_least32_t;
+typedef unsigned long long uint_least64_t;
+
+/* Fast types */
+
+typedef signed char int_fast8_t;
+typedef signed long long int_fast64_t;
+
+typedef unsigned char uint_fast8_t;
+typedef unsigned int uint_fast32_t;
+typedef unsigned long long uint_fast64_t;
+
+/* Maximal types */
 
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+#if __SIZEOF_POINTER__ == 4
+#include <bitsize32/stdint.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <bitsize64/stdint.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
 #endif /* _BITSIZE_STDINT_H */
diff --git a/com32/include/bitsize/stdintconst.h b/com32/include/bitsize/stdintconst.h
index 8157dd0..ae4e9fc 100644
--- a/com32/include/bitsize/stdintconst.h
+++ b/com32/include/bitsize/stdintconst.h
@@ -1,18 +1,16 @@
 /*
- * bits32/stdintconst.h
+ * bitsize/stdintconst.h
  */
 
 #ifndef _BITSIZE_STDINTCONST_H
 #define _BITSIZE_STDINTCONST_H
 
-#define INT_FAST16_C(c)	 INT32_C(c)
-#define INT_FAST32_C(c)  INT32_C(c)
-
-#define UINT_FAST16_C(c) UINT32_C(c)
-#define UINT_FAST32_C(c) UINT32_C(c)
-
-#define INTPTR_C(c)	 INT32_C(c)
-#define UINTPTR_C(c)	 UINT32_C(c)
-#define PTRDIFF_C(c)     INT32_C(c)
+#if __SIZEOF_POINTER__ == 4
+#include <bitsize32/stdintconst.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <bitsize64/stdintconst.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
 
 #endif /* _BITSIZE_STDINTCONST_H */
diff --git a/com32/include/bitsize/stdintlimits.h b/com32/include/bitsize/stdintlimits.h
index b44fe01..9f3657d 100644
--- a/com32/include/bitsize/stdintlimits.h
+++ b/com32/include/bitsize/stdintlimits.h
@@ -1,22 +1,16 @@
 /*
- * bits32/stdintlimits.h
+ * bitsize/stdintlimits.h
  */
 
 #ifndef _BITSIZE_STDINTLIMITS_H
 #define _BITSIZE_STDINTLIMITS_H
 
-#define INT_FAST16_MIN	INT32_MIN
-#define INT_FAST32_MIN	INT32_MIN
-#define INT_FAST16_MAX	INT32_MAX
-#define INT_FAST32_MAX	INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INTPTR_MIN	INT32_MIN
-#define INTPTR_MAX	INT32_MAX
-#define UINTPTR_MAX	UINT32_MAX
-
-#define PTRDIFF_MIN	INT32_MIN
-#define PTRDIFF_MAX	INT32_MAX
+#if __SIZEOF_POINTER__ == 4
+#include <bitsize32/stdintlimits.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <bitsize64/stdintlimits.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
 
 #endif /* _BITSIZE_STDINTLIMITS_H */
diff --git a/com32/include/bitsize/limits.h b/com32/include/bitsize32/limits.h
similarity index 85%
copy from com32/include/bitsize/limits.h
copy to com32/include/bitsize32/limits.h
index f90e524..8eb97d6 100644
--- a/com32/include/bitsize/limits.h
+++ b/com32/include/bitsize32/limits.h
@@ -11,4 +11,4 @@
 #define LONG_MAX	2147483647L
 #define ULONG_MAX	4294967295UL
 
-#endif /* _BITSIZE_LIMITS_H */
+#endif				/* _BITSIZE_LIMITS_H */
diff --git a/com32/include/bitsize/stddef.h b/com32/include/bitsize32/stddef.h
similarity index 72%
copy from com32/include/bitsize/stddef.h
copy to com32/include/bitsize32/stddef.h
index caa5e72..e5d4937 100644
--- a/com32/include/bitsize/stddef.h
+++ b/com32/include/bitsize32/stddef.h
@@ -2,9 +2,6 @@
  * bits32/stddef.h
  */
 
-#ifndef _BITSIZE_STDDEF_H
-#define _BITSIZE_STDDEF_H
-
 #define _SIZE_T
 #if defined(__s390__) || defined(__hppa__) || defined(__cris__)
 typedef unsigned long size_t;
@@ -14,5 +11,3 @@ typedef unsigned int size_t;
 
 #define _PTRDIFF_T
 typedef signed int ptrdiff_t;
-
-#endif /* _BITSIZE_STDDEF_H */
diff --git a/com32/include/bitsize32/stdint.h b/com32/include/bitsize32/stdint.h
new file mode 100644
index 0000000..c886a4c
--- /dev/null
+++ b/com32/include/bitsize32/stdint.h
@@ -0,0 +1,41 @@
+/*
+ * bits32/stdint.h
+ */
+
+
+/*
+typedef signed char		int8_t;
+typedef short int		int16_t;
+typedef int			int32_t;
+typedef long long int		int64_t;
+
+typedef unsigned char		uint8_t;
+typedef unsigned short int	uint16_t;
+typedef unsigned int		uint32_t;
+typedef unsigned long long int	uint64_t;
+
+typedef int			int_fast16_t;
+typedef int			int_fast32_t;
+
+typedef unsigned int		uint_fast16_t;
+typedef unsigned int		uint_fast32_t;
+
+typedef int			intptr_t;
+typedef unsigned int		uintptr_t;
+
+#define __INT64_C(c)   c ## LL
+#define __UINT64_C(c)  c ## ULL
+
+#define __PRI64_RANK   "ll"
+#define __PRIFAST_RANK ""
+#define __PRIPTR_RANK  ""
+*/
+
+/* changes made according compiler output */
+typedef signed int int_fast16_t;	/* was short */
+typedef signed int int_fast32_t;
+typedef unsigned int uint_fast16_t;	/* was ushort */
+/* Pointer types */
+
+typedef int32_t intptr_t;
+typedef uint32_t uintptr_t;
diff --git a/com32/include/bitsize/stdintconst.h b/com32/include/bitsize32/stdintconst.h
similarity index 73%
copy from com32/include/bitsize/stdintconst.h
copy to com32/include/bitsize32/stdintconst.h
index 8157dd0..71ece42 100644
--- a/com32/include/bitsize/stdintconst.h
+++ b/com32/include/bitsize32/stdintconst.h
@@ -2,9 +2,6 @@
  * bits32/stdintconst.h
  */
 
-#ifndef _BITSIZE_STDINTCONST_H
-#define _BITSIZE_STDINTCONST_H
-
 #define INT_FAST16_C(c)	 INT32_C(c)
 #define INT_FAST32_C(c)  INT32_C(c)
 
@@ -14,5 +11,3 @@
 #define INTPTR_C(c)	 INT32_C(c)
 #define UINTPTR_C(c)	 UINT32_C(c)
 #define PTRDIFF_C(c)     INT32_C(c)
-
-#endif /* _BITSIZE_STDINTCONST_H */
diff --git a/com32/include/bitsize/stdintlimits.h b/com32/include/bitsize32/stdintlimits.h
similarity index 65%
copy from com32/include/bitsize/stdintlimits.h
copy to com32/include/bitsize32/stdintlimits.h
index b44fe01..175cdcd 100644
--- a/com32/include/bitsize/stdintlimits.h
+++ b/com32/include/bitsize32/stdintlimits.h
@@ -2,9 +2,6 @@
  * bits32/stdintlimits.h
  */
 
-#ifndef _BITSIZE_STDINTLIMITS_H
-#define _BITSIZE_STDINTLIMITS_H
-
 #define INT_FAST16_MIN	INT32_MIN
 #define INT_FAST32_MIN	INT32_MIN
 #define INT_FAST16_MAX	INT32_MAX
@@ -19,4 +16,8 @@
 #define PTRDIFF_MIN	INT32_MIN
 #define PTRDIFF_MAX	INT32_MAX
 
-#endif /* _BITSIZE_STDINTLIMITS_H */
+/* sig_atomic_t limit */
+# define SIG_ATOMIC_MIN         INT32_MIN //(-2147483647-1)
+# define SIG_ATOMIC_MAX         INT32_MAX //(2147483647)
+/* size_t limit */
+# define SIZE_MAX		UINT32_MAX //(4294967295U)
diff --git a/com32/include/bitsize64/limits.h b/com32/include/bitsize64/limits.h
new file mode 100644
index 0000000..f5bbf83
--- /dev/null
+++ b/com32/include/bitsize64/limits.h
@@ -0,0 +1,14 @@
+/*
+ * bits64/limits.h
+ */
+
+#ifndef _BITSIZE_LIMITS_H
+#define _BITSIZE_LIMITS_H
+
+#define LONG_BIT	64
+
+#define LONG_MIN	(-9223372036854775807L-1)
+#define LONG_MAX	9223372036854775807L
+#define ULONG_MAX	18446744073709551615UL
+
+#endif				/* _BITSIZE_LIMITS_H */
diff --git a/com32/include/bitsize64/stddef.h b/com32/include/bitsize64/stddef.h
new file mode 100644
index 0000000..057a721
--- /dev/null
+++ b/com32/include/bitsize64/stddef.h
@@ -0,0 +1,10 @@
+/*
+ * bits64/stddef.h
+ */
+
+
+#define _SIZE_T
+typedef unsigned long size_t;
+#define _PTRDIFF_T
+typedef signed long ptrdiff_t;
+
diff --git a/com32/include/bitsize64/stdint.h b/com32/include/bitsize64/stdint.h
new file mode 100644
index 0000000..32de44c
--- /dev/null
+++ b/com32/include/bitsize64/stdint.h
@@ -0,0 +1,41 @@
+/*
+ * bits64/stdint.h
+ */
+
+
+/*
+typedef signed char		int8_t;
+typedef short int		int16_t;
+typedef int			int32_t;
+typedef long int		int64_t;
+
+typedef unsigned char		uint8_t;
+typedef unsigned short int	uint16_t;
+typedef unsigned int		uint32_t;
+typedef unsigned long int	uint64_t;
+
+typedef long int		int_fast16_t;
+typedef long int		int_fast32_t;
+
+typedef unsigned long int	uint_fast16_t;
+typedef unsigned long int	uint_fast32_t;
+
+typedef long int		intptr_t;
+typedef unsigned long int	uintptr_t;
+
+#define __INT64_C(c)  c ## L
+#define __UINT64_C(c) c ## UL
+
+#define __PRI64_RANK	"l"
+#define __PRIFAST_RANK  "l"
+#define __PRIPTR_RANK	"l"
+*/
+
+/* based on compiler output */
+typedef signed long int_fast16_t;
+typedef signed long int int_fast32_t;
+typedef unsigned long int uint_fast16_t;
+/* Pointer types */
+
+typedef long int intptr_t;
+typedef long unsigned int uintptr_t;
diff --git a/com32/include/bitsize64/stdintconst.h b/com32/include/bitsize64/stdintconst.h
new file mode 100644
index 0000000..139ab20
--- /dev/null
+++ b/com32/include/bitsize64/stdintconst.h
@@ -0,0 +1,13 @@
+/*
+ * bits64/stdintconst.h
+ */
+
+#define INT_FAST16_C(c)	 INT64_C(c)
+#define INT_FAST32_C(c)  INT64_C(c)
+
+#define UINT_FAST16_C(c) UINT64_C(c)
+#define UINT_FAST32_C(c) UINT64_C(c)
+
+#define INTPTR_C(c)	 INT64_C(c)
+#define UINTPTR_C(c)	 UINT64_C(c)
+#define PTRDIFF_C(c)     INT64_C(c)
diff --git a/com32/include/bitsize64/stdintlimits.h b/com32/include/bitsize64/stdintlimits.h
new file mode 100644
index 0000000..a775a7f
--- /dev/null
+++ b/com32/include/bitsize64/stdintlimits.h
@@ -0,0 +1,23 @@
+/*
+ * bits64/stdintlimits.h
+ */
+
+#define INT_FAST16_MIN	INT64_MIN
+#define INT_FAST32_MIN	INT64_MIN
+#define INT_FAST16_MAX	INT64_MAX
+#define INT_FAST32_MAX	INT64_MAX
+#define UINT_FAST16_MAX UINT64_MAX
+#define UINT_FAST32_MAX UINT64_MAX
+
+#define INTPTR_MIN	INT64_MIN
+#define INTPTR_MAX	INT64_MAX
+#define UINTPTR_MAX	UINT64_MAX
+
+#define PTRDIFF_MIN	INT64_MIN
+#define PTRDIFF_MAX	INT64_MAX
+
+/* sig_atomic_t limit */
+# define SIG_ATOMIC_MAX         INT32_MAX //(2147483647)
+# define SIG_ATOMIC_MIN         (-SIG_ATOMIC_MAX-1) //(-2147483647-1)
+/* size_t limit */
+# define SIZE_MAX		UINT64_MAX
diff --git a/com32/include/klibc/archsetjmp.h b/com32/include/klibc/i386/archsetjmp.h
similarity index 100%
copy from com32/include/klibc/archsetjmp.h
copy to com32/include/klibc/i386/archsetjmp.h
diff --git a/com32/include/klibc/x86_64/archsetjmp.h b/com32/include/klibc/x86_64/archsetjmp.h
new file mode 100644
index 0000000..454fc60
--- /dev/null
+++ b/com32/include/klibc/x86_64/archsetjmp.h
@@ -0,0 +1,21 @@
+/*
+ * arch/x86_64/include/klibc/archsetjmp.h
+ */
+
+#ifndef _KLIBC_ARCHSETJMP_H
+#define _KLIBC_ARCHSETJMP_H
+
+struct __jmp_buf {
+	unsigned long __rbx;
+	unsigned long __rsp;
+	unsigned long __rbp;
+	unsigned long __r12;
+	unsigned long __r13;
+	unsigned long __r14;
+	unsigned long __r15;
+	unsigned long __rip;
+};
+
+typedef struct __jmp_buf jmp_buf[1];
+
+#endif				/* _SETJMP_H */
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index d2af351..d3fba17 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -27,8 +27,16 @@ static inline __constfunc uint16_t __htons(uint16_t v)
 
 static inline __constfunc uint32_t __htonl(uint32_t v)
 {
+#if __SIZEOF_POINTER__ == 4
     asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
 	: "+q" (v));
+#elif __SIZEOF_POINTER__ == 8
+    asm("bswap	%0"
+	: "=r" (v)
+	: "0" (v));
+#else
+#error "unable to build for architecture"
+#endif
     return v;
 }
 
diff --git a/com32/include/setjmp.h b/com32/include/setjmp.h
index 11b18fb..e709095 100644
--- a/com32/include/setjmp.h
+++ b/com32/include/setjmp.h
@@ -9,7 +9,13 @@
 #include <klibc/compiler.h>
 #include <stddef.h>
 
-#include <klibc/archsetjmp.h>
+#if __SIZEOF_POINTER__ == 4
+#include <klibc/i386/archsetjmp.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <klibc/x86_64/archsetjmp.h>
+#else
+#error "unsupported architecture"
+#endif
 
 __extern int setjmp(jmp_buf);
 __extern __noreturn longjmp(jmp_buf, int);
diff --git a/com32/include/stdint.h b/com32/include/stdint.h
index a8391bf..0d0e8f6 100644
--- a/com32/include/stdint.h
+++ b/com32/include/stdint.h
@@ -5,6 +5,11 @@
 #ifndef _STDINT_H
 #define _STDINT_H
 
+/* FIXME: Move common typedefs to bitsize/stdint.h
+ * and architecture specificis to bitsize32/64
+ */
+#include <bitsize/stdint.h>
+#if 0
 /* Exact types */
 
 typedef signed char int8_t;
@@ -32,25 +37,28 @@ typedef unsigned long long uint_least64_t;
 /* Fast types */
 
 typedef signed char int_fast8_t;
-typedef signed short int_fast16_t;
-typedef signed int int_fast32_t;
-typedef signed long long int_fast64_t;
+typedef signed short int_fast16_t;	/* ?? 32: int 64: long */
+typedef signed int int_fast32_t;	/* ?? 64: long int */
+typedef signed long long int_fast64_t;	/* 64: long int */
 
 typedef unsigned char uint_fast8_t;
-typedef unsigned short uint_fast16_t;
+typedef unsigned short uint_fast16_t;	/* 32: unsigned int 64: short unsigned int */
 typedef unsigned int uint_fast32_t;
-typedef unsigned long long uint_fast64_t;
+typedef unsigned long long uint_fast64_t;/* 64: long unsigned int */
 
 /* Pointer types */
 
-typedef int32_t intptr_t;
-typedef uint32_t uintptr_t;
+typedef int32_t intptr_t;	/* 64: long int */
+typedef uint32_t uintptr_t;	/* 64: long unsigned int */
 
 /* Maximal types */
 
 typedef int64_t intmax_t;
 typedef uint64_t uintmax_t;
-
+#endif
+/* FIXME: move common definitions to bitsize/stdint.h and
+ * architecture specifics to bitsize32/64/stdintlimits.h as appropriate
+ */
 /*
  * To be strictly correct...
  */
@@ -71,54 +79,58 @@ typedef uint64_t uintmax_t;
 # define UINT32_MAX             (4294967295U)
 # define UINT64_MAX             (18446744073709551615ULL)
 
-# define INT_LEAST8_MIN               (-128)
-# define INT_LEAST16_MIN              (-32767-1)
-# define INT_LEAST32_MIN              (-2147483647-1)
-# define INT_LEAST64_MIN              (-9223372036854775807LL-1)
-
-# define INT_LEAST8_MAX               (127)
-# define INT_LEAST16_MAX              (32767)
-# define INT_LEAST32_MAX              (2147483647)
-# define INT_LEAST64_MAX              (9223372036854775807LL)
-
-# define UINT_LEAST8_MAX              (255U)
-# define UINT_LEAST16_MAX             (65535U)
-# define UINT_LEAST32_MAX             (4294967295U)
-# define UINT_LEAST64_MAX             (18446744073709551615ULL)
-
-# define INT_FAST8_MIN               (-128)
-# define INT_FAST16_MIN              (-32767-1)
-# define INT_FAST32_MIN              (-2147483647-1)
-# define INT_FAST64_MIN              (-9223372036854775807LL-1)
-
-# define INT_FAST8_MAX               (127)
-# define INT_FAST16_MAX              (32767)
-# define INT_FAST32_MAX              (2147483647)
-# define INT_FAST64_MAX              (9223372036854775807LL)
-
-# define UINT_FAST8_MAX              (255U)
-# define UINT_FAST16_MAX             (65535U)
-# define UINT_FAST32_MAX             (4294967295U)
-# define UINT_FAST64_MAX             (18446744073709551615ULL)
-
-# define INTPTR_MIN		(-2147483647-1)
-# define INTPTR_MAX		(2147483647)
-# define UINTPTR_MAX		(4294967295U)
+# define INT_LEAST8_MIN               INT8_MIN //(-128)
+# define INT_LEAST16_MIN              INT16_MIN //(-32767-1)
+# define INT_LEAST32_MIN              INT32_MIN //(-2147483647-1)
+# define INT_LEAST64_MIN              INT64_MIN //(-9223372036854775807LL-1)
+
+# define INT_LEAST8_MAX               INT8_MAX //(127)
+# define INT_LEAST16_MAX              INT16_MAX //(32767)
+# define INT_LEAST32_MAX              INT32_MAX //(2147483647)
+# define INT_LEAST64_MAX              INT64_MAX //(9223372036854775807LL)
+
+# define UINT_LEAST8_MAX              UINT8_MAX //(255U)
+# define UINT_LEAST16_MAX             UINT16_MAX //(65535U)
+# define UINT_LEAST32_MAX             UINT32_MAX //(4294967295U)
+# define UINT_LEAST64_MAX             UINT64_MAX //(18446744073709551615ULL)
+
+# define INT_FAST8_MIN               INT8_MIN //(-128)
+//# define INT_FAST16_MIN              (-32767-1)
+//# define INT_FAST32_MIN              (-2147483647-1)
+# define INT_FAST64_MIN              INT64_MIN //(-9223372036854775807LL-1)
+
+# define INT_FAST8_MAX               INT8_MAX //(127)
+//# define INT_FAST16_MAX              (32767)
+//# define INT_FAST32_MAX              (2147483647)
+# define INT_FAST64_MAX              INT64_MAX //(9223372036854775807LL)
+
+# define UINT_FAST8_MAX              UINT8_MAX //(255U)
+//# define UINT_FAST16_MAX             (65535U)
+//# define UINT_FAST32_MAX             (4294967295U)
+# define UINT_FAST64_MAX             UINT64_MAX //(18446744073709551615ULL)
+
+//FIXME: Move *INTPTR to architecture specific as they vary
+//# define INTPTR_MIN		(-2147483647-1)
+//# define INTPTR_MAX		(2147483647)
+//# define UINTPTR_MAX		(4294967295U)
 
 # define INTMAX_MIN		(-9223372036854775807LL-1)
 # define INTMAX_MAX		(9223372036854775807LL)
 # define UINTMAX_MAX		(18446744073709551615ULL)
 
+/* FIXME: include the architecture specific limits from bitsizexx/stdintlimits.h */
 /* ptrdiff_t limit */
-# define PTRDIFF_MIN		(-2147483647-1)
-# define PTRDIFF_MAX		(2147483647)
+//# define PTRDIFF_MIN		(-2147483647-1)
+//# define PTRDIFF_MAX		(2147483647)
 
 /* sig_atomic_t limit */
-# define SIG_ATOMIC_MIN         (-2147483647-1)
-# define SIG_ATOMIC_MAX         (2147483647)
+//# define SIG_ATOMIC_MIN         (-2147483647-1)
+//# define SIG_ATOMIC_MAX         (2147483647)
 
 /* size_t limit */
-# define SIZE_MAX		(4294967295U)
+//# define SIZE_MAX		(4294967295U)
+
+#include <bitsize/stdintlimits.h>
 
 #endif /* STDC_LIMIT_MACROS */
 
@@ -134,9 +146,31 @@ typedef uint64_t uintmax_t;
 # define UINT32_C(n)	n ## U
 # define UINT64_C(n)	n ## ULL
 
-# define INTMAX_C(n)	n ## LL
-# define UINTMAX_C(n)	n ## ULL
+//# define INTMAX_C(n)	n ## LL
+//# define UINTMAX_C(n)	n ## ULL
+
+/* included from klibc/usr/include/stdint.h */
+
+#define INT_LEAST8_C(c)	 INT8_C(c)
+#define INT_LEAST16_C(c) INT16_C(c)
+#define INT_LEAST32_C(c) INT32_C(c)
+#define INT_LEAST64_C(c) INT64_C(c)
+
+#define UINT_LEAST8_C(c)  UINT8_C(c)
+#define UINT_LEAST16_C(c) UINT16_C(c)
+#define UINT_LEAST32_C(c) UINT32_C(c)
+#define UINT_LEAST64_C(c) UINT64_C(c)
+
+#define INT_FAST8_C(c)	INT8_C(c)
+#define INT_FAST64_C(c) INT64_C(c)
+
+#define UINT_FAST8_C(c)  UINT8_C(c)
+#define UINT_FAST64_C(c) UINT64_C(c)
+
+#define INTMAX_C(c)	INT64_C(c)
+#define UINTMAX_C(c)	UINT64_C(c)
 
+#include <bitsize/stdintconst.h>
 #endif /* STDC_CONSTANT_MACROS */
 
 #endif /* _STDINT_H */
diff --git a/com32/include/sys/bitops.h b/com32/include/sys/bitops.h
index 40e09fe..de30d93 100644
--- a/com32/include/sys/bitops.h
+++ b/com32/include/sys/bitops.h
@@ -36,27 +36,11 @@
 
 #include <klibc/compiler.h>
 
-static inline void set_bit(long __bit, void *__bitmap)
-{
-    asm volatile("btsl %1,%0"
-		 : "+m" (*(unsigned char *)__bitmap)
-		 : "Ir" (__bit) : "memory");
-}
-
-static inline void clr_bit(long __bit, void *__bitmap)
-{
-    asm volatile("btcl %1,%0"
-		 : "+m" (*(unsigned char *)__bitmap)
-		 : "Ir" (__bit) : "memory");
-}
-
-static inline int __purefunc test_bit(long __bit, const void *__bitmap)
-{
-    unsigned char __r;
-    asm("btl %2,%1; setc %0"
-	: "=qm" (__r)
-	: "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
-    return __r;
-}
-
+#if __SIZEOF_POINTER__ == 4
+#include <i386/bitops.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <x86_64/bitops.h>
+#else
+#error "Unable to build for to-be-defined architecture type"
+#endif
 #endif /* _BITOPS_H */
diff --git a/com32/include/sys/cpu.h b/com32/include/sys/cpu.h
index 53a6250..05c9884 100644
--- a/com32/include/sys/cpu.h
+++ b/com32/include/sys/cpu.h
@@ -5,138 +5,12 @@
 #include <stdint.h>
 #include <klibc/compiler.h>
 
-static inline uint64_t rdtsc(void)
-{
-    uint64_t v;
-    asm volatile("rdtsc" : "=A" (v));
-    return v;
-}
-
-static inline uint32_t rdtscl(void)
-{
-    uint32_t v;
-    asm volatile("rdtsc" : "=a" (v) : : "edx");
-    return v;
-}
-
-static inline void cpuid_count(uint32_t op, uint32_t cnt,
-			       uint32_t * eax, uint32_t * ebx,
-			       uint32_t * ecx, uint32_t * edx)
-{
-    asm volatile("movl %%ebx,%1 ; "
-		 "cpuid ; "
-		 "xchgl %1,%%ebx"
-		 : "=a" (*eax), "=SD" (*ebx), "=c" (*ecx), "=d" (*edx)
-		 : "a"(op), "c"(cnt));
-}
-
-static inline void cpuid(uint32_t op, uint32_t * eax, uint32_t * ebx,
-			 uint32_t * ecx, uint32_t * edx)
-{
-    cpuid_count(op, 0, eax, ebx, ecx, edx);
-}
-
-static inline __constfunc uint32_t cpuid_eax(uint32_t level)
-{
-    uint32_t v;
-
-    asm volatile("pushl %%ebx ; "
-		 "cpuid ; "
-		 "popl %%ebx"
-		 : "=a" (v)
-		 : "a"(level)
-		 : "ecx", "edx");
-    return v;
-}
-
-static inline __constfunc uint32_t cpuid_ebx(uint32_t level)
-{
-    uint32_t v;
-
-    asm volatile("movl %%ebx,%0 ; "
-		 "cpuid ; "
-		 "xchgl %0,%%ebx"
-		 : "=SD" (v), "+a" (level)
-		 : : "ecx", "edx");
-    return v;
-}
-
-static inline __constfunc uint32_t cpuid_ecx(uint32_t level)
-{
-    uint32_t v;
-
-    asm volatile("pushl %%ebx ; "
-		 "cpuid ; "
-		 "popl %%ebx"
-		 : "=c" (v), "+a" (level)
-		 : : "edx");
-    return v;
-}
-
-static inline __constfunc uint32_t cpuid_edx(uint32_t level)
-{
-    uint32_t v;
-
-    asm volatile("pushl %%ebx ; "
-		 "cpuid ; "
-		 "popl %%ebx"
-		 : "=d" (v), "+a" (level)
-		 : : "ecx");
-    return v;
-}
-
-/* Standard macro to see if a specific flag is changeable */
-static inline __constfunc bool cpu_has_eflag(uint32_t flag)
-{
-	uint32_t f0, f1;
-
-	asm("pushfl ; "
-	    "pushfl ; "
-	    "popl %0 ; "
-	    "movl %0,%1 ; "
-	    "xorl %2,%1 ; "
-	    "pushl %1 ; "
-	    "popfl ; "
-	    "pushfl ; "
-	    "popl %1 ; "
-	    "popfl"
-	    : "=&r" (f0), "=&r" (f1)
-	    : "ri" (flag));
-
-	return !!((f0^f1) & flag);
-}
-
-static inline uint64_t rdmsr(uint32_t msr)
-{
-    uint64_t v;
-
-    asm volatile("rdmsr" : "=A" (v) : "c"(msr));
-    return v;
-}
-
-static inline void wrmsr(uint64_t v, uint32_t msr)
-{
-    asm volatile("wrmsr" : : "A" (v), "c" (msr));
-}
-
-static inline void cpu_relax(void)
-{
-    asm volatile("rep ; nop");
-}
-
-static inline void hlt(void)
-{
-    asm volatile("hlt");
-}
-
-static inline void cli(void)
-{
-    asm volatile("cli");
-}
-
-static inline void sti(void)
-{
-    asm volatile("sti");
-}
+#if __SIZEOF_POINTER__ == 4
+#include <i386/cpu.h>
+#elif __SIZEOF_POINTER__ == 8
+#include <x86_64/cpu.h>
+#else 
+#error "unsupported architecture"
+#endif
 
 #endif
diff --git a/com32/include/sys/bitops.h b/com32/include/sys/i386/bitops.h
similarity index 94%
copy from com32/include/sys/bitops.h
copy to com32/include/sys/i386/bitops.h
index 40e09fe..663b267 100644
--- a/com32/include/sys/bitops.h
+++ b/com32/include/sys/i386/bitops.h
@@ -26,16 +26,10 @@
  * ----------------------------------------------------------------------- */
 
 /*
- * bitops.h
+ * i386 bitops.h
  *
  * Simple bitwise operations
  */
-
-#ifndef _BITOPS_H
-#define _BITOPS_H
-
-#include <klibc/compiler.h>
-
 static inline void set_bit(long __bit, void *__bitmap)
 {
     asm volatile("btsl %1,%0"
@@ -58,5 +52,3 @@ static inline int __purefunc test_bit(long __bit, const void *__bitmap)
 	: "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
     return __r;
 }
-
-#endif /* _BITOPS_H */
diff --git a/com32/include/sys/cpu.h b/com32/include/sys/i386/cpu.h
similarity index 95%
copy from com32/include/sys/cpu.h
copy to com32/include/sys/i386/cpu.h
index 53a6250..63d0f5e 100644
--- a/com32/include/sys/cpu.h
+++ b/com32/include/sys/i386/cpu.h
@@ -1,9 +1,4 @@
-#ifndef _CPU_H
-#define _CPU_H
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <klibc/compiler.h>
+/* i386 cpu.h */
 
 static inline uint64_t rdtsc(void)
 {
@@ -138,5 +133,3 @@ static inline void sti(void)
 {
     asm volatile("sti");
 }
-
-#endif
diff --git a/com32/include/sys/bitops.h b/com32/include/sys/x86_64/bitops.h
similarity index 92%
copy from com32/include/sys/bitops.h
copy to com32/include/sys/x86_64/bitops.h
index 40e09fe..7b1cc2b 100644
--- a/com32/include/sys/bitops.h
+++ b/com32/include/sys/x86_64/bitops.h
@@ -26,19 +26,14 @@
  * ----------------------------------------------------------------------- */
 
 /*
- * bitops.h
+ * bitops.h - i386
  *
  * Simple bitwise operations
  */
 
-#ifndef _BITOPS_H
-#define _BITOPS_H
-
-#include <klibc/compiler.h>
-
 static inline void set_bit(long __bit, void *__bitmap)
 {
-    asm volatile("btsl %1,%0"
+    asm volatile("bts %1,%0"
 		 : "+m" (*(unsigned char *)__bitmap)
 		 : "Ir" (__bit) : "memory");
 }
@@ -53,10 +48,8 @@ static inline void clr_bit(long __bit, void *__bitmap)
 static inline int __purefunc test_bit(long __bit, const void *__bitmap)
 {
     unsigned char __r;
-    asm("btl %2,%1; setc %0"
+    asm("bt %2,%1; setc %0"
 	: "=qm" (__r)
 	: "m" (*(const unsigned char *)__bitmap), "Ir" (__bit));
     return __r;
 }
-
-#endif /* _BITOPS_H */
diff --git a/com32/include/sys/x86_64/cpu.h b/com32/include/sys/x86_64/cpu.h
new file mode 100644
index 0000000..89d7915
--- /dev/null
+++ b/com32/include/sys/x86_64/cpu.h
@@ -0,0 +1,148 @@
+#ifndef _CPU_X86_64_H
+#define _CPU_X86_64_H
+
+/* x86_64 cpu.h  */
+
+static inline uint64_t rdtsc(void)
+{
+    uint64_t v;
+    asm volatile("rdtsc" : "=A" (v));
+    return v;
+}
+
+static inline uint32_t rdtscl(void)
+{
+    uint32_t v;
+    asm volatile("rdtsc" : "=a" (v) : : "edx");
+    return v;
+}
+
+static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
+                                unsigned int *ecx, unsigned int *edx)
+{
+        /* ecx is often an input as well as an output. */
+        asm volatile("cpuid"
+            : "=a" (*eax),
+              "=b" (*ebx),
+              "=c" (*ecx),
+              "=d" (*edx)
+            : "0" (*eax), "2" (*ecx)
+            : "memory");
+}
+/*
+ * Generic CPUID function
+ * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
+ * resulting in stale register contents being returned.
+ */
+static inline void cpuid(uint32_t op,
+                         uint32_t *eax, uint32_t *ebx,
+                         uint32_t *ecx, uint32_t *edx)
+{
+        *eax = op;
+        *ecx = 0;
+        native_cpuid(eax, ebx, ecx, edx);
+}
+
+/*
+ * CPUID functions returning a single datum
+ */
+static inline uint32_t cpuid_eax(uint32_t op)
+{
+        uint32_t eax, ebx, ecx, edx;
+
+        cpuid(op, &eax, &ebx, &ecx, &edx);
+
+        return eax;
+}
+
+static inline uint32_t cpuid_ebx(uint32_t op)
+{
+        uint32_t eax, ebx, ecx, edx;
+
+        cpuid(op, &eax, &ebx, &ecx, &edx);
+
+        return ebx;
+}
+
+static inline uint32_t cpuid_ecx(uint32_t op)
+{
+        uint32_t eax, ebx, ecx, edx;
+
+        cpuid(op, &eax, &ebx, &ecx, &edx);
+
+        return ecx;
+}
+
+static inline uint32_t cpuid_edx(uint32_t op)
+{
+        uint32_t eax, ebx, ecx, edx;
+
+        cpuid(op, &eax, &ebx, &ecx, &edx);
+
+        return edx;
+}
+
+static inline void cpuid_count(uint32_t op, uint32_t cnt,
+			       uint32_t * eax, uint32_t * ebx,
+			       uint32_t * ecx, uint32_t * edx)
+{
+    asm volatile("movl %%ebx,%1 ; "
+		 "cpuid ; "
+		 "xchgl %1,%%ebx"
+		 : "=a" (*eax), "=SD" (*ebx), "=c" (*ecx), "=d" (*edx)
+		 : "a"(op), "c"(cnt));
+}
+
+/* Standard macro to see if a specific flag is changeable */
+static inline __constfunc bool cpu_has_eflag(uint32_t flag)
+{
+	/* x86_64 */
+	uint64_t f0, f1;
+	asm("pushf ; "
+	    "pushf ; "
+	    "pop %0 ; "
+	    "mov %0,%1 ; "
+	    "xor %2,%1 ; "
+	    "push %1 ; "
+	    "popf ; "
+	    "pushf ; "
+	    "pop %1 ; "
+	    "popf"
+	    : "=&r" (f0), "=&r" (f1)
+	    : "ri" (flag));
+	return !!((f0^f1) & flag);
+}
+
+static inline uint64_t rdmsr(uint32_t msr)
+{
+    uint64_t v;
+
+    asm volatile("rdmsr" : "=A" (v) : "c"(msr));
+    return v;
+}
+
+static inline void wrmsr(uint64_t v, uint32_t msr)
+{
+    asm volatile("wrmsr" : : "A" (v), "c" (msr));
+}
+
+static inline void cpu_relax(void)
+{
+    asm volatile("rep ; nop");
+}
+
+static inline void hlt(void)
+{
+    asm volatile("hlt");
+}
+
+static inline void cli(void)
+{
+    asm volatile("cli");
+}
+
+static inline void sti(void)
+{
+    asm volatile("sti");
+}
+#endif
diff --git a/dos/stdlib.h b/dos/stdlib.h
index d346705..d982670 100644
--- a/dos/stdlib.h
+++ b/dos/stdlib.h
@@ -2,7 +2,14 @@
 #define STDLIB_H
 
 typedef int ssize_t;
+/* size_t is defined elsewhere */
+#if __SIZEOF_POINTER__ == 4
 typedef unsigned int size_t;
+#elif __SIZEOF_POINTER__ == 8
+typedef unsigned long size_t;
+#else
+#error "unsupported architecture"
+#endif
 
 void __attribute__ ((noreturn)) exit(int);
 


More information about the Syslinux-commits mailing list