From patchwork Sun Sep 27 16:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1372104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fuxpqudZ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BzrzH2HqLz9sSG for ; Mon, 28 Sep 2020 02:42:19 +1000 (AEST) Received: from localhost ([::1]:41114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMZkf-0003Bk-7r for incoming@patchwork.ozlabs.org; Sun, 27 Sep 2020 12:42:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMZiI-0002BW-KB for qemu-devel@nongnu.org; Sun, 27 Sep 2020 12:39:50 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kMZiH-0005Ir-5w for qemu-devel@nongnu.org; Sun, 27 Sep 2020 12:39:50 -0400 Received: by mail-wr1-x442.google.com with SMTP id z1so9187321wrt.3 for ; Sun, 27 Sep 2020 09:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wcij9GO4gLo8n4f2y2Sh6IBkKvCpAomrBCYklDDmQdw=; b=fuxpqudZwh1ft/RJqtRtR2byLfUT/nc8uWACxJX6YyI0b9IsdpM9QOK5jIKW/GSAbn TwfmOMF0gl/in4ANDJU6DK2kvqS2PhLZ0HEnEhEJFn2BID8J7Qs43zsJuoidNzD/IMDb L2BHm8JoT9hLnV+j233x81Lb+mNwfrNG59w0q2drWhYaLyVIKAbCtiUGZrVRJnDOrBVq Ul6K6ZbIJji5xFRd6l531+zpd1V0nO51cJcLW/NvVgkxkTeCjMWR1SLUzczC1zbcYBws TBUXwe2w0dysleakmmSGvvgrpTDM8ITKIwcc5XpMQ45G77mQZRilyg4l2ESS0R4ysPzK bXgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wcij9GO4gLo8n4f2y2Sh6IBkKvCpAomrBCYklDDmQdw=; b=Hz5ZLzt+lcwiVY2sjG6jC1jy0FRIItEz8+UabljMPy4BLDpnkdwM8/fozSfJ+kFHmn ZcUvld2mo7FNL+m37ZWElslNmmBd1Llc1Jwk9VDL/EmCTYSlFUuGJ5ReyI9zUZ9Clnrd IGey3dMXWHkQMG+kU70YpvMeyzn0NpNf+4s5OpMZRGKfdKjmzhkuhP2LsERL2D0sUhhg 9SRF3kAgIL9rRUlZzDQHHMPHcggPQQUo+Gr354B75909PWXXV+VagVgqVUrvjOLUUaM+ PkqYxhwbb9I2AHXywDD+NrWcYHucWJ7BIFzpTs4uSUhKR64XXXjoj/i0exuufUn+NTMf SqNQ== X-Gm-Message-State: AOAM530b9X8Kuz2G+zITpnrtZyFbJYktt4kfnhBrjdqH1q4OHZ1AaqbL dRomDPPTeus3xjnrYt5tJPChmBVoRh4= X-Google-Smtp-Source: ABdhPJyutFygH37n6cayc8Nm+sya0joDBCNlf8HDoGOMnfQormB6elJNj0HrXRLKTgSfiN0Q9A+udg== X-Received: by 2002:adf:ef0a:: with SMTP id e10mr14502107wro.362.1601224787118; Sun, 27 Sep 2020 09:39:47 -0700 (PDT) Received: from localhost.localdomain (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id m10sm5820184wmi.9.2020.09.27.09.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 09:39:46 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/2] hw/mips: Simplify loading 64-bit ELF kernels Date: Sun, 27 Sep 2020 18:39:42 +0200 Message-Id: <20200927163943.614604-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200927163943.614604-1-f4bug@amsat.org> References: <20200927163943.614604-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.078, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huacai Chen , Aleksandar Rikalo , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Aleksandar Markovic , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since 82790064116 ("Cast ELF datatypes properly to host 64bit types") we don't need to sign-extend the entry_point address. Remove this unnecessary code. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/mips/mipssim.c | 6 +----- hw/mips/r4k.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c index 1b3b7622035..3aeb1207e1a 100644 --- a/hw/mips/mipssim.c +++ b/hw/mips/mipssim.c @@ -76,11 +76,7 @@ static int64_t load_kernel(void) (uint64_t *)&entry, NULL, (uint64_t *)&kernel_high, NULL, big_endian, EM_MIPS, 1, 0); - if (kernel_size >= 0) { - if ((entry & ~0x7fffffffULL) == 0x80000000) { - entry = (int32_t)entry; - } - } else { + if (kernel_size < 0) { error_report("could not load kernel '%s': %s", loaderparams.kernel_filename, load_elf_strerror(kernel_size)); diff --git a/hw/mips/r4k.c b/hw/mips/r4k.c index 3487013a4a1..74f916a3982 100644 --- a/hw/mips/r4k.c +++ b/hw/mips/r4k.c @@ -101,11 +101,7 @@ static int64_t load_kernel(void) (uint64_t *)&entry, NULL, (uint64_t *)&kernel_high, NULL, big_endian, EM_MIPS, 1, 0); - if (kernel_size >= 0) { - if ((entry & ~0x7fffffffULL) == 0x80000000) { - entry = (int32_t)entry; - } - } else { + if (kernel_size < 0) { error_report("could not load kernel '%s': %s", loaderparams.kernel_filename, load_elf_strerror(kernel_size)); From patchwork Sun Sep 27 16:39:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1372105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kcePoqC/; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bzs0Z0sg0z9sSf for ; Mon, 28 Sep 2020 02:43:26 +1000 (AEST) Received: from localhost ([::1]:43722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMZlk-0004Ha-3G for incoming@patchwork.ozlabs.org; Sun, 27 Sep 2020 12:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMZiJ-0002Bf-DH for qemu-devel@nongnu.org; Sun, 27 Sep 2020 12:39:52 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kMZiH-0005Iw-UB for qemu-devel@nongnu.org; Sun, 27 Sep 2020 12:39:51 -0400 Received: by mail-wm1-x341.google.com with SMTP id x23so4056062wmi.3 for ; Sun, 27 Sep 2020 09:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v2AAXqYVbggYqD2O82lQGNTgT9BbKcX2OEontmBjDXk=; b=kcePoqC/il0PHMHBaHYw5MgQELKldh1nRgODSlIBuKx6G2WYyw3idFGnVwxnJFwG2T GbOmzBngiqtRUJmcn7gJJQOkT++H7HnZk2lFxcAk/TTrMLuf2Wr4p6JGTNI2n2PZLGpO kmd24enYnaMR/HMA8r2fWzlawbcGYYNHIbYyyuwIgjytMWEDJ6lKFZOFiSQ/qugNQJcT pfnyZkCdAscH8Aut237MZEG5IebugPjgh47IG4kUyIsuVcVc31Pees85r0vHpc7UqWUW 4lRTQFVHiEN5jsUFkBmBIWHO5wQSfiYSWRG1Hqbu26R1oLE7BGlrdJbO8s0nftQfJZ93 XyaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=v2AAXqYVbggYqD2O82lQGNTgT9BbKcX2OEontmBjDXk=; b=PH+SqUUBbRo/oopB34Wg40iQtYonwJgJ0hFjLmKJT9QFtBS5+ZIoJbVsrt1AmQTFAo /iWH6O4NRT13Bk/qaG2kTSGp5uL8QGl4Lxm8ROGYquOCU6Z52j6KqmUlylKely3mgkN6 K4HM8xnof2LV32wK30sUq+CMIfbaPCvDhy0wh/aszihHELJWoRrsq1A4veXut+GfYSKI boPYQd4c5BiCDtsEOfko5y+Tow9SwBhwwjU4IRL70W3AadyYXDFabCvNMNmRI8uU/TiQ ahO/HExSd0dNhgf6TXkglJyFHKKVxu6uDrnOw4/J8lU/2WR/FatbX6SZhdk2vx5vSc5/ P/mw== X-Gm-Message-State: AOAM533EojzWwPHQVF5Mhe954LtRPSfrA2MFo5bpipE1mNlk3YEZo83j E48CYk0uGfqZo1bzWAIFB8VMXgy9IKU= X-Google-Smtp-Source: ABdhPJydbLG609apzb9XsDTaup4cXrqHD2NRV3RLa8xV3fimjfRKwQu71axI1dkCjKL7N9/JkmI7OQ== X-Received: by 2002:a05:600c:2054:: with SMTP id p20mr7475146wmg.173.1601224788309; Sun, 27 Sep 2020 09:39:48 -0700 (PDT) Received: from localhost.localdomain (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id m10sm5820184wmi.9.2020.09.27.09.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 09:39:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/2] hw/mips: Simplify code using ROUND_UP(INITRD_PAGE_SIZE) Date: Sun, 27 Sep 2020 18:39:43 +0200 Message-Id: <20200927163943.614604-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200927163943.614604-1-f4bug@amsat.org> References: <20200927163943.614604-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.078, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huacai Chen , Aleksandar Rikalo , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Aleksandar Markovic , Huacai Chen , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of using a INITRD_PAGE_MASK definition, use the simpler INITRD_PAGE_SIZE one which allows us to simplify the code by using directly the self-explicit ROUND_UP() macro. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/mips/mips.h | 4 +++- hw/mips/fuloong2e.c | 3 +-- hw/mips/malta.c | 6 +++--- hw/mips/mipssim.c | 3 +-- hw/mips/r4k.c | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/hw/mips/mips.h b/include/hw/mips/mips.h index 0af4c3d5d74..6c9c8805f3f 100644 --- a/include/hw/mips/mips.h +++ b/include/hw/mips/mips.h @@ -2,8 +2,10 @@ #define HW_MIPS_H /* Definitions for mips board emulation. */ +#include "qemu/units.h" + /* Kernels can be configured with 64KB pages */ -#define INITRD_PAGE_MASK (~((1 << 16) - 1)) +#define INITRD_PAGE_SIZE (64 * KiB) #include "exec/memory.h" diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c index f28609976bf..ef5dbe97b7d 100644 --- a/hw/mips/fuloong2e.c +++ b/hw/mips/fuloong2e.c @@ -132,8 +132,7 @@ static int64_t load_kernel(CPUMIPSState *env) if (loaderparams.initrd_filename) { initrd_size = get_image_size(loaderparams.initrd_filename); if (initrd_size > 0) { - initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) & - INITRD_PAGE_MASK; + initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE); if (initrd_offset + initrd_size > ram_size) { error_report("memory too small for initial ram disk '%s'", loaderparams.initrd_filename); diff --git a/hw/mips/malta.c b/hw/mips/malta.c index 4019c9dc1a8..5de5cb152eb 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -1074,9 +1074,9 @@ static int64_t load_kernel(void) * the initrd. It takes at most 128kiB for 2GB RAM and 4kiB * pages. */ - initrd_offset = (loaderparams.ram_low_size - initrd_size - - (128 * KiB) - - ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK; + initrd_offset = ROUND_UP(loaderparams.ram_low_size + - (initrd_size + 128 * KiB), + INITRD_PAGE_SIZE); if (kernel_high >= initrd_offset) { error_report("memory too small for initial ram disk '%s'", loaderparams.initrd_filename); diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c index 3aeb1207e1a..1862eeda396 100644 --- a/hw/mips/mipssim.c +++ b/hw/mips/mipssim.c @@ -89,8 +89,7 @@ static int64_t load_kernel(void) if (loaderparams.initrd_filename) { initrd_size = get_image_size(loaderparams.initrd_filename); if (initrd_size > 0) { - initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) & - INITRD_PAGE_MASK; + initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE); if (initrd_offset + initrd_size > loaderparams.ram_size) { error_report("memory too small for initial ram disk '%s'", loaderparams.initrd_filename); diff --git a/hw/mips/r4k.c b/hw/mips/r4k.c index 74f916a3982..24cee357f34 100644 --- a/hw/mips/r4k.c +++ b/hw/mips/r4k.c @@ -114,8 +114,7 @@ static int64_t load_kernel(void) if (loaderparams.initrd_filename) { initrd_size = get_image_size(loaderparams.initrd_filename); if (initrd_size > 0) { - initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) & - INITRD_PAGE_MASK; + initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE); if (initrd_offset + initrd_size > ram_size) { error_report("memory too small for initial ram disk '%s'", loaderparams.initrd_filename);