1*916b1547Srin /* $NetBSD: kvm_powerpc64.c,v 1.8 2023/08/23 14:00:11 rin Exp $ */
221d9d384Sross
321d9d384Sross /*
421d9d384Sross * Copyright (c) 2005 Wasabi Systems, Inc.
521d9d384Sross * All rights reserved.
621d9d384Sross *
721d9d384Sross * Written by Allen Briggs for Wasabi Systems, Inc.
821d9d384Sross *
921d9d384Sross * Redistribution and use in source and binary forms, with or without
1021d9d384Sross * modification, are permitted provided that the following conditions
1121d9d384Sross * are met:
1221d9d384Sross * 1. Redistributions of source code must retain the above copyright
1321d9d384Sross * notice, this list of conditions and the following disclaimer.
1421d9d384Sross * 2. Redistributions in binary form must reproduce the above copyright
1521d9d384Sross * notice, this list of conditions and the following disclaimer in the
1621d9d384Sross * documentation and/or other materials provided with the distribution.
1721d9d384Sross * 3. All advertising materials mentioning features or use of this software
1821d9d384Sross * must display the following acknowledgement:
1921d9d384Sross * This product includes software developed for the NetBSD Project by
2021d9d384Sross * Wasabi Systems, Inc.
2121d9d384Sross * 4. The name of Wasabi Systems, Inc. may not be used to endorse
2221d9d384Sross * or promote products derived from this software without specific prior
2321d9d384Sross * written permission.
2421d9d384Sross *
2521d9d384Sross * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
2621d9d384Sross * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2721d9d384Sross * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2821d9d384Sross * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
2921d9d384Sross * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3021d9d384Sross * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3121d9d384Sross * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3221d9d384Sross * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3321d9d384Sross * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3421d9d384Sross * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3521d9d384Sross * POSSIBILITY OF SUCH DAMAGE.
3621d9d384Sross */
3721d9d384Sross /*-
3821d9d384Sross * Copyright (C) 1996 Wolfgang Solfrank.
3921d9d384Sross * Copyright (C) 1996 TooLs GmbH.
4021d9d384Sross * All rights reserved.
4121d9d384Sross *
4221d9d384Sross * Redistribution and use in source and binary forms, with or without
4321d9d384Sross * modification, are permitted provided that the following conditions
4421d9d384Sross * are met:
4521d9d384Sross * 1. Redistributions of source code must retain the above copyright
4621d9d384Sross * notice, this list of conditions and the following disclaimer.
4721d9d384Sross * 2. Redistributions in binary form must reproduce the above copyright
4821d9d384Sross * notice, this list of conditions and the following disclaimer in the
4921d9d384Sross * documentation and/or other materials provided with the distribution.
5021d9d384Sross * 3. All advertising materials mentioning features or use of this software
5121d9d384Sross * must display the following acknowledgement:
5221d9d384Sross * This product includes software developed by TooLs GmbH.
5321d9d384Sross * 4. The name of TooLs GmbH may not be used to endorse or promote products
5421d9d384Sross * derived from this software without specific prior written permission.
5521d9d384Sross *
5621d9d384Sross * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
5721d9d384Sross * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5821d9d384Sross * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5921d9d384Sross * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6021d9d384Sross * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
6121d9d384Sross * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
6221d9d384Sross * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
6321d9d384Sross * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
6421d9d384Sross * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
6521d9d384Sross * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6621d9d384Sross */
6721d9d384Sross
6821d9d384Sross /*
6921d9d384Sross * PowerPC machine dependent routines for kvm.
7021d9d384Sross */
7121d9d384Sross
7221d9d384Sross #include <sys/param.h>
7321d9d384Sross #include <sys/exec.h>
74962a341dSjym #include <sys/types.h>
7521d9d384Sross
7621d9d384Sross #include <uvm/uvm_extern.h>
7721d9d384Sross
7821d9d384Sross #include <db.h>
7921d9d384Sross #include <limits.h>
8021d9d384Sross #include <kvm.h>
8121d9d384Sross #include <stdlib.h>
8221d9d384Sross #include <unistd.h>
8321d9d384Sross
8421d9d384Sross #include "kvm_private.h"
8521d9d384Sross
8621d9d384Sross #include <sys/kcore.h>
8721d9d384Sross #include <machine/kcore.h>
8821d9d384Sross
8921d9d384Sross #include <powerpc/spr.h>
9021d9d384Sross #include <powerpc/oea/bat.h>
9121d9d384Sross #include <powerpc/oea/pte.h>
9221d9d384Sross
93*916b1547Srin __RCSID("$NetBSD: kvm_powerpc64.c,v 1.8 2023/08/23 14:00:11 rin Exp $");
940deb66dfSmatt
9521d9d384Sross void
_kvm_freevtop(kvm_t * kd)966dc46b92Sjym _kvm_freevtop(kvm_t *kd)
9721d9d384Sross {
9821d9d384Sross if (kd->vmst != 0)
9921d9d384Sross free(kd->vmst);
10021d9d384Sross }
10121d9d384Sross
10221d9d384Sross /*ARGSUSED*/
10321d9d384Sross int
_kvm_initvtop(kvm_t * kd)1046dc46b92Sjym _kvm_initvtop(kvm_t *kd)
10521d9d384Sross {
10621d9d384Sross
10721d9d384Sross return 0;
10821d9d384Sross }
10921d9d384Sross
11021d9d384Sross #define SR_VSID_HASH_MASK 0x0007ffff
11121d9d384Sross
11221d9d384Sross #define HASH_MASK 0x0007ffff
11321d9d384Sross
11421d9d384Sross /*
11521d9d384Sross * Translate a KVA to a PA
11621d9d384Sross */
11721d9d384Sross int
_kvm_kvatop(kvm_t * kd,vaddr_t va,paddr_t * pa)118962a341dSjym _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
11921d9d384Sross {
12021d9d384Sross
12121d9d384Sross if (ISALIVE(kd)) {
12221d9d384Sross _kvm_err(kd, 0, "vatop called in live kernel!");
12321d9d384Sross return 0;
12421d9d384Sross }
12521d9d384Sross
126cc87ea3aSmatt #if 0
127cc87ea3aSmatt cpu_kcore_hdr_t *cpu_kh = kd->cpu_data;
128cc87ea3aSmatt uint32_t pvr = (cpu_kh->pvr >> 16);
129cc87ea3aSmatt #endif
13021d9d384Sross
13121d9d384Sross
13221d9d384Sross /* No hit -- no translation */
13321d9d384Sross *pa = (u_long)~0UL;
13421d9d384Sross return 0;
13521d9d384Sross }
13621d9d384Sross
13721d9d384Sross off_t
_kvm_pa2off(kvm_t * kd,paddr_t pa)138962a341dSjym _kvm_pa2off(kvm_t *kd, paddr_t pa)
13921d9d384Sross {
14021d9d384Sross cpu_kcore_hdr_t *cpu_kh;
14121d9d384Sross phys_ram_seg_t *ram;
14221d9d384Sross off_t off;
14321d9d384Sross void *e;
14421d9d384Sross
14521d9d384Sross cpu_kh = kd->cpu_data;
14621d9d384Sross e = (char *) kd->cpu_data + kd->cpu_dsize;
14721d9d384Sross ram = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh));
14821d9d384Sross off = kd->dump_off;
14921d9d384Sross do {
15021d9d384Sross if (pa >= ram->start && (pa - ram->start) < ram->size) {
15121d9d384Sross return off + (pa - ram->start);
15221d9d384Sross }
15321d9d384Sross ram++;
15421d9d384Sross off += ram->size;
15521d9d384Sross } while ((void *) ram < e && ram->size);
15621d9d384Sross
15721d9d384Sross _kvm_err(kd, 0, "pa2off failed for pa 0x%08lx\n", pa);
15821d9d384Sross return (off_t) -1;
15921d9d384Sross }
16021d9d384Sross
16121d9d384Sross /*
16221d9d384Sross * Machine-dependent initialization for ALL open kvm descriptors,
16321d9d384Sross * not just those for a kernel crash dump. Some architectures
16421d9d384Sross * have to deal with these NOT being constants! (i.e. m68k)
16521d9d384Sross */
16621d9d384Sross int
_kvm_mdopen(kvm_t * kd)1676dc46b92Sjym _kvm_mdopen(kvm_t *kd)
16821d9d384Sross {
16921d9d384Sross uintptr_t max_uva;
17021d9d384Sross extern struct ps_strings *__ps_strings;
17121d9d384Sross
17221d9d384Sross #if 0 /* XXX - These vary across powerpc machines... */
17321d9d384Sross kd->min_uva = VM_MIN_ADDRESS;
17421d9d384Sross kd->max_uva = VM_MAXUSER_ADDRESS;
17521d9d384Sross #endif
17621d9d384Sross /* This is somewhat hack-ish, but it works. */
17721d9d384Sross max_uva = (uintptr_t) (__ps_strings + 1);
17821d9d384Sross kd->max_uva = max_uva;
17921d9d384Sross kd->min_uva = 0;
18021d9d384Sross
18121d9d384Sross return (0);
18221d9d384Sross }
183