1*9c5546f0Sskrll /* $NetBSD: kvm_riscv.c,v 1.4 2024/10/12 12:19:16 skrll Exp $ */ 26cf6fe02Smatt 36cf6fe02Smatt /*- 46cf6fe02Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc. 56cf6fe02Smatt * All rights reserved. 66cf6fe02Smatt * 76cf6fe02Smatt * This code is derived from software contributed to The NetBSD Foundation 86cf6fe02Smatt * by Matt Thomas of 3am Software Foundry. 96cf6fe02Smatt * 106cf6fe02Smatt * Redistribution and use in source and binary forms, with or without 116cf6fe02Smatt * modification, are permitted provided that the following conditions 126cf6fe02Smatt * are met: 136cf6fe02Smatt * 1. Redistributions of source code must retain the above copyright 146cf6fe02Smatt * notice, this list of conditions and the following disclaimer. 156cf6fe02Smatt * 2. Redistributions in binary form must reproduce the above copyright 166cf6fe02Smatt * notice, this list of conditions and the following disclaimer in the 176cf6fe02Smatt * documentation and/or other materials provided with the distribution. 186cf6fe02Smatt * 196cf6fe02Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 206cf6fe02Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 216cf6fe02Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 226cf6fe02Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 236cf6fe02Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 246cf6fe02Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 256cf6fe02Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 266cf6fe02Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 276cf6fe02Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 286cf6fe02Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 296cf6fe02Smatt * POSSIBILITY OF SUCH DAMAGE. 306cf6fe02Smatt */ 316cf6fe02Smatt 326cf6fe02Smatt /* 336cf6fe02Smatt * OR1K machine dependent routines for kvm. 346cf6fe02Smatt */ 356cf6fe02Smatt 366cf6fe02Smatt #include <sys/param.h> 376cf6fe02Smatt #include <sys/exec.h> 386cf6fe02Smatt #include <sys/types.h> 396cf6fe02Smatt 406cf6fe02Smatt #include <uvm/uvm_extern.h> 416cf6fe02Smatt 426cf6fe02Smatt #include <db.h> 436cf6fe02Smatt #include <limits.h> 446cf6fe02Smatt #include <kvm.h> 456cf6fe02Smatt #include <stdlib.h> 466cf6fe02Smatt #include <unistd.h> 476cf6fe02Smatt 486cf6fe02Smatt #include "kvm_private.h" 496cf6fe02Smatt 506cf6fe02Smatt #include <sys/kcore.h> 516cf6fe02Smatt #include <machine/kcore.h> 526cf6fe02Smatt #include <machine/vmparam.h> 536cf6fe02Smatt 54*9c5546f0Sskrll __RCSID("$NetBSD: kvm_riscv.c,v 1.4 2024/10/12 12:19:16 skrll Exp $"); 556cf6fe02Smatt 566cf6fe02Smatt void 576cf6fe02Smatt _kvm_freevtop(kvm_t *kd) 586cf6fe02Smatt { 596cf6fe02Smatt if (kd->vmst != 0) 606cf6fe02Smatt free(kd->vmst); 616cf6fe02Smatt } 626cf6fe02Smatt 636cf6fe02Smatt /*ARGSUSED*/ 646cf6fe02Smatt int 656cf6fe02Smatt _kvm_initvtop(kvm_t *kd) 666cf6fe02Smatt { 676cf6fe02Smatt 686cf6fe02Smatt return 0; 696cf6fe02Smatt } 706cf6fe02Smatt 716cf6fe02Smatt /* 726cf6fe02Smatt * Translate a KVA to a PA 736cf6fe02Smatt */ 746cf6fe02Smatt int 756cf6fe02Smatt _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa) 766cf6fe02Smatt { 776cf6fe02Smatt // cpu_kcore_hdr_t *cpu_kh; 786cf6fe02Smatt 796cf6fe02Smatt if (ISALIVE(kd)) { 806cf6fe02Smatt _kvm_err(kd, 0, "vatop called in live kernel!"); 816cf6fe02Smatt return 0; 826cf6fe02Smatt } 836cf6fe02Smatt 846cf6fe02Smatt /* No hit -- no translation */ 85*9c5546f0Sskrll *pa = ~0UL; 866cf6fe02Smatt return 0; 876cf6fe02Smatt } 886cf6fe02Smatt 896cf6fe02Smatt off_t 906cf6fe02Smatt _kvm_pa2off(kvm_t *kd, paddr_t pa) 916cf6fe02Smatt { 926cf6fe02Smatt cpu_kcore_hdr_t *cpu_kh; 936cf6fe02Smatt phys_ram_seg_t *ram; 946cf6fe02Smatt off_t off; 956cf6fe02Smatt void *e; 966cf6fe02Smatt 976cf6fe02Smatt cpu_kh = kd->cpu_data; 986cf6fe02Smatt e = (char *) kd->cpu_data + kd->cpu_dsize; 996cf6fe02Smatt ram = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh)); 1006cf6fe02Smatt off = kd->dump_off; 1016cf6fe02Smatt do { 1026cf6fe02Smatt if (pa >= ram->start && (pa - ram->start) < ram->size) { 1036cf6fe02Smatt return off + (pa - ram->start); 1046cf6fe02Smatt } 1056cf6fe02Smatt ram++; 1066cf6fe02Smatt off += ram->size; 1076cf6fe02Smatt } while ((void *) ram < e && ram->size); 1086cf6fe02Smatt 1096cf6fe02Smatt _kvm_err(kd, 0, "pa2off failed for pa %#" PRIxPADDR "\n", pa); 1106cf6fe02Smatt return (off_t) -1; 1116cf6fe02Smatt } 1126cf6fe02Smatt 1136cf6fe02Smatt /* 1146cf6fe02Smatt * Machine-dependent initialization for ALL open kvm descriptors, 1156cf6fe02Smatt * not just those for a kernel crash dump. Some architectures 1166cf6fe02Smatt * have to deal with these NOT being constants! (i.e. m68k) 1176cf6fe02Smatt */ 1186cf6fe02Smatt int 1196cf6fe02Smatt _kvm_mdopen(kvm_t *kd) 1206cf6fe02Smatt { 1216cf6fe02Smatt kd->min_uva = VM_MIN_ADDRESS; 1226cf6fe02Smatt kd->max_uva = VM_MAXUSER_ADDRESS; 1236cf6fe02Smatt 1246cf6fe02Smatt return (0); 1256cf6fe02Smatt } 126