xref: /netbsd-src/lib/libkvm/kvm_or1k.c (revision 916b154777c03001385d7553acc2d6430fb1a919)
1*916b1547Srin /*	$NetBSD: kvm_or1k.c,v 1.3 2023/08/23 14:00:11 rin Exp $	*/
227620987Smatt 
327620987Smatt /*-
427620987Smatt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
527620987Smatt  * All rights reserved.
627620987Smatt  *
727620987Smatt  * This code is derived from software contributed to The NetBSD Foundation
827620987Smatt  * by Matt Thomas of 3am Software Foundry.
927620987Smatt  *
1027620987Smatt  * Redistribution and use in source and binary forms, with or without
1127620987Smatt  * modification, are permitted provided that the following conditions
1227620987Smatt  * are met:
1327620987Smatt  * 1. Redistributions of source code must retain the above copyright
1427620987Smatt  *    notice, this list of conditions and the following disclaimer.
1527620987Smatt  * 2. Redistributions in binary form must reproduce the above copyright
1627620987Smatt  *    notice, this list of conditions and the following disclaimer in the
1727620987Smatt  *    documentation and/or other materials provided with the distribution.
1827620987Smatt  *
1927620987Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2027620987Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2127620987Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2227620987Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2327620987Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2427620987Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2527620987Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2627620987Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2727620987Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2827620987Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2927620987Smatt  * POSSIBILITY OF SUCH DAMAGE.
3027620987Smatt  */
3127620987Smatt 
3227620987Smatt /*
3327620987Smatt  * OR1K machine dependent routines for kvm.
3427620987Smatt  */
3527620987Smatt 
3627620987Smatt #include <sys/param.h>
3727620987Smatt #include <sys/exec.h>
3827620987Smatt #include <sys/types.h>
3927620987Smatt 
4027620987Smatt #include <uvm/uvm_extern.h>
4127620987Smatt 
4227620987Smatt #include <db.h>
4327620987Smatt #include <limits.h>
4427620987Smatt #include <kvm.h>
4527620987Smatt #include <stdlib.h>
4627620987Smatt #include <unistd.h>
4727620987Smatt 
4827620987Smatt #include "kvm_private.h"
4927620987Smatt 
5027620987Smatt #include <sys/kcore.h>
5127620987Smatt #include <machine/kcore.h>
5227620987Smatt #include <machine/vmparam.h>
5327620987Smatt 
54*916b1547Srin __RCSID("$NetBSD: kvm_or1k.c,v 1.3 2023/08/23 14:00:11 rin Exp $");
5527620987Smatt 
5627620987Smatt void
_kvm_freevtop(kvm_t * kd)5727620987Smatt _kvm_freevtop(kvm_t *kd)
5827620987Smatt {
5927620987Smatt 	if (kd->vmst != 0)
6027620987Smatt 		free(kd->vmst);
6127620987Smatt }
6227620987Smatt 
6327620987Smatt /*ARGSUSED*/
6427620987Smatt int
_kvm_initvtop(kvm_t * kd)6527620987Smatt _kvm_initvtop(kvm_t *kd)
6627620987Smatt {
6727620987Smatt 
6827620987Smatt 	return 0;
6927620987Smatt }
7027620987Smatt 
7127620987Smatt /*
7227620987Smatt  * Translate a KVA to a PA
7327620987Smatt  */
7427620987Smatt int
_kvm_kvatop(kvm_t * kd,vaddr_t va,paddr_t * pa)7527620987Smatt _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
7627620987Smatt {
7727620987Smatt //	cpu_kcore_hdr_t	*cpu_kh;
7827620987Smatt 
7927620987Smatt 	if (ISALIVE(kd)) {
8027620987Smatt 		_kvm_err(kd, 0, "vatop called in live kernel!");
8127620987Smatt 		return 0;
8227620987Smatt 	}
8327620987Smatt 
8427620987Smatt 	/* No hit -- no translation */
8527620987Smatt 	*pa = (u_long)~0UL;
8627620987Smatt 	return 0;
8727620987Smatt }
8827620987Smatt 
8927620987Smatt off_t
_kvm_pa2off(kvm_t * kd,paddr_t pa)9027620987Smatt _kvm_pa2off(kvm_t *kd, paddr_t pa)
9127620987Smatt {
9227620987Smatt 	cpu_kcore_hdr_t	*cpu_kh;
9327620987Smatt 	phys_ram_seg_t	*ram;
9427620987Smatt 	off_t		off;
9527620987Smatt 	void		*e;
9627620987Smatt 
9727620987Smatt 	cpu_kh = kd->cpu_data;
9827620987Smatt 	e = (char *) kd->cpu_data + kd->cpu_dsize;
9927620987Smatt 	ram = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh));
10027620987Smatt 	off = kd->dump_off;
10127620987Smatt 	do {
10227620987Smatt 		if (pa >= ram->start && (pa - ram->start) < ram->size) {
10327620987Smatt 			return off + (pa - ram->start);
10427620987Smatt 		}
10527620987Smatt 		ram++;
10627620987Smatt 		off += ram->size;
10727620987Smatt 	} while ((void *) ram < e && ram->size);
10827620987Smatt 
10927620987Smatt 	_kvm_err(kd, 0, "pa2off failed for pa %#" PRIxPADDR "\n", pa);
11027620987Smatt 	return (off_t) -1;
11127620987Smatt }
11227620987Smatt 
11327620987Smatt /*
11427620987Smatt  * Machine-dependent initialization for ALL open kvm descriptors,
11527620987Smatt  * not just those for a kernel crash dump.  Some architectures
11627620987Smatt  * have to deal with these NOT being constants!  (i.e. m68k)
11727620987Smatt  */
11827620987Smatt int
_kvm_mdopen(kvm_t * kd)11927620987Smatt _kvm_mdopen(kvm_t *kd)
12027620987Smatt {
12127620987Smatt 	kd->min_uva = VM_MIN_ADDRESS;
12227620987Smatt 	kd->max_uva = VM_MAXUSER_ADDRESS;
12327620987Smatt 
12427620987Smatt 	return (0);
12527620987Smatt }
126