From nobody Wed Apr  9 10:24:12 2025
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=quarantine dis=none)  header.from=kernel.org
ARC-Seal: i=1; a=rsa-sha256; t=1735341513; cv=none;
	d=zohomail.com; s=zohoarc;
	b=JG2jiQhBHW373AotK6ZrVoESVy+hW4TKtlHa93JEcy695/bcPgDcAuNrUMriiFHKXZVRAYJ+sF9bFhvbhRLJCA/4GMReThurfB/BwIl/FJ8iGb77hF9E0NvKXA6l5tm4kYXxHUaqcJocc1qNuWd4ercXsoDpgUtrvWwQqxyt6FA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1735341513;
 h=Content-Type:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc;
	bh=3F6PAqTCXvVnpYwb+/jnw6rJZLNI0uK2pUgw+P7BEs8=;
	b=fvfihJOtyH9rIU9ulVQiA9tAx1YoT0qUtYLfTRXA9Y9tWbpBLsbTFKaFfwRSfePRPOIPytGEjx8eU8lfJ+OaJ+tk/ItZKaNrDqEm1XAOfuUhhBfk2SaTBFnH6gFvPeGFI5wchKIfOlwHE5eVCqfQlolc8XSKd5sDzs6RPKQkCbE=
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=<deller@kernel.org> (p=quarantine dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1735341513246594.543098792952;
 Fri, 27 Dec 2024 15:18:33 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tRJaW-0006Ha-40; Fri, 27 Dec 2024 18:17:48 -0500
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 <deller@kernel.org>) id 1tRJaT-0006HB-3Y
 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 18:17:46 -0500
Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <deller@kernel.org>) id 1tRJaR-0004Sr-1r
 for qemu-devel@nongnu.org; Fri, 27 Dec 2024 18:17:44 -0500
Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])
 by dfw.source.kernel.org (Postfix) with ESMTP id EF0F15C56C4;
 Fri, 27 Dec 2024 23:16:55 +0000 (UTC)
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F4CCC4CED0;
 Fri, 27 Dec 2024 23:17:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
 s=k20201202; t=1735341457;
 bh=RazBM8DZZS1Gp1MXsL7b4TS0C0IpC3P/3NW+FPvbJD8=;
 h=Date:From:To:Subject:From;
 b=uNULvGhKMbWzvsSFoNqqBnlhOLq8aDCFe+e9QxB/jxgnxLXC3zI6VDh/FBv/0ivrr
 pqYyD7kk1t+HHyAzIjbcUxT4/94pCChG8RO4/bdcCKzywm1cGFmVgYvarzuNTjA0++
 pH2MfWBYT7TIj8R3rYIOWgagtruYMGkR/fHIfX0l78Ylz3LoqvxDLTUTLiCmI41kYc
 /jsu86QsOQ8R766Ogaq2XlV6XCPhVNeDmB6kjmjg6TphH/wmEL5kPIzGw15EjvC6Sz
 aeawrzbtAnDDf5k6Xt/0Gf0BCfNg6mAlVdBrGUn7HRkluul1/Is3lJhSuMZWLAYiqM
 B5NqWBP3YUZZA==
Date: Sat, 28 Dec 2024 00:17:33 +0100
From: Helge Deller <deller@kernel.org>
To: peter.maydell@linaro.org, richard.henderson@linaro.org,
 qemu-devel@nongnu.org
Subject: [PATCH v3] target/hppa: Add CPU reset method
Message-ID: <Z281jSej_buitgV8@p100>
MIME-Version: 1.0
Content-Disposition: inline
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=2604:1380:4641:c500::1;
 envelope-from=deller@kernel.org; helo=dfw.source.kernel.org
X-Spam_score_int: -44
X-Spam_score: -4.5
X-Spam_bar: ----
X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.138,
 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_MED=-2.3, 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=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 @kernel.org)
X-ZM-MESSAGEID: 1735341515277116600
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

Add the CPU reset method, which resets all CPU registers and the TLB to
zero. Then the CPU will switch to 32-bit mode (PSW_W bit is not set) and
start execution at address 0xf0000004.
Although we currently want to zero out all values in the CPUHPPAState
struct, add the end_reset_fields marker in case the state structs gets
extended with other variables later on which should not be reset.

Signed-off-by: Helge Deller <deller@gmx.de>

V3:
- Call reset function from hppa_machine_reset() instead

V2:
- Add end_reset_fields marker
- call reset function in hppa_cpu_initfn()

diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index a31dc32a9f..05fd43ce9c 100644
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -655,12 +655,12 @@ static void hppa_machine_reset(MachineState *ms, Rese=
tType type)
     for (i =3D 0; i < smp_cpus; i++) {
         CPUState *cs =3D CPU(cpu[i]);
=20
+        /* reset CPU */
+        resettable_reset(OBJECT(cs), RESET_TYPE_COLD);
+
         cpu_set_pc(cs, firmware_entry);
         cpu[i]->env.psw =3D PSW_Q;
         cpu[i]->env.gr[5] =3D CPU_HPA + i * 0x1000;
-
-        cs->exception_index =3D -1;
-        cs->halted =3D 0;
     }
=20
     /* already initialized by machine_hppa_init()? */
diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index c38439c180..b908cf65c6 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -235,15 +235,39 @@ static const TCGCPUOps hppa_tcg_ops =3D {
 #endif /* !CONFIG_USER_ONLY */
 };
=20
+static void hppa_cpu_reset_hold(Object *obj, ResetType type)
+{
+    HPPACPU *cpu =3D HPPA_CPU(obj);
+    HPPACPUClass *scc =3D HPPA_CPU_GET_CLASS(cpu);
+    CPUHPPAState *env =3D &cpu->env;
+    CPUState *cs =3D CPU(cpu);
+
+    if (scc->parent_phases.hold) {
+        scc->parent_phases.hold(obj, type);
+    }
+
+    memset(env, 0, offsetof(CPUHPPAState, end_reset_fields));
+    cpu_set_pc(cs, 0xf0000004);
+    cpu_hppa_put_psw(env, hppa_is_pa20(env) ? PSW_W : 0);
+    cpu_hppa_loaded_fr0(env);
+
+    cs->exception_index =3D -1;
+    cs->halted =3D 0;
+}
+
 static void hppa_cpu_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc =3D DEVICE_CLASS(oc);
     CPUClass *cc =3D CPU_CLASS(oc);
     HPPACPUClass *acc =3D HPPA_CPU_CLASS(oc);
+    ResettableClass *rc =3D RESETTABLE_CLASS(oc);
=20
     device_class_set_parent_realize(dc, hppa_cpu_realizefn,
                                     &acc->parent_realize);
=20
+    resettable_class_set_parent_phases(rc, NULL, hppa_cpu_reset_hold, NULL,
+                                       &acc->parent_phases);
+
     cc->class_by_name =3D hppa_cpu_class_by_name;
     cc->has_work =3D hppa_cpu_has_work;
     cc->mmu_index =3D hppa_cpu_mmu_index;
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index e45ba50a59..32a674a8b8 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -263,6 +263,9 @@ typedef struct CPUArchState {
     IntervalTreeRoot tlb_root;
=20
     HPPATLBEntry tlb[HPPA_TLB_ENTRIES];
+
+    /* Fields up to this point are cleared by a CPU reset */
+    struct {} end_reset_fields;
 } CPUHPPAState;
=20
 /**
@@ -281,6 +284,7 @@ struct ArchCPU {
 /**
  * HPPACPUClass:
  * @parent_realize: The parent class' realize handler.
+ * @parent_phases: The parent class' reset phase handlers.
  *
  * An HPPA CPU model.
  */
@@ -288,6 +292,7 @@ struct HPPACPUClass {
     CPUClass parent_class;
=20
     DeviceRealize parent_realize;
+    ResettablePhases parent_phases;
 };
=20
 #include "exec/cpu-all.h"