From nobody Mon Nov 25 12:40:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1715428578; cv=none; d=zohomail.com; s=zohoarc; b=R80IQwUrtso9KaV//SDArOEtZ3CSVcWTHc8IEfsmiKVzmiuBlGMBRq21wrsPmQIrCw658XJQkEmFG0EXWnOYNumraOyYgJqEUaU4D/AK9Gr50rty8TSWSeJbg+QuEFHB63QK/Dxq1r3hxD/DwS5GVUfY6jYPVfQbVMGWIPxIXk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715428578; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HpcdEdoUPPV0pGSNw4XA78udWGrbKRqXBRNX1k+qgFI=; b=WQYru1Dy85tNFh+clZIM7c7cOIeZBEDNUbNosbvUfnu+l5rHPeN99yMj3+HdmXaaF83VoVbxXrMV5wi2/20JChlnHVSH59NHlOEOBWbPUfs2j1zvOxho22emfBSKehQmTuM6r3SOH6qgURmQqkcAC2S61m06bTO5tixZzCQy/8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715428577815777.1408768189381; Sat, 11 May 2024 04:56:17 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGx81vB/JJP5fudw8OsZJWVoabCGGS0f6VSU4LywGDIHddoFzD7onoYIPCjDy3US4ZPYvteTg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1715428578451100005 Content-Type: text/plain; charset="utf-8" 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 =20 #include "config.h" #include "risu.h" @@ -371,6 +373,57 @@ static void load_image(const char *imgfile) close(fd); image_start =3D addr; image_start_address =3D (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) =3D=3D 0) { + const unsigned char *e_ident =3D addr; + bool swap, is_64; + + switch (e_ident[EI_DATA]) { + case ELFDATA2LSB: + swap =3D __BYTE_ORDER !=3D __LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + swap =3D __BYTE_ORDER =3D=3D __LITTLE_ENDIAN; + break; + default: + fprintf(stderr, "%s: Bad elf header: EI_DATA =3D %x\n", + imgfile, e_ident[EI_DATA]); + exit(1); + } + switch (e_ident[EI_CLASS]) { + case ELFCLASS32: + is_64 =3D false; + break; + case ELFCLASS64: + is_64 =3D true; + break; + default: + fprintf(stderr, "%s: Bad elf header: EI_CLASS =3D %x\n", + imgfile, e_ident[EI_CLASS]); + exit(1); + } + + if (is_64) { + const Elf64_Ehdr *h64 =3D addr; + Elf64_Addr e64 =3D h64->e_entry; + if (swap) { + e64 =3D __builtin_bswap64(e64); + } + image_start =3D addr + e64; + } else { + const Elf32_Ehdr *h32 =3D addr; + Elf32_Addr e32 =3D h32->e_entry; + if (swap) { + e32 =3D __builtin_bswap32(e32); + } + image_start =3D addr + e32; + } + } } =20 static int master(void) --=20 2.34.1