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