1 /* $OpenBSD: kvm_arm64.c,v 1.1 2017/01/11 14:32:36 patrick Exp $ */ 2 /* 3 * Copyright (c) 2006 Miodrag Vallat. 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice, this permission notice, and the disclaimer below 8 * appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 /*- 19 * Copyright (C) 1996 Wolfgang Solfrank. 20 * Copyright (C) 1996 TooLs GmbH. 21 * All rights reserved. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the above copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * This product includes software developed by TooLs GmbH. 34 * 4. The name of TooLs GmbH may not be used to endorse or promote products 35 * derived from this software without specific prior written permission. 36 * 37 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 38 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 40 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 42 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 43 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 45 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 46 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 */ 48 49 /* 50 * ARM64 machine dependent routines for kvm. 51 */ 52 53 #include <sys/param.h> 54 #include <sys/core.h> 55 #include <sys/kcore.h> 56 #include <sys/vnode.h> 57 58 #include <unistd.h> 59 #include <stdlib.h> 60 #include <nlist.h> 61 #include <kvm.h> 62 63 #include <db.h> 64 65 #include "kvm_private.h" 66 67 #include <arm64/kcore.h> 68 69 void 70 _kvm_freevtop(kvm_t *kd) 71 { 72 free(kd->vmst); 73 kd->vmst = NULL; 74 } 75 76 int 77 _kvm_initvtop(kvm_t *kd) 78 { 79 return (0); 80 } 81 82 /* 83 * Translate a kernel virtual address to a physical address by walking 84 * the kernels page table. 85 */ 86 87 int 88 _kvm_kvatop(kvm_t *kd, u_long va, paddr_t *pa) 89 { 90 cpu_kcore_hdr_t *cpup = kd->cpu_data; 91 92 if (ISALIVE(kd)) { 93 _kvm_err(kd, 0, "vatop called in live kernel!"); 94 return (0); 95 } 96 97 /* 98 * This relies upon the kernel text and data being contiguous 99 * in the first memory segment. 100 * Other virtual addresses are not reachable yet. 101 */ 102 103 if (va >= cpup->kernelbase + cpup->kerneloffs && 104 va < cpup->kernelbase + cpup->kerneloffs + cpup->staticsize) { 105 *pa = (va - cpup->kernelbase) + 106 (paddr_t)cpup->ram_segs[0].start; 107 return (int)(kd->nbpg - (va & (kd->nbpg - 1))); 108 } 109 110 _kvm_err(kd, 0, "kvm_vatop: va %lx unreachable", va); 111 return (0); 112 } 113 114 off_t 115 _kvm_pa2off(kvm_t *kd, paddr_t pa) 116 { 117 cpu_kcore_hdr_t *cpup = kd->cpu_data; 118 phys_ram_seg_t *mp = cpup->ram_segs; 119 off_t off = 0; 120 int block; 121 122 for (block = 0; block < NPHYS_RAM_SEGS; block++, mp++) { 123 if (pa >= mp->start && pa < mp->start + mp->size) 124 return (kd->dump_off + off + 125 (off_t)(pa - (paddr_t)mp->start)); 126 off += (off_t)mp->size; 127 } 128 129 _kvm_err(kd, 0, "not a physical address: %lx", pa); 130 return (-1); 131 } 132