1: #
   2: #include "../param.h"
   3: #include "../user.h"
   4: #include "../systm.h"
   5: #include "../proc.h"
   6: #include "../text.h"
   7: #include "../inode.h"
   8: #include "../seg.h"
   9: 
  10: #define CLOCK1  0177546
  11: #define CLOCK2  0172540
  12: /*
  13:  * Icode is the octal bootstrap
  14:  * program executed in user mode
  15:  * to bring up the system.
  16:  */
  17: int icode[]
  18: {
  19:     0104413,    /* sys exec; init; initp */
  20:     0000014,
  21:     0000010,
  22:     0000777,    /* br . */
  23:     0000014,    /* initp: init; 0 */
  24:     0000000,
  25:     0062457,    /* init: </etc/init\0> */
  26:     0061564,
  27:     0064457,
  28:     0064556,
  29:     0000164,
  30: };
  31: 
  32: /*
  33:  * Initialization code.
  34:  * Called from m40.s or m45.s as
  35:  * soon as a stack and segmentation
  36:  * have been established.
  37:  * Functions:
  38:  *	clear and free user core
  39:  *	find which clock is configured
  40:  *	hand craft 0th process
  41:  *	call all initialization routines
  42:  *	fork - process 0 to schedule
  43:  *	     - process 1 execute bootstrap
  44:  *
  45:  * panic: no clock -- neither clock responds
  46:  * loop at loc 6 in user mode -- /etc/init
  47:  *	cannot be executed.
  48:  */
  49: main()
  50: {
  51:     extern schar;
  52:     register i, *p;
  53: 
  54:     /*
  55: 	 * zero and free all of core
  56: 	 */
  57: 
  58:     updlock = 0;
  59:     i = *ka6 + USIZE;
  60:     UISD->r[0] = 077406;
  61:     for(;;) {
  62:         UISA->r[0] = i;
  63:         if(fuibyte(0) < 0)
  64:             break;
  65:         clearseg(i);
  66:         maxmem++;
  67:         mfree(coremap, 1, i);
  68:         i++;
  69:     }
  70:     if(cputype == 70)
  71:     for(i=0; i<62; i=+2) {
  72:         UBMAP->r[i] = i<<12;
  73:         UBMAP->r[i+1] = 0;
  74:     }
  75:     printf("mem = %l\n", maxmem*5/16);
  76:     maxmem = min(maxmem, MAXMEM);
  77:     mfree(swapmap, nswap, swplo);
  78: 
  79:     /*
  80: 	 * determine clock
  81: 	 */
  82: 
  83:     UISA->r[7] = ka6[1]; /* io segment */
  84:     UISD->r[7] = 077406;
  85:     lks = CLOCK1;
  86:     if(fuiword(lks) == -1) {
  87:         lks = CLOCK2;
  88:         if(fuiword(lks) == -1)
  89:             panic("no clock");
  90:     }
  91: 
  92:     /*
  93: 	 * set up system process
  94: 	 */
  95: 
  96:     proc[0].p_addr = *ka6;
  97:     proc[0].p_size = USIZE;
  98:     proc[0].p_stat = SRUN;
  99:     proc[0].p_flag =| SLOAD|SSYS;
 100:     u.u_procp = &proc[0];
 101: 
 102:     /*
 103: 	 * set up 'known' i-nodes
 104: 	 */
 105: 
 106:     *lks = 0115;
 107:     cinit();
 108:     binit();
 109:     iinit();
 110:     rootdir = iget(rootdev, ROOTINO);
 111:     rootdir->i_flag =& ~ILOCK;
 112:     u.u_cdir = iget(rootdev, ROOTINO);
 113:     u.u_cdir->i_flag =& ~ILOCK;
 114: 
 115:     /*
 116: 	 * make init process
 117: 	 * enter scheduling loop
 118: 	 * with system process
 119: 	 */
 120: 
 121:     if(newproc()) {
 122:         expand(USIZE+1);
 123:         estabur(0, 1, 0, 0);
 124:         copyout(icode, 0, sizeof icode);
 125:         /*
 126: 		 * Return goes to loc. 0 of user init
 127: 		 * code just copied out.
 128: 		 */
 129:         return;
 130:     }
 131:     sched();
 132: }
 133: 
 134: /*
 135:  * Load the user hardware segmentation
 136:  * registers from the software prototype.
 137:  * The software registers must have
 138:  * been setup prior by estabur.
 139:  */
 140: sureg()
 141: {
 142:     register *up, *rp, a;
 143: 
 144:     a = u.u_procp->p_addr;
 145:     up = &u.u_uisa[16];
 146:     rp = &UISA->r[16];
 147:     if(cputype == 40) {
 148:         up =- 8;
 149:         rp =- 8;
 150:     }
 151:     while(rp > &UISA->r[0])
 152:         *--rp = *--up + a;
 153:     if((up=u.u_procp->p_textp) != NULL)
 154:         a =- up->x_caddr;
 155:     up = &u.u_uisd[16];
 156:     rp = &UISD->r[16];
 157:     if(cputype == 40) {
 158:         up =- 8;
 159:         rp =- 8;
 160:     }
 161:     while(rp > &UISD->r[0]) {
 162:         *--rp = *--up;
 163:         if((*rp & WO) == 0)
 164:             rp[(UISA-UISD)/2] =- a;
 165:     }
 166: }
 167: 
 168: /*
 169:  * Set up software prototype segmentation
 170:  * registers to implement the 3 pseudo
 171:  * text,data,stack segment sizes passed
 172:  * as arguments.
 173:  * The argument sep specifies if the
 174:  * text and data+stack segments are to
 175:  * be separated.
 176:  */
 177: estabur(nt, nd, ns, sep)
 178: {
 179:     register a, *ap, *dp;
 180: 
 181:     if(sep) {
 182:         if(cputype == 40)
 183:             goto err;
 184:         if(nseg(nt) > 8 || nseg(nd)+nseg(ns) > 8)
 185:             goto err;
 186:     } else
 187:         if(nseg(nt)+nseg(nd)+nseg(ns) > 8)
 188:             goto err;
 189:     if(nt+nd+ns+USIZE > maxmem)
 190:         goto err;
 191:     a = 0;
 192:     ap = &u.u_uisa[0];
 193:     dp = &u.u_uisd[0];
 194:     while(nt >= 128) {
 195:         *dp++ = (127<<8) | RO;
 196:         *ap++ = a;
 197:         a =+ 128;
 198:         nt =- 128;
 199:     }
 200:     if(nt) {
 201:         *dp++ = ((nt-1)<<8) | RO;
 202:         *ap++ = a;
 203:     }
 204:     if(sep)
 205:     while(ap < &u.u_uisa[8]) {
 206:         *ap++ = 0;
 207:         *dp++ = 0;
 208:     }
 209:     a = USIZE;
 210:     while(nd >= 128) {
 211:         *dp++ = (127<<8) | RW;
 212:         *ap++ = a;
 213:         a =+ 128;
 214:         nd =- 128;
 215:     }
 216:     if(nd) {
 217:         *dp++ = ((nd-1)<<8) | RW;
 218:         *ap++ = a;
 219:         a =+ nd;
 220:     }
 221:     while(ap < &u.u_uisa[8]) {
 222:         *dp++ = 0;
 223:         *ap++ = 0;
 224:     }
 225:     if(sep)
 226:     while(ap < &u.u_uisa[16]) {
 227:         *dp++ = 0;
 228:         *ap++ = 0;
 229:     }
 230:     a =+ ns;
 231:     while(ns >= 128) {
 232:         a =- 128;
 233:         ns =- 128;
 234:         *--dp = (127<<8) | RW;
 235:         *--ap = a;
 236:     }
 237:     if(ns) {
 238:         *--dp = ((128-ns)<<8) | RW | ED;
 239:         *--ap = a-128;
 240:     }
 241:     if(!sep) {
 242:         ap = &u.u_uisa[0];
 243:         dp = &u.u_uisa[8];
 244:         while(ap < &u.u_uisa[8])
 245:             *dp++ = *ap++;
 246:         ap = &u.u_uisd[0];
 247:         dp = &u.u_uisd[8];
 248:         while(ap < &u.u_uisd[8])
 249:             *dp++ = *ap++;
 250:     }
 251:     sureg();
 252:     return(0);
 253: 
 254: err:
 255:     u.u_error = ENOMEM;
 256:     return(-1);
 257: }
 258: 
 259: /*
 260:  * Return the arg/128 rounded up.
 261:  */
 262: nseg(n)
 263: {
 264: 
 265:     return((n+127)>>7);
 266: }

Defined functions

estabur defined in line 177; used 8 times
main defined in line 49; used 2 times
nseg defined in line 262; used 7 times
sureg defined in line 140; used 3 times

Defined variables

icode defined in line 17; used 2 times
  • in line 124(2)

Defined macros

CLOCK1 defined in line 10; used 1 times
  • in line 85
CLOCK2 defined in line 11; used 1 times
  • in line 87
Last modified: 1975-07-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1282
Valid CSS Valid XHTML 1.0 Strict