1 /* $OpenBSD: kvm_arm.c,v 1.8 2013/03/28 16:27:31 deraadt 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 * ARM 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 <arm/kcore.h> 68 69 void 70 _kvm_freevtop(kvm_t *kd) 71 { 72 if (kd->vmst != NULL) { 73 free(kd->vmst); 74 kd->vmst = NULL; 75 } 76 } 77 78 int 79 _kvm_initvtop(kvm_t *kd) 80 { 81 return (0); 82 } 83 84 /* 85 * Translate a kernel virtual address to a physical address by walking 86 * the kernels page table. 87 */ 88 89 int 90 _kvm_kvatop(kvm_t *kd, u_long va, paddr_t *pa) 91 { 92 cpu_kcore_hdr_t *cpup = kd->cpu_data; 93 94 if (ISALIVE(kd)) { 95 _kvm_err(kd, 0, "vatop called in live kernel!"); 96 return (0); 97 } 98 99 /* 100 * This relies upon the kernel text and data being contiguous 101 * in the first memory segment. 102 * Other virtual addresses are not reachable yet. 103 */ 104 105 if (va >= cpup->kernelbase + cpup->kerneloffs && 106 va < cpup->kernelbase + cpup->kerneloffs + cpup->staticsize) { 107 *pa = (va - cpup->kernelbase) + 108 (paddr_t)cpup->ram_segs[0].start; 109 return (int)(kd->nbpg - (va & (kd->nbpg - 1))); 110 } 111 112 _kvm_err(kd, 0, "kvm_vatop: va %x unreachable", va); 113 return (0); 114 } 115 116 off_t 117 _kvm_pa2off(kvm_t *kd, paddr_t pa) 118 { 119 cpu_kcore_hdr_t *cpup = kd->cpu_data; 120 phys_ram_seg_t *mp = cpup->ram_segs; 121 off_t off = 0; 122 int block; 123 124 for (block = 0; block < NPHYS_RAM_SEGS; block++, mp++) { 125 if (pa >= mp->start && pa < mp->start + mp->size) 126 return (kd->dump_off + off + 127 (off_t)(pa - (paddr_t)mp->start)); 128 off += (off_t)mp->size; 129 } 130 131 _kvm_err(kd, 0, "not a physical address: %x", pa); 132 return (-1); 133 } 134