blob: 7802a06ad25ef2778d4a4c8213994b2829dd3531 (
plain) (
tree)
|
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#include "generated/integers.c"
enum libsyscalls_error
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:
maxalign = 32;
break;
case LIBSYSCALLS_ARCH_AMD64:
case LIBSYSCALLS_ARCH_AMD64_X32:
case LIBSYSCALLS_ARCH_ALPHA: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
case LIBSYSCALLS_ARCH_IA64: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
case LIBSYSCALLS_ARCH_MIPS_O32: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
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: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
case LIBSYSCALLS_ARCH_SPARC_32: /* https://www.gaisler.com/doc/sparcv8.pdf (page 46) */
case LIBSYSCALLS_ARCH_SPARC_64: /* https://static.lwn.net/images/pdf/LDD3/ch11.pdf */
case LIBSYSCALLS_ARCH_XTENSA: /* https://loboris.eu/ESP32/Xtensa_lx%20Overview%20handbook.pdf (page 97) */
maxalign = 64;
break;
default:
return LIBSYSCALLS_E_ARCHNOSUP;
}
if (width_in_bits & (width_in_bits - 1) || width_in_bits & 7 || width_in_bits > 64)
return LIBSYSCALLS_E_NOSUCHTYPE;
*alignment_out = width_in_bits < maxalign ? width_in_bits : maxalign;
#define CASE(UPPERCASE, LOWERCASE)\
case LIBSYSCALLS_OS_##UPPERCASE:\
return get_##LOWERCASE##_integer_alignment(arch, width_in_bits, alignment_out)
switch ((int)os) {
LIST_OSES(CASE, ;);
default:
return LIBSYSCALLS_E_OSNOSUP;
}
#undef CASE
}
|