From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106216 invoked by alias); 30 Jun 2016 01:33:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 105700 invoked by uid 89); 30 Jun 2016 01:33:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=IA-64, IA64, ia-64, ia64 X-HELO: mail-qk0-f174.google.com Received: from mail-qk0-f174.google.com (HELO mail-qk0-f174.google.com) (209.85.220.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 30 Jun 2016 01:33:14 +0000 Received: by mail-qk0-f174.google.com with SMTP id a125so120524868qkc.2 for ; Wed, 29 Jun 2016 18:33:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jTSUtYvNW4Bdwq5dBD+WXEShDbC/ZOHKiYezJcJcQfQ=; b=dX2fpzLtmjKxWhKRQdfvzetHZBsWx4bG6lPbNwj1MQygTDZTmblFXHbQgCC3seuH4Y mj90fhio9sJ2o5jXvdd0728+kl6qAZZQctLT2us+eIKayn5r5WSzibZ1tUTTTCfNwaeI hd7EPWvtYLXlM74OZww1vhwqpIjvl4jB6c04gomaYh6vCBHwMWwbTj04H9OJJ1goB1Gh mLOPhXYMJYQII/XEpSDuOlPoccVU+MLspuqxVMUQ3lFAJ049IsHET/5IN3FmFXqpE/Kv SQEaYtDKuXz96/ISSJoXLWUwHRVx6uNbzFLdOnAnGiSux6ozNsGLW/kXWeo+wpCFbBbF MadQ== X-Gm-Message-State: ALyK8tJ6myDyPfWHZIbZ118QQ9JV7WQiDyQ3c9bHudiut0AjmAAhhgwC/uT0KqafaAnxXwKI/tqt94pNyjqbCQqa X-Received: by 10.13.241.199 with SMTP id a190mr5319845ywf.47.1467250392125; Wed, 29 Jun 2016 18:33:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.9.213 with HTTP; Wed, 29 Jun 2016 18:33:11 -0700 (PDT) In-Reply-To: References: From: Jim Wilson Date: Thu, 30 Jun 2016 01:33:00 -0000 Message-ID: Subject: Re: [PATCH] aarch64 sim big-endian support To: Nick Clifton Cc: gdb-patches@sourceware.org Content-Type: multipart/mixed; boundary=94eb2c0327206b9255053674dab3 X-SW-Source: 2016-06/txt/msg00528.txt.bz2 --94eb2c0327206b9255053674dab3 Content-Type: text/plain; charset=UTF-8 Content-length: 3473 On Mon, Jun 13, 2016 at 5:38 AM, Nick Clifton wrote: > I think that I agree with this comment, although I could not find > the raw opcode reading functions to which he was referring, (unless > he meant sim_core_read_buffer), so would you mind trying out this > variation of your patch to see if it works instead ? I finally got back to this. I don't see any raw read function other than sim_core_read_buffer either. A raw read is not quite what I want, as I need a little-endian to host translation, but I can call endian_le2h_4 to do the swap after the raw read. The interface is a little awkward, as sim_core_read_buffer stores into a buffer instead of returning a pointer, so I need to store the instruction, and then read it back out again, swap it, and store it back again. An alternative solution might be to make a copy of sim-n-core.h, call it sim-n-core-le.h, and then change all of the T2H_M/H2T_M calls into LE2H_M/H2LE_M calls, along with a few other minor changes to complete the conversion. We can then call sim_core_read_le_aligned_N instead of sim_core_read_aligned_N for the instruction loads. Note that big-endian aarch64 is not the only target with this problem. big-endian ARMv7-A works the same way, and if we had an IA-64 simulator, it would work the same way too. So there are other potential users of these functions. This is maybe a little overkill though for now, as we don't need the unaligned and misaligned read functions for aarch64/armv7-a/ia-64 instruction loads, and we don't need the write functions either. We only need the aligned read functions. I tried testing this for all four combinations of big/little endian host/target with a hello world program, and discovered that the big-endian host support is broken. The problem is with the GRegisterValue untion. You have typedef union GRegisterValue { int8_t s8; ... int64_t s64; } GRegister; On a little-endian host, the s8 member will match the low-byte of the s64 member, which is what we want. However, on a big-endian host, the s8 member will match the high-byte of the u64 member, and the simulator fails. I can fix this by using an anonymous struct for the big-endian case typedef union GRegisterValue { struct { int64_t :56; int8_t s8; }; ...l sint64_t s64; } GRegister; There are other ways to fix this, but this just seemed to me like the quickest and smallest patch that would make it work. There may also be other issues here, as I only tested an integer hello world program. Fixing the problem this way means that we require either an ISO C 2011 compiler, or a compiler that supports GCC extensions to ISO C 1990 or 1999. Otherwise, you may get an error for the anonymous structs. Or alternatively, it requires using a C++ compiler, as C++ added anonymous structs long before C did. I'm not sure how much of a problem this will be. If this is a serious problem, it could be fixed by giving names to the structs, adding the structs to the little endian side also with the field order switched, and then fixing all users to use the new names for the fields. That will be a bigger patch. With both changes, a hello world program works on all four combinations of big/little host/target. if you aren't happy with the cpustate.h change, it would be nice to get an approval for just the simulator.c change, as that is the part I care more about. We can worry about how to fix the big-endian host cpustate.h support later. Jim --94eb2c0327206b9255053674dab3 Content-Type: text/x-patch; charset=US-ASCII; name="gdb-sim-aarch64.patch" Content-Disposition: attachment; filename="gdb-sim-aarch64.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iq1msd5v1 Content-length: 2571 MjAxNi0wNi0yOSAgSmltIFdpbHNvbiAgPGppbS53aWxzb25AbGluYXJvLm9y Zz4KCglzaW0vYWFyY2g2NC8KCSogY3B1c3RhdGUuaDogSW5jbHVkZSBjb25m aWcuaC4KCSh1bmlvbiBHUmVnaXN0ZXJWYWx1ZSk6IEFkZCBXT1JEU19CSUdF TkRJQU4gY2hlY2suICBGb3IgYmlnIGVuZGlhbiBjb2RlCgl1c2UgYW5vbnlt b3VzIHN0cnVjdHMgdG8gYWxpZ24gbWVtYmVycy4KCSogc2ltdWxhdG9yLmMg KGFhcmNoNjRfc3RlcCk6IFVzZSBzaW1fY29yZV9yZWFkX2J1ZmZlciBhbmQK CWVuZGl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