xref: /minix/lib/libkvm/kvm_riscv.c (revision 9da22751)
1*9da22751SDavid van Moolenbroek /*	$NetBSD: kvm_riscv.c,v 1.1 2014/09/19 17:36:25 matt Exp $	*/
2*9da22751SDavid van Moolenbroek 
3*9da22751SDavid van Moolenbroek /*-
4*9da22751SDavid van Moolenbroek  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*9da22751SDavid van Moolenbroek  * All rights reserved.
6*9da22751SDavid van Moolenbroek  *
7*9da22751SDavid van Moolenbroek  * This code is derived from software contributed to The NetBSD Foundation
8*9da22751SDavid van Moolenbroek  * by Matt Thomas of 3am Software Foundry.
9*9da22751SDavid van Moolenbroek  *
10*9da22751SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
11*9da22751SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
12*9da22751SDavid van Moolenbroek  * are met:
13*9da22751SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
14*9da22751SDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer.
15*9da22751SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce the above copyright
16*9da22751SDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer in the
17*9da22751SDavid van Moolenbroek  *    documentation and/or other materials provided with the distribution.
18*9da22751SDavid van Moolenbroek  *
19*9da22751SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*9da22751SDavid van Moolenbroek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*9da22751SDavid van Moolenbroek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*9da22751SDavid van Moolenbroek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*9da22751SDavid van Moolenbroek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*9da22751SDavid van Moolenbroek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*9da22751SDavid van Moolenbroek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*9da22751SDavid van Moolenbroek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*9da22751SDavid van Moolenbroek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*9da22751SDavid van Moolenbroek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*9da22751SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGE.
30*9da22751SDavid van Moolenbroek  */
31*9da22751SDavid van Moolenbroek 
32*9da22751SDavid van Moolenbroek /*
33*9da22751SDavid van Moolenbroek  * OR1K machine dependent routines for kvm.
34*9da22751SDavid van Moolenbroek  */
35*9da22751SDavid van Moolenbroek 
36*9da22751SDavid van Moolenbroek #include <sys/param.h>
37*9da22751SDavid van Moolenbroek #include <sys/exec.h>
38*9da22751SDavid van Moolenbroek #include <sys/types.h>
39*9da22751SDavid van Moolenbroek 
40*9da22751SDavid van Moolenbroek #include <uvm/uvm_extern.h>
41*9da22751SDavid van Moolenbroek 
42*9da22751SDavid van Moolenbroek #include <db.h>
43*9da22751SDavid van Moolenbroek #include <limits.h>
44*9da22751SDavid van Moolenbroek #include <kvm.h>
45*9da22751SDavid van Moolenbroek #include <stdlib.h>
46*9da22751SDavid van Moolenbroek #include <unistd.h>
47*9da22751SDavid van Moolenbroek 
48*9da22751SDavid van Moolenbroek #include "kvm_private.h"
49*9da22751SDavid van Moolenbroek 
50*9da22751SDavid van Moolenbroek #include <sys/kcore.h>
51*9da22751SDavid van Moolenbroek #include <machine/kcore.h>
52*9da22751SDavid van Moolenbroek #include <machine/vmparam.h>
53*9da22751SDavid van Moolenbroek 
54*9da22751SDavid van Moolenbroek __RCSID("$NetBSD: kvm_riscv.c,v 1.1 2014/09/19 17:36:25 matt Exp $");
55*9da22751SDavid van Moolenbroek 
56*9da22751SDavid van Moolenbroek void
_kvm_freevtop(kvm_t * kd)57*9da22751SDavid van Moolenbroek _kvm_freevtop(kvm_t *kd)
58*9da22751SDavid van Moolenbroek {
59*9da22751SDavid van Moolenbroek 	if (kd->vmst != 0)
60*9da22751SDavid van Moolenbroek 		free(kd->vmst);
61*9da22751SDavid van Moolenbroek }
62*9da22751SDavid van Moolenbroek 
63*9da22751SDavid van Moolenbroek /*ARGSUSED*/
64*9da22751SDavid van Moolenbroek int
_kvm_initvtop(kvm_t * kd)65*9da22751SDavid van Moolenbroek _kvm_initvtop(kvm_t *kd)
66*9da22751SDavid van Moolenbroek {
67*9da22751SDavid van Moolenbroek 
68*9da22751SDavid van Moolenbroek 	return 0;
69*9da22751SDavid van Moolenbroek }
70*9da22751SDavid van Moolenbroek 
71*9da22751SDavid van Moolenbroek /*
72*9da22751SDavid van Moolenbroek  * Translate a KVA to a PA
73*9da22751SDavid van Moolenbroek  */
74*9da22751SDavid van Moolenbroek int
_kvm_kvatop(kvm_t * kd,vaddr_t va,paddr_t * pa)75*9da22751SDavid van Moolenbroek _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
76*9da22751SDavid van Moolenbroek {
77*9da22751SDavid van Moolenbroek //	cpu_kcore_hdr_t	*cpu_kh;
78*9da22751SDavid van Moolenbroek 
79*9da22751SDavid van Moolenbroek 	if (ISALIVE(kd)) {
80*9da22751SDavid van Moolenbroek 		_kvm_err(kd, 0, "vatop called in live kernel!");
81*9da22751SDavid van Moolenbroek 		return 0;
82*9da22751SDavid van Moolenbroek 	}
83*9da22751SDavid van Moolenbroek 
84*9da22751SDavid van Moolenbroek 	/* No hit -- no translation */
85*9da22751SDavid van Moolenbroek 	*pa = (u_long)~0UL;
86*9da22751SDavid van Moolenbroek 	return 0;
87*9da22751SDavid van Moolenbroek }
88*9da22751SDavid van Moolenbroek 
89*9da22751SDavid van Moolenbroek off_t
_kvm_pa2off(kvm_t * kd,paddr_t pa)90*9da22751SDavid van Moolenbroek _kvm_pa2off(kvm_t *kd, paddr_t pa)
91*9da22751SDavid van Moolenbroek {
92*9da22751SDavid van Moolenbroek 	cpu_kcore_hdr_t	*cpu_kh;
93*9da22751SDavid van Moolenbroek 	phys_ram_seg_t	*ram;
94*9da22751SDavid van Moolenbroek 	off_t		off;
95*9da22751SDavid van Moolenbroek 	void		*e;
96*9da22751SDavid van Moolenbroek 
97*9da22751SDavid van Moolenbroek 	cpu_kh = kd->cpu_data;
98*9da22751SDavid van Moolenbroek 	e = (char *) kd->cpu_data + kd->cpu_dsize;
99*9da22751SDavid van Moolenbroek         ram = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh));
100*9da22751SDavid van Moolenbroek 	off = kd->dump_off;
101*9da22751SDavid van Moolenbroek 	do {
102*9da22751SDavid van Moolenbroek 		if (pa >= ram->start && (pa - ram->start) < ram->size) {
103*9da22751SDavid van Moolenbroek 			return off + (pa - ram->start);
104*9da22751SDavid van Moolenbroek 		}
105*9da22751SDavid van Moolenbroek 		ram++;
106*9da22751SDavid van Moolenbroek 		off += ram->size;
107*9da22751SDavid van Moolenbroek 	} while ((void *) ram < e && ram->size);
108*9da22751SDavid van Moolenbroek 
109*9da22751SDavid van Moolenbroek 	_kvm_err(kd, 0, "pa2off failed for pa %#" PRIxPADDR "\n", pa);
110*9da22751SDavid van Moolenbroek 	return (off_t) -1;
111*9da22751SDavid van Moolenbroek }
112*9da22751SDavid van Moolenbroek 
113*9da22751SDavid van Moolenbroek /*
114*9da22751SDavid van Moolenbroek  * Machine-dependent initialization for ALL open kvm descriptors,
115*9da22751SDavid van Moolenbroek  * not just those for a kernel crash dump.  Some architectures
116*9da22751SDavid van Moolenbroek  * have to deal with these NOT being constants!  (i.e. m68k)
117*9da22751SDavid van Moolenbroek  */
118*9da22751SDavid van Moolenbroek int
_kvm_mdopen(kvm_t * kd)119*9da22751SDavid van Moolenbroek _kvm_mdopen(kvm_t *kd)
120*9da22751SDavid van Moolenbroek {
121*9da22751SDavid van Moolenbroek 	kd->usrstack = USRSTACK;
122*9da22751SDavid van Moolenbroek 	kd->min_uva = VM_MIN_ADDRESS;
123*9da22751SDavid van Moolenbroek 	kd->max_uva = VM_MAXUSER_ADDRESS;
124*9da22751SDavid van Moolenbroek 
125*9da22751SDavid van Moolenbroek 	return (0);
126*9da22751SDavid van Moolenbroek }
127