home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / sys / c / syslib < prev    next >
Encoding:
Text File  |  1994-09-30  |  2.9 KB  |  154 lines

  1. static char sccs_id[] = "@(#) syslib.c 4.2 " __DATE__ " HJR";
  2.  
  3. /* syslib.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <signal.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. #include "sys/syslib.h"
  13. #include "sys/os.h"
  14. #include "sys/unix.h"
  15.  
  16. struct env __Cenv[1] =
  17. {
  18.   {
  19.     {
  20.       {0, 0, 0},        /* MemoryLimit */
  21.       {__h_sigill, 0, 0},    /* Undefined Inst. */
  22.       {__h_sigsegv0, 0, 0},    /* Prefetch Abort */
  23.       {__h_sigsegv1, 0, 0},    /* Data Abort */
  24.       {__h_sigbus, 0, 0},    /* Address Exception */
  25.       {0, 0, 0},        /* Other Exception */
  26.       {__h_error, 0, 0},    /* Error */
  27.       {__h_cback, 0, (void *) __cbreg},        /* CallBack */
  28.       {0, 0, 0},        /* BreakPoint */
  29.       {__h_sigint, 0, 0},    /* Escape */
  30.       {__h_event, 0, 0},    /* Event */
  31.       {__h_exit, 0, 0},        /* Exit */
  32.       {0 /* __h_sigsys */ , 0, 0}    /* Unknown SWI */
  33.     }
  34.   }
  35. };
  36. struct env __Oenv[1];
  37.  
  38. struct proc *__u;
  39.  
  40. extern int main (int, char **);
  41.  
  42. void
  43. _main (void)
  44. {
  45.   register struct env *e;
  46.   register int i;
  47.  
  48.   e = __Oenv;
  49.   for (i = 0; i < 13; i++)
  50.     __rdenv (i, e->h + i);
  51.  
  52.   __h_errbuf = (char *) e->h[6].b;
  53.  
  54.   __sigrec = 0;
  55.  
  56.   for (i = 0; i < 20; i++)
  57.     __sigvec[i] = __sigdfl[i];    /*signal handlers */
  58.  
  59.   e = __Cenv;
  60.   for (i = 0; i < 13; i++)
  61.     __wrenv (i, e->h + i);
  62.  
  63.   /* handlers installed */
  64.  
  65.   __fpinit ();            /* flag FP presence */
  66.  
  67.   __allocinit ();        /* initialise malloc() & c. */
  68.  
  69.   __unixinit ();        /* initialise UNIX */
  70.  
  71.   if (___stdioinit)
  72.     (*___stdioinit) ();        /* initialise stdin,stdout & stderr */
  73.  
  74.   if (___do_global_ctors)
  75.     (*___do_global_ctors) ();    /* if C++ call constructors */
  76.  
  77.   /* For __uname() - If __uname_dont_pack is set, unset vowel dropping bit */
  78.   if (__uname_dont_pack_ptr && *__uname_dont_pack_ptr)
  79.     __uname_control &= ~4;
  80.  
  81.   exit (main (__u->argc, __u->argv));    /* ... ignition */
  82.  
  83. /* not reached */
  84. }
  85.  
  86. void (*__ax[__MAX_AXCNT]) (void);
  87. int __axcnt = 0;
  88.  
  89. void
  90. exit (int r)
  91. {
  92.   register int i;
  93.  
  94.   i = __axcnt;
  95.   while (i)
  96.     (*__ax[--i]) ();
  97.  
  98.   if (___stdioexit)
  99.     (*___stdioexit) ();        /* close streams & delete tmpfile() */
  100.  
  101.   _exit (r);
  102. }
  103.  
  104. void
  105. __reset (void)
  106. {
  107.   register int i;
  108.   register struct env *e;
  109.  
  110.   if (__u)
  111.     __unixexit ();        /* shutdown UNIX (close all fds etc.) */
  112.  
  113.   e = __Oenv;
  114.   for (i = 0; i < 13; i++)
  115.     __wrenv (i, e->h + i);
  116. }
  117.  
  118. void
  119. _exit (int r)
  120. {
  121.   if (__u)
  122.     alarm (0);
  123.  
  124.   if (!__u || !(__u->flag & __U_PPROC) || !___vret)
  125.     {
  126.       int regs[10];
  127.       __reset ();
  128.       regs[0] = (int) "Sys$ReturnCode";
  129.       regs[1] = (int) &r;
  130.       regs[2] = 4;
  131.       regs[3] = 0;
  132.       regs[4] = 1;
  133.       os_swi (0x24, regs);
  134. #ifdef DEBUG
  135.       os_print ("Setting return code = ");
  136.       os_prhex (r);
  137.       os_print ("\r\n");
  138. #endif
  139.  
  140.       __exit (r);        /* OS_Exit with return value <r> */
  141.     }
  142.   else
  143.     (*___vret) (r);
  144. }
  145.  
  146. void
  147. __fpinit (void)
  148. {
  149.   __fpflag = -1;
  150.   signal (SIGILL, __fpclr);
  151.   __fptest ();
  152.   signal (SIGILL, SIG_DFL);
  153. }
  154.