From patchwork Sat May 11 11:53:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796232 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp1236189wra; Sat, 11 May 2024 04:56:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX+Yk8c7zzboaa188vmuzXCQ3OVAWVJFnTJPRcPQkXn03DrCiRZyZbJ3EPljfYSzn/Jvxu+zkxExNlf+/r1yxVp X-Google-Smtp-Source: AGHT+IEc8zCbRgWb4kzLbPL7S9eXInMVCHxB+g50uFhmVZi9M2e1dxsA51OK1PBpNiwGrOGzccJy X-Received: by 2002:a05:620a:3b8b:b0:792:9a4a:1c3e with SMTP id af79cd13be357-792c75aefc3mr548130385a.42.1715428577428; Sat, 11 May 2024 04:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715428577; cv=none; d=google.com; s=arc-20160816; b=WkdZI+Y7cSEdDi44esuiGm2e3yCVWiCPF3P725efyLnvNprZV04LawetcCG2NKSxIt Jc9pBSUnb7rhrjJNWUucbexsozkixf39DgtfU063gQmF+kDYq/qp1UBL5NANhUuWkYKb 1yWqE4ilSZkYNqnwS/d1wYRMDxpv7pc1AGt9FQ739dBm7fo89lGaZJFCDxaUEGLDrYnM G/TfKLcFRxfoKaJ0mfgqDh3194NMlC7fx4zussCVKCiKgPyCNzYxojd1yrLiHH1FQ0aH Smx6uWdVLo+jkzDvgkzmP4fhkLOLrMew4/9cTwvL18wSI4TMsEnX1jZDgu6d6Ot0H1Vm 6Icw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HpcdEdoUPPV0pGSNw4XA78udWGrbKRqXBRNX1k+qgFI=; fh=UQCixiNfr28ZOrfhmxiGPA65dFhly8CmRsnoYC6xI9k=; b=aJGQQlPrKZouNg2dTTQXotZfdZQSl38vggXik9tS25cBkcTkaYXbRqJEiChMZPCQST nF2ssBygFyQEXjIXhC44bplagW5xvgSNvVgZBqZHTrt/UtwuuKjcD5rz4nyihPbHSbBy 0CMKRRkttNEvumjvAgntuL+a2hg338oVB9nY8o9C2OgENud92OdotdYLY8prpBseGNUQ Ku0IAKrAzwboAdNF0X2kZDCJBOAd3QtH1OsJiUi61Cpiv+OfWyFwyGP6VEbUQq6bkeBp 3kcNVGrkoGXuJMlQpQkrYfjcC2AApnpnu+eHMe26n40ucLBhGMVhRiKJW1fcVEN1cMJ7 WGSg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GCqB3v4/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-792bf360a50si549216585a.609.2024.05.11.04.56.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 May 2024 04:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GCqB3v4/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5lJ0-0000NZ-IA; Sat, 11 May 2024 07:54:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s5lIy-0000MQ-BD for qemu-devel@nongnu.org; Sat, 11 May 2024 07:54:20 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s5lIw-00070X-KJ for qemu-devel@nongnu.org; Sat, 11 May 2024 07:54:20 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2e5218112a6so18706701fa.2 for ; Sat, 11 May 2024 04:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715428457; x=1716033257; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HpcdEdoUPPV0pGSNw4XA78udWGrbKRqXBRNX1k+qgFI=; b=GCqB3v4/zunCpwCFjyevBNANzScPlhgiENPS0Y4TbsOYRTiTDdpWhUhSksdm4NuZKb kq0LcMI5GnYRYr11t7ZR9E7AbclNDK5TsU6PMtOB4osxKx8nbltj4HXI5prG9XT4Z4FE VGiHBclEASdEu3SBd6Sg4xzCNRZrPMtod1Kh+jfVv1YbjIRPReEvMisczCghNHgMmuky 0yW/vTVk6KZbUWB+iCqatFp2qgJvi5J8GvpxQdeUcS8ZNYKmkv/yD9zQ0CJQz4gjz+wd J96owNjqN+f+j7SYxJlTzhdD7dXdD9OA1QOqasY5BwEYv7C9052cbc5oBS1wYsbkEa45 9WDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715428457; x=1716033257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HpcdEdoUPPV0pGSNw4XA78udWGrbKRqXBRNX1k+qgFI=; b=v3zNriyAhHNM0jM/ENoyVfqktVUhTRUZxi/YJXBG49WOyjUCCklP7mIwQ0/gMm/xTz 73bLRALby0uJCrYpQ+c98dv9WMdjZZKLwl+WwtzBRoFrUhW0PXpax3EOs/+mRDjfxP60 52mTQaw/NnqOeJnHPnfTx/PNti9peRl4ZQE92/apIchxrZvGm1BaSwKA5iOSzUHgs7M2 iEgHWeLgrM8KrTIoeEI5XaaP0GkhWDccJFtGz1ypfqfx4m9zTqnfy3V/7tfMjCCOz/PA i62bqrxChpj6bqU/Uqg7X68e/EZ14PCu1ztfH24mfTkz31+nfmUFtYjKlbcGFlEKzytn wi2A== X-Gm-Message-State: AOJu0YyAiXWY1kYwep2aWBblHMBTJ6SCAqfL6rqIJHPMiiYNtE7hYEjL oN92qNx+ZpbGyKXwstf890FICoVlXzpDE9ordZ8nB54RZOOv1WAJ/+5QSewPAFaKZk+BRutVQlV 6JX8= X-Received: by 2002:a2e:9b4e:0:b0:2e1:bb65:8306 with SMTP id 38308e7fff4ca-2e5204b1d89mr31245551fa.44.1715428457056; Sat, 11 May 2024 04:54:17 -0700 (PDT) Received: from stoup.. ([195.76.196.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502bbbbf20sm6764797f8f.93.2024.05.11.04.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 04:54:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH 15/17] risu: Allow use of ELF test files Date: Sat, 11 May 2024 13:53:58 +0200 Message-Id: <20240511115400.7587-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240511115400.7587-1-richard.henderson@linaro.org> References: <20240511115400.7587-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org By using elf files, we make it easier to disassemble the test file, to match comparison failures to code. Signed-off-by: Richard Henderson --- risu.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/risu.c b/risu.c index c28b4a5..e3845f6 100644 --- a/risu.c +++ b/risu.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "config.h" #include "risu.h" @@ -371,6 +373,57 @@ static void load_image(const char *imgfile) close(fd); image_start = addr; image_start_address = (uintptr_t) addr; + + /* + * TODO: More complete parsing of ELF file, verify assumtion, namely: + * Single PT_LOAD covering the ELF header, code and data. + * For now, simply update image_start from the elf header. + */ + if (memcmp(addr, ELFMAG, SELFMAG) == 0) { + const unsigned char *e_ident = addr; + bool swap, is_64; + + switch (e_ident[EI_DATA]) { + case ELFDATA2LSB: + swap = __BYTE_ORDER != __LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + swap = __BYTE_ORDER == __LITTLE_ENDIAN; + break; + default: + fprintf(stderr, "%s: Bad elf header: EI_DATA = %x\n", + imgfile, e_ident[EI_DATA]); + exit(1); + } + switch (e_ident[EI_CLASS]) { + case ELFCLASS32: + is_64 = false; + break; + case ELFCLASS64: + is_64 = true; + break; + default: + fprintf(stderr, "%s: Bad elf header: EI_CLASS = %x\n", + imgfile, e_ident[EI_CLASS]); + exit(1); + } + + if (is_64) { + const Elf64_Ehdr *h64 = addr; + Elf64_Addr e64 = h64->e_entry; + if (swap) { + e64 = __builtin_bswap64(e64); + } + image_start = addr + e64; + } else { + const Elf32_Ehdr *h32 = addr; + Elf32_Addr e32 = h32->e_entry; + if (swap) { + e32 = __builtin_bswap32(e32); + } + image_start = addr + e32; + } + } } static int master(void)