|
|
1.1 ! root 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: * @(#)vmmac.h 7.4 (Berkeley) 11/12/87 ! 7: */ ! 8: ! 9: /* ! 10: * Virtual memory related conversion macros ! 11: */ ! 12: ! 13: /* Core clicks to number of pages of page tables needed to map that much */ ! 14: #define ctopt(x) (((x)+NPTEPG-1)/NPTEPG) ! 15: ! 16: #if defined(vax) || defined(tahoe) ! 17: /* Virtual page numbers to text|data|stack segment page numbers and back */ ! 18: #define vtotp(p, v) ((int)(v)) ! 19: #define vtodp(p, v) ((int)((v) - stoc(ctos((p)->p_tsize)))) ! 20: #define vtosp(p, v) ((int)(BTOPUSRSTACK - 1 - (v))) ! 21: #define tptov(p, i) ((unsigned)(i)) ! 22: #define dptov(p, i) ((unsigned)(stoc(ctos((p)->p_tsize)) + (i))) ! 23: #define sptov(p, i) ((unsigned)(BTOPUSRSTACK - 1 - (i))) ! 24: ! 25: /* Tell whether virtual page numbers are in text|data|stack segment */ ! 26: #define isassv(p, v) ((v) >= BTOPUSRSTACK - (p)->p_ssize) ! 27: #define isatsv(p, v) ((v) < (p)->p_tsize) ! 28: #define isadsv(p, v) ((v) >= stoc(ctos((p)->p_tsize)) && \ ! 29: (v) < (p)->p_tsize + (p)->p_dsize) ! 30: #else ! 31: /* Virtual page numbers to text|data|stack segment page numbers and back */ ! 32: #define vtotp(p, v) ((int)(v)-LOWPAGES) ! 33: #define vtodp(p, v) ((int)((v) - stoc(ctos((p)->p_tsize)) - LOWPAGES)) ! 34: #define vtosp(p, v) ((int)(BTOPUSRSTACK - 1 - (v))) ! 35: #define tptov(p, i) ((unsigned)(i) + LOWPAGES) ! 36: #define dptov(p, i) ((unsigned)(stoc(ctos((p)->p_tsize)) + (i) + LOWPAGES)) ! 37: #define sptov(p, i) ((unsigned)(BTOPUSRSTACK - 1 - (i))) ! 38: ! 39: /* Tell whether virtual page numbers are in text|data|stack segment */ ! 40: #define isassv(p, v) ((v) >= BTOPUSRSTACK - (p)->p_ssize) ! 41: #define isatsv(p, v) (((v) - LOWPAGES) < (p)->p_tsize) ! 42: #define isadsv(p, v) (((v) - LOWPAGES) >= stoc(ctos((p)->p_tsize)) && \ ! 43: !isassv(p, v)) ! 44: #endif ! 45: ! 46: /* Tell whether pte's are text|data|stack */ ! 47: #define isaspte(p, pte) ((pte) > sptopte(p, (p)->p_ssize)) ! 48: #define isatpte(p, pte) ((pte) < dptopte(p, 0)) ! 49: #define isadpte(p, pte) (!isaspte(p, pte) && !isatpte(p, pte)) ! 50: ! 51: /* Text|data|stack pte's to segment page numbers and back */ ! 52: #define ptetotp(p, pte) ((pte) - (p)->p_p0br) ! 53: #define ptetodp(p, pte) (((pte) - (p)->p_p0br) - (p)->p_tsize) ! 54: #define ptetosp(p, pte) (((p)->p_addr - (pte)) - 1) ! 55: ! 56: #define tptopte(p, i) ((p)->p_p0br + (i)) ! 57: #define dptopte(p, i) ((p)->p_p0br + ((p)->p_tsize + (i))) ! 58: #define sptopte(p, i) ((p)->p_addr - (1 + (i))) ! 59: ! 60: /* Convert a virtual page number to a pte address. */ ! 61: #define vtopte(p, v) \ ! 62: (((v) < (p)->p_tsize + (p)->p_dsize) ? ((p)->p_p0br + (v)) : \ ! 63: ((p)->p_addr - (BTOPUSRSTACK - (v)))) ! 64: ! 65: /* Bytes to pages without rounding, and back */ ! 66: #define btop(x) (((unsigned)(x)) >> PGSHIFT) ! 67: #define ptob(x) ((caddr_t)((x) << PGSHIFT)) ! 68: ! 69: /* Turn virtual addresses into kernel map indices */ ! 70: #define kmxtob(a) (usrpt + (a) * NPTEPG) ! 71: #define btokmx(b) (((b) - usrpt) / NPTEPG) ! 72: ! 73: /* User area address and pcb bases */ ! 74: #define uaddr(p) (&((p)->p_p0br[(p)->p_szpt * NPTEPG - UPAGES])) ! 75: #if defined(vax) || defined(tahoe) ! 76: #define pcbb(p) ((p)->p_addr[0].pg_pfnum) ! 77: #endif ! 78: ! 79: /* Average new into old with aging factor time */ ! 80: #define ave(smooth, cnt, time) \ ! 81: smooth = ((time - 1) * (smooth) + (cnt)) / (time) ! 82: ! 83: /* Abstract machine dependent operations */ ! 84: #if defined(vax) ! 85: #define setp0br(x) (u.u_pcb.pcb_p0br = (x), mtpr(P0BR, x)) ! 86: #define setp0lr(x) (u.u_pcb.pcb_p0lr = \ ! 87: (x) | (u.u_pcb.pcb_p0lr & AST_CLR), \ ! 88: mtpr(P0LR, x)) ! 89: #define setp1br(x) (u.u_pcb.pcb_p1br = (x), mtpr(P1BR, x)) ! 90: #define setp1lr(x) (u.u_pcb.pcb_p1lr = (x), mtpr(P1LR, x)) ! 91: #define initp1br(x) ((x) - P1PAGES) ! 92: #endif ! 93: ! 94: #if defined(tahoe) ! 95: #define setp0br(x) (u.u_pcb.pcb_p0br = (x), mtpr(P0BR, x)) ! 96: #define setp0lr(x) (u.u_pcb.pcb_p0lr = (x), mtpr(P0LR, x)) ! 97: #define setp1br(x) (u.u_pcb.pcb_p1br = (x), mtpr(P1BR, x)) ! 98: #define setp1lr(x) (u.u_pcb.pcb_p1lr = (x), mtpr(P1LR, x)) ! 99: #define setp2br(x) (u.u_pcb.pcb_p2br = (x), mtpr(P2BR, x)) ! 100: #define setp2lr(x) (u.u_pcb.pcb_p2lr = (x), mtpr(P2LR, x)) ! 101: #define initp2br(x) ((x) - P2PAGES) ! 102: #endif ! 103: ! 104: #define outofmem() wakeup((caddr_t)&proc[2]); ! 105: ! 106: /* ! 107: * Page clustering macros. ! 108: * ! 109: * dirtycl(pte) is the page cluster dirty? ! 110: * anycl(pte,fld) does any pte in the cluster has fld set? ! 111: * zapcl(pte,fld) = val set all fields fld in the cluster to val ! 112: * distcl(pte) distribute high bits to cluster; note that ! 113: * distcl copies everything but pg_pfnum, ! 114: * INCLUDING pg_m!!! ! 115: * ! 116: * In all cases, pte must be the low pte in the cluster, even if ! 117: * the segment grows backwards (e.g. the stack). ! 118: */ ! 119: #define H(pte) ((struct hpte *)(pte)) ! 120: ! 121: #if CLSIZE==1 ! 122: #define dirtycl(pte) dirty(pte) ! 123: #define anycl(pte,fld) ((pte)->fld) ! 124: #define zapcl(pte,fld) (pte)->fld ! 125: #define distcl(pte) ! 126: #endif ! 127: ! 128: #if CLSIZE==2 ! 129: #define dirtycl(pte) (dirty(pte) || dirty((pte)+1)) ! 130: #define anycl(pte,fld) ((pte)->fld || (((pte)+1)->fld)) ! 131: #define zapcl(pte,fld) (pte)[1].fld = (pte)[0].fld ! 132: #endif ! 133: ! 134: #if CLSIZE==4 ! 135: #define dirtycl(pte) \ ! 136: (dirty(pte) || dirty((pte)+1) || dirty((pte)+2) || dirty((pte)+3)) ! 137: #define anycl(pte,fld) \ ! 138: ((pte)->fld || (((pte)+1)->fld) || (((pte)+2)->fld) || (((pte)+3)->fld)) ! 139: #define zapcl(pte,fld) \ ! 140: (pte)[3].fld = (pte)[2].fld = (pte)[1].fld = (pte)[0].fld ! 141: #endif ! 142: ! 143: #ifndef distcl ! 144: #define distcl(pte) zapcl(H(pte),pg_high) ! 145: #endif ! 146: ! 147: /* ! 148: * Lock a page frame. ! 149: */ ! 150: #define MLOCK(c) { \ ! 151: while ((c)->c_lock) { \ ! 152: (c)->c_want = 1; \ ! 153: sleep((caddr_t)(c), PSWP+1); \ ! 154: } \ ! 155: (c)->c_lock = 1; \ ! 156: } ! 157: /* ! 158: * Unlock a page frame. ! 159: */ ! 160: #define MUNLOCK(c) { \ ! 161: if ((c)->c_want) { \ ! 162: wakeup((caddr_t)(c)); \ ! 163: (c)->c_want = 0; \ ! 164: } \ ! 165: (c)->c_lock = 0; \ ! 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.