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