home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 500 / 471 / rccl145 < prev    next >
Text File  |  1987-03-02  |  5KB  |  202 lines

  1. /*
  2.  *      trap handler to simulate unix kernel traps
  3.  */
  4.  
  5.  
  6. #define DLV     ((struct dlvp *)0177560)
  7. /*
  8. #define DLV     ((struct dlvp *)0176500)
  9. */
  10. #define READY   0200
  11. #define ENXIO   6
  12.  
  13.  
  14. struct dlvp {
  15.     int     rcsr;
  16.     int     rbuf;
  17.     int     xcsr;
  18.     int     xbuf;
  19. };
  20.  
  21. struct  sys {
  22.     int     s_args;
  23.     int     (*s_fun)();
  24. };
  25.  
  26.     extern  zexit(),zread(),zwrite(),nosys();
  27.  
  28. /*
  29.  * This table is the switch used to transfer
  30.  * to the appropriate routine for processing a system call.
  31.  * Each row contains the number of arguments expected
  32.  * and a pointer to the routine.
  33.  */
  34. struct sys sysent[] = {
  35.  
  36.     0, nosys,                      /*  0 = indir */
  37.     0, zexit,                      /*  1 = exit */
  38.     0, nosys,                      /*  2 = fork */
  39.     2, zread,                      /*  3 = read */
  40.     2, zwrite,                     /*  4 = write */
  41.     2, nosys,                      /*  5 = open */
  42.     0, nosys,                      /*  6 = close */
  43.     0, nosys,                      /*  7 = wait */
  44.     2, nosys,                      /*  8 = creat */
  45.     2, nosys,                      /*  9 = link */
  46.     1, nosys,                      /* 10 = unlink */
  47.     2, nosys,                      /* 11 = exec */
  48.     1, nosys,                      /* 12 = chdir */
  49.     0, nosys,                      /* 13 = time */
  50.     3, nosys,                      /* 14 = mknod */
  51.     2, nosys,                      /* 15 = chmod */
  52.     2, nosys,                      /* 16 = chown */
  53.     1, nosys,                      /* 17 = break */
  54.     2, nosys,                      /* 18 = stat */
  55.     2, nosys,                      /* 19 = seek */
  56.     0, nosys,                      /* 20 = getpid */
  57.     3, nosys,                      /* 21 = mount */
  58.     1, nosys,                      /* 22 = umount */
  59.     0, nosys,                      /* 23 = setuid */
  60.     0, nosys,                      /* 24 = getuid */
  61.     0, nosys,                      /* 25 = stime */
  62.     3, nosys,                      /* 26 = ptrace */
  63.     0, nosys,                      /* 27 = alarm */
  64.     1, nosys,                      /* 28 = fstat */
  65.     0, nosys,                      /* 29 = pause */
  66.     1, nosys,                      /* 30 = smdate; inoperative */
  67.     1, nosys,                      /* 31 = stty */
  68.     1, nosys,                      /* 32 = gtty */
  69.     2, nosys,                      /* 33 = access */
  70.     0, nosys,                      /* 34 = nice */
  71.     0, nosys,                      /* 35 = sleep */
  72.     0, nosys,                      /* 36 = sync */
  73.     1, nosys,                      /* 37 = kill */
  74.     0, nosys,                      /* 38 = switch */
  75.     0, nosys,                      /* 39 = x */
  76.     0, nosys,                      /* 40 = tell */
  77.     0, nosys,                      /* 41 = dup */
  78.     0, nosys,                      /* 42 = pipe */
  79.     1, nosys,                      /* 43 = times */
  80.     4, nosys,                      /* 44 = prof */
  81.     0, nosys,                      /* 45 = tiu */
  82.     0, nosys,                      /* 46 = setgid (nop) */
  83.     0, nosys,                      /* 47 = getgid (nop) */
  84.     2, nosys,                      /* 48 = sig */
  85.     0, nosys,                      /* 49 = geteuid (16 bit effective uid) */
  86.     0, nosys,                      /* 50 = clrtty (clear controlling tty) */
  87.     1, nosys,                      /* 51 = nicer (nice on another job) */
  88.     0, nosys,                      /* 52 = wakeup (for debugging) */
  89.     0, nosys,                      /* 53 = x */
  90.     0, nosys,                      /* 54 = x */
  91.     0, nosys,                      /* 55 = x */
  92.     0, nosys,                      /* 56 = x */
  93.     0, nosys,                      /* 57 = x */
  94.     0, nosys,                      /* 58 = x */
  95.     0, nosys,                      /* 59 = x */
  96.     0, nosys,                      /* 60 = x */
  97.     0, nosys,                      /* 61 = x */
  98.     0, nosys,                      /* 62 = x */
  99.     0, nosys                       /* 63 = x */
  100. };
  101.  
  102. int     u_arg[4];
  103. int     u_error;
  104. int     r0,r1;
  105.  
  106.  
  107. _trap(cr1,cr0,pc,ps)
  108. int cr1, cr0;
  109. int *pc;
  110. int ps;
  111. {
  112.     register int *ptrap,i;
  113.     register struct sys *sysp;
  114.     int type,indirect;
  115.     ptrap = pc - 1;
  116.     r0 = cr0;  r1 = cr1;
  117.     indirect = 0;
  118.     while ((type = *ptrap++ & 077) == 0) {
  119.         indirect++;
  120.         pc++;
  121.         ptrap = *ptrap;
  122.     }
  123.     sysp = &sysent[type];
  124.     for (i=0 ; i<sysp->s_args ; i++) {
  125.         u_arg[i] = *ptrap++;
  126.         if (!indirect)
  127.             ++pc;
  128.     }
  129.     u_error = 0;
  130.     (*sysp->s_fun)();
  131.     if (u_error) {
  132.         ps |= 1;        /* set carry (error) */
  133.         r0 = u_error;
  134.     } else
  135.         ps &= ~1;       /* clear carry */
  136.     cr1 = r1;  cr0 = r0;
  137. }
  138.  
  139. zwrite()
  140. {
  141.     char *cp,c;
  142.     int n;
  143.     if (znxio())return;
  144.     cp = u_arg[0];
  145.     r0 = n = u_arg[1];
  146.     while (n--) {
  147.         c = *cp++;
  148.         if (c == '\n')
  149.             zwriteone('\r');
  150.         zwriteone(c);
  151.     }
  152. }
  153.  
  154. zwriteone(c)
  155. {
  156.     while ((DLV->xcsr & READY) == 0)
  157.         ;
  158.     DLV->xbuf = c;
  159. }
  160.  
  161. zread()
  162. {
  163.     char *cp,c;
  164.     int n,nr;
  165.     if (znxio()) return;
  166.     cp = u_arg[0];
  167.     n = u_arg[1];
  168.     nr = 0;
  169.     while (n--) {
  170.         c = zreadone();
  171.         zwriteone(c);
  172.         if (c == '\r') {
  173.             c = '\n';
  174.             zwriteone(c);
  175.         }
  176.         *cp++ = c;
  177.         nr++;
  178.         if (c == '\n') break;
  179.     }
  180.     r0 = nr;
  181. }
  182.  
  183. zreadone()
  184. {
  185.     while ((DLV->rcsr & READY) == 0);
  186.     return(DLV->rbuf & 0177);
  187. }
  188.  
  189. znxio()
  190. {
  191.     if (u_arg[1] <= 0 || r0 < 0 || r0 > 2) {
  192.         u_error = ENXIO;
  193.         return(1);
  194.     }
  195.     return(0);
  196. }
  197.  
  198. nosys()
  199. {
  200.     u_error = ENXIO;
  201. }
  202.