|
|
1.1 root 1: /*
2: * Virtual memory related conversion macros
3: */
4:
5: /* Core clicks to number of pages of page tables needed to map that much */
6: #define ctopt(x) (((x)+NPTEPG-1)/NPTEPG)
7:
8: /* Virtual page numbers to text|data|stack segment page numbers and back */
9: #define vtotp(p, v) ((int)(v))
10: #define vtodp(p, v) ((int)((v) - (p)->p_tsize))
11: #define vtosp(p, v) ((int)(btop(USRSTACK) - 1 - (v)))
12: #define tptov(p, i) ((unsigned)(i))
13: #define dptov(p, i) ((unsigned)((p)->p_tsize + (i)))
14: #define sptov(p, i) ((unsigned)(btop(USRSTACK) - 1 - (i)))
15:
16: /* Tell whether virtual page numbers are in text|data|stack segment */
17: #define isassv(p, v) ((v) & P1TOP)
18: #define isatsv(p, v) ((v) < (p)->p_tsize)
19: #define isadsv(p, v) ((v) >= (p)->p_tsize && !isassv(p, v))
20:
21: /* Tell whether pte's are text|data|stack */
22: #define isaspte(p, pte) ((pte) > sptopte(p, (p)->p_ssize))
23: #define isatpte(p, pte) ((pte) < dptopte(p, 0))
24: #define isadpte(p, pte) (!isaspte(p, pte) && !isatpte(p, pte))
25:
26: /* Text|data|stack pte's to segment page numbers and back */
27: #define ptetotp(p, pte) ((pte) - (p)->p_p0br)
28: #define ptetodp(p, pte) ((pte) - ((p)->p_p0br + (p)->p_tsize))
29: #define ptetosp(p, pte) \
30: (((p)->p_p0br + (p)->p_szpt*NPTEPG - UPAGES - 1) - (pte))
31:
32: #define tptopte(p, i) ((p)->p_p0br + (i))
33: #define dptopte(p, i) ((p)->p_p0br + (p)->p_tsize + (i))
34: #define sptopte(p, i) \
35: (((p)->p_p0br + (p)->p_szpt*NPTEPG - UPAGES - 1) - (i))
36:
37: /* Bytes to pages without rounding, and back */
38: #define btop(x) (((unsigned)(x)) >> PGSHIFT)
39: #define ptob(x) ((caddr_t)((x) << PGSHIFT))
40:
41: /* Turn virtual addresses into kernel map indices */
42: #define kmxtob(a) (usrpt + (a) * NPTEPG)
43: #define btokmx(b) (((b) - usrpt) / NPTEPG)
44:
45: /* User area address and pcb bases */
46: #define uaddr(p) (&((p)->p_p0br[(p)->p_szpt * NPTEPG - UPAGES]))
47: #define pcbb(p) ((p)->p_addr[0].pg_pfnum)
48:
49: /* Average new into old with aging factor time */
50: #define ave(smooth, cnt, time) \
51: smooth = ((time - 1) * (smooth) + (cnt)) / (time)
52:
53: /*
54: * Page clustering macros.
55: *
56: * dirtycl(pte) is the page cluster dirty?
57: * anycl(pte,fld) does any pte in the cluster has fld set?
58: * zapcl(pte,fld) = val set all fields fld in the cluster to val
59: * distcl(pte) distribute high bits to cluster; note that
60: * distcl copies everything but pg_pfnum,
61: * INCLUDING pg_m!!!
62: *
63: * In all cases, pte must be the low pte in the cluster, even if
64: * the segment grows backwards (e.g. the stack).
65: */
66: #define H(pte) ((struct hpte *)(pte))
67:
68: #if CLSIZE==1
69: #define dirtycl(pte) dirty(pte)
70: #define anycl(pte,fld) ((pte)->fld)
71: #define zapcl(pte,fld) (pte)->fld
72: #define distcl(pte)
73: #endif
74:
75: #if CLSIZE==2
76: #define dirtycl(pte) (dirty(pte) || dirty((pte)+1))
77: #define anycl(pte,fld) ((pte)->fld || (((pte)+1)->fld))
78: #define zapcl(pte,fld) (pte)[1].fld = (pte)[0].fld
79: #endif
80:
81: #if CLSIZE==4
82: #define dirtycl(pte) \
83: (dirty(pte) || dirty((pte)+1) || dirty((pte)+2) || dirty((pte)+3))
84: #define anycl(pte,fld) \
85: ((pte)->fld || (((pte)+1)->fld) || (((pte)+2)->fld) || (((pte)+3)->fld))
86: #define zapcl(pte,fld) \
87: (pte)[3].fld = (pte)[2].fld = (pte)[1].fld = (pte)[0].fld
88: #endif
89:
90: #ifndef distcl
91: #define distcl(pte) zapcl(H(pte),pg_high)
92: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.