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