From patchwork Tue May 3 19:48:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569012 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9808447map; Tue, 3 May 2022 13:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqWjNIy8cY5w5VHyoPpNeZdfhLv/Doe75mL2mzgJWe/K44rcPtORuHAnkjWZmZGUG81+Tv X-Received: by 2002:a05:620a:2902:b0:69f:fcd3:a3b7 with SMTP id m2-20020a05620a290200b0069ffcd3a3b7mr4874645qkp.486.1651611083455; Tue, 03 May 2022 13:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611083; cv=none; d=google.com; s=arc-20160816; b=gND+0ijGSTbRf3izB0s6cv3p4hh1zkGyESh/flPzPqAPODpiarRwzHJquYznwyuKPM BlK3TGR2WiU3v16dYQpGvyE9pCxGhAwF6o/LrgvJG89HP8Wus8GYYm1e2YoYNy2k/PwU Q7i/Env/LmbvfSW9tXoBkSurBWsG5E7ArZIpuY1kgwy/beu63LziGuja5oBYJYe2g7lV bOnGRDtOB1AGA/eBSpjOWMB6H4nv1xryS6YInAV0RYtVMHDqXr/Ueka6YNwDWp0n1u+M rE1me+goBHETBiXaUngij+hlPGLMfGXxExSrUspde/oj8vDo4wRjpR276XWpzK6oCVtS 5MNw== 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:to:from :dkim-signature; bh=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=PwGP60O9ma2au0V6Oil3WuhOx1gyiTQLJ3xvLYxqsoVBK//2kCY7AzOKSGxt8m8zni PXLh8oqnnP18JGc1ujljGxXPr+7gDv+HLS6Fe5AKi+ADsh7YiDGyWEeikez8I9f6qWP5 OPkDzScOilb8LVgfEqtrm3IoJlVfp9oDUm685wvoFmJ41HCB7q2FN3IaG69gZ1Vsuw7x QuMHhHlm2+LvG+6VduZUAtHs5Xk0lU2A+gZ9WzVPWTI4gRAyxvP4wGPjMqfwFMQzOWK+ dna8ocFi+gD67YjfAF3Re9pcX99KdCSh8+6yxZ+o13Yb0KDWToj0MclcjUmbVeBVdlfg LPLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eUJ6tNVT; 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 u5-20020a05620a454500b0069fc79d86b8si5597276qkp.46.2022.05.03.13.51.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:51:23 -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=eUJ6tNVT; 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]:57396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzUQ-00032t-Uv for patch@linaro.org; Tue, 03 May 2022 16:51:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0000le-SQ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:01 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:35738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZr-0006O0-Ap for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:59 -0400 Received: by mail-pj1-x1033.google.com with SMTP id w5-20020a17090aaf8500b001d74c754128so3254562pjq.0 for ; Tue, 03 May 2022 12:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=eUJ6tNVTMwM1wm+HV9JryQMqqsYDnb7huOrG1P+TLz+Czcy2+mrfwXx37Jd6irFwEL 7D49/BSHQu3fiRquAyJ2VZjBTXmBpkp6n52MfAjpn1v2rnoGq/cQmPTWxtFSWqDvqjuG PgkUBdQC4IujNo4UcwJicw2ZFPi9wAChGyLkppGbbLNjWVGIZOhvJCR6ugcDTADRb0LC goQKKCEl2+mXawAorMQA9ChQ8rS//tjiyIpWFpZlvU10K3iW9iaqC24alU7ZkXMLic8g LEaFwpChD5Q4/Xy8nrKPmgh5t0F1ceXh4a15ZEwVU6O4hG4dNKoA/W1El/of5IvPiuCX IW7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=B6Jl3mwtMXdlaC9Db/4blZsKVJ+BeQmoTnUE/RxU4Avh+nTxFcca/6TjA20wnPCsd8 BqbXExZHcZZSytUMW1DtcpkE1K9yH7Q+NEhe/ojZvzKv5kJAqrwpb2hvVXjJjNFH6YwB KPp6oMSjCTfWb7hirKiIxxcEiUvrRbAQnDUIoHWMO80HXlez9YnYDvDZ8Sxik6N4+EJ+ nUNW3YokeZRV4I8S0pIsbaAgd7ws9KjEDSHVBkiQ+rhYEpod5B1DUmzgpK6+jhD5S00/ HEGvo4M1AVMWsXwISrLLalCMt3MCc7fuBhl4SE9DOB05dqBoj1MnFVjCHwK/s+4rWbkV Cevg== X-Gm-Message-State: AOAM530g36n+58g2VzOC2iG7ksjIattL4YJuN2zhBmoPHXNjYc7ZyZzB NqmDieOq/voqGsk1b18GKKL6plkDUHBcfA== X-Received: by 2002:a17:903:410b:b0:15c:fd57:aa34 with SMTP id r11-20020a170903410b00b0015cfd57aa34mr17922864pld.82.1651607573962; Tue, 03 May 2022 12:52:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 68/74] hw/rx: Handle a kernel file that is ELF Date: Tue, 3 May 2022 12:48:37 -0700 Message-Id: <20220503194843.1379101-69-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503194843.1379101-1-richard.henderson@linaro.org> References: <20220503194843.1379101-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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, T_SCC_BODY_TEXT_LINE=-0.01 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" Attempt to load the kernel with load_elf. If this fails with ELF_LOAD_NOT_ELF, continue to treat the kernel as a raw image. This will be handy for running semihosting programs. Signed-off-by: Richard Henderson --- hw/rx/rx-gdbsim.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c index be147b4bd9..64b533181d 100644 --- a/hw/rx/rx-gdbsim.c +++ b/hw/rx/rx-gdbsim.c @@ -26,6 +26,7 @@ #include "sysemu/device_tree.h" #include "hw/boards.h" #include "qom/object.h" +#include "elf.h" /* Same address of GDB integrated simulator */ #define SDRAM_BASE EXT_CS_BASE @@ -57,15 +58,32 @@ static void rx_load_image(RXCPU *cpu, const char *filename, uint32_t start, uint32_t size) { static uint32_t extable[32]; - long kernel_size; + ssize_t kernel_size; + uint64_t kernel_entry; int i; + /* Try an ELF image first. */ + + kernel_size = load_elf(filename, NULL, NULL, NULL, &kernel_entry, + NULL, NULL, NULL, false, EM_RX, false, false); + if (kernel_size >= 0) { + cpu_set_pc(CPU(cpu), kernel_entry); + return; + } + if (kernel_size != ELF_LOAD_NOT_ELF) { + error_report("could not load kernel '%s': %s", + filename, load_elf_strerror(kernel_size)); + exit(1); + } + + /* Not ELF: load a raw image, e.g. zImage. */ + kernel_size = load_image_targphys(filename, start, size); if (kernel_size < 0) { - fprintf(stderr, "qemu: could not load kernel '%s'\n", filename); + error_report("could not load kernel '%s'", filename); exit(1); } - cpu->env.pc = start; + cpu_set_pc(CPU(cpu), start); /* setup exception trap trampoline */ /* linux kernel only works little-endian mode */