From patchwork Wed Apr 3 16:40:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Chouteau X-Patchwork-Id: 233558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8835B2C04E5 for ; Thu, 4 Apr 2013 03:42:36 +1100 (EST) Received: from localhost ([::1]:60830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNQle-0001Cx-GZ for incoming@patchwork.ozlabs.org; Wed, 03 Apr 2013 12:42:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNQjs-0007Pv-Qk for qemu-devel@nongnu.org; Wed, 03 Apr 2013 12:40:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNQjq-0005Ab-8L for qemu-devel@nongnu.org; Wed, 03 Apr 2013 12:40:44 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:38924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNQjq-0005A8-0O; Wed, 03 Apr 2013 12:40:42 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id F3FA329005C; Wed, 3 Apr 2013 18:40:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at eu.adacore.com Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sY4+adV29AzQ; Wed, 3 Apr 2013 18:40:40 +0200 (CEST) Received: from PomPomGalli.act-europe.fr (pompomgalli.act-europe.fr [10.10.1.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id C82DA29005A; Wed, 3 Apr 2013 18:40:40 +0200 (CEST) From: Fabien Chouteau To: qemu-devel@nongnu.org Date: Wed, 3 Apr 2013 18:40:12 +0200 Message-Id: <1365007213-27603-3-git-send-email-chouteau@adacore.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1365007213-27603-1-git-send-email-chouteau@adacore.com> References: <1365007213-27603-1-git-send-email-chouteau@adacore.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 194.98.77.210 Cc: qemu-ppc@nongnu.org, agraf@suse.de Subject: [Qemu-devel] [PATCH 2/3] PPC PReP: Use kernel entry to set nip at reset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When we load an ELF kernel we can start the board at the entry point. Signed-off-by: Fabien Chouteau --- hw/ppc/prep.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index a2730c8..12198ff 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -56,6 +56,12 @@ #define KERNEL_LOAD_ADDR 0x01000000 #define INITRD_LOAD_ADDR 0x01800000 +typedef struct ResetData { + PowerPCCPU *cpu; + bool use_entry; + target_ulong entry; /* save kernel entry in case of reset */ +} ResetData; + #if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO) #define DEBUG_PPC_IO #endif @@ -425,8 +431,13 @@ static void cpu_request_exit(void *opaque, int irq, int level) static void ppc_prep_reset(void *opaque) { - PowerPCCPU *cpu = opaque; + ResetData *s = (ResetData *)opaque; + PowerPCCPU *cpu = s->cpu; + + if (s->use_entry) { + cpu->env.nip = s->entry; + } cpu_reset(CPU(cpu)); } @@ -463,11 +474,14 @@ static void ppc_prep_init(QEMUMachineInitArgs *args) qemu_irq *cpu_exit_irq; int ppc_boot_device; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + ResetData *reset_data; sysctrl = g_malloc0(sizeof(sysctrl_t)); linux_boot = (kernel_filename != NULL); + reset_data = g_malloc0(sizeof(ResetData) * smp_cpus); + /* init CPUs */ if (cpu_model == NULL) cpu_model = "602"; @@ -486,7 +500,11 @@ static void ppc_prep_init(QEMUMachineInitArgs *args) /* Set time-base frequency to 100 Mhz */ cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); } - qemu_register_reset(ppc_prep_reset, cpu); + + /* Reset data */ + reset_data[i].cpu = cpu; + reset_data[i].use_entry = false; + qemu_register_reset(ppc_prep_reset, &reset_data[i]); } /* allocate RAM */ @@ -521,19 +539,27 @@ static void ppc_prep_init(QEMUMachineInitArgs *args) } if (linux_boot) { + uint64_t entry; + kernel_base = KERNEL_LOAD_ADDR; /* Try to load the kernel as an ELF file */ - kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, NULL, NULL, + kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL, 1, ELF_MACHINE, 0); - if (kernel_size < 0) { + if (kernel_size > 0) { + /* Entry point for CPU #0 */ + reset_data[0].entry = entry; + reset_data[0].use_entry = true; + } else { /* Try to load the kernel as an binary file */ kernel_size = load_image_targphys(kernel_filename, kernel_base, ram_size - kernel_base); } + if (kernel_size < 0) { hw_error("qemu: could not load kernel '%s'\n", kernel_filename); } + /* load initrd */ if (initrd_filename) { initrd_base = INITRD_LOAD_ADDR;