[BACK]Return to kvm_alpha.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libkvm

Annotation of src/lib/libkvm/kvm_alpha.c, Revision 1.22

1.22    ! wiz         1: /* $NetBSD: kvm_alpha.c,v 1.21 2003/04/09 22:46:39 nathanw Exp $ */
1.1       cgd         2:
                      3: /*
                      4:  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Author: Chris G. Demetriou
1.15      simonb      8:  *
1.1       cgd         9:  * Permission to use, copy, modify and distribute this software and
                     10:  * its documentation is hereby granted, provided that both the copyright
                     11:  * notice and this permission notice appear in all copies of the
                     12:  * software, derivative works or modified versions, and any portions
                     13:  * thereof, and that both notices appear in supporting documentation.
1.15      simonb     14:  *
                     15:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     16:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1.1       cgd        17:  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.15      simonb     18:  *
1.1       cgd        19:  * Carnegie Mellon requests users of this software to return to
                     20:  *
                     21:  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
                     22:  *  School of Computer Science
                     23:  *  Carnegie Mellon University
                     24:  *  Pittsburgh PA 15213-3890
                     25:  *
                     26:  * any improvements or extensions that they make and grant Carnegie the
                     27:  * rights to redistribute these changes.
                     28:  */
                     29:
1.11      thorpej    30: #define        __KVM_ALPHA_PRIVATE             /* see <machine/pte.h> */
                     31:
1.1       cgd        32: #include <sys/param.h>
                     33: #include <sys/user.h>
                     34: #include <sys/proc.h>
                     35: #include <sys/stat.h>
1.4       cgd        36: #include <sys/kcore.h>
                     37: #include <machine/kcore.h>
1.1       cgd        38: #include <unistd.h>
                     39: #include <nlist.h>
                     40: #include <kvm.h>
                     41:
1.18      mrg        42: #include <uvm/uvm_extern.h>
1.19      matt       43: #include <machine/pmap.h>
1.20      matt       44: #include <machine/vmparam.h>
1.1       cgd        45:
                     46: #include <limits.h>
                     47: #include <db.h>
1.7       mrg        48: #include <stdlib.h>
1.1       cgd        49:
                     50: #include "kvm_private.h"
                     51:
1.21      nathanw    52: /*ARGSUSED*/
1.1       cgd        53: void
                     54: _kvm_freevtop(kd)
                     55:        kvm_t *kd;
                     56: {
1.21      nathanw    57:        return;
1.1       cgd        58: }
                     59:
1.21      nathanw    60: /*ARGSUSED*/
1.1       cgd        61: int
                     62: _kvm_initvtop(kd)
                     63:        kvm_t *kd;
                     64: {
                     65:        return (0);
                     66: }
                     67:
                     68: int
                     69: _kvm_kvatop(kd, va, pa)
                     70:        kvm_t *kd;
                     71:        u_long va;
                     72:        u_long *pa;
                     73: {
1.4       cgd        74:        cpu_kcore_hdr_t *cpu_kh;
1.5       cgd        75:        alpha_pt_entry_t pte;
1.13      thorpej    76:        u_long pteoff, page_off;
                     77:        int rv;
1.2       cgd        78:
1.4       cgd        79:         if (ISALIVE(kd)) {
                     80:                 _kvm_err(kd, 0, "vatop called in live kernel!");
                     81:                 return(0);
                     82:         }
                     83:
                     84:        cpu_kh = kd->cpu_data;
                     85:        page_off = va & (cpu_kh->page_size - 1);
                     86:
                     87:        if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
                     88:                /*
1.5       cgd        89:                 * Direct-mapped address: just convert it.
1.4       cgd        90:                 */
1.5       cgd        91:
1.4       cgd        92:                *pa = ALPHA_K0SEG_TO_PHYS(va);
                     93:                rv = cpu_kh->page_size - page_off;
                     94:        } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
                     95:                /*
1.5       cgd        96:                 * Real kernel virtual address: do the translation.
1.4       cgd        97:                 */
1.5       cgd        98:
                     99:                /* Find and read the L1 PTE. */
                    100:                pteoff = cpu_kh->lev1map_pa +
1.10      thorpej   101:                    l1pte_index(va) * sizeof(alpha_pt_entry_t);
1.12      thorpej   102:                if (pread(kd->pmfd, &pte, sizeof(pte),
                    103:                    _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
1.5       cgd       104:                        _kvm_syserr(kd, 0, "could not read L1 PTE");
                    105:                        goto lose;
                    106:                }
                    107:
                    108:                /* Find and read the L2 PTE. */
                    109:                if ((pte & ALPHA_PTE_VALID) == 0) {
                    110:                        _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
                    111:                        goto lose;
                    112:                }
                    113:                pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
1.10      thorpej   114:                    l2pte_index(va) * sizeof(alpha_pt_entry_t);
1.12      thorpej   115:                if (pread(kd->pmfd, &pte, sizeof(pte),
                    116:                    _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
1.5       cgd       117:                        _kvm_syserr(kd, 0, "could not read L2 PTE");
                    118:                        goto lose;
                    119:                }
                    120:
                    121:                /* Find and read the L3 PTE. */
                    122:                if ((pte & ALPHA_PTE_VALID) == 0) {
                    123:                        _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
                    124:                        goto lose;
                    125:                }
                    126:                pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
1.10      thorpej   127:                    l3pte_index(va) * sizeof(alpha_pt_entry_t);
1.12      thorpej   128:                if (pread(kd->pmfd, &pte, sizeof(pte),
                    129:                    _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
1.5       cgd       130:                        _kvm_syserr(kd, 0, "could not read L3 PTE");
                    131:                        goto lose;
                    132:                }
                    133:
                    134:                /* Fill in the PA. */
                    135:                if ((pte & ALPHA_PTE_VALID) == 0) {
                    136:                        _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
                    137:                        goto lose;
                    138:                }
1.8       ross      139:                *pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
1.5       cgd       140:                rv = cpu_kh->page_size - page_off;
1.4       cgd       141:        } else {
                    142:                /*
1.5       cgd       143:                 * Bogus address (not in KV space): punt.
1.4       cgd       144:                 */
1.5       cgd       145:
                    146:                _kvm_err(kd, 0, "invalid kernel virtual address");
                    147: lose:
1.4       cgd       148:                *pa = -1;
                    149:                rv = 0;
                    150:        }
1.1       cgd       151:
1.4       cgd       152:        return (rv);
1.3       cgd       153: }
                    154:
                    155: /*
1.22    ! wiz       156:  * Translate a physical address to a file-offset in the crash dump.
1.3       cgd       157:  */
1.15      simonb    158: off_t
1.3       cgd       159: _kvm_pa2off(kd, pa)
                    160:        kvm_t *kd;
                    161:        u_long pa;
                    162: {
1.9       cgd       163:        cpu_kcore_hdr_t *cpu_kh;
                    164:        phys_ram_seg_t *ramsegs;
1.4       cgd       165:        off_t off;
1.9       cgd       166:        int i;
1.4       cgd       167:
                    168:        cpu_kh = kd->cpu_data;
1.9       cgd       169:        ramsegs = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
1.4       cgd       170:
                    171:        off = 0;
1.9       cgd       172:        for (i = 0; i < cpu_kh->nmemsegs; i++) {
                    173:                if (pa >= ramsegs[i].start &&
                    174:                    (pa - ramsegs[i].start) < ramsegs[i].size) {
                    175:                        off += (pa - ramsegs[i].start);
                    176:                        break;
                    177:                }
                    178:                off += ramsegs[i].size;
                    179:        }
1.3       cgd       180:
1.9       cgd       181:        return (kd->dump_off + off);
1.6       gwr       182: }
                    183:
                    184: /*
                    185:  * Machine-dependent initialization for ALL open kvm descriptors,
                    186:  * not just those for a kernel crash dump.  Some architectures
                    187:  * have to deal with these NOT being constants!  (i.e. m68k)
                    188:  */
                    189: int
                    190: _kvm_mdopen(kd)
                    191:        kvm_t   *kd;
                    192: {
                    193:
                    194:        kd->usrstack = USRSTACK;
                    195:        kd->min_uva = VM_MIN_ADDRESS;
                    196:        kd->max_uva = VM_MAXUSER_ADDRESS;
                    197:
                    198:        return (0);
1.1       cgd       199: }

CVSweb <webmaster@jp.NetBSD.org>