home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / UZIUTILS.ARK / XMACHDEP.C < prev   
Text File  |  1988-12-24  |  5KB  |  271 lines

  1.  
  2. /**************************************************
  3. UZI (Unix Z80 Implementation) Utilities:  xmachdep.c
  4. ***************************************************/
  5.  
  6.  
  7. #include "unix.h"
  8. #include "extern.h"
  9.  
  10.  
  11. /* This is called at the very beginning to initialize everything. */
  12. /* It is the equivalent of main() */
  13.  
  14. fs_init()
  15. {
  16.     inint = 0;
  17.     udata.u_euid = 0;
  18.     udata.u_insys = 1;
  19. }
  20.  
  21.  
  22. /* This checks to see if a user-suppled address is legitimate */
  23. valadr(base,size)
  24. char *base;
  25. uint16 size;
  26. {
  27.     return(1);
  28. }
  29.  
  30.  
  31. /* This adds two tick counts together.
  32. The t_time field holds up to one second of ticks,
  33. while the t_date field counts minutes */
  34.  
  35. addtick(t1,t2)
  36. time_t *t1, *t2;
  37. {
  38.  
  39.     t1->t_time += t2->t_time;
  40.     t1->t_date += t2->t_date;
  41.     if (t1->t_time >= 60*TICKSPERSEC)
  42.     {
  43.     t1->t_time -= 60*TICKSPERSEC;
  44.     ++t1->t_date;
  45.     }
  46. }
  47.  
  48. incrtick(t)
  49. time_t *t;
  50. {
  51.     if (++t->t_time == 60*TICKSPERSEC)
  52.     {
  53.     t->t_time = 0;
  54.     ++t->t_date;
  55.     }
  56. }
  57.  
  58.  
  59.  
  60. stkreset()
  61. {
  62. #asm 8080
  63.     POP    H
  64.     LXI    SP,udata?-2
  65.     PCHL
  66. #endasm
  67. }
  68.  
  69.  
  70. /* Port addresses of clock chip registers. */
  71.  
  72. #define SECS 0xe2
  73. #define MINS 0xe3
  74. #define HRS 0xe4
  75. #define DAY 0xe6
  76. #define MON 0xe7
  77. #define YEAR 86
  78.  
  79. sttime()
  80. {
  81.     panic("Calling sttime");
  82. }
  83.  
  84.  
  85. rdtime(tloc)
  86. time_t *tloc;
  87. {
  88.     tloc->t_time = (tread(SECS)>>1) | (tread(MINS)<<5) | (tread(HRS)<<11);
  89.     tloc->t_date = tread(DAY) | (tread(MON)<<5) | (YEAR<<9);
  90. }
  91.  
  92.  
  93. /* Update global time of day */
  94. rdtod()
  95. {
  96.     tod.t_time = (tread(SECS)>>1) | (tread(MINS)<<5) | (tread(HRS)<<11);
  97.     tod.t_date = tread(DAY) | (tread(MON)<<5) | (YEAR<<9);
  98. }
  99.  
  100.  
  101. /* Read BCD clock register, convert to binary. */
  102. tread(port)
  103. uint16 port;
  104. {
  105.     int n;
  106.  
  107.     n = in(port);
  108.     return ( 10*((n>>4)&0x0f) + (n&0x0f) );
  109. }
  110.  
  111.  
  112. /* Disable interrupts */
  113. di()
  114. {
  115. #asm 8080
  116.     DI    ;disable interrupts
  117. #endasm
  118. }
  119.  
  120. /* Enable interrupts if we are not in service routine */
  121. ei()
  122. {
  123.     if (inint)
  124.     return;
  125.     ;    /* Empty statement necessary to fool compiler */
  126.  
  127. #asm 8080
  128.     EI    ;disable interrupts
  129. #endasm
  130. }
  131.  
  132.  
  133.  
  134. /* This shifts an unsigned int right 8 places. */
  135.  
  136. shift8()
  137. {
  138. #asm 8080
  139.     POP    D      ;ret addr
  140.     POP    H
  141.     MOV    L,H
  142.     MVI    H,0
  143.     MOV    A,L
  144.     ANA    A    ;set Z flag on result
  145.     PUSH    H
  146.     PUSH    D    ;restore stack
  147. #endasm
  148. }
  149.  
  150.  
  151. /* This prints an error message and dies. */
  152.  
  153. panic(s)
  154. char *s;
  155. {
  156.     inint = 1;
  157.     kprintf("PANIC: %s\n",s);
  158.     idump();
  159.     abort();
  160. }
  161.  
  162.  
  163. warning(s)
  164. char *s;
  165. {
  166.     kprintf("WARNING: %s\n",s);
  167. }
  168.  
  169.  
  170. kputs(s)
  171. char *s;
  172. {
  173.     while (*s)
  174.     kputchar(*(s++));
  175. }
  176.  
  177. kputchar(c)
  178. int c;
  179. {
  180.     if (c == '\n')
  181.     _putc('\r');
  182.     _putc(c);
  183. }
  184.  
  185.  
  186.  
  187. idump()
  188. {
  189.     inoptr ip;
  190.     ptptr pp;
  191.     extern struct cinode i_tab[];
  192.     bufptr j;
  193.  
  194.     kprintf(
  195.         "   MAGIC  DEV  NUM  MODE  NLINK (DEV) REFS DIRTY err %d root %d\n",
  196.             udata.u_error, root - i_tab);
  197.  
  198.     for (ip=i_tab; ip < i_tab+ITABSIZE; ++ip)
  199.     {
  200.     kprintf("%d %d %d %u 0%o %d %d %d %d\n",
  201.            ip-i_tab, ip->c_magic,ip->c_dev, ip->c_num,
  202.            ip->c_node.i_mode,ip->c_node.i_nlink,ip->c_node.i_addr[0],
  203.            ip->c_refs,ip->c_dirty);
  204.     ifnot (ip->c_magic)    
  205.         break;
  206.     }
  207.  
  208.     kprintf("\n   STAT WAIT   PID PPTR  ALARM  PENDING  IGNORED\n");
  209.     for (pp=ptab; pp < ptab+PTABSIZE; ++pp)
  210.     {
  211.     kprintf("%d %d    0x%x %d %d  %d 0x%x 0x%x\n",
  212.            pp-ptab, pp->p_status, pp->p_wait,  pp->p_pid,
  213.            pp->p_pptr-ptab, pp->p_alarm, pp->p_pending,
  214.         pp->p_ignored);
  215.         ifnot(pp->p_pptr)
  216.         break;
  217.     }    
  218.     
  219.     kprintf("\ndev blk drty bsy\n");
  220.     for (j=bufpool; j < bufpool+NBUFS; ++j)
  221.     kprintf("%d %u %d %d\n",j->bf_dev,j->bf_blk,j->bf_dirty,j->bf_busy);
  222.  
  223.     kprintf("\ninsys %d ptab %d call %d cwd %d sp 0x%x\n",
  224.     udata.u_insys,udata.u_ptab-ptab, udata.u_callno, udata.u_cwd-i_tab,
  225.        udata.u_sp);
  226. }
  227.  
  228.  
  229.  
  230. /* Short version of printf to save space */
  231. kprintf(nargs)
  232.     {
  233.     register char **arg, *fmt;
  234.     register c, base;
  235.     char s[7], *itob();
  236.  
  237.     arg = (char **)&nargs + nargs;
  238.     fmt = *arg;
  239.     while (c = *fmt++) {
  240.         if (c != '%') {
  241.             kputchar(c);
  242.             continue;
  243.             }
  244.         switch (c = *fmt++) {
  245.         case 'c':
  246.             kputchar(*--arg);
  247.             continue;
  248.         case 'd':
  249.             base = -10;
  250.             goto prt;
  251.         case 'o':
  252.             base = 8;
  253.             goto prt;
  254.         case 'u':
  255.             base = 10;
  256.             goto prt;
  257.         case 'x':
  258.             base = 16;
  259.         prt:
  260.             kputs(itob(*--arg, s, base));
  261.             continue;
  262.         case 's':
  263.             kputs(*--arg);
  264.             continue;
  265.         default:
  266.             kputchar(c);
  267.             continue;
  268.             }
  269.         }
  270.     }
  271.