2008-11-06 16:20:27 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008 Semihalf, Grzegorz Bernacki
|
|
|
|
* Copyright (c) 2006 Peter Wemm
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* From: FreeBSD: src/lib/libkvm/kvm_minidump_i386.c,v 1.2 2006/06/05 08:51:14
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARM machine dependent routines for kvm and minidumps.
|
|
|
|
*/
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
#include <sys/endian.h>
|
2008-11-06 16:20:27 +00:00
|
|
|
#include <sys/param.h>
|
2015-11-27 18:58:26 +00:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
2008-11-06 16:20:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-02-12 02:08:42 +00:00
|
|
|
#include "../../sys/arm/include/minidump.h"
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
#include "kvm_private.h"
|
2015-11-27 18:58:26 +00:00
|
|
|
#include "kvm_arm.h"
|
2008-11-06 16:20:27 +00:00
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
#define arm_round_page(x) roundup2((kvaddr_t)(x), ARM_PAGE_SIZE)
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
struct vmstate {
|
|
|
|
struct minidumphdr hdr;
|
|
|
|
void *ptemap;
|
2015-11-27 18:58:26 +00:00
|
|
|
unsigned char ei_data;
|
2008-11-06 16:20:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2015-11-27 18:58:26 +00:00
|
|
|
_arm_minidump_probe(kvm_t *kd)
|
2008-11-06 16:20:27 +00:00
|
|
|
{
|
2015-11-27 18:58:26 +00:00
|
|
|
|
|
|
|
return (_kvm_probe_elf_kernel(kd, ELFCLASS32, EM_ARM) &&
|
|
|
|
_kvm_is_minidump(kd));
|
2008-11-06 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static void
|
|
|
|
_arm_minidump_freevtop(kvm_t *kd)
|
2008-11-06 16:20:27 +00:00
|
|
|
{
|
|
|
|
struct vmstate *vm = kd->vmst;
|
|
|
|
|
2016-07-18 01:55:25 +00:00
|
|
|
free(vm->ptemap);
|
2008-11-06 16:20:27 +00:00
|
|
|
free(vm);
|
|
|
|
kd->vmst = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static int
|
|
|
|
_arm_minidump_initvtop(kvm_t *kd)
|
2008-11-06 16:20:27 +00:00
|
|
|
{
|
|
|
|
struct vmstate *vmst;
|
2016-07-18 01:55:25 +00:00
|
|
|
off_t off, sparse_off;
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
vmst = _kvm_malloc(kd, sizeof(*vmst));
|
2016-04-22 18:05:34 +00:00
|
|
|
if (vmst == NULL) {
|
2008-11-06 16:20:27 +00:00
|
|
|
_kvm_err(kd, kd->program, "cannot allocate vm");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
kd->vmst = vmst;
|
|
|
|
|
|
|
|
if (pread(kd->pmfd, &vmst->hdr,
|
|
|
|
sizeof(vmst->hdr), 0) != sizeof(vmst->hdr)) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot read dump header");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(MINIDUMP_MAGIC, vmst->hdr.magic,
|
|
|
|
sizeof(vmst->hdr.magic)) != 0) {
|
|
|
|
_kvm_err(kd, kd->program, "not a minidump for this platform");
|
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
vmst->hdr.version = _kvm32toh(kd, vmst->hdr.version);
|
2008-11-06 16:20:27 +00:00
|
|
|
if (vmst->hdr.version != MINIDUMP_VERSION) {
|
|
|
|
_kvm_err(kd, kd->program, "wrong minidump version. "
|
|
|
|
"Expected %d got %d", MINIDUMP_VERSION, vmst->hdr.version);
|
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
vmst->hdr.msgbufsize = _kvm32toh(kd, vmst->hdr.msgbufsize);
|
|
|
|
vmst->hdr.bitmapsize = _kvm32toh(kd, vmst->hdr.bitmapsize);
|
|
|
|
vmst->hdr.ptesize = _kvm32toh(kd, vmst->hdr.ptesize);
|
|
|
|
vmst->hdr.kernbase = _kvm32toh(kd, vmst->hdr.kernbase);
|
2016-01-15 18:53:06 +00:00
|
|
|
vmst->hdr.arch = _kvm32toh(kd, vmst->hdr.arch);
|
|
|
|
vmst->hdr.mmuformat = _kvm32toh(kd, vmst->hdr.mmuformat);
|
|
|
|
if (vmst->hdr.mmuformat == MINIDUMP_MMU_FORMAT_UNKNOWN) {
|
|
|
|
/* This is a safe default as 1K pages are not used. */
|
|
|
|
vmst->hdr.mmuformat = MINIDUMP_MMU_FORMAT_V6;
|
|
|
|
}
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
/* Skip header and msgbuf */
|
2015-11-27 18:58:26 +00:00
|
|
|
off = ARM_PAGE_SIZE + arm_round_page(vmst->hdr.msgbufsize);
|
2008-11-06 16:20:27 +00:00
|
|
|
|
2016-07-18 01:55:25 +00:00
|
|
|
sparse_off = off + arm_round_page(vmst->hdr.bitmapsize) +
|
|
|
|
arm_round_page(vmst->hdr.ptesize);
|
|
|
|
if (_kvm_pt_init(kd, vmst->hdr.bitmapsize, off, sparse_off,
|
|
|
|
ARM_PAGE_SIZE, sizeof(uint32_t)) == -1) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot load core bitmap");
|
2008-11-06 16:20:27 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
off += arm_round_page(vmst->hdr.bitmapsize);
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
vmst->ptemap = _kvm_malloc(kd, vmst->hdr.ptesize);
|
|
|
|
if (vmst->ptemap == NULL) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot allocate %d bytes for "
|
|
|
|
"ptemap", vmst->hdr.ptesize);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
|
2011-01-23 11:08:28 +00:00
|
|
|
(ssize_t)vmst->hdr.ptesize) {
|
2008-11-06 16:20:27 +00:00
|
|
|
_kvm_err(kd, kd->program, "cannot read %d bytes for ptemap",
|
|
|
|
vmst->hdr.ptesize);
|
|
|
|
return (-1);
|
|
|
|
}
|
2016-07-18 01:55:25 +00:00
|
|
|
off += arm_round_page(vmst->hdr.ptesize);
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:58:26 +00:00
|
|
|
static int
|
|
|
|
_arm_minidump_kvatop(kvm_t *kd, kvaddr_t va, off_t *pa)
|
2008-11-06 16:20:27 +00:00
|
|
|
{
|
|
|
|
struct vmstate *vm;
|
2015-11-27 18:58:26 +00:00
|
|
|
arm_pt_entry_t pte;
|
|
|
|
arm_physaddr_t offset, a;
|
|
|
|
kvaddr_t pteindex;
|
2008-11-06 16:20:27 +00:00
|
|
|
off_t ofs;
|
2015-11-27 18:58:26 +00:00
|
|
|
arm_pt_entry_t *ptemap;
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
if (ISALIVE(kd)) {
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, 0, "_arm_minidump_kvatop called in live kernel!");
|
2008-11-06 16:20:27 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
vm = kd->vmst;
|
|
|
|
ptemap = vm->ptemap;
|
|
|
|
|
|
|
|
if (va >= vm->hdr.kernbase) {
|
2015-11-27 18:58:26 +00:00
|
|
|
pteindex = (va - vm->hdr.kernbase) >> ARM_PAGE_SHIFT;
|
2016-07-18 01:03:39 +00:00
|
|
|
if (pteindex >= vm->hdr.ptesize / sizeof(*ptemap))
|
|
|
|
goto invalid;
|
2015-11-27 18:58:26 +00:00
|
|
|
pte = _kvm32toh(kd, ptemap[pteindex]);
|
2016-01-15 18:53:06 +00:00
|
|
|
if ((pte & ARM_L2_TYPE_MASK) == ARM_L2_TYPE_INV) {
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"_arm_minidump_kvatop: pte not valid");
|
2008-11-06 16:20:27 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
if ((pte & ARM_L2_TYPE_MASK) == ARM_L2_TYPE_L) {
|
2016-01-15 18:53:06 +00:00
|
|
|
/* 64K page -> convert to be like 4K page */
|
|
|
|
offset = va & ARM_L2_S_OFFSET;
|
|
|
|
a = (pte & ARM_L2_L_FRAME) +
|
|
|
|
(va & ARM_L2_L_OFFSET & ARM_L2_S_FRAME);
|
|
|
|
} else {
|
|
|
|
if (kd->vmst->hdr.mmuformat == MINIDUMP_MMU_FORMAT_V4 &&
|
|
|
|
(pte & ARM_L2_TYPE_MASK) == ARM_L2_TYPE_T) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"_arm_minidump_kvatop: pte not supported");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
/* 4K page */
|
2015-11-27 18:58:26 +00:00
|
|
|
offset = va & ARM_L2_S_OFFSET;
|
|
|
|
a = pte & ARM_L2_S_FRAME;
|
2016-01-15 18:53:06 +00:00
|
|
|
}
|
2008-11-06 16:20:27 +00:00
|
|
|
|
2016-07-18 01:55:25 +00:00
|
|
|
ofs = _kvm_pt_find(kd, a);
|
2008-11-06 16:20:27 +00:00
|
|
|
if (ofs == -1) {
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, kd->program, "_arm_minidump_kvatop: "
|
|
|
|
"physical address 0x%jx not in minidump",
|
|
|
|
(uintmax_t)a);
|
2008-11-06 16:20:27 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pa = ofs + offset;
|
2015-11-27 18:58:26 +00:00
|
|
|
return (ARM_PAGE_SIZE - offset);
|
2008-11-06 16:20:27 +00:00
|
|
|
} else
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, kd->program, "_arm_minidump_kvatop: virtual "
|
|
|
|
"address 0x%jx not minidumped", (uintmax_t)va);
|
2008-11-06 16:20:27 +00:00
|
|
|
|
|
|
|
invalid:
|
2015-11-27 18:58:26 +00:00
|
|
|
_kvm_err(kd, 0, "invalid address (0x%jx)", (uintmax_t)va);
|
2008-11-06 16:20:27 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2015-11-27 18:58:26 +00:00
|
|
|
|
2017-03-22 02:42:00 +00:00
|
|
|
static struct kvm_arch kvm_arm_minidump = {
|
2015-11-27 18:58:26 +00:00
|
|
|
.ka_probe = _arm_minidump_probe,
|
|
|
|
.ka_initvtop = _arm_minidump_initvtop,
|
|
|
|
.ka_freevtop = _arm_minidump_freevtop,
|
|
|
|
.ka_kvatop = _arm_minidump_kvatop,
|
|
|
|
.ka_native = _arm_native,
|
|
|
|
};
|
|
|
|
|
|
|
|
KVM_ARCH(kvm_arm_minidump);
|