Home | History | Annotate | Line # | Download | only in libkvm
kvm_powerpc64.c revision 1.4.12.1
      1  1.4.12.1   tls /*	$NetBSD: kvm_powerpc64.c,v 1.4.12.1 2014/08/20 00:02:17 tls Exp $	*/
      2       1.1  ross 
      3       1.1  ross /*
      4       1.1  ross  * Copyright (c) 2005 Wasabi Systems, Inc.
      5       1.1  ross  * All rights reserved.
      6       1.1  ross  *
      7       1.1  ross  * Written by Allen Briggs for Wasabi Systems, Inc.
      8       1.1  ross  *
      9       1.1  ross  * Redistribution and use in source and binary forms, with or without
     10       1.1  ross  * modification, are permitted provided that the following conditions
     11       1.1  ross  * are met:
     12       1.1  ross  * 1. Redistributions of source code must retain the above copyright
     13       1.1  ross  *    notice, this list of conditions and the following disclaimer.
     14       1.1  ross  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  ross  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  ross  *    documentation and/or other materials provided with the distribution.
     17       1.1  ross  * 3. All advertising materials mentioning features or use of this software
     18       1.1  ross  *    must display the following acknowledgement:
     19       1.1  ross  *      This product includes software developed for the NetBSD Project by
     20       1.1  ross  *      Wasabi Systems, Inc.
     21       1.1  ross  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1  ross  *    or promote products derived from this software without specific prior
     23       1.1  ross  *    written permission.
     24       1.1  ross  *
     25       1.1  ross  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1  ross  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1  ross  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1  ross  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1  ross  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1  ross  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1  ross  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1  ross  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1  ross  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1  ross  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1  ross  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1  ross  */
     37       1.1  ross /*-
     38       1.1  ross  * Copyright (C) 1996 Wolfgang Solfrank.
     39       1.1  ross  * Copyright (C) 1996 TooLs GmbH.
     40       1.1  ross  * All rights reserved.
     41       1.1  ross  *
     42       1.1  ross  * Redistribution and use in source and binary forms, with or without
     43       1.1  ross  * modification, are permitted provided that the following conditions
     44       1.1  ross  * are met:
     45       1.1  ross  * 1. Redistributions of source code must retain the above copyright
     46       1.1  ross  *    notice, this list of conditions and the following disclaimer.
     47       1.1  ross  * 2. Redistributions in binary form must reproduce the above copyright
     48       1.1  ross  *    notice, this list of conditions and the following disclaimer in the
     49       1.1  ross  *    documentation and/or other materials provided with the distribution.
     50       1.1  ross  * 3. All advertising materials mentioning features or use of this software
     51       1.1  ross  *    must display the following acknowledgement:
     52       1.1  ross  *	This product includes software developed by TooLs GmbH.
     53       1.1  ross  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     54       1.1  ross  *    derived from this software without specific prior written permission.
     55       1.1  ross  *
     56       1.1  ross  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     57       1.1  ross  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     58       1.1  ross  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59       1.1  ross  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     60       1.1  ross  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     61       1.1  ross  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     62       1.1  ross  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     63       1.1  ross  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     64       1.1  ross  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     65       1.1  ross  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     66       1.1  ross  */
     67       1.1  ross 
     68       1.1  ross /*
     69       1.1  ross  * PowerPC machine dependent routines for kvm.
     70       1.1  ross  */
     71       1.1  ross 
     72       1.1  ross #include <sys/param.h>
     73       1.1  ross #include <sys/exec.h>
     74       1.4   jym #include <sys/types.h>
     75       1.1  ross 
     76       1.1  ross #include <uvm/uvm_extern.h>
     77       1.1  ross 
     78       1.1  ross #include <db.h>
     79       1.1  ross #include <limits.h>
     80       1.1  ross #include <kvm.h>
     81       1.1  ross #include <stdlib.h>
     82       1.1  ross #include <unistd.h>
     83       1.1  ross 
     84       1.1  ross #include "kvm_private.h"
     85       1.1  ross 
     86       1.1  ross #include <sys/kcore.h>
     87       1.1  ross #include <machine/kcore.h>
     88       1.1  ross 
     89       1.1  ross #include <powerpc/spr.h>
     90       1.1  ross #include <powerpc/oea/bat.h>
     91       1.1  ross #include <powerpc/oea/pte.h>
     92       1.1  ross 
     93  1.4.12.1   tls __RCSID("$NetBSD: kvm_powerpc64.c,v 1.4.12.1 2014/08/20 00:02:17 tls Exp $");
     94  1.4.12.1   tls 
     95       1.1  ross void
     96       1.3   jym _kvm_freevtop(kvm_t *kd)
     97       1.1  ross {
     98       1.1  ross 	if (kd->vmst != 0)
     99       1.1  ross 		free(kd->vmst);
    100       1.1  ross }
    101       1.1  ross 
    102       1.1  ross /*ARGSUSED*/
    103       1.1  ross int
    104       1.3   jym _kvm_initvtop(kvm_t *kd)
    105       1.1  ross {
    106       1.1  ross 
    107       1.1  ross 	return 0;
    108       1.1  ross }
    109       1.1  ross 
    110       1.1  ross #define SR_VSID_HASH_MASK	0x0007ffff
    111       1.1  ross 
    112       1.1  ross #define HASH_MASK	0x0007ffff
    113       1.1  ross 
    114       1.1  ross /*
    115       1.1  ross  * Translate a KVA to a PA
    116       1.1  ross  */
    117       1.1  ross int
    118       1.4   jym _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
    119       1.1  ross {
    120       1.1  ross 	cpu_kcore_hdr_t	*cpu_kh;
    121       1.1  ross 	uint32_t	pvr;
    122       1.1  ross 
    123       1.1  ross 	if (ISALIVE(kd)) {
    124       1.1  ross 		_kvm_err(kd, 0, "vatop called in live kernel!");
    125       1.1  ross 		return 0;
    126       1.1  ross 	}
    127       1.1  ross 
    128       1.1  ross 	cpu_kh = kd->cpu_data;
    129       1.1  ross 
    130       1.1  ross 	pvr = (cpu_kh->pvr >> 16);
    131       1.1  ross 
    132       1.1  ross 
    133       1.1  ross 	/* No hit -- no translation */
    134       1.1  ross 	*pa = (u_long)~0UL;
    135       1.1  ross 	return 0;
    136       1.1  ross }
    137       1.1  ross 
    138       1.1  ross off_t
    139       1.4   jym _kvm_pa2off(kvm_t *kd, paddr_t pa)
    140       1.1  ross {
    141       1.1  ross 	cpu_kcore_hdr_t	*cpu_kh;
    142       1.1  ross 	phys_ram_seg_t	*ram;
    143       1.1  ross 	off_t		off;
    144       1.1  ross 	void		*e;
    145       1.1  ross 
    146       1.1  ross 	cpu_kh = kd->cpu_data;
    147       1.1  ross 	e = (char *) kd->cpu_data + kd->cpu_dsize;
    148       1.1  ross         ram = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh));
    149       1.1  ross 	off = kd->dump_off;
    150       1.1  ross 	do {
    151       1.1  ross 		if (pa >= ram->start && (pa - ram->start) < ram->size) {
    152       1.1  ross 			return off + (pa - ram->start);
    153       1.1  ross 		}
    154       1.1  ross 		ram++;
    155       1.1  ross 		off += ram->size;
    156       1.1  ross 	} while ((void *) ram < e && ram->size);
    157       1.1  ross 
    158       1.1  ross 	_kvm_err(kd, 0, "pa2off failed for pa 0x%08lx\n", pa);
    159       1.1  ross 	return (off_t) -1;
    160       1.1  ross }
    161       1.1  ross 
    162       1.1  ross /*
    163       1.1  ross  * Machine-dependent initialization for ALL open kvm descriptors,
    164       1.1  ross  * not just those for a kernel crash dump.  Some architectures
    165       1.1  ross  * have to deal with these NOT being constants!  (i.e. m68k)
    166       1.1  ross  */
    167       1.1  ross int
    168       1.3   jym _kvm_mdopen(kvm_t *kd)
    169       1.1  ross {
    170       1.1  ross 	uintptr_t max_uva;
    171       1.1  ross 	extern struct ps_strings *__ps_strings;
    172       1.1  ross 
    173       1.1  ross #if 0   /* XXX - These vary across powerpc machines... */
    174       1.1  ross 	kd->usrstack = USRSTACK;
    175       1.1  ross 	kd->min_uva = VM_MIN_ADDRESS;
    176       1.1  ross 	kd->max_uva = VM_MAXUSER_ADDRESS;
    177       1.1  ross #endif
    178       1.1  ross 	/* This is somewhat hack-ish, but it works. */
    179       1.1  ross 	max_uva = (uintptr_t) (__ps_strings + 1);
    180       1.1  ross 	kd->usrstack = max_uva;
    181       1.1  ross 	kd->max_uva  = max_uva;
    182       1.1  ross 	kd->min_uva  = 0;
    183       1.1  ross 
    184       1.1  ross 	return (0);
    185       1.1  ross }
    186