summaryrefslogtreecommitdiffstats
path: root/libsyscalls_get_integer_alignment.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-12-17 13:23:51 +0100
committerMattias Andrée <maandree@kth.se>2023-12-17 13:23:51 +0100
commit2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea (patch)
treea321a6a0b4bc93cbc1b7704239a675c490383b6d /libsyscalls_get_integer_alignment.c
parentTell the user whether signals and errors are signed or unsigned (diff)
downloadlibsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.gz
libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.bz2
libsyscalls-2e7b4df9f7dfd6a4a6796cd2fcee010ea78427ea.tar.xz
Miscellaneous improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsyscalls_get_integer_alignment.c')
-rw-r--r--libsyscalls_get_integer_alignment.c69
1 files changed, 11 insertions, 58 deletions
diff --git a/libsyscalls_get_integer_alignment.c b/libsyscalls_get_integer_alignment.c
index 1c2d10e..f13f40f 100644
--- a/libsyscalls_get_integer_alignment.c
+++ b/libsyscalls_get_integer_alignment.c
@@ -4,73 +4,26 @@
#include "generated/integers.c"
+#define X(ARCH, CHARBITS, INTPTR_BITS, SIZE_BITS, INTMAX_ALIGN, ENDIAN, SIGN) [ARCH] = INTMAX_ALIGN
+static const unsigned char aligntable[] = {LIST_ARCH_SPECS(X, COMMA)};
+#undef X
+
enum libsyscalls_error
-libsyscalls_get_integer_alignment(enum libsyscalls_os os, enum libsyscalls_arch arch, unsigned width_in_bits, unsigned *alignment_out)
+libsyscalls_get_integer_alignment(enum libsyscalls_os os, enum libsyscalls_arch arch,
+ unsigned width_in_bits, unsigned *alignment_out)
{
unsigned maxalign;
if (!width_in_bits)
return LIBSYSCALLS_E_INVAL;
- switch ((int)arch) {
- case LIBSYSCALLS_ARCH_M68K: /* https://m680x0.github.io/doc/abi.html#scalar-types
- * https://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg04797.html */
- maxalign = 16;
- break;
-
- case LIBSYSCALLS_ARCH_I386:
- case LIBSYSCALLS_ARCH_ARM_OABI_LE: /* https://wiki.debian.org/ArmEabiPort#A64-bit_data_type_alignment */
- case LIBSYSCALLS_ARCH_ARM_OABI_BE:
- case LIBSYSCALLS_ARCH_SH_LE: /* https://www.st.com/resource/en/reference_manual/rm0197-sh4-generic-and-c-specific-application-binary-interface-stmicroelectronics.pdf (page 12) */
- case LIBSYSCALLS_ARCH_SH_BE:
- case LIBSYSCALLS_ARCH_MICROBLAZE_32_LE: /* https://www.ecb.torontomu.ca/~courses/ee8205/Data-Sheets/sopc/MicroBlaze_DataSheet.pdf */
- case LIBSYSCALLS_ARCH_MICROBLAZE_32_BE:
- maxalign = 32;
- break;
-
- case LIBSYSCALLS_ARCH_AMD64:
- case LIBSYSCALLS_ARCH_AMD64_X32:
- case LIBSYSCALLS_ARCH_ARM_EABI_LE: /* https://wiki.debian.org/ArmEabiPort#A64-bit_data_type_alignment */
- case LIBSYSCALLS_ARCH_ARM_EABI_BE:
- case LIBSYSCALLS_ARCH_ALPHA_LE: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
- case LIBSYSCALLS_ARCH_ALPHA_BE:
- case LIBSYSCALLS_ARCH_IA64_LE: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
- case LIBSYSCALLS_ARCH_IA64_BE:
- case LIBSYSCALLS_ARCH_IA64_P32_LE:
- case LIBSYSCALLS_ARCH_IA64_P32_BE:
- case LIBSYSCALLS_ARCH_MIPS_O32_LE: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
- case LIBSYSCALLS_ARCH_MIPS_O32_BE:
- case LIBSYSCALLS_ARCH_MIPS_N32_LE: /* https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00083-2B-MIPS64INT-AFP-05.04.pdf (page 40) */
- case LIBSYSCALLS_ARCH_MIPS_N32_BE:
- case LIBSYSCALLS_ARCH_MIPS_N64_LE:
- case LIBSYSCALLS_ARCH_MIPS_N64_BE:
- case LIBSYSCALLS_ARCH_PARISC_32: /* https://www.ece.lsu.edu/ee4720/doc/pa1.1.pdf (page 26) */
- case LIBSYSCALLS_ARCH_PARISC_64:
- case LIBSYSCALLS_ARCH_POWERPC_32_LE: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
- case LIBSYSCALLS_ARCH_POWERPC_32_BE:
- case LIBSYSCALLS_ARCH_POWERPC_64_LE: /* https://www.slac.stanford.edu/exp/npa/software/eabi_app.pdf */
- case LIBSYSCALLS_ARCH_POWERPC_64_BE:
- case LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE:
- case LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE:
- case LIBSYSCALLS_ARCH_POWERPC_SPU_LE:
- case LIBSYSCALLS_ARCH_POWERPC_SPU_BE:
- case LIBSYSCALLS_ARCH_S390_32: /* https://refspecs.linuxbase.org/ELF/zSeries/lzsabi0_s390.html */
- case LIBSYSCALLS_ARCH_S390_64:
- case LIBSYSCALLS_ARCH_SPARC_32: /* https://www.gaisler.com/doc/sparcv8.pdf (page 46) */
- case LIBSYSCALLS_ARCH_SPARC_64_LE: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
- case LIBSYSCALLS_ARCH_SPARC_64_BE:
- case LIBSYSCALLS_ARCH_XTENSA_LE: /* https://loboris.eu/ESP32/Xtensa_lx%20Overview%20handbook.pdf (page 97) */
- case LIBSYSCALLS_ARCH_XTENSA_BE:
- case LIBSYSCALLS_ARCH_MICROBLAZE_64_LE: /* https://www.amd.com/content/dam/xilinx/support/documents/sw_manuals/xilinx2021_2/ug984-vivado-microblaze-ref.pdf */
- case LIBSYSCALLS_ARCH_MICROBLAZE_64_BE:
- maxalign = 64;
- break;
-
- default:
+ if ((size_t)arch >= ELEMSOF(aligntable))
+ return LIBSYSCALLS_E_ARCHNOSUP;
+ maxalign = aligntable[(size_t)arch];
+ if (!maxalign)
return LIBSYSCALLS_E_ARCHNOSUP;
- }
- if (width_in_bits & (width_in_bits - 1) || width_in_bits & 7 || width_in_bits > 64)
+ if (IS_NOT_2POW(width_in_bits) || width_in_bits % 8 || width_in_bits > 64)
return LIBSYSCALLS_E_NOSUCHTYPE;
*alignment_out = width_in_bits < maxalign ? width_in_bits : maxalign;