Home | History | Annotate | Line # | Download | only in libkvm
kvm_m68k.c revision 1.15.34.1
      1  1.15.34.1      yamt /*	$NetBSD: kvm_m68k.c,v 1.15.34.1 2008/05/18 12:30:38 yamt Exp $	*/
      2        1.7   thorpej 
      3        1.1       cgd /*-
      4       1.10       gwr  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5       1.10       gwr  * All rights reserved.
      6        1.1       cgd  *
      7       1.10       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8       1.11   thorpej  * by Gordon W. Ross and Jason R. Thorpe.
      9        1.1       cgd  *
     10        1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11        1.1       cgd  * modification, are permitted provided that the following conditions
     12        1.1       cgd  * are met:
     13        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18        1.1       cgd  *
     19       1.10       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.10       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.10       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.10       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.10       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.10       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.10       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.10       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.10       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.10       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.10       gwr  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1       cgd  */
     31        1.1       cgd 
     32        1.1       cgd /*
     33       1.10       gwr  * Run-time kvm dispatcher for m68k machines.
     34       1.10       gwr  * The actual MD code is in the files:
     35       1.10       gwr  * kvm_m68k_cmn.c kvm_sun3.c ...
     36       1.13       gwr  *
     37       1.13       gwr  * Note: This file has to build on ALL m68k machines,
     38       1.14     veego  * so do NOT include any <machine/[*].h> files here.
     39        1.1       cgd  */
     40        1.1       cgd 
     41        1.1       cgd #include <sys/param.h>
     42       1.12       gwr #include <sys/exec.h>
     43       1.12       gwr #include <sys/kcore.h>
     44       1.10       gwr #include <sys/sysctl.h>
     45       1.10       gwr 
     46       1.10       gwr #include <stdio.h>
     47       1.10       gwr #include <string.h>
     48       1.10       gwr #include <stdlib.h>
     49        1.6       leo 
     50        1.1       cgd #include <unistd.h>
     51        1.6       leo #include <limits.h>
     52        1.1       cgd #include <nlist.h>
     53        1.1       cgd #include <kvm.h>
     54        1.1       cgd #include <db.h>
     55        1.1       cgd 
     56       1.13       gwr #include <m68k/kcore.h>
     57       1.11   thorpej 
     58        1.1       cgd #include "kvm_private.h"
     59       1.10       gwr #include "kvm_m68k.h"
     60        1.1       cgd 
     61       1.10       gwr struct name_ops {
     62       1.11   thorpej 	const char *name;
     63       1.10       gwr 	struct kvm_ops *ops;
     64       1.10       gwr };
     65       1.10       gwr 
     66       1.11   thorpej /*
     67       1.11   thorpej  * Match specific kcore types first, falling into a default.
     68       1.11   thorpej  */
     69       1.10       gwr static struct name_ops optbl[] = {
     70       1.15  fredette 	{ "sun2",	&_kvm_ops_sun2 },
     71       1.11   thorpej 	{ "sun3",	&_kvm_ops_sun3 },
     72       1.11   thorpej 	{ "sun3x",	&_kvm_ops_sun3x },
     73       1.11   thorpej 	{ NULL,		&_kvm_ops_cmn },
     74       1.10       gwr };
     75        1.1       cgd 
     76       1.10       gwr /*
     77       1.10       gwr  * Prepare for translation of kernel virtual addresses into offsets
     78       1.10       gwr  * into crash dump files.  This is where we do the dispatch work.
     79       1.10       gwr  */
     80        1.1       cgd int
     81        1.1       cgd _kvm_initvtop(kd)
     82        1.1       cgd 	kvm_t *kd;
     83        1.1       cgd {
     84       1.11   thorpej 	cpu_kcore_hdr_t *h;
     85       1.10       gwr 	struct name_ops *nop;
     86       1.11   thorpej 	struct vmstate *vm;
     87       1.10       gwr 
     88       1.11   thorpej 	vm = (struct vmstate *)_kvm_malloc(kd, sizeof (*vm));
     89       1.11   thorpej 	if (vm == 0)
     90       1.10       gwr 		return (-1);
     91       1.10       gwr 
     92       1.11   thorpej 	kd->vmst = vm;
     93       1.11   thorpej 
     94       1.11   thorpej 	/*
     95       1.11   thorpej 	 * Use the machine name in the kcore header to determine
     96       1.11   thorpej 	 * our ops vector.  When we reach an ops vector with
     97       1.11   thorpej 	 * no name, we've found a default.
     98       1.11   thorpej 	 */
     99       1.11   thorpej 	h = kd->cpu_data;
    100       1.11   thorpej 	h->name[sizeof(h->name) - 1] = '\0';	/* sanity */
    101       1.11   thorpej 	for (nop = optbl; nop->name != NULL; nop++)
    102       1.11   thorpej 		if (strcmp(nop->name, h->name) == 0)
    103       1.11   thorpej 			break;
    104       1.11   thorpej 
    105       1.11   thorpej 	vm->ops = nop->ops;
    106       1.11   thorpej 
    107       1.11   thorpej 	/*
    108       1.11   thorpej 	 * Compute pgshift and pgofset.
    109       1.11   thorpej 	 */
    110       1.11   thorpej 	for (vm->pgshift = 0; (1 << vm->pgshift) < h->page_size; vm->pgshift++)
    111       1.11   thorpej 		/* nothing */ ;
    112       1.11   thorpej 	if ((1 << vm->pgshift) != h->page_size)
    113       1.11   thorpej 		goto bad;
    114       1.11   thorpej 	vm->pgofset = h->page_size - 1;
    115       1.11   thorpej 
    116       1.11   thorpej 	if ((vm->ops->initvtop)(kd) < 0)
    117       1.11   thorpej 		goto bad;
    118       1.11   thorpej 
    119       1.11   thorpej 	return (0);
    120       1.11   thorpej 
    121       1.11   thorpej  bad:
    122       1.11   thorpej 	kd->vmst = NULL;
    123       1.11   thorpej 	free(vm);
    124       1.10       gwr 	return (-1);
    125        1.1       cgd }
    126        1.1       cgd 
    127       1.10       gwr void
    128       1.10       gwr _kvm_freevtop(kd)
    129        1.1       cgd 	kvm_t *kd;
    130        1.1       cgd {
    131       1.11   thorpej 	(kd->vmst->ops->freevtop)(kd);
    132       1.11   thorpej 	free(kd->vmst);
    133        1.1       cgd }
    134        1.1       cgd 
    135        1.1       cgd int
    136       1.10       gwr _kvm_kvatop(kd, va, pap)
    137        1.1       cgd 	kvm_t *kd;
    138        1.1       cgd 	u_long va;
    139       1.10       gwr 	u_long *pap;
    140        1.1       cgd {
    141       1.11   thorpej 	return ((kd->vmst->ops->kvatop)(kd, va, pap));
    142        1.8       gwr }
    143        1.8       gwr 
    144        1.8       gwr off_t
    145        1.8       gwr _kvm_pa2off(kd, pa)
    146        1.8       gwr 	kvm_t	*kd;
    147        1.8       gwr 	u_long	pa;
    148        1.8       gwr {
    149       1.11   thorpej 	return ((kd->vmst->ops->pa2off)(kd, pa));
    150       1.12       gwr }
    151       1.12       gwr 
    152       1.12       gwr /*
    153       1.12       gwr  * Machine-dependent initialization for ALL open kvm descriptors,
    154       1.12       gwr  * not just those for a kernel crash dump.  Some architectures
    155       1.12       gwr  * have to deal with these NOT being constants!  (i.e. m68k)
    156       1.12       gwr  */
    157       1.12       gwr int
    158       1.12       gwr _kvm_mdopen(kd)
    159       1.12       gwr 	kvm_t	*kd;
    160       1.12       gwr {
    161       1.12       gwr 	u_long max_uva;
    162       1.12       gwr 	extern struct ps_strings *__ps_strings;
    163       1.12       gwr 
    164       1.12       gwr #if 0	/* XXX - These vary across m68k machines... */
    165       1.12       gwr 	kd->usrstack = USRSTACK;
    166       1.12       gwr 	kd->min_uva = VM_MIN_ADDRESS;
    167       1.12       gwr 	kd->max_uva = VM_MAXUSER_ADDRESS;
    168       1.12       gwr #endif
    169       1.12       gwr 	/* This is somewhat hack-ish, but it works. */
    170       1.12       gwr 	max_uva = (u_long) (__ps_strings + 1);
    171       1.12       gwr 	kd->usrstack = max_uva;
    172       1.12       gwr 	kd->max_uva  = max_uva;
    173       1.12       gwr 	kd->min_uva  = 0;
    174       1.12       gwr 
    175       1.12       gwr 	return (0);
    176        1.1       cgd }
    177