1 #ifndef lint 2 static char sccsid[] = " unixstart.c 4.2 84/05/05 "; 3 #endif 4 5 /* From Lou Salkind: compat/RCS/unixstart.c,v 1.2 84/01/31 13:34:27 */ 6 7 /* Start up a version 6 or version 7 pdp-11 UNIX compatability mode 8 * program. Must set up the memory layout with args etc. 9 * Art Wetzel August 1979 10 */ 11 #include <stdio.h> 12 #include "defs.h" 13 #define MAXARGS 100 14 start(argv, envp) unsigned char **argv, **envp; { 15 register unsigned char *sp, *ap; 16 register unsigned short *ssp; 17 register int i, argc, envc; 18 unsigned char *envps[MAXARGS], *argps[MAXARGS], **av, *p1, *p2; 19 extern unsigned char *progname, *nameend; 20 /* set up initial memory layout for unix */ 21 /* set stack pointer to top of memory */ 22 sp = memsiz; 23 #ifdef V7UNIX 24 /* zero top 2 bytes */ 25 *(--sp) = 0; 26 *(--sp) = 0; 27 /* point to environment pointer list */ 28 av = envp; 29 envc = 0; 30 /* count up number of env elements */ 31 while(*(av++)) envc++; 32 /* last UNIX V7 env ptr is 0 */ 33 envps[envc] = (unsigned char *)0; 34 /* copy actual environment (assume byte text) - last first */ 35 for(i=envc-1; i>=0; i--) { 36 ap = envp[i]; 37 while(*(ap++)) ; 38 while(ap != envp[i]) *(--sp) = *(--ap); 39 /* force stack word alignment - required per arg in v7 */ 40 if((int)sp & 1) { 41 ap = sp--; 42 while((*(ap-1) = *ap)) ap++; 43 } 44 envps[i] = sp; 45 } 46 #endif 47 /* point to argument pointer list */ 48 av = argv; 49 argc = 0; 50 /* count up number of args */ 51 while(*(av++)) argc++; 52 #ifdef V7UNIX 53 /* last UNIX V7 arg ptr is 0 */ 54 argps[argc] = (unsigned char *)0; 55 #endif 56 #ifdef V6UNIX 57 /* last UNIX V6 arg ptr is -1 */ 58 argps[argc] = (unsigned char *)-1; 59 #endif 60 /* copy actual arguments (assume byte text) - last first */ 61 for(i=argc-1; i>=0; i--) { 62 ap = argv[i]; 63 while(*(ap++)) ; 64 while(ap != argv[i]) *(--sp) = *(--ap); 65 /* force stack word alignment - required per arg in v7 */ 66 if((int)sp & 1) { 67 ap = sp--; 68 while((*(ap-1) = *ap)) ap++; 69 } 70 argps[i] = sp; 71 } 72 ssp = (unsigned short *)sp; 73 #ifdef V7UNIX 74 /* set up environment pointers */ 75 for(i=envc; i>=0; i--) { 76 *(--ssp) = (short)(long)envps[i]; 77 } 78 #endif 79 /* set up argument pointers */ 80 for(i=argc; i>=0; i--) { 81 *(--ssp) = (short)(long)argps[i]; 82 } 83 /* then argument count */ 84 *(--ssp) = argc; 85 /* set up stack pointer */ 86 regs[6] = (int)ssp; 87 /* set up a psl with cleared condition codes */ 88 psl = 0x83c00000; 89 /* copy out part of the program name and args where ps can get them */ 90 /* flag it with a * so it shows up as a compatability mode process */ 91 /* check for case with no env and reset nameend */ 92 if(nameend < progname) nameend = (unsigned char *)2147483647; 93 for(p1=progname, *p1++ = '*', i=1, p2=argv[0]; p1<nameend; p1++) { 94 if((*p1 = *p2)) 95 p2++; 96 else if(argv[i]) 97 p2 = argv[i++]; 98 else break; 99 } 100 while(p1 < nameend) *p1++ = ' '; 101 *p1 = 0; 102 /* clear out registers other than sp */ 103 regs[0] = 0; 104 regs[1] = 0; 105 regs[2] = 0; 106 regs[3] = 0; 107 regs[4] = 0; 108 regs[5] = 0; 109 /* finally get around to actually starting up in compatability mode */ 110 incompat++; 111 compat(); 112 } 113