view dyncall/dyncall_callvm_sparc.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 ddfb9577a00e
children
line wrap: on
line source

/*

 Package: dyncall
 Library: dyncall
 File: dyncall/dyncall_callvm_sparc.c
 Description: Call VM for sparc processor architecture.
 License:

   Copyright (c) 2011-2020 Daniel Adler <dadler@uni-goettingen.de>

   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_callvm_sparc.h"
#include "dyncall_utils.h"
#include "dyncall_alloc.h"
#define DEFAULT_STACK_ALIGN	16


void dcCall_sparc(DCpointer target, DCsize size, DCpointer data);


/* Destructor. */
static void dc_callvm_free_sparc(DCCallVM* in_self)
{
  dcFreeMem(in_self);
}

/* Reset argument buffer. */
static void dc_callvm_reset_sparc(DCCallVM* in_self)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecReset(&self->mVecHead);
}

/* Load integer 32-bit. */
static void dc_callvm_argInt_sparc(DCCallVM* in_self, DCint x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DCint));
}

/* we propagate Bool,Char,Short to Int. */

static void dc_callvm_argBool_sparc(DCCallVM* in_self, DCbool x) { dc_callvm_argInt_sparc(in_self, (DCint)x); }
static void dc_callvm_argChar_sparc(DCCallVM* in_self, DCchar x) { dc_callvm_argInt_sparc(in_self, (DCint)x); }
static void dc_callvm_argShort_sparc(DCCallVM* in_self, DCshort x) { dc_callvm_argInt_sparc(in_self, (DCint)x); }

/* handle others Pointer, Long, LongLong, Float and Double as-is. */

static void dc_callvm_argPointer_sparc(DCCallVM* in_self, DCpointer x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DCpointer));
}

static void dc_callvm_argLong_sparc(DCCallVM* in_self, DClong x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DClong));
}
static void dc_callvm_argLongLong_sparc(DCCallVM* in_self, DClonglong x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DClonglong));
}
static void dc_callvm_argFloat_sparc(DCCallVM* in_self, DCfloat x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DCfloat));
}
static void dc_callvm_argDouble_sparc(DCCallVM* in_self, DCdouble x)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcVecAppend(&self->mVecHead, &x, sizeof(DCdouble));
}

/* we call directly with 'RTYPE dcCall(DCCallVM* in_self, DCpointer target)' */
#if 0
/* call: delegate to default call kernel */
static void dc_callvm_call_sparc(DCCallVM* in_self, DCpointer target)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  dcCall_sparc(target, dcVecSize(&self->mVecHead), dcVecData(&self->mVecHead));
}
#endif

static void dc_callvm_mode_sparc(DCCallVM* in_self, DCint mode);

/* CallVM virtual table. */
DCCallVM_vt gVT_sparc =
{
  &dc_callvm_free_sparc,
  &dc_callvm_reset_sparc,
  &dc_callvm_mode_sparc,
  &dc_callvm_argBool_sparc,
  &dc_callvm_argChar_sparc,
  &dc_callvm_argShort_sparc,
  &dc_callvm_argInt_sparc,
  &dc_callvm_argLong_sparc,
  &dc_callvm_argLongLong_sparc,
  &dc_callvm_argFloat_sparc,
  &dc_callvm_argDouble_sparc,
  &dc_callvm_argPointer_sparc,
  NULL /* argAggr */,
  (DCvoidvmfunc*)       &dcCall_sparc,
  (DCboolvmfunc*)       &dcCall_sparc,
  (DCcharvmfunc*)       &dcCall_sparc,
  (DCshortvmfunc*)      &dcCall_sparc,
  (DCintvmfunc*)        &dcCall_sparc,
  (DClongvmfunc*)       &dcCall_sparc,
  (DClonglongvmfunc*)   &dcCall_sparc,
  (DCfloatvmfunc*)      &dcCall_sparc,
  (DCdoublevmfunc*)     &dcCall_sparc,
  (DCpointervmfunc*)    &dcCall_sparc,
  NULL /* callAggr */,
  NULL /* beginAggr */
};

/* mode: only a single mode available currently. */
static void dc_callvm_mode_sparc(DCCallVM* in_self, DCint mode)
{
  DCCallVM_sparc* self = (DCCallVM_sparc*)in_self;
  DCCallVM_vt* vt;

  switch(mode) {
    case DC_CALL_C_DEFAULT:
    case DC_CALL_C_DEFAULT_THIS:
    case DC_CALL_C_SPARC32:
    case DC_CALL_C_ELLIPSIS:
    case DC_CALL_C_ELLIPSIS_VARARGS:
      vt = &gVT_sparc;
      break;
    default:
      self->mInterface.mError = DC_ERROR_UNSUPPORTED_MODE;
      return;
  }
  dc_callvm_base_init(&self->mInterface, vt);
}

/* Public API. */
DCCallVM* dcNewCallVM(DCsize size)
{
  DCCallVM_sparc* p;

  /* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */
  size = DC_MAX(size, sizeof(void*)*(6+1));
  p = (DCCallVM_sparc*)dcAllocMem(sizeof(DCCallVM_sparc)+size);

  dc_callvm_mode_sparc((DCCallVM*)p, DC_CALL_C_DEFAULT);

  dcVecInit(&p->mVecHead, size);

  return (DCCallVM*)p;
}