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