From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94297 invoked by alias); 13 Apr 2019 18:26:32 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 94288 invoked by uid 89); 13 Apr 2019 18:26:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,SPF_PASS autolearn=ham version=3.3.1 spammy=HTo:U*libffi-discuss, consulting, 9000, 12th X-HELO: mail.unix.io Received: from mail.unix.io (HELO mail.unix.io) (168.235.70.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 13 Apr 2019 18:26:29 +0000 Received: from gateway.int.ninth-art.de (gateway.int.ninth-art.de [10.8.0.3]) by mail.unix.io (Postfix) with ESMTP id 253DE1CAD4A4 for ; Sat, 13 Apr 2019 14:26:28 -0400 (EDT) Received: from gateway.int.ninth-art.de (orion.int.ninth-art.de [192.168.0.6]) by gateway.int.ninth-art.de (Postfix) with ESMTP id 6F68E32E0B for ; Sat, 13 Apr 2019 20:26:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bege.email; h=reply-to:to :from:subject:message-id:date:mime-version:content-type; s= mail141202; bh=FetnbB0IS1UvmrD6CYyAVzsFVPE=; b=KRYcfgKiRyF0iHaQL RNbK+wAUabv8c1vxRbGVGP79ChOJMcYz241YrckaPZLS0DsHwQWo+72nRkHnBwfr yx0yHEl8VX/ENUfVPdocrgbjdZ98Aup9uLibeTblKPWVDyPsFVwAWEFRt6S/FACC JX7PEoTBuhaadrfc8UmT1K/sBo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=bege.email; h=reply-to:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=mail141202; b=6rBSBglYlEpdbIzUGwXfWu2DS5pJrBs4w9Y94F0pjsH5jnk 72ldDBNu9aCN6fXlqs0YoMUT8yldl3a6rGvTo8Knnw+swn9T8HKJkzqTbAYkfe/g jqIPW/EzKv0p+vUGxs8ISSxdSFTxm0olnLVIqGmnr+LesWKskQR11pH6uRTE= Received: from lazarus.int.ninth-art.de (relay [10.8.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by gateway.int.ninth-art.de (Postfix) with ESMTPSA id 6E1AA32C7D for ; Sat, 13 Apr 2019 20:26:25 +0200 (CEST) Reply-To: georg@bege.email To: libffi-discuss@sourceware.org From: Georg Bege Subject: libffi on the HPPA (parisc) Message-ID: <77683e46-59c5-ba8b-4f4c-1274d29b5555@bege.email> Date: Sat, 13 Apr 2019 18:26:00 -0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5AC08B3DF9BCEDB12CE6200F" X-IsSubscribed: yes X-SW-Source: 2019/txt/msg00001.txt.bz2 This is a multi-part message in MIME format. --------------5AC08B3DF9BCEDB12CE6200F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-length: 1882 Hello guys, Im recently tinkering with PARISC machines which I've left. I've got two of them, one with HPUX 11iv1 (old, I know) and one with Linux. According to the libffi main page, HPPA is indeed supported (not on=20 Linux, but this is outdated?). I've written a simple test code, in order to sanity check libffi's basic=20 functionality. This code is working fine on i386 and amd64.. just for reference. My main goal is getting libffi working (eg. ported) to HPUX LP64... I've=20 began consulting the proper documents from HP and learning a bit of=20 PARISC asm.. but Im still at the beginning. Right now, I wanted to confirm the functionality which is obviously=20 existing... The first try I've given is on the C8k with Gentoo Linux: Linux hppa 4.9.49-gentoo-r1-hppa64 #4 SMP Fri Jun 8 19:33:13 CEST 2018=20 parisc64 PA8900 (Shortfin) 9000/785/C8000 GNU/Linux therion@hppa ~ $ qlist -Iv libffi dev-libs/libffi-3.2.1 virtual/libffi-3.0.13-r1 So far so good... I've this installation now for a while... The thing is that my test code is failing with 64bit signed integers. Im hoping that any of you may look into it, or can lend me a hand - was=20 this ever supposed to work? Is it actually working? My test code is buggy? If so which part? :) Since it's just test I'll attach my code here. Output: ---------------snip-------------------- therion@hppa ~ $ ./test-ffi Signed 8bit integer result: 126 Unsigned 8bit integer result: 254 Signed 16bit integer result: 32766 Unsigned 16bit integer result: 65534 Signed 32bit integer result: 2147483646 Unsigned 32bit integer result: 4294967294 Signed 64bit integer result: 0, expected: 2147483646 test-ffi: test-ffi.c:151: main: Assertion `*src =3D=3D result' failed. Aborted ---------------snip-------------------- best regards, --=20 Georg Bege Mail: georg@bege.email XMPP: therion@ninth-art.de IRC: megaTherion @ Freenode --------------5AC08B3DF9BCEDB12CE6200F Content-Type: text/x-csrc; name="test-ffi.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="test-ffi.c" Content-length: 6806 /** * libffi C99 test code * - proves that libffi calls are working correctly * copyright (C) 2019 * Created on: 12th April 2019 * Modified on: 13th April 2019 */ #include #include #include #include #include #include #include typedef void (*ffi_callback)(void); typedef struct { int _1; int _2; } simple_t; /* adder functors */ int8_t add_signed8(int8_t a, int8_t b) { return a + b; } uint8_t add_unsigned8(uint8_t a, uint8_t b) { return a + b; } int16_t add_signed16(int16_t a, int16_t b) { return a + b; } uint16_t add_unsigned16(uint16_t a, uint16_t b) { return a + b; } int32_t add_signed32(int32_t a, int32_t b) { return a + b; } uint32_t add_unsigned32(uint32_t a, uint32_t b) { return a + b; } int64_t add_signed64(int64_t a, int64_t b) { return a + b; } uint64_t add_unsigned64(uint64_t a, uint64_t b) { return a + b; } float add_floatS(float a, float b) { return a + b; } double add_floatD(double a, double b) { return a + b; } simple_t add_simple(simple_t a, simple_t b) { simple_t ret =3D { a._1 + b._1, a._2 + b._2 }; return ret; } /* ffi proxy function */ ffi_arg call(ffi_type **args, void **values, ffi_type *retarg, size_t len, ffi_callback func) { ffi_cif cif; ffi_arg rc; =09 /* Iniitalize the cif */ int ret =3D ffi_prep_cif(&cif, FFI_DEFAULT_ABI, len, retarg, args); if(ret !=3D FFI_OK) { fprintf(stderr, "[%s] Cant prepare ffi context: %d\n", __func__, ret); exit(EXIT_FAILURE); } =09 ffi_call(&cif, func, &rc, values); return rc; } int main(void) { ffi_cif cif; /* 8bit signed integer test */ { int8_t a =3D (CHAR_MAX / 2) + 1, b =3D (CHAR_MAX / 2) - 1; const int8_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_sint8, &ffi_type_sint8}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_sint8, 2, (ffi_callback)add_s= igned8); printf("Signed 8bit integer result:\t%"PRIi8"\n", (int8_t)rc); assert( (int8_t)rc =3D=3D result ); } =09 /* 8bit unsigned integer test */ { uint8_t a =3D (UCHAR_MAX / 2) + 1, b =3D (UCHAR_MAX / 2) - 1; const uint8_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_uint8, &ffi_type_uint8}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_uint8, 2, (ffi_callback)add_u= nsigned8); printf("Unsigned 8bit integer result:\t%"PRIu8"\n", (uint8_t)rc); assert( (uint8_t)rc =3D=3D result); } =09 /* 16bit signed integer test */ { int16_t a =3D (SHRT_MAX / 2) + 1, b =3D (SHRT_MAX / 2) - 1; const int16_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_sint16, &ffi_type_sint16}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_sint16, 2, (ffi_callback)add_= signed16); printf("Signed 16bit integer result:\t%"PRIi16"\n", (int16_t)rc); assert( (int16_t)rc =3D=3D result ); } =09 /* 16bit unsigned integer test */ { uint16_t a =3D (USHRT_MAX / 2) + 1, b =3D (USHRT_MAX / 2) - 1; const uint16_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_uint16, &ffi_type_uint16}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_uint16, 2, (ffi_callback)add_= unsigned16); printf("Unsigned 16bit integer result:\t%"PRIu16"\n", (uint16_t)rc); assert( (uint16_t)rc =3D=3D result ); } =09 /* 32bit signed integer test */ { int32_t a =3D (INT_MAX / 2) + 1, b =3D (INT_MAX / 2) - 1; const int32_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_sint32, &ffi_type_sint32}; void *values[] =3D {&a, &b}; =09 ffi_arg rc =3D call(args, values, &ffi_type_sint32, 2, (ffi_callback)add_= signed32); printf("Signed 32bit integer result:\t%"PRIi32"\n", (int32_t)rc); assert( (int32_t)rc =3D=3D result ); } =09 /* 32bit unsigned integer test */ { uint32_t a =3D (UINT_MAX / 2) + 1, b =3D (UINT_MAX / 2) - 1; const uint32_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_uint32, &ffi_type_uint32}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_uint32, 2, (ffi_callback)add_= unsigned32); printf("Unsigned 32bit integer result:\t%"PRIu32"\n", (uint32_t)rc); assert( (uint32_t)rc =3D=3D result ); } =09 /* 64bit signed integer test */ { int64_t a =3D (LONG_MAX / 2) + 1, b =3D (LONG_MAX / 2) - 1; const int64_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_sint64, &ffi_type_sint64}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_sint64, 2, (ffi_callback)add_= signed64); const int64_t *src =3D (int64_t*)&rc; =09=09 printf("Signed 64bit integer result:\t%"PRIi64", expected: %"PRIi64"\n", = *src, result); assert( *src =3D=3D result ); } =09 /* 64bit unsigned integer test */ { uint64_t a =3D (ULONG_MAX / 2) + 1, b =3D (ULONG_MAX / 2) - 1; const uint64_t result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_uint64, &ffi_type_uint64}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_uint64, 2, (ffi_callback)add_= unsigned64); const uint64_t *urc =3D (uint64_t*)&rc; =09=09 printf("Unsigned 64bit integer result:\t%"PRIu64"\n", *urc); assert( *urc =3D=3D result ); } =09 /* single precision float test */ { float a =3D (FLT_MAX / 2.0F) + 0.5F, b =3D (FLT_MAX / 2.0F) - 0.5F; const float result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_float, &ffi_type_float}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_float, 2, (ffi_callback)add_f= loatS); const float *frc =3D (float*)&rc; =09=09 printf("Single precision float result:\t%f\n", *frc); assert( *frc =3D=3D result ); } =09 /* double precision float test */ { double a =3D (DBL_MAX / 2.0) + 0.5, b =3D (DBL_MAX / 2.0) - 0.5; const double result =3D a + b; =09=09 ffi_type *args[] =3D {&ffi_type_double, &ffi_type_double}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_double, 2, (ffi_callback)add_= floatD); const double *frc =3D (double*)&rc; =09=09 printf("Double precision float result:\t%lf\n", *frc); assert( *frc =3D=3D result ); } =09 #if 0 /* struct test */ { simple_t a =3D {(INT_MAX / 2) + 1, (INT_MAX / 2) - 1}; simple_t b =3D {(INT_MAX / 2) - 1, (INT_MAX / 2) + 1}; const simple_t result =3D {a._1 + b._1, a._2 + b._2}; =09=09 ffi_type *args[] =3D {&ffi_type_pointer, &ffi_type_pointer}; void *values[] =3D {&a, &b}; =09=09 ffi_arg rc =3D call(args, values, &ffi_type_pointer, 2, (ffi_callback)add= _simple); const simple_t *src =3D (simple_t*)&rc; =09=09 printf("Simple_t result:\t%d, %d\n", src->_1, src->_2); assert( src->_1 =3D=3D result._1 && src->_2 =3D=3D result._2 ); } #endif =09 exit(EXIT_SUCCESS); } --------------5AC08B3DF9BCEDB12CE6200F--