1: /*
2: * Copyright (c) 1982, 1986 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: *
6: * @(#)vm_subr.c 7.1 (Berkeley) 6/5/86
7: */
8:
9: #include "../machine/pte.h"
10:
11: #include "param.h"
12: #include "systm.h"
13: #include "dir.h"
14: #include "user.h"
15: #include "vm.h"
16: #include "proc.h"
17: #include "cmap.h"
18: #include "inode.h"
19: #include "buf.h"
20: #include "text.h"
21: #include "fs.h"
22:
23: #ifdef vax
24: #include "../vax/mtpr.h"
25: #endif
26:
27: /*
28: * Make uarea of process p addressible at kernel virtual
29: * address uarea through sysmap locations starting at map.
30: */
31: uaccess(p, map, uarea)
32: register struct proc *p;
33: struct pte *map;
34: register struct user *uarea;
35: {
36: register int i;
37: register struct pte *mp = map;
38:
39: for (i = 0; i < UPAGES; i++) {
40: *(int *)mp = 0;
41: mp->pg_pfnum = p->p_addr[i].pg_pfnum;
42: mp++;
43: }
44: vmaccess(map, (caddr_t)uarea, UPAGES);
45: }
46:
47: /*
48: * Validate the kernel map for size ptes which
49: * start at ppte in the sysmap, and which map
50: * kernel virtual addresses starting with vaddr.
51: */
52: vmaccess(ppte0, vaddr, size0)
53: struct pte *ppte0;
54: register caddr_t vaddr;
55: int size0;
56: {
57: register struct pte *ppte = ppte0;
58: register int size = size0;
59:
60: while (size != 0) {
61: mapin(ppte, btop(vaddr), (unsigned)(*(int *)ppte & PG_PFNUM), 1,
62: (int)(PG_V|PG_KW));
63: ppte++;
64: vaddr += NBPG;
65: --size;
66: }
67: }
68:
69: /*
70: * Convert a pte pointer to
71: * a virtual page number.
72: */
73: ptetov(p, pte)
74: register struct proc *p;
75: struct pte *pte;
76: {
77: register int j;
78:
79: j = pte - p->p_p0br;
80: if (j < p->p_tsize + p->p_dsize)
81: return (j);
82: return ((BTOPUSRSTACK + UPAGES) - p->p_szpt * NPTEPG + j);
83: }
84:
85: #ifdef notdef
86: /*
87: * Convert a virtual page
88: * number to a pte address.
89: */
90: struct pte *
91: vtopte(p, v)
92: register struct proc *p;
93: int v;
94: {
95:
96: if (v < p->p_tsize + p->p_dsize)
97: return (p->p_p0br + v);
98: return (p->p_p0br + (p->p_szpt * NPTEPG + v - (BTOPUSRSTACK + UPAGES)));
99: }
100: #endif notdef
101:
102: /*
103: * Initialize the page tables for paging from an inode,
104: * by scouring up the indirect blocks in order.
105: * Corresponding area of memory should have been vmemfree()d
106: * first or just created.
107: */
108: vinifod(pte, fileno, ip, bfirst, count)
109: register struct fpte *pte;
110: int fileno;
111: register struct inode *ip;
112: daddr_t bfirst;
113: size_t count;
114: {
115: int blast = bfirst + howmany(count, CLSIZE);
116: register int i, j;
117: int bn;
118: register struct fs *fs = ip->i_fs;
119: int nclpbsize = fs->fs_bsize / CLBYTES;
120:
121: while (bfirst < blast) {
122: i = bfirst % nclpbsize;
123: bn = fsbtodb(fs, bmap(ip, bfirst / nclpbsize, B_READ, 0));
124: for ( ; i < nclpbsize; i++) {
125: pte->pg_fod = 1;
126: pte->pg_fileno = fileno;
127: if (u.u_error || bn < 0) {
128: pte->pg_blkno = 0;
129: pte->pg_fileno = PG_FZERO;
130: cnt.v_nzfod += CLSIZE;
131: } else {
132: pte->pg_blkno = bn + btodb(i * CLBYTES);
133: cnt.v_nexfod += CLSIZE;
134: }
135: for (j = 1; j < CLSIZE; j++)
136: pte[j] = pte[0];
137: pte += CLSIZE;
138: bfirst++;
139: if (bfirst == blast)
140: break;
141: }
142: }
143: }
Defined functions
vtopte
defined in line
90; used 15 times