]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libkvm/kvm_mips.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libkvm / kvm_mips.c
1 /*-
2  * Copyright (C) 2006 Bruce M. Simpson.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Bruce M. Simpson.
16  * 4. The name of Bruce M. Simpson may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY BRUCE M. SIMPSON ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL BRUCE M. SIMPSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /*
32  * MIPS machine dependent routines for kvm.
33  */
34
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37
38 #include <sys/param.h>
39 #include <sys/elf32.h>
40 #include <sys/mman.h>
41
42 #include <vm/vm.h>
43 #include <vm/vm_param.h>
44 #include <vm/pmap.h>
45
46 #include <machine/pmap.h>
47
48 #include <db.h>
49 #include <limits.h>
50 #include <kvm.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <unistd.h>
54
55 #include "kvm_private.h"
56
57 /* minidump must be the first item! */
58 struct vmstate {
59         int minidump;           /* 1 = minidump mode */
60         void *mmapbase;
61         size_t mmapsize;
62 };
63
64 void
65 _kvm_freevtop(kvm_t *kd)
66 {
67         if (kd->vmst != 0) {
68                 if (kd->vmst->minidump)
69                         return (_kvm_minidump_freevtop(kd));
70                 if (kd->vmst->mmapbase != NULL)
71                         munmap(kd->vmst->mmapbase, kd->vmst->mmapsize);
72                 free(kd->vmst);
73                 kd->vmst = NULL;
74         }
75 }
76
77 int
78 _kvm_initvtop(kvm_t *kd)
79 {
80         char minihdr[8];
81
82         if (!kd->rawdump) {
83                 if (pread(kd->pmfd, &minihdr, 8, 0) == 8) {
84                         if (memcmp(&minihdr, "minidump", 8) == 0)
85                                 return (_kvm_minidump_initvtop(kd));
86                 } else {
87                         _kvm_err(kd, kd->program, "cannot read header");
88                         return (-1);
89                 }
90         }
91
92         _kvm_err(kd, 0, "_kvm_initvtop: Unsupported image type");
93         return (-1);
94 }
95
96 int
97 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
98 {
99
100         if (kd->vmst->minidump)
101                 return _kvm_minidump_kvatop(kd, va, pa);
102
103
104         _kvm_err(kd, 0, "_kvm_kvatop: Unsupported image type");
105         return (0);
106 }
107
108 /*
109  * Machine-dependent initialization for ALL open kvm descriptors,
110  * not just those for a kernel crash dump.  Some architectures
111  * have to deal with these NOT being constants!  (i.e. m68k)
112  */
113 #ifdef FBSD_NOT_YET
114 int
115 _kvm_mdopen(kvm_t *kd __unused)
116 {
117
118         return (0);
119 }
120 #endif