summaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common.h102
1 files changed, 53 insertions, 49 deletions
diff --git a/common.h b/common.h
index e2a5422..8b2ff2b 100644
--- a/common.h
+++ b/common.h
@@ -57,12 +57,16 @@
#define COMMA ,
-#define MISALIGNMENT(ADDR, ALIGN) (((ADDR) - ((ADDR) % (uintptr_t)(ALIGN))) % (uintptr_t)(ALIGN))
-#define ALIGN_BUF(BUF, ALIGN) (&(BUF)[(size_t)MISALIGNMENT((uintptr_t)(char *)(BUF), (ALIGN))])
+#define MISALIGNMENT(ADDR, ALIGN) ((ADDR) & ((uintptr_t)(ALIGN) - 1U))
+#define ALIGNMENT_ADJUSTMENT(ADDR, ALIGN) MISALIGNMENT((ALIGN) - MISALIGNMENT((ADDR), (ALIGN)), (ALIGN))
+#define ALIGN_BUF(BUF, ALIGN) (&(BUF)[(size_t)ALIGNMENT_ADJUSTMENT((uintptr_t)(char *)(BUF), (ALIGN))])
#define ELEMSOF(ARR) (sizeof(ARR) / sizeof *(ARR))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define LOWEST_BIT(X) ((X) & ~((X) - 1))
-#define POST_HIGHEST_OF_CONSECUTIVELY_BITS(X) ((X) + LOWEST_BIT(X))
+#define POST_HIGHEST_OF_CONSECUTIVELY_BITS(X) ((X) + LOWEST_BIT((X)))
+#define IS_NOT_2POW(X) ((X) & ((X) - 1))
+#define SET_MASK_TRAIL(X) ((X) | ((X) - 1U))
+#define USAT_MINUS(A, B) ((A) < (B) ? 0 : (A) - (B))
struct libsyscalls_symbol_printer_data {
@@ -76,54 +80,54 @@ enum endian {
Little
};
-
-/* Don't forget to update SUPPORTED_ARCHES in Makefile */
-#define LIST_ARCH_SPECS(X, D) /* byte intptr size_t endian sign */\
- X(LIBSYSCALLS_ARCH_ALPHA_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_ALPHA_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_AMD64, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_AMD64_X32, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
+ /* [------ size ------] [align] */
+#define LIST_ARCH_SPECS(X, D) /* byte intptr size_t intmax endian sign */\
+ X(LIBSYSCALLS_ARCH_ALPHA_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_ALPHA_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_AMD64, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_AMD64_X32, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
/*
- X(LIBSYSCALLS_ARCH_ARM_OABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_ARM_OABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_ARM_EABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_ARM_EABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_ARM_OABI_LE, 8, TODO, TODO, 32, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_ARM_OABI_BE, 8, TODO, TODO, 32, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_ARM_EABI_LE, 8, TODO, TODO, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_ARM_EABI_BE, 8, TODO, TODO, 64, Big, TWOS_COMPLEMENT) D\
*/\
- X(LIBSYSCALLS_ARCH_IA64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_IA64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_IA64_P32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_IA64_P32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_M68K, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MICROBLAZE_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MICROBLAZE_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MICROBLAZE_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MICROBLAZE_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_O32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_O32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_N32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_N32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_N64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_MIPS_N64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_PARISC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_PARISC_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_SPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_POWERPC_SPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_S390_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_S390_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_SH_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_SH_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_SPARC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_SPARC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_SPARC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_I386, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_XTENSA_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\
- X(LIBSYSCALLS_ARCH_XTENSA_BE, 8, 32, 32, Big, TWOS_COMPLEMENT)
+ X(LIBSYSCALLS_ARCH_IA64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_IA64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_IA64_P32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_IA64_P32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_M68K, 8, 32, 32, 16, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MICROBLAZE_32_LE, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MICROBLAZE_32_BE, 8, 32, 32, 32, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MICROBLAZE_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MICROBLAZE_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_O32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_O32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_N32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_N32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_N64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_MIPS_N64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_PARISC_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_PARISC_64, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_32_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_32_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_SPU_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_POWERPC_SPU_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_S390_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_S390_64, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_SH_LE, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_SH_BE, 8, 32, 32, 32, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_SPARC_32, 8, 32, 32, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_SPARC_64_LE, 8, 64, 64, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_SPARC_64_BE, 8, 64, 64, 64, Big, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_I386, 8, 32, 32, 32, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_XTENSA_LE, 8, 32, 32, 64, Little, TWOS_COMPLEMENT) D\
+ X(LIBSYSCALLS_ARCH_XTENSA_BE, 8, 32, 32, 64, Big, TWOS_COMPLEMENT)
+ /* Don't forget to update SUPPORTED_ARCHES in Makefile */
#include "generated/oses.h"