2004-05-14 12:24:03 +00:00
|
|
|
/*-
|
2007-01-08 18:25:58 +00:00
|
|
|
* Copyright (c) 2005 Olivier Houchard
|
|
|
|
* Copyright (c) 1989, 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software developed by the Computer Systems
|
|
|
|
* Engineering group at Lawrence Berkeley Laboratory under DARPA contract
|
|
|
|
* BG 91-66 and contributed to Berkeley.
|
2004-05-14 12:24:03 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2007-01-08 18:25:58 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2004-05-14 12:24:03 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARM machine dependent routines for kvm.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2015-11-27 18:58:26 +00:00
|
|
|
#include <sys/endian.h>
|
2004-05-14 12:24:03 +00:00
|
|
|
#include <kvm.h>
|
2015-11-27 18:58:26 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
2004-05-14 12:24:03 +00:00
|
|
|
#include <stdlib.h>
|
2008-11-06 16:20:27 +00:00
|
|
|
#include <unistd.h>
|
2004-05-14 12:24:03 +00:00
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
#ifdef __arm__
|
|
|
|
#include <machine/vmparam.h>
|
|
|
|
#endif
|
|
|
|
|
2004-05-14 12:24:03 +00:00
|
|
|
#include "kvm_private.h"
|
2015-11-27 18:58:26 +00:00
|
|
|
#include "kvm_arm.h"
|
2004-05-14 12:24:03 +00:00
|
|
|
|
2005-10-03 14:21:14 +00:00
|
|
|
struct vmstate {
|
2015-11-27 18:58:26 +00:00
|
|
|
arm_pd_entry_t *l1pt;
|
|
|
|
size_t phnum;
|
|
|
|
GElf_Phdr *phdr;
|
2005-10-03 14:21:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a physical memory address to a file-offset in the crash-dump.
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
_kvm_pa2off(kvm_t *kd, uint64_t pa, off_t *ofs, size_t pgsz)
|
|
|
|
{
|
2015-11-27 18:58:26 +00:00
|
|
|
struct vmstate *vm = kd->vmst;
|
|
|
|
GElf_Phdr *p;
|
|
|
|
size_t n;
|
2005-10-03 14:21:14 +00:00
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
p = vm->phdr;
|
|
|
|
n = vm->phnum;
|
2005-10-03 14:21:14 +00:00
|
|
|
while (n && (pa < p->p_paddr || pa >= p->p_paddr + p->p_memsz))
|
|
|
|
p++, n--;
|
|
|
|
if (n == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
*ofs = (pa - p->p_paddr) + p->p_offset;
|
|
|
|
if (pgsz == 0)
|
|
|
|
return (p->p_memsz - (pa - p->p_paddr));
|
|
|
|
return (pgsz - ((size_t)pa & (pgsz - 1)));
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static void
|
|
|
|
_arm_freevtop(kvm_t *kd)
|
2004-05-14 12:24:03 +00:00
|
|
|
{
|
2015-11-27 18:58:26 +00:00
|
|
|
struct vmstate *vm = kd->vmst;
|
|
|
|
|
|
|
|
free(vm->phdr);
|
|
|
|
free(vm);
|
|
|
|
kd->vmst = NULL;
|
2004-05-14 12:24:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static int
|
|
|
|
_arm_probe(kvm_t *kd)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (_kvm_probe_elf_kernel(kd, ELFCLASS32, EM_ARM) &&
|
|
|
|
!_kvm_is_minidump(kd));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_arm_initvtop(kvm_t *kd)
|
2004-05-14 12:24:03 +00:00
|
|
|
{
|
2008-11-06 16:20:27 +00:00
|
|
|
struct vmstate *vm;
|
2015-11-27 18:58:26 +00:00
|
|
|
struct kvm_nlist nl[2];
|
|
|
|
kvaddr_t kernbase;
|
|
|
|
arm_physaddr_t physaddr, pa;
|
|
|
|
arm_pd_entry_t *l1pt;
|
|
|
|
size_t i;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
if (kd->rawdump) {
|
|
|
|
_kvm_err(kd, kd->program, "raw dumps not supported on arm");
|
|
|
|
return (-1);
|
2008-11-06 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vm = _kvm_malloc(kd, sizeof(*vm));
|
2016-04-22 18:05:34 +00:00
|
|
|
if (vm == NULL) {
|
2005-10-03 14:21:14 +00:00
|
|
|
_kvm_err(kd, kd->program, "cannot allocate vm");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
kd->vmst = vm;
|
|
|
|
vm->l1pt = NULL;
|
2015-11-27 18:58:26 +00:00
|
|
|
|
|
|
|
if (_kvm_read_core_phdrs(kd, &vm->phnum, &vm->phdr) == -1)
|
2005-10-03 14:21:14 +00:00
|
|
|
return (-1);
|
|
|
|
|
2014-10-19 20:23:31 +00:00
|
|
|
found = 0;
|
2015-11-27 18:58:26 +00:00
|
|
|
for (i = 0; i < vm->phnum; i++) {
|
|
|
|
if (vm->phdr[i].p_type == PT_DUMP_DELTA) {
|
|
|
|
kernbase = vm->phdr[i].p_vaddr;
|
|
|
|
physaddr = vm->phdr[i].p_paddr;
|
2014-10-19 20:23:31 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nl[1].n_name = NULL;
|
|
|
|
if (!found) {
|
|
|
|
nl[0].n_name = "kernbase";
|
2015-11-27 18:58:26 +00:00
|
|
|
if (kvm_nlist2(kd, nl) != 0) {
|
|
|
|
#ifdef __arm__
|
2014-10-19 20:23:31 +00:00
|
|
|
kernbase = KERNBASE;
|
2015-11-27 18:58:26 +00:00
|
|
|
#else
|
|
|
|
_kvm_err(kd, kd->program, "cannot resolve kernbase");
|
|
|
|
return (-1);
|
|
|
|
#endif
|
|
|
|
} else
|
2014-10-19 20:23:31 +00:00
|
|
|
kernbase = nl[0].n_value;
|
|
|
|
|
|
|
|
nl[0].n_name = "physaddr";
|
2015-11-27 18:58:26 +00:00
|
|
|
if (kvm_nlist2(kd, nl) != 0) {
|
2014-10-19 20:23:31 +00:00
|
|
|
_kvm_err(kd, kd->program, "couldn't get phys addr");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
physaddr = nl[0].n_value;
|
2005-10-03 14:21:14 +00:00
|
|
|
}
|
2011-01-23 11:08:28 +00:00
|
|
|
nl[0].n_name = "kernel_l1pa";
|
2015-11-27 18:58:26 +00:00
|
|
|
if (kvm_nlist2(kd, nl) != 0) {
|
2005-10-03 14:21:14 +00:00
|
|
|
_kvm_err(kd, kd->program, "bad namelist");
|
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
if (kvm_read2(kd, (nl[0].n_value - kernbase + physaddr), &pa,
|
2005-10-03 14:21:14 +00:00
|
|
|
sizeof(pa)) != sizeof(pa)) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot read kernel_l1pa");
|
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
l1pt = _kvm_malloc(kd, ARM_L1_TABLE_SIZE);
|
2016-04-22 18:05:34 +00:00
|
|
|
if (l1pt == NULL) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot allocate l1pt");
|
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
if (kvm_read2(kd, pa, l1pt, ARM_L1_TABLE_SIZE) != ARM_L1_TABLE_SIZE) {
|
2005-10-03 14:21:14 +00:00
|
|
|
_kvm_err(kd, kd->program, "cannot read l1pt");
|
|
|
|
free(l1pt);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
vm->l1pt = l1pt;
|
2004-05-14 12:24:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-03 14:21:14 +00:00
|
|
|
/* from arm/pmap.c */
|
2015-11-27 18:58:26 +00:00
|
|
|
#define ARM_L1_IDX(va) ((va) >> ARM_L1_S_SHIFT)
|
|
|
|
|
|
|
|
#define l1pte_section_p(pde) (((pde) & ARM_L1_TYPE_MASK) == ARM_L1_TYPE_S)
|
2005-10-03 14:21:14 +00:00
|
|
|
#define l1pte_valid(pde) ((pde) != 0)
|
|
|
|
#define l2pte_valid(pte) ((pte) != 0)
|
2016-02-18 09:30:04 +00:00
|
|
|
#define l2pte_index(v) (((v) & ARM_L1_S_OFFSET) >> ARM_L2_S_SHIFT)
|
2005-10-03 14:21:14 +00:00
|
|
|
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static int
|
|
|
|
_arm_kvatop(kvm_t *kd, kvaddr_t va, off_t *pa)
|
2004-05-14 12:24:03 +00:00
|
|
|
{
|
2005-10-03 14:21:14 +00:00
|
|
|
struct vmstate *vm = kd->vmst;
|
2015-11-27 18:58:26 +00:00
|
|
|
arm_pd_entry_t pd;
|
|
|
|
arm_pt_entry_t pte;
|
|
|
|
arm_physaddr_t pte_pa;
|
|
|
|
off_t pte_off;
|
2008-11-06 16:20:27 +00:00
|
|
|
|
2005-10-03 14:21:14 +00:00
|
|
|
if (vm->l1pt == NULL)
|
2015-11-27 18:58:26 +00:00
|
|
|
return (_kvm_pa2off(kd, va, pa, ARM_PAGE_SIZE));
|
|
|
|
pd = _kvm32toh(kd, vm->l1pt[ARM_L1_IDX(va)]);
|
2005-10-03 14:21:14 +00:00
|
|
|
if (!l1pte_valid(pd))
|
|
|
|
goto invalid;
|
|
|
|
if (l1pte_section_p(pd)) {
|
|
|
|
/* 1MB section mapping. */
|
2015-11-27 18:58:26 +00:00
|
|
|
*pa = (pd & ARM_L1_S_ADDR_MASK) + (va & ARM_L1_S_OFFSET);
|
|
|
|
return (_kvm_pa2off(kd, *pa, pa, ARM_L1_S_SIZE));
|
2005-10-03 14:21:14 +00:00
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
pte_pa = (pd & ARM_L1_C_ADDR_MASK) + l2pte_index(va) * sizeof(pte);
|
|
|
|
_kvm_pa2off(kd, pte_pa, &pte_off, ARM_L1_S_SIZE);
|
|
|
|
if (pread(kd->pmfd, &pte, sizeof(pte), pte_off) != sizeof(pte)) {
|
|
|
|
_kvm_syserr(kd, kd->program, "_arm_kvatop: pread");
|
2005-10-03 14:21:14 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
pte = _kvm32toh(kd, pte);
|
2005-10-03 14:21:14 +00:00
|
|
|
if (!l2pte_valid(pte)) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
if ((pte & ARM_L2_TYPE_MASK) == ARM_L2_TYPE_L) {
|
|
|
|
*pa = (pte & ARM_L2_L_FRAME) | (va & ARM_L2_L_OFFSET);
|
|
|
|
return (_kvm_pa2off(kd, *pa, pa, ARM_L2_L_SIZE));
|
2005-10-03 14:21:14 +00:00
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
*pa = (pte & ARM_L2_S_FRAME) | (va & ARM_L2_S_OFFSET);
|
|
|
|
return (_kvm_pa2off(kd, *pa, pa, ARM_PAGE_SIZE));
|
2005-10-03 14:21:14 +00:00
|
|
|
invalid:
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, 0, "Invalid address (%jx)", (uintmax_t)va);
|
2004-05-14 12:24:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Machine-dependent initialization for ALL open kvm descriptors,
|
|
|
|
* not just those for a kernel crash dump. Some architectures
|
|
|
|
* have to deal with these NOT being constants! (i.e. m68k)
|
|
|
|
*/
|
2011-01-23 11:08:28 +00:00
|
|
|
#ifdef FBSD_NOT_YET
|
2004-05-14 12:24:03 +00:00
|
|
|
int
|
2011-01-23 11:08:28 +00:00
|
|
|
_kvm_mdopen(kvm_t *kd)
|
2004-05-14 12:24:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
kd->usrstack = USRSTACK;
|
|
|
|
kd->min_uva = VM_MIN_ADDRESS;
|
|
|
|
kd->max_uva = VM_MAXUSER_ADDRESS;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2011-01-23 11:08:28 +00:00
|
|
|
#endif
|
2015-11-27 18:58:26 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
_arm_native(kvm_t *kd)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef __arm__
|
|
|
|
#if _BYTE_ORDER == _LITTLE_ENDIAN
|
|
|
|
return (kd->nlehdr.e_ident[EI_DATA] == ELFDATA2LSB);
|
|
|
|
#else
|
|
|
|
return (kd->nlehdr.e_ident[EI_DATA] == ELFDATA2MSB);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
struct kvm_arch kvm_arm = {
|
|
|
|
.ka_probe = _arm_probe,
|
|
|
|
.ka_initvtop = _arm_initvtop,
|
|
|
|
.ka_freevtop = _arm_freevtop,
|
|
|
|
.ka_kvatop = _arm_kvatop,
|
|
|
|
.ka_native = _arm_native,
|
|
|
|
};
|
|
|
|
|
|
|
|
KVM_ARCH(kvm_arm);
|