diff options
Diffstat (limited to 'com32/include')
26 files changed, 830 insertions, 235 deletions
diff --git a/com32/include/bitsize/limits.h b/com32/include/bitsize/limits.h index f90e524b..7129c4a6 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 caa5e726..3d5c3e7a 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 8cbfc5dd..854c5430 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 8157dd06..ae4e9fc0 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 b44fe011..9f3657d2 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/bitsize32/limits.h b/com32/include/bitsize32/limits.h new file mode 100644 index 00000000..8eb97d6d --- /dev/null +++ b/com32/include/bitsize32/limits.h @@ -0,0 +1,14 @@ +/* + * bits32/limits.h + */ + +#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 + +#endif /* _BITSIZE_LIMITS_H */ diff --git a/com32/include/bitsize32/stddef.h b/com32/include/bitsize32/stddef.h new file mode 100644 index 00000000..e5d49376 --- /dev/null +++ b/com32/include/bitsize32/stddef.h @@ -0,0 +1,13 @@ +/* + * bits32/stddef.h + */ + +#define _SIZE_T +#if defined(__s390__) || defined(__hppa__) || defined(__cris__) +typedef unsigned long size_t; +#else +typedef unsigned int size_t; +#endif + +#define _PTRDIFF_T +typedef signed int ptrdiff_t; diff --git a/com32/include/bitsize32/stdint.h b/com32/include/bitsize32/stdint.h new file mode 100644 index 00000000..c886a4c2 --- /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/bitsize32/stdintconst.h b/com32/include/bitsize32/stdintconst.h new file mode 100644 index 00000000..71ece423 --- /dev/null +++ b/com32/include/bitsize32/stdintconst.h @@ -0,0 +1,13 @@ +/* + * bits32/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) diff --git a/com32/include/bitsize32/stdintlimits.h b/com32/include/bitsize32/stdintlimits.h new file mode 100644 index 00000000..175cdcd4 --- /dev/null +++ b/com32/include/bitsize32/stdintlimits.h @@ -0,0 +1,23 @@ +/* + * bits32/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 + +/* 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 00000000..f5bbf830 --- /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 00000000..057a721f --- /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 00000000..32de44c5 --- /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 00000000..139ab203 --- /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 00000000..a775a7fd --- /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/i386/archsetjmp.h b/com32/include/klibc/i386/archsetjmp.h new file mode 100644 index 00000000..a0def6a1 --- /dev/null +++ b/com32/include/klibc/i386/archsetjmp.h @@ -0,0 +1,19 @@ +/* + * arch/i386/include/klibc/archsetjmp.h + */ + +#ifndef _KLIBC_ARCHSETJMP_H +#define _KLIBC_ARCHSETJMP_H + +struct __jmp_buf { + unsigned int __ebx; + unsigned int __esp; + unsigned int __ebp; + unsigned int __esi; + unsigned int __edi; + unsigned int __eip; +}; + +typedef struct __jmp_buf jmp_buf[1]; + +#endif /* _SETJMP_H */ diff --git a/com32/include/klibc/x86_64/archsetjmp.h b/com32/include/klibc/x86_64/archsetjmp.h new file mode 100644 index 00000000..454fc60a --- /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 d2af351f..d3fba17f 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 11b18fbd..e7090955 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 a8391bf9..0d0e8f69 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 40e09fe7..de30d932 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 53a6250e..05c98843 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/i386/bitops.h b/com32/include/sys/i386/bitops.h new file mode 100644 index 00000000..663b267a --- /dev/null +++ b/com32/include/sys/i386/bitops.h @@ -0,0 +1,54 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010-2011 Intel Corporation; author: H. Peter Anvin + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- */ + +/* + * i386 bitops.h + * + * Simple bitwise operations + */ +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; +} diff --git a/com32/include/sys/i386/cpu.h b/com32/include/sys/i386/cpu.h new file mode 100644 index 00000000..63d0f5ed --- /dev/null +++ b/com32/include/sys/i386/cpu.h @@ -0,0 +1,135 @@ +/* i386 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 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"); +} diff --git a/com32/include/sys/x86_64/bitops.h b/com32/include/sys/x86_64/bitops.h new file mode 100644 index 00000000..7b1cc2b6 --- /dev/null +++ b/com32/include/sys/x86_64/bitops.h @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010-2011 Intel Corporation; author: H. Peter Anvin + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- */ + +/* + * bitops.h - i386 + * + * Simple bitwise operations + */ + +static inline void set_bit(long __bit, void *__bitmap) +{ + asm volatile("bts %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("bt %2,%1; setc %0" + : "=qm" (__r) + : "m" (*(const unsigned char *)__bitmap), "Ir" (__bit)); + return __r; +} diff --git a/com32/include/sys/x86_64/cpu.h b/com32/include/sys/x86_64/cpu.h new file mode 100644 index 00000000..89d79154 --- /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 |