home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_open.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  8.3 KB  |  333 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.53.36;    author amiga;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    92.05.20.01.31.30;    author mwild;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    92.05.18.12.20.27;    author mwild;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    92.05.14.19.55.40;    author mwild;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @open function of library
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @clean up
  38. @
  39. text
  40. @/*
  41.  *  This file is part of ixemul.library for the Amiga.
  42.  *  Copyright (C) 1991, 1992  Markus M. Wild
  43.  *
  44.  *  This library is free software; you can redistribute it and/or
  45.  *  modify it under the terms of the GNU Library General Public
  46.  *  License as published by the Free Software Foundation; either
  47.  *  version 2 of the License, or (at your option) any later version.
  48.  *
  49.  *  This library is distributed in the hope that it will be useful,
  50.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  51.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  52.  *  Library General Public License for more details.
  53.  *
  54.  *  You should have received a copy of the GNU Library General Public
  55.  *  License along with this library; if not, write to the Free
  56.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  57.  *
  58.  *  $Id: ix_open.c,v 1.3 1992/05/20 01:31:30 mwild Exp $
  59.  *
  60.  *  $Log: ix_open.c,v $
  61.  *  Revision 1.3  1992/05/20  01:31:30  mwild
  62.  *  move atexit(_cleanup) into ix_get_vars2 after stdio initialisation
  63.  *
  64.  * Revision 1.2  1992/05/18  12:20:27  mwild
  65.  * change async mp to be global
  66.  *
  67.  * Revision 1.1  1992/05/14  19:55:40  mwild
  68.  * Initial revision
  69.  *
  70.  */
  71.  
  72. #define KERNEL
  73. #include "ixemul.h"
  74. #undef u
  75. #include <hardware/intbits.h>
  76.  
  77. #include <exec/memory.h>
  78. #define BASE_EXT_DECL
  79. #define BASE_PAR_DECL    struct ixemul_base *ixbase,
  80. #define BASE_PAR_DECL0    struct ixemul_base *ixbase
  81. #define BASE_NAME    ixbase->ix_intui_base
  82. #include <inline/intuition.h>
  83.  
  84. /* #undef DEBUG */
  85.  
  86. #ifdef DEBUG
  87. #define DP(a) kprintf a
  88. #else
  89. #define DP(a)
  90. #endif
  91.  
  92. extern void trap_20 (), trap_00 (), launch_glue (), switch_glue ();
  93. extern int ix_timer();
  94. extern void mp_interrupt ();
  95. extern int _dos20;
  96. extern struct ExecBase *SysBase;
  97.  
  98. struct ixemul_base *
  99. ix_open (struct ixemul_base *ixbase)
  100. {
  101.   /* here we must initialize our `user' structure */
  102.   struct user *u;
  103.   /* an errno for those that later don't set it in ix_startup() */
  104.   static int default_errno;
  105.   struct Task *me;
  106.   
  107.   me = SysBase->ThisTask;
  108.  
  109.   DP(("ix_open1\n"));
  110.   u = (struct user *) kmalloc (sizeof (struct user));
  111.   DP(("ix_open2\n"));
  112.   if (u)  
  113.     {
  114.       curproc = u;
  115.  
  116.       /* bzero is safe, ie. doesn't need to reference struct user */
  117.       bzero (u, sizeof (struct user));
  118.  
  119.       /* remember old state */
  120.       u->u_otask_flags = me->tc_Flags;
  121.       u->u_olaunch     = me->tc_Launch;
  122.       u->u_oswitch     = me->tc_Switch;
  123.       u->u_otrap_code  = me->tc_TrapCode;
  124.       u->u_otrap_data  = me->tc_TrapData;
  125.       
  126.       NewList ((struct List *) & u->u_md.md_list);
  127.  
  128.       DP(("ix_open: curproc = $%lx, ix_open @@$lx\n", curproc, ix_open));
  129.  
  130.       me->tc_TrapData  = (APTR) u;
  131.       me->tc_TrapCode  = (APTR) ((SysBase->AttnFlags & AFF_68020) ? 
  132.                            trap_20 : trap_00);
  133.  
  134. #if 0
  135. DP(("ix_open: flags = $%lx, launch = $%lx, code = $%lx, data = $%lx\n",
  136.    u->u_otask_flags, u->u_olaunch, u->u_otrap_code, u->u_otrap_data));
  137.  
  138.  
  139. DP(("SysBase->TDNestCnt = %ld, SysBase->IDNestCnt = %ld\n",
  140.     SysBase->TDNestCnt, SysBase->IDNestCnt));
  141. #endif
  142.  
  143.       /* setup the p_sigignore mask correctly */
  144.       siginit (u);
  145.       me->tc_SigRecvd &= 0x0fff;
  146.  
  147.       /* this library is a replacement for any c-library, thus we should be
  148.        * started at the START of a program, and out of 16 available signals 
  149.        * this calls has to simply succeed... I know I'm a lazy guy ;-) */
  150.       u->u_sleep_sig   = AllocSignal (-1);
  151.  
  152.       me->tc_Launch    = launch_glue;
  153.       me->tc_Switch    = switch_glue;
  154.       me->tc_Flags    |= TF_LAUNCH | TF_SWITCH;
  155.       
  156.       u->u_itimerint.is_Node.ln_Type = NT_INTERRUPT;
  157.       u->u_itimerint.is_Node.ln_Name = me->tc_Node.ln_Name;
  158.       u->u_itimerint.is_Node.ln_Pri  = 1;
  159.       u->u_itimerint.is_Data         = (APTR) me;
  160.       u->u_itimerint.is_Code         = (APTR) ix_timer;
  161.       AddIntServer (INTB_VERTB, & u->u_itimerint);
  162. #if later
  163. #endif
  164.  
  165. #ifdef DEBUG
  166. /*      reset_watchdog();*/
  167. #endif
  168.  
  169.       u->u_trace_flags = 1;
  170.       u->u_ixbase = ixbase;
  171.       u->u_errno = &default_errno;
  172. #if 0
  173.       /* move this into a library global place. Since this port is used by
  174.          multiple processes, and since it's not tied to a task specific
  175.          signal, it should be library global */
  176.       u->u_async_mp = (struct MsgPort *) CreateInterruptPort (0, 0, mp_interrupt, 0);
  177. #endif
  178.       u->u_sync_mp = (struct MsgPort *) syscall (SYS_CreatePort, 0, 0);
  179.       /* the CD storage. since 0 is a valid value for a lock, we use -1 */
  180.       u->u_startup_cd = (BPTR)-1;
  181.  
  182.       /* support for subprocesses ala Unix */
  183.  
  184.       /* each process starts out to be in its own process group. vfork()
  185.        * scribbles over this to inherit the parents process group instead */
  186.       u->p_pgrp = (int) me;
  187.       u->p_pptr = (struct Process *) 1;        /* hi init ;-)) */
  188.       u->p_cptr =
  189.         u->p_osptr =
  190.           u->p_ysptr = 0;            /* no children to start with */
  191.       u->p_vfork_msg = 0;
  192.       u->p_zombie_sig = AllocSignal (-1);
  193.       NewList ((struct List *) &u->p_zombies);
  194.  
  195.       if (/* u->u_async_mp && */ u->u_sync_mp)
  196.         {
  197.           u->u_time_req = (struct timerequest *)
  198.         syscall (SYS_CreateExtIO, u->u_sync_mp, sizeof (struct timerequest));
  199.       
  200.       if (u->u_time_req)
  201.         {
  202.           if (!OpenDevice (TIMERNAME, UNIT_MICROHZ,
  203.                          (struct IORequest *) u->u_time_req, 0))
  204.             {
  205.           syscall (SYS_gettimeofday, &u->u_start, 0);
  206.  
  207.           /* have to mask out ALL signals until ix_startup has had a
  208.            * chance to setup its exit jmp_buf. If not, _longjmp will
  209.            * generate a longjmp-botch using a not initialized jmpbuf! */
  210.           syscall (SYS_sigsetmask, ~0);
  211.  
  212.           /* if enabled, set the red zone pointer for stack watch */
  213.           if (ixbase->ix_red_zone_size)
  214.             {
  215.               struct Process *mep = (struct Process *) me;
  216.               struct CommandLineInterface *CLI = BTOCPTR (mep->pr_CLI);
  217.               u_int stack_size = CLI ? CLI->cli_DefaultStack * 4 : mep->pr_StackSize;
  218.  
  219.               /* I guess the above approach to find the correct stack
  220.                  size will work most of the time. But using tc_Lower
  221.                  as lower bound would probably not work. Thus I'm using
  222.                  the current stack value, not the unknown `real' top stack
  223.              as top and subtract the stack_size to get to the bottom */
  224.  
  225.               if (stack_size > ixbase->ix_red_zone_size)
  226.                 u->u_red_zone = (void *)(get_sp () - stack_size 
  227.                              + ixbase->ix_red_zone_size);
  228.             }
  229.  
  230.           return ixbase;
  231.         }
  232.           /* couldn't open the timer device */
  233.           syscall (SYS_DeleteExtIO, u->u_time_req);
  234.         }
  235.         }
  236.  
  237.       if (u->u_sync_mp)
  238.         syscall (SYS_DeletePort, u->u_sync_mp);
  239. #if 0
  240.       if (u->u_async_mp)
  241.         DeleteInterruptPort (u->u_async_mp);
  242. #endif
  243.  
  244.       RemIntServer (INTB_VERTB, & u->u_itimerint);
  245.       me->tc_Flags    = u->u_otask_flags;
  246.       me->tc_Launch   = u->u_olaunch;
  247.       FreeSignal (u->u_sleep_sig);
  248.  
  249.       /* all_free() MUST come before we remove the pointer to u */
  250.       all_free ();
  251.       me->tc_TrapCode = u->u_otrap_code;
  252.       me->tc_TrapData = u->u_otrap_data;
  253.  
  254.       kfree (u);
  255.     }
  256.  
  257.   return 0;
  258. }
  259. @
  260.  
  261.  
  262. 1.3
  263. log
  264. @move atexit(_cleanup) into ix_get_vars2 after stdio initialisation
  265. @
  266. text
  267. @d19 1
  268. a19 1
  269.  *  $Id: ix_open.c,v 1.2 1992/05/18 12:20:27 mwild Exp $
  270. d22 3
  271. d57 1
  272. a65 1
  273.   int wb_started;
  274. a66 1
  275.   struct ExecBase *SysBase;
  276. a67 5
  277.   /* remember whether we were started by Workbench.
  278.    * NOTE: you need to call ix_startup() to get all wb-startup things running
  279.    *       ok!
  280.    */
  281.   SysBase = *(struct ExecBase **)4;
  282. a68 1
  283.   wb_started = ! ((struct Process *)me)->pr_CLI;
  284. d70 1
  285. d72 1
  286. d75 2
  287. d89 2
  288. d127 1
  289. a127 1
  290.       reset_watchdog();
  291. @
  292.  
  293.  
  294. 1.2
  295. log
  296. @change async mp to be global
  297. @
  298. text
  299. @d19 1
  300. a19 1
  301.  *  $Id: ix_open.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  302. d22 3
  303. a52 1
  304. extern void _cleanup ();
  305. a164 3
  306.  
  307.           /* make sure all stdio buffers are flushed on exit() */
  308.           atexit (_cleanup);
  309. @
  310.  
  311.  
  312. 1.1
  313. log
  314. @Initial revision
  315. @
  316. text
  317. @d19 1
  318. a19 1
  319.  *  $Id$
  320. d21 4
  321. a24 1
  322.  *  $Log$
  323. d129 4
  324. d134 1
  325. d152 1
  326. a152 1
  327.       if (u->u_async_mp && u->u_sync_mp)
  328. d198 2
  329. a199 1
  330.         syscall (SYS_DeletePort, u->u_async_mp);
  331. d202 1
  332. @
  333.