1: #include "param.h"
   2: #include <sys/systm.h>
   3: #include <sys/dir.h>
   4: #include <sys/user.h>
   5: #include <sys/proc.h>
   6: #include <sys/text.h>
   7: #include <sys/seg.h>
   8: 
   9: /*
  10:  *	SCCS id	@(#)ureg.c	2.1 (Berkeley)	8/29/83
  11:  */
  12: 
  13: /*
  14:  * Load the user hardware segmentation
  15:  * registers from the software prototype.
  16:  * The software registers must have
  17:  * been setup prior by estabur.
  18:  */
  19: sureg()
  20: {
  21:     register *udp, *uap, *rdp;
  22:     int *rap, *limudp;
  23:     int taddr, daddr;
  24: #ifdef  VIRUS_VFORK
  25:     int saddr;
  26: #endif
  27:     struct text *tp;
  28: 
  29: #ifdef  VIRUS_VFORK
  30:     taddr = daddr = u.u_procp->p_daddr;
  31:     saddr = u.u_procp->p_saddr;
  32: #else
  33:     taddr = daddr = u.u_procp->p_addr;
  34: #endif
  35:     if ((tp=u.u_procp->p_textp) != NULL)
  36:         taddr = tp->x_caddr;
  37: #ifndef NONSEPARATE
  38:     if (sep_id)
  39:         limudp = &u.u_uisd[16];
  40:     else
  41: #endif
  42:         limudp = &u.u_uisd[8];
  43:     rap = (int *) UISA;
  44:     rdp = (int *) UISD;
  45:     uap = &u.u_uisa[0];
  46:     for (udp = &u.u_uisd[0]; udp < limudp;) {
  47: #ifdef  VIRUS_VFORK
  48:         *rap++ = *uap++ +
  49:             (*udp & TX? taddr: (*udp&ED? saddr: (*udp&ABS? 0: daddr)));
  50: #else
  51:         *rap++ = *uap++ + (*udp & TX?  taddr: (*udp & ABS?  0: daddr));
  52: #endif
  53:         *rdp++ = *udp++;
  54:     }
  55: #ifdef  MENLO_OVLY
  56:     /*
  57: 	 *  Since software prototypes are not maintained for overlay
  58: 	 *  segments, force overlay change.  The test for TX is because
  59: 	 *  there is no text if called from core().
  60: 	 */
  61:     if (u.u_ovdata.uo_ovbase && (u.u_uisd[0] & TX))
  62:         choverlay(u.u_uisd[0] & ACCESS);
  63: #endif
  64: }
  65: 
  66: /*
  67:  * Set up software prototype segmentation
  68:  * registers to implement the 3 pseudo
  69:  * text,data,stack segment sizes passed
  70:  * as arguments.
  71:  * The argument sep specifies if the
  72:  * text and data+stack segments are to
  73:  * be separated.
  74:  * The last argument determines whether the text
  75:  * segment is read-write or read-only.
  76:  */
  77: estabur(nt, nd, ns, sep, xrw)
  78: unsigned nt, nd, ns;
  79: {
  80:     register a, *ap, *dp;
  81: #ifdef  MENLO_OVLY
  82:     unsigned ts;
  83: #endif
  84: 
  85: #ifdef  MENLO_OVLY
  86:     if (u.u_ovdata.uo_ovbase && nt)
  87:         ts = u.u_ovdata.uo_dbase;
  88:     else
  89:         ts = nt;
  90: #endif
  91:     if(sep) {
  92: #ifndef NONSEPARATE
  93:         if(!sep_id)
  94:             goto err;
  95: #ifdef  MENLO_OVLY
  96:         if(ctos(ts) > 8 || ctos(nd)+ctos(ns) > 8)
  97: #else
  98:         if(ctos(nt) > 8 || ctos(nd)+ctos(ns) > 8)
  99: #endif
 100: #endif	NONSEPARATE
 101:             goto err;
 102:     } else
 103: #ifdef  MENLO_OVLY
 104:         if(ctos(ts) + ctos(nd) + ctos(ns) > 8)
 105:             goto err;
 106:     if (u.u_ovdata.uo_ovbase && nt)
 107:         ts = u.u_ovdata.uo_ov_offst[NOVL];
 108:     if(ts + nd + ns + USIZE > maxmem)
 109:         goto err;
 110: #else
 111:         if(ctos(nt) + ctos(nd) + ctos(ns) > 8)
 112:             goto err;
 113:     if(nt + nd + ns + USIZE > maxmem)
 114:         goto err;
 115: #endif
 116:     a = 0;
 117:     ap = &u.u_uisa[0];
 118:     dp = &u.u_uisd[0];
 119:     while(nt >= 128) {
 120:         *dp++ = (127 << 8) | xrw | TX;
 121:         *ap++ = a;
 122:         a += 128;
 123:         nt -= 128;
 124:     }
 125:     if(nt) {
 126:         *dp++ = ((nt - 1) << 8) | xrw | TX;
 127:         *ap++ = a;
 128:     }
 129: #ifdef  MENLO_OVLY
 130: #ifdef  NONSEPARATE
 131:     if (u.u_ovdata.uo_ovbase && ts)
 132: #else
 133:     if ((u.u_ovdata.uo_ovbase && ts) && !sep)
 134: #endif
 135:         {
 136:         /*
 137: 		 * overlay process, adjust accordingly.
 138: 		 * The overlay segment's registers will be set by
 139:  		 * choverlay() from sureg().
 140: 		 */
 141:         register novlseg;
 142:         for(novlseg = 0; novlseg < u.u_ovdata.uo_nseg; novlseg++) {
 143:             *ap++ = 0;
 144:             *dp++ = 0;
 145:         }
 146:     }
 147: #endif
 148: #ifndef NONSEPARATE
 149:     if(sep)
 150:         while(ap < &u.u_uisa[8]) {
 151:             *ap++ = 0;
 152:             *dp++ = 0;
 153:         }
 154: #endif
 155: 
 156: #ifdef  VIRUS_VFORK
 157:     a = 0;
 158: #else
 159:     a = USIZE;
 160: #endif
 161:     while(nd >= 128) {
 162:         *dp++ = (127 << 8) | RW;
 163:         *ap++ = a;
 164:         a += 128;
 165:         nd -= 128;
 166:     }
 167:     if(nd) {
 168:         *dp++ = ((nd - 1) << 8) | RW;
 169:         *ap++ = a;
 170:         a += nd;
 171:     }
 172:     while(ap < &u.u_uisa[8]) {
 173:         if(*dp & ABS) {
 174:             dp++;
 175:             ap++;
 176:             continue;
 177:         }
 178:         *dp++ = 0;
 179:         *ap++ = 0;
 180:     }
 181: #ifndef NONSEPARATE
 182:     if(sep)
 183:         while(ap < &u.u_uisa[16]) {
 184:             if(*dp & ABS) {
 185:                 dp++;
 186:                 ap++;
 187:                 continue;
 188:             }
 189:             *dp++ = 0;
 190:             *ap++ = 0;
 191:         }
 192: #endif
 193: #ifdef  VIRUS_VFORK
 194:     a = ns;
 195:     while(ns >= 128) {
 196:         a -= 128;
 197:         ns -= 128;
 198:         *--dp = (0 << 8) | RW | ED;
 199:         *--ap = a;
 200:     }
 201: #else
 202:     a += ns;
 203:     while(ns >= 128) {
 204:         a -= 128;
 205:         ns -= 128;
 206:         *--dp = (127 << 8) | RW;
 207:         *--ap = a;
 208:     }
 209: #endif
 210:     if(ns) {
 211:         *--dp = ((128 - ns) << 8) | RW | ED;
 212:         *--ap = a - 128;
 213:     }
 214: #ifndef NONSEPARATE
 215:     if(!sep) {
 216:         ap = &u.u_uisa[0];
 217:         dp = &u.u_uisa[8];
 218:         while(ap < &u.u_uisa[8])
 219:             *dp++ = *ap++;
 220:         ap = &u.u_uisd[0];
 221:         dp = &u.u_uisd[8];
 222:         while(ap < &u.u_uisd[8])
 223:             *dp++ = *ap++;
 224:     }
 225: #endif
 226:     sureg();
 227:     return(0);
 228: 
 229: err:
 230:     u.u_error = ENOMEM;
 231:     return(-1);
 232: }
 233: 
 234: #ifdef  MENLO_OVLY
 235: /*
 236:  * Routine to change overlays.
 237:  * Only hardware registers are changed;
 238:  * must be called from sureg
 239:  * since the software prototypes will be out of date.
 240:  */
 241: choverlay(xrw)
 242: {
 243:     register int *rap, *rdp;
 244:     register nt;
 245:     int addr, *limrdp;
 246: 
 247:     rap = &(UISA[u.u_ovdata.uo_ovbase]);
 248:     rdp = &(UISD[u.u_ovdata.uo_ovbase]);
 249:     limrdp = &(UISD[u.u_ovdata.uo_ovbase + u.u_ovdata.uo_nseg]);
 250:     if (u.u_ovdata.uo_curov) {
 251:         addr = u.u_ovdata.uo_ov_offst[u.u_ovdata.uo_curov - 1];
 252:         nt = u.u_ovdata.uo_ov_offst[u.u_ovdata.uo_curov] - addr;
 253:         addr += u.u_procp->p_textp->x_caddr;
 254:         while (nt >= 128) {
 255:             *rap++ = addr;
 256:             *rdp++ = (127 << 8) | xrw;
 257:             addr += 128;
 258:             nt -= 128;
 259:         }
 260:         if (nt) {
 261:             *rap++ = addr;
 262:             *rdp++ = ((nt-1) << 8) | xrw;
 263:         }
 264:     }
 265:     while (rdp < limrdp) {
 266:         *rap++ = 0;
 267:         *rdp++ = 0;
 268:     }
 269: #ifndef NONSEPARATE
 270:     /*
 271: 	 * This section copies the UISA/UISD registers to the
 272: 	 * UDSA/UDSD registers.  It is only needed for data fetches
 273: 	 * on the overlaid segment, which normally don't happen.
 274: 	 */
 275:     if (!u.u_sep && sep_id) {
 276:         rdp = &(UISD[u.u_ovdata.uo_ovbase]);
 277:         rap = rdp + 8;
 278:         /* limrdp is still correct */
 279:         while (rdp < limrdp)
 280:             *rap++ = *rdp++;
 281:         rdp = &(UISA[u.u_ovdata.uo_ovbase]);
 282:         rap = rdp + 8;
 283:         limrdp = &(UISA[u.u_ovdata.uo_ovbase + u.u_ovdata.uo_nseg]);
 284:         while (rdp < limrdp)
 285:             *rap++ = *rdp++;
 286:     }
 287: #endif
 288: }
 289: #endif	MENLO_OVLY

Defined functions

choverlay defined in line 241; used 4 times
sureg defined in line 19; used 9 times
Last modified: 1983-08-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 849
Valid CSS Valid XHTML 1.0 Strict