From patchwork Wed Feb 13 15:44:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10810203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59814139A for ; Wed, 13 Feb 2019 15:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46CB82DB63 for ; Wed, 13 Feb 2019 15:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B2F62DB76; Wed, 13 Feb 2019 15:53:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A0ABF2DA93 for ; Wed, 13 Feb 2019 15:53:02 +0000 (UTC) Received: from localhost ([127.0.0.1]:58927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtwqL-0006sc-Ej for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Feb 2019 10:53:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtwj7-0002Io-92 for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:45:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtwj4-00075m-Qv for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:45:33 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtwj2-0006p7-Pg for qemu-devel@nongnu.org; Wed, 13 Feb 2019 10:45:30 -0500 Received: by mail-pg1-x542.google.com with SMTP id z11so1313721pgu.0 for ; Wed, 13 Feb 2019 07:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:cc:from:to; bh=BophRMwowisaYaC1U48VeLPl6f830QgtoDxDV4XkaXM=; b=iIUsRiskzYV2GBY+HhpAeOdyOINwilUB7oRUyCDd59nAm72ch1yUIxxgDz4bh2S1DM RdWUjZ3bBpoKeLENm5OqQWg/jKSp5seyaVZfKTOhS56Eb0gFgWZYBP3R+gKF1Xw0gTrQ i5y8/N6bb3bc0RwnNGmjrEVV0fLVddxfbW8gYQerh+RxQy0F4MAKjtsIrS4l/+iSCJ2e 9nJi+0I3JIYa3ntFpuQ34tLiBYCUQFAPqnrSBRfi2+l7dnMb5PZo8UflijgoRgpLQEFo rSaYb805qM6W0+jXl5EetLGr10PwHN6SnOk3gOUh7UKPEaGpSIPVA0ind65mB/a4JJMa nD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:cc:from:to; bh=BophRMwowisaYaC1U48VeLPl6f830QgtoDxDV4XkaXM=; b=pOS+rjy0bQdgOxn6vy1Lt2TpR3gYaZNNMCR8IUXe/WTopDTXIDz5+W676100PHLuxD Jc/QWX9esJ4YFgWl4dw6HEFskxjSwMNmqdQsXkMNEdy6zWQE6TM8VyilhajqY1wfGe2+ Fa/fu1rRPAR1k46y7HYNpW9ciGaCJfafDvcLhHLtf54s+ArqwFp1IAg9ffHQXTovdbV2 LLkPPRVHtgSxQWBI3ZrTDygaV4HjfpeoXbvoGtv7I5kFbn7cFmkiEu88I2tUEdM3aata 17wDw5d4+4+iGeZwByKQ7cgDS0jZPz7Cmw9zVe9NL4TVioJYsbu3FFaG868Gddz1QvWG kJWA== X-Gm-Message-State: AHQUAuYFXj4ZsE61USJdKKO9d3GEz7EtsbqvVAMuIuIRMc+80+Fup+v7 JQORNqXzVOxOrc6Bce45iOuYDQ== X-Google-Smtp-Source: AHgI3Iax+llcgeGzvFhQI4b8sx4SrWyWdkMVlsl0lXwqFz9lL7sy+vZUFG9RnHhsaP4iGcYJe/+L/Q== X-Received: by 2002:a63:125a:: with SMTP id 26mr1043383pgs.314.1550072721042; Wed, 13 Feb 2019 07:45:21 -0800 (PST) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id v26sm4782101pfg.62.2019.02.13.07.45.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 07:45:20 -0800 (PST) Date: Wed, 13 Feb 2019 07:44:50 -0800 Message-Id: <20190213154450.14749-12-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190213154450.14749-1-palmer@sifive.com> References: <20190213154450.14749-1-palmer@sifive.com> MIME-Version: 1.0 From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PULL 11/11] riscv: Ensure the kernel start address is correctly cast X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , Palmer Dabbelt , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alistair Francis Cast the kernel start address to the target bit length. This ensures that we calculate the initrd offset to a valid address for the architecture. Steps to reproduce the original problem (reported by Alex): Build U-Boot for the virt machine for riscv32. Then run it with $ qemu-system-riscv32 -M virt -kernel u-boot -nographic -initrd You can find the initrd address with U-Boot# fdt addr $fdtcontroladdr U-Boot# fdt ls /chosen Then take a peek at that address: U-Boot# md.b and you will see that there is nothing there without this patch. The reason is that the binary was loaded to a negative address. Signed-off-by: Alistair Francis Suggested-by: Alexander Graf Reported-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Palmer Dabbelt --- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 2 +- hw/riscv/virt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c index bfc086609cb9..b1cd11363c93 100644 --- a/hw/riscv/sifive_e.c +++ b/hw/riscv/sifive_e.c @@ -74,7 +74,7 @@ static const struct MemmapEntry { [SIFIVE_E_DTIM] = { 0x80000000, 0x4000 } }; -static uint64_t load_kernel(const char *kernel_filename) +static target_ulong load_kernel(const char *kernel_filename) { uint64_t kernel_entry, kernel_high; diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 2730b25b6032..7bc25820feaa 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -65,7 +65,7 @@ static const struct MemmapEntry { #define GEM_REVISION 0x10070109 -static uint64_t load_kernel(const char *kernel_filename) +static target_ulong load_kernel(const char *kernel_filename) { uint64_t kernel_entry, kernel_high; diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index c66ffc50cc74..2a000a58009a 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -53,7 +53,7 @@ static const struct MemmapEntry { [SPIKE_DRAM] = { 0x80000000, 0x0 }, }; -static uint64_t load_kernel(const char *kernel_filename) +static target_ulong load_kernel(const char *kernel_filename) { uint64_t kernel_entry, kernel_high; diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 3e8b19c66898..fc4c6b306e13 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -62,7 +62,7 @@ static const struct MemmapEntry { [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, }; -static uint64_t load_kernel(const char *kernel_filename) +static target_ulong load_kernel(const char *kernel_filename) { uint64_t kernel_entry, kernel_high;