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