From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19961 invoked by alias); 13 Apr 2019 21:34:53 -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 19547 invoked by uid 89); 13 Apr 2019 21:34:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,SPF_PASS autolearn=ham version=3.3.1 spammy= 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 21:34:48 +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 AD7001CACF1D for ; Sat, 13 Apr 2019 17:34:46 -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 5663032E0B for ; Sat, 13 Apr 2019 23:34:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bege.email; h=reply-to :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=mail141202; bh=TkrvQNBXZh85VBshd8NJ 7/hhVvc=; b=5OGFcJH+KXAG25NWfja8QLDzipKnUT3DeAV+Fixyak6Op5SUH/aY Ouizrd3kWtjTJTSvtG15KTjXPVmNUyVqGl7X20+iauVLoZPi/cuwOy7qu70BKju9 hoWMQ3yKW3oz6Q0PzZWwCSlt3fDKxk/pA+Z7P2/KjWfCFcOobRi6OIg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=bege.email; h=reply-to :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=mail141202; b=ZqJ15HVrb7wX7D 2FZV7tCZjchk61C/bd1Y/0HINv6pB7mHoakvWFe+S7nc606gGVsvTyTsvDDMEU7W AxusXFXc7vy3/Re/BfsTEJb6EsNy7U2lTN5B0J+6UHoHvYEIO9ZyK5PCT6lS50PP pKm41KXKYAmepQn7FXN8b+5WSZTa4= 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 52D8D32C7D for ; Sat, 13 Apr 2019 23:34:43 +0200 (CEST) Reply-To: georg@bege.email Subject: Re: libffi on the HPPA (parisc) To: libffi-discuss@sourceware.org References: <77683e46-59c5-ba8b-4f4c-1274d29b5555@bege.email> From: Georg Bege Message-ID: <66d2f3c2-a40e-5968-b6c5-9f4d8bed246f@bege.email> Date: Sat, 13 Apr 2019 21:34:00 -0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 In-Reply-To: <77683e46-59c5-ba8b-4f4c-1274d29b5555@bege.email> Content-Type: multipart/mixed; boundary="------------46E45643DF5CE34986B94475" X-IsSubscribed: yes X-SW-Source: 2019/txt/msg00002.txt.bz2 This is a multi-part message in MIME format. --------------46E45643DF5CE34986B94475 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-length: 2622 Hi again, Ok I think I've found my mistake - the rc type wasnt large enough to=20 hold 64bit of data. ffi_arg seems to be 32bit on 32bit systems.. should have known, I fixed=20 my code accordingly. I also fixed my bug regarding custom struct handling, it works now on=20 multiple arch's (i386, amd64, parisc, arm). :) However, feel free to pass along helpful advice regarding my testing=20 code and/or regarding porting libffi to parisc64. Am 13.04.19 um 20:26 schrieb Georg Bege: > Hello guys, >=20 > 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 Linu= x. >=20 > 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. >=20 > 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. >=20 > 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: >=20 > 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 >=20 > therion@hppa ~ $ qlist -Iv libffi > dev-libs/libffi-3.2.1 > virtual/libffi-3.0.13-r1 >=20 > 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. >=20 > 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? :) >=20 > Since it's just test I'll attach my code here. >=20 > Output: > ---------------snip-------------------- > therion@hppa ~ $ ./test-ffi > Signed 8bit integer result:=C2=A0=C2=A0=C2=A0 126 > Unsigned 8bit integer result:=C2=A0=C2=A0=C2=A0 254 > Signed 16bit integer result:=C2=A0=C2=A0=C2=A0 32766 > Unsigned 16bit integer result:=C2=A0=C2=A0=C2=A0 65534 > Signed 32bit integer result:=C2=A0=C2=A0=C2=A0 2147483646 > Unsigned 32bit integer result:=C2=A0=C2=A0=C2=A0 4294967294 > Signed 64bit integer result:=C2=A0=C2=A0=C2=A0 0, expected: 2147483646 > test-ffi: test-ffi.c:151: main: Assertion `*src =3D=3D result' failed. > Aborted > ---------------snip-------------------- >=20 > best regards, --=20 Georg Bege Mail: georg@bege.email XMPP: therion@ninth-art.de IRC: megaTherion @ Freenode --------------46E45643DF5CE34986B94475 Content-Type: text/x-csrc; name="test-ffi.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test-ffi.c" Content-length: 6496 /** * 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 = { a._1 + b._1, a._2 + b._2 }; return ret; } /* ffi proxy function */ ffi_arg call(ffi_type **args, void **values, size_t nargs, ffi_type rctype, ffi_callback func) { ffi_cif cif; ffi_arg rc; /* Iniitalize the cif */ int ret = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, &rctype, args); if(ret != FFI_OK) { fprintf(stderr, "[%s] Cant prepare ffi context: %d\n", __func__, ret); exit(EXIT_FAILURE); } ffi_call(&cif, func, &rc, values); return rc; } void call_ext(ffi_type **args, void **values, size_t nargs, ffi_type rctype, void *rc, ffi_callback func) { ffi_cif cif; /* Iniitalize the cif */ int ret = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, &rctype, args); if(ret != FFI_OK) { fprintf(stderr, "[%s] Cant prepare ffi context: %d\n", __func__, ret); exit(EXIT_FAILURE); } ffi_call(&cif, func, rc, values); } int main(void) { /* 8bit signed integer test */ { int8_t a = (SCHAR_MAX / 2) + 1, b = (SCHAR_MAX / 2) - 1; const int8_t result = a + b; ffi_type *args[] = {&ffi_type_sint8, &ffi_type_sint8}; void *values[] = {&a, &b}; int8_t rc = (int8_t)call(args, values, 2, ffi_type_sint8, (ffi_callback)add_signed8); printf("Signed 8bit integer result:\t%"PRIi8"\n", rc); assert(rc == result); } /* 8bit unsigned integer test */ { uint8_t a = (UCHAR_MAX / 2) + 1, b = (UCHAR_MAX / 2) - 1; const uint8_t result = a + b; ffi_type *args[] = {&ffi_type_uint8, &ffi_type_uint8}; void *values[] = {&a, &b}; uint8_t rc = call(args, values, 2, ffi_type_uint8, (ffi_callback)add_unsigned8); printf("Unsigned 8bit integer result:\t%"PRIu8"\n", rc); assert(rc == result); } /* 16bit signed integer test */ { int16_t a = (SHRT_MAX / 2) + 1, b = (SHRT_MAX / 2) - 1; const int16_t result = a + b; ffi_type *args[] = {&ffi_type_sint16, &ffi_type_sint16}; void *values[] = {&a, &b}; int16_t rc = call(args, values, 2, ffi_type_sint16, (ffi_callback)add_signed16); printf("Signed 16bit integer result:\t%"PRIi16"\n", rc); assert(rc == result); } /* 16bit unsigned integer test */ { uint16_t a = (USHRT_MAX / 2) + 1, b = (USHRT_MAX / 2) - 1; const uint16_t result = a + b; ffi_type *args[] = {&ffi_type_uint16, &ffi_type_uint16}; void *values[] = {&a, &b}; uint16_t rc = call(args, values, 2, ffi_type_uint16, (ffi_callback)add_unsigned16); printf("Unsigned 16bit integer result:\t%"PRIu16"\n", rc); assert(rc == result); } /* 32bit signed integer test */ { int32_t a = (INT_MAX / 2) + 1, b = (INT_MAX / 2) - 1; const int32_t result = a + b; ffi_type *args[] = {&ffi_type_sint32, &ffi_type_sint32}; void *values[] = {&a, &b}; int32_t rc = call(args, values, 2, ffi_type_sint32, (ffi_callback)add_signed32); printf("Signed 32bit integer result:\t%"PRIi32"\n", rc); assert(rc == result); } /* 32bit unsigned integer test */ { uint32_t a = (UINT_MAX / 2) + 1, b = (UINT_MAX / 2) - 1; const uint32_t result = a + b; ffi_type *args[] = {&ffi_type_uint32, &ffi_type_uint32}; void *values[] = {&a, &b}; uint32_t rc = call(args, values, 2, ffi_type_uint32, (ffi_callback)add_unsigned32); printf("Unsigned 32bit integer result:\t%"PRIu32"\n", rc); assert(rc == result); } /* 64bit signed integer test */ { int64_t a = (LONG_MAX / 2) + 1, b = (LONG_MAX / 2) - 1, rc; const int64_t result = a + b; ffi_type *args[] = {&ffi_type_sint64, &ffi_type_sint64}; void *values[] = {&a, &b}; call_ext(args, values, 2, ffi_type_sint64, &rc, (ffi_callback)add_signed64); printf("Signed 64bit integer result:\t%"PRIi64"\n", rc); assert(rc == result); } /* 64bit unsigned integer test */ { uint64_t a = (ULONG_MAX / 2) + 1, b = (ULONG_MAX / 2) - 1, rc; const uint64_t result = a + b; ffi_type *args[] = {&ffi_type_uint64, &ffi_type_uint64}; void *values[] = {&a, &b}; call_ext(args, values, 2, ffi_type_uint64, &rc, (ffi_callback)add_unsigned64); printf("Unsigned 64bit integer result:\t%"PRIu64"\n", rc); assert(rc == result); } /* single precision float test */ { float a = (FLT_MAX / 2.0F) + 0.5F, b = (FLT_MAX / 2.0F) - 0.5F, rc; const float result = a + b; ffi_type *args[] = {&ffi_type_float, &ffi_type_float}; void *values[] = {&a, &b}; call_ext(args, values, 2, ffi_type_float, &rc, (ffi_callback)add_floatS); printf("Single precision float result:\t%f\n", rc); assert(rc == result); } /* double precision float test */ { double a = (DBL_MAX / 2.0) + 0.5, b = (DBL_MAX / 2.0) - 0.5, rc; const double result = a + b; ffi_type *args[] = {&ffi_type_double, &ffi_type_double}; void *values[] = {&a, &b}; call_ext(args, values, 2, ffi_type_double, &rc, (ffi_callback)add_floatD); printf("Double precision float result:\t%lf\n", rc); assert(rc == result); } /* struct test */ { simple_t a = {(INT_MAX / 2) + 1, (INT_MAX / 2) - 1}; simple_t b = {(INT_MAX / 2) - 1, (INT_MAX / 2) + 1}, rc; const simple_t result = {a._1 + b._1, a._2 + b._2}; ffi_type *prim[] = {&ffi_type_sint32, &ffi_type_sint32, NULL}; ffi_type sc = {0, 0, FFI_TYPE_STRUCT, (ffi_type**)&prim}; ffi_type *args[] = {&sc, &sc}; void *values[] = {&a, &b}; call_ext(args, values, 2, sc, &rc, (ffi_callback)add_simple); printf("Simple_t result:\t%d, %d\n", rc._1, rc._2); assert(rc._1 == result._1 && rc._2 == result._2); } exit(EXIT_SUCCESS); } --------------46E45643DF5CE34986B94475--