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