home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_init.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  9.8 KB  |  425 lines

  1. head    1.4;
  2. access;
  3. symbols
  4.     version39-41:1.3;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.4
  10. date    92.08.09.20.52.38;    author amiga;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    92.05.22.01.43.46;    author mwild;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    92.05.18.00.49.07;    author mwild;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    92.05.17.21.25.55;    author mwild;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @library initialization
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @change to new way of remembering open libraries
  38. get prepared to deal with ttys
  39. @
  40. text
  41. @/*
  42.  *  This file is part of ixemul.library for the Amiga.
  43.  *  Copyright (C) 1991, 1992  Markus M. Wild
  44.  *
  45.  *  This library is free software; you can redistribute it and/or
  46.  *  modify it under the terms of the GNU Library General Public
  47.  *  License as published by the Free Software Foundation; either
  48.  *  version 2 of the License, or (at your option) any later version.
  49.  *
  50.  *  This library is distributed in the hope that it will be useful,
  51.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  52.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  53.  *  Library General Public License for more details.
  54.  *
  55.  *  You should have received a copy of the GNU Library General Public
  56.  *  License along with this library; if not, write to the Free
  57.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  58.  *
  59.  *  $Id: ix_init.c,v 1.3 1992/05/22 01:43:46 mwild Exp $
  60.  *
  61.  *  $Log: ix_init.c,v $
  62.  *  Revision 1.3  1992/05/22  01:43:46  mwild
  63.  *  initialize buddy allocator
  64.  *
  65.  * Revision 1.2  1992/05/18  00:49:07  mwild
  66.  * changed async mp to be global
  67.  *
  68.  * Revision 1.1  1992/05/14  19:55:40  mwild
  69.  * Initial revision
  70.  *
  71.  */
  72.  
  73. #define KERNEL
  74. #include "ixemul.h"
  75.  
  76. #include <exec/memory.h>
  77.  
  78. /* #undef DEBUG */
  79.  
  80. #ifdef DEBUG
  81. #define DP(a) kprintf a
  82. #else
  83. #define DP(a)
  84. #endif
  85.  
  86. /* not changed after the library is initialized */
  87. struct ixemul_base *ixemulbase = 0;
  88. int _dos20;
  89.  
  90. /* used by gnulib.. I was too lazy to convert that library as well ;-) */
  91. void *MathIeeeDoubBasBase, *MathIeeeDoubTransBase,
  92.      *MathIeeeSingBasBase;
  93.  
  94. struct ExecBase *SysBase;
  95.  
  96. /* global port for asynchronous packet notification */
  97. struct MsgPort *ix_async_mp;
  98. extern int mp_interrupt ();
  99.  
  100. /* global port for tty handling */
  101. struct MsgPort *ix_tty_mp;
  102. extern int tty_interrupt ();
  103.  
  104. /* since gcc can now statically initialize unions, they're quite useful;-) */
  105. union lib {
  106.   char *name;
  107.   struct Library *base;
  108. };
  109.  
  110. void
  111. open_libraries (union lib *libs)
  112. {
  113.   SysBase = *(struct ExecBase **)4;
  114.  
  115.   /* on input `libs' contains a pointer to the library name, on output it
  116.      contains the library base pointer */
  117.   do
  118.     libs->base = OpenLibrary (libs->name, 0) ? : (struct Library *) -1;
  119.   while ((++libs)->name);
  120. }
  121.  
  122. void
  123. close_libraries (union lib *libs)
  124. {
  125.   do
  126.     if (libs->base != (struct Library *) -1)
  127.       CloseLibrary (libs->base);
  128.   while ((++libs)->base);
  129. }
  130.  
  131. /* these are the libraries we are potentially interested in. Not finding
  132.    a certain library doesn't mean we can't continue. */
  133. static union lib ix_libs[] = {
  134.   "dos.library",
  135.   "arp.library",
  136.   "intuition.library",
  137.   "graphics.library",
  138.   "mathieeesingbas.library",
  139.   "mathieeedoubbas.library",
  140.   "mathieeedoubtrans.library",
  141.   0,
  142. };
  143. enum { DOS_LIB=0, ARP_LIB, INTUI_LIB, GFX_LIB, SINGB_LIB, DOUBB_LIB, DOUBT_LIB };
  144.  
  145.  
  146. struct ixemul_base *
  147. ix_init (struct ixemul_base *ixbase)
  148. {
  149.   int i;
  150.  
  151.   DP (("ix_init1, ix_init @@$%lx\n", ix_init));
  152.   ixemulbase = ixbase;
  153.   open_libraries (ix_libs);
  154.  
  155.   /* these ones are necessary and are very (!) unlikely to be missing */
  156.   if (   ! (ixbase->ix_dos_base = ix_libs[DOS_LIB].base)
  157.       || ! (ixbase->ix_intui_base = (struct IntuitionBase *) ix_libs[INTUI_LIB].base)
  158.       || ! (ixbase->ix_gfx_base = (struct GfxBase *) ix_libs[GFX_LIB].base))
  159.     {
  160.       close_libraries (ix_libs);
  161.       return 0;
  162.     }
  163.  
  164.   DP(("ix_init2\n"));
  165.   _dos20 = ixbase->ix_dos_base->lib_Version >= 36;
  166.  
  167.   /* arp is only needed for 1.3, but there it's vital */
  168.   if (! (ixbase->ix_arp_base = (struct ArpBase *) ix_libs[ARP_LIB].base) && ! _dos20)
  169.     {
  170.       /* but in that case we have intuition open, and can display a requester
  171.          complaining in more detail than just failing */
  172.       ix_panic ("arp.library required below kick 2.0");
  173.       close_libraries (ix_libs);
  174.       return 0;
  175.     }
  176.  
  177.   DP(("ix_init3\n"));
  178.   /* those are more or less optional, and if not available cause 
  179.      ix_patch_functions() to replace functions that need them by aborting
  180.      functions */
  181.   ixbase->ix_ms_base = 
  182.     MathIeeeSingBasBase = ix_libs[SINGB_LIB].base;
  183.   ixbase->ix_md_base =
  184.     MathIeeeDoubBasBase = ix_libs[DOUBB_LIB].base;
  185.   ixbase->ix_mdt_base =
  186.     MathIeeeDoubTransBase = ix_libs[DOUBT_LIB].base;
  187.  
  188.   ixbase->ix_file_tab = (struct file *)
  189.     AllocMem (NOFILE * sizeof(struct file), MEMF_PUBLIC | MEMF_CLEAR);
  190.   ixbase->ix_fileNFILE = ixbase->ix_file_tab + NOFILE;
  191.   ixbase->ix_lastf = ixbase->ix_file_tab;
  192.   ixbase->ix_red_zone_size = 0; /* not enabled by default */
  193.   ixbase->ix_membuf_limit = 0;
  194.   ixbase->ix_fs_buf_factor = 64;
  195.   ixbase->ix_watch_stack = 0;
  196.   ixbase->ix_translate_dots = 1;
  197.   ixbase->ix_translate_slash = 1;
  198.   ixbase->ix_translate_symlinks = 0;
  199.   ixbase->ix_force_translation = 0;
  200.   ixbase->ix_ignore_global_env = 0;
  201.  
  202.   DP(("ix_init4\n"));
  203.   /* initialize the list structures for the allocator */
  204.   init_buddy ();
  205.  
  206.   DP(("ix_init5\n"));
  207.   /* patch our library to optimally adapt to the given hardware */
  208.   ix_patch_functions (ixbase);
  209.  
  210.   DP(("ix_init6\n"));
  211.   ix_async_mp = (struct MsgPort *) CreateInterruptPort (0, 0, mp_interrupt, 0);
  212.   ix_tty_mp = 0; /* (struct MsgPort *) CreateInterruptPort (0, 0, tty_interrupt, 0);*/
  213.  
  214.   if (ixbase->ix_file_tab && ix_async_mp /* && ix_tty_mp */)
  215.     {
  216.       InitSemaphore (& ixbase->ix_semaph);
  217.  
  218.       configure_context_switch ();
  219.  
  220.       NewList ((struct List *) &ixbase->ix_socket_list);
  221.  
  222.       for (i = 0; i < IX_NUM_SLEEP_QUEUES; i++)
  223.         NewList ((struct List *) &ixbase->ix_sleep_queues[i]);
  224.  
  225.       /* pass the array over to ix_expunge () */
  226.       ixbase->ix_libs = ix_libs;
  227.  
  228.       return ixbase;
  229.     }
  230.         
  231.   if (ix_async_mp)
  232.     DeleteInterruptPort (ix_async_mp);
  233.  
  234.   if (ix_tty_mp)
  235.     DeleteInterruptPort (ix_tty_mp);
  236.  
  237.   if (ixbase->ix_file_tab)
  238.     FreeMem (ixbase->ix_file_tab, NOFILE * sizeof(struct file));
  239.   else
  240.     ix_panic ("out of memory");
  241.  
  242.   close_libraries (ix_libs);
  243.   
  244.   return 0;
  245. }      
  246.  
  247.  
  248. void
  249. ix_lock_base ()
  250. {
  251.   u_save.u_oldmask = u_save.p_sigmask;
  252.   u_save.p_sigmask = ~0;
  253.   ObtainSemaphore (& ix.ix_semaph);
  254. }
  255.  
  256. void
  257. ix_unlock_base ()
  258. {
  259.   ReleaseSemaphore (& ix.ix_semaph);
  260.   u_save.p_sigmask = u_save.u_oldmask;
  261. }
  262. @
  263.  
  264.  
  265. 1.3
  266. log
  267. @initialize buddy allocator
  268. @
  269. text
  270. @d19 1
  271. a19 1
  272.  *  $Id: ix_init.c,v 1.2 1992/05/18 00:49:07 mwild Exp $
  273. d22 3
  274. a34 1
  275. #include <libraries/arpbase.h>
  276. d38 1
  277. a38 1
  278. #undef DEBUG
  279. d52 3
  280. a54 1
  281.      *MathIeeeSingBasBase, *MathIeeeSingTransBase;
  282. d58 46
  283. a103 1
  284. extern int mp_interrupt();
  285. d105 1
  286. d111 37
  287. d152 1
  288. a152 1
  289.   ixbase->ix_red_zone_size = 0;    /* not enabled by default */
  290. d160 1
  291. a160 2
  292.  
  293.   ixemulbase = ixbase;
  294. d162 1
  295. d166 1
  296. d170 1
  297. d172 1
  298. d174 1
  299. a174 1
  300.   if (ixbase->ix_file_tab && ix_async_mp)
  301. d176 13
  302. a188 77
  303.       ixbase->ix_arp_base = 
  304.         (struct ArpBase *) OpenLibrary (ArpName, ArpVersion);
  305.       
  306.       if (ixbase->ix_arp_base)
  307.         {
  308.             /* Arpbase is so kind to provide us with 3 free further libraries ;-) */
  309.           ixbase->ix_dos_base = 
  310.         (struct DOSBase *) ixbase->ix_arp_base->DosBase;
  311.         
  312.       _dos20 = ((struct Library *)ixbase->ix_dos_base)->lib_Version >= 36;
  313.  
  314.       ixbase->ix_intui_base =
  315.         (struct IntuitionBase *) ixbase->ix_arp_base->IntuiBase;
  316.         
  317.       ixbase->ix_gfx_base =
  318.         (struct GfxBase *) ixbase->ix_arp_base->GfxBase;
  319.         
  320.       /* now go for the math-libraries */
  321.       ixbase->ix_ms_base = (struct MathIeeeSingBasBase *) 
  322.             OpenLibrary ("mathieeesingbas.library", 0);
  323.  
  324.       if (ixbase->ix_ms_base)
  325.         {
  326.           ixbase->ix_mst_base = (struct MathIeeeSingTransBase *)
  327.             OpenLibrary ("mathieeesingtrans.library", 0);
  328.             
  329.           if (ixbase->ix_mst_base)
  330.             {
  331.               ixbase->ix_md_base = (struct MathIeeeDoubBasBase *)
  332.                 OpenLibrary ("mathieeedoubbas.library", 0);
  333.  
  334.           if (ixbase->ix_md_base)
  335.             {
  336.               ixbase->ix_mdt_base = (struct MathIeeeDoubTransBase *)
  337.                 OpenLibrary ("mathieeedoubtrans.library", 0);
  338.  
  339.               MathIeeeDoubBasBase = ixbase->ix_md_base;
  340.               MathIeeeSingBasBase = ixbase->ix_ms_base;
  341.               MathIeeeDoubTransBase = ixbase->ix_mdt_base;
  342.               MathIeeeSingTransBase = ixbase->ix_mst_base;
  343.  
  344.               InitSemaphore (& ixbase->ix_semaph);
  345.  
  346.               configure_context_switch ();
  347.  
  348.               NewList ((struct List *) &ixbase->ix_socket_list);
  349.  
  350.               for (i = 0; i < IX_NUM_SLEEP_QUEUES; i++)
  351.                 NewList ((struct List *) &ixbase->ix_sleep_queues[i]);
  352.  
  353.               if (ixbase->ix_mdt_base)
  354.             return ixbase;
  355.  
  356.               ix_panic ("can't open `mathieeedoubtrans.library'");
  357.  
  358.               /* else we have to backup what we obtained */
  359.               CloseLibrary (ixbase->ix_md_base);
  360.             }
  361.           else
  362.             ix_panic ("can't open `mathieeedoubbas.library'");
  363.           
  364.           CloseLibrary (ixbase->ix_mst_base);
  365.         }
  366.           else
  367.               ix_panic ("can't open `mathieeesingtrans.library'");
  368.         
  369.           CloseLibrary (ixbase->ix_ms_base);
  370.         }
  371.       else
  372.         ix_panic ("can't open `mathieeesingbas.library'");
  373.        
  374.       CloseLibrary (ixbase->ix_arp_base);
  375.     }
  376.       else
  377.         ix_panic ("can't open `arp.library'");
  378.     
  379.       FreeMem (ixbase->ix_file_tab, NOFILE * sizeof(struct file));
  380. d190 9
  381. d202 1
  382. a202 5
  383.   if (ixbase->ix_file_tab)
  384.     FreeMem (ixbase->ix_file_tab, NOFILE * sizeof (struct file));
  385.  
  386.   if (ix_async_mp)
  387.     DeleteInterruptPort (ix_async_mp);
  388. d211 2
  389. a212 2
  390.   u.u_oldmask = u.p_sigmask;
  391.   u.p_sigmask = ~0;
  392. d220 1
  393. a220 1
  394.   u.p_sigmask = u.u_oldmask;
  395. @
  396.  
  397.  
  398. 1.2
  399. log
  400. @changed async mp to be global
  401. @
  402. text
  403. @d19 1
  404. a19 1
  405.  *  $Id: ix_init.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  406. d22 3
  407. d75 3
  408. @
  409.  
  410.  
  411. 1.1
  412. log
  413. @Initial revision
  414. @
  415. text
  416. @d18 7
  417. d49 4
  418. d76 3
  419. a78 1
  420.   if (ixbase->ix_file_tab)
  421. d160 6
  422. a176 1
  423.   u.p_sigmask = u.p_sigmask;
  424. @
  425.