view dyncallback/dyncall_args_arm32.c @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents f5577f6bf97a
children 2562c89d5bb5
line wrap: on
line source

/*

 Package: dyncall
 Library: dyncallback
 File: dyncallback/dyncall_args_arm32.c
 Description: Callback's Arguments VM - Implementation for ARM32 (ARM and THUMB mode)
 License:

   Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
                           Tassilo Philipp <tphilipp@potion-studios.com>

   Permission to use, copy, modify, and distribute this software for any
   purpose with or without fee is hereby granted, provided that the above
   copyright notice and this permission notice appear in all copies.

   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/



#include "dyncall_args_arm32.h"


static void arm_align_64(DCArgs* args)
{
  /* Look at signature to see if current calling convention needs alignment */
  /* or not (e.g. EABI has different alignment). If nothing specified, fall */
  /* back to default behaviour for this platform.                           */
  /* @@@ check signature string */

  int sig =
#if defined(DC__ABI_ARM_EABI) || defined(DC__ABI_ARM_HF)
    0; /* EABI */
#else
    1; /* ATPCS */
#endif
  if(sig == 0) {
    if(args->reg_count < 4)
      args->reg_count = (args->reg_count+1)&~1;
    if(args->reg_count >= 4 && (int)args->stack_ptr & 4)
      ++args->stack_ptr;
  }
}


static void* arm_word(DCArgs* args)
{
  if(args->reg_count < 4)
    return &args->reg_data[args->reg_count++];
  else
    return (void*)args->stack_ptr++;
}

static DCfloat arm_float(DCArgs* args)
{
#if defined(DC__ABI_ARM_HF)
  DCfloat f;
  if(args->freg_count < 16) {
    f = args->f[args->freg_count++];

    /* if freg_count was odd, sync with dreg_count */
    if(!(args->freg_count & 1) && (args->freg_count < args->dreg_count))
      args->freg_count = args->dreg_count;

    return f;
  }
#endif
  return *(DCfloat*)arm_word(args);
}

static DCdouble arm_double(DCArgs* args)
{
  union {
    DCdouble d;
    DClong   l[2];
  } d;
#if defined(DC__ABI_ARM_HF)
  if(args->dreg_count < args->freg_count)
    args->dreg_count = (args->freg_count+1)&0x1e; /* clear last bit, counter won't be higher than 16, anyways */

  if(args->dreg_count < 16) {
    d.d = *(DCdouble*)&args->f[args->dreg_count];
    args->dreg_count += 2;

    /* freg_count is either odd (pointing to a gap), or always the same as dreg_count */
    if(!(args->freg_count & 1))
      args->freg_count = args->dreg_count;
    return d.d;
  }
  args->freg_count = 16; /* fp registers all full - need to use stack now: stop filling gaps for single precision, also */
#endif
  arm_align_64(args);
  d.l[0] = *(DClong*)arm_word(args);
  d.l[1] = *(DClong*)arm_word(args);
  return d.d;
}

static DClonglong arm_longlong(DCArgs* args)
{
  union {
    DClonglong ll;
    DClong     l[2];
  } ll;
  arm_align_64(args);
  ll.l[0] = *(DClong*)arm_word(args);
  ll.l[1] = *(DClong*)arm_word(args);
  return ll.ll;
}


DClonglong  dcbArgLongLong (DCArgs* p) { return arm_longlong(p); }
DClong      dcbArgLong     (DCArgs* p) { return *(DClong*)arm_word(p); }
DCint       dcbArgInt      (DCArgs* p) { return (DCint)   dcbArgLong(p); }
DCchar      dcbArgChar     (DCArgs* p) { return (DCchar)  dcbArgLong(p); }
DCshort     dcbArgShort    (DCArgs* p) { return (DCshort) dcbArgLong(p); }
DCbool      dcbArgBool     (DCArgs* p) { return (dcbArgLong(p) == 0) ? 0 : 1; }

DCuint      dcbArgUInt     (DCArgs* p) { return (DCuint)     dcbArgInt(p);      }
DCuchar     dcbArgUChar    (DCArgs* p) { return (DCuchar)    dcbArgChar(p);     }
DCushort    dcbArgUShort   (DCArgs* p) { return (DCushort)   dcbArgShort(p);    }
DCulong     dcbArgULong    (DCArgs* p) { return (DCulong)    dcbArgLong(p);     }
DCulonglong dcbArgULongLong(DCArgs* p) { return (DCulonglong)dcbArgLongLong(p); }


DCpointer   dcbArgPointer  (DCArgs* p) { return (DCpointer)  dcbArgLong(p); }

DCdouble    dcbArgDouble   (DCArgs* p) { return arm_double(p); }
DCfloat     dcbArgFloat    (DCArgs* p) { return arm_float(p); }

void        dcbArgAggr     (DCArgs* p, DCpointer target)                   { /* @@@AGGR not impl */ }
void        dcbReturnAggr  (DCArgs *args, DCValue *result, DCpointer ret)  { /* @@@AGGR not impl */ }