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

  1. head    1.3;
  2. access;
  3. symbols
  4.     version39-41:1.2;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.3
  10. date    92.08.09.20.55.51;    author amiga;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    92.07.04.19.18.21;    author mwild;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    92.05.14.19.55.40;    author mwild;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @startup code for programs invoked by standard shells (commandline parsing)
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @import sysbase
  33. @
  34. text
  35. @/*
  36.  *  This file is part of ixemul.library for the Amiga.
  37.  *  Copyright (C) 1991, 1992  Markus M. Wild
  38.  *
  39.  *  This library is free software; you can redistribute it and/or
  40.  *  modify it under the terms of the GNU Library General Public
  41.  *  License as published by the Free Software Foundation; either
  42.  *  version 2 of the License, or (at your option) any later version.
  43.  *
  44.  *  This library is distributed in the hope that it will be useful,
  45.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  46.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  47.  *  Library General Public License for more details.
  48.  *
  49.  *  You should have received a copy of the GNU Library General Public
  50.  *  License along with this library; if not, write to the Free
  51.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52.  *
  53.  *  $Id: ix_startup.c,v 1.2 1992/07/04 19:18:21 mwild Exp $
  54.  *
  55.  *  $Log: ix_startup.c,v $
  56.  *  Revision 1.2  1992/07/04  19:18:21  mwild
  57.  *  remove SIGWINCH handler before returning
  58.  *
  59.  * Revision 1.1  1992/05/14  19:55:40  mwild
  60.  * Initial revision
  61.  *
  62.  */
  63.  
  64. #define KERNEL
  65. #include "ixemul.h"
  66.  
  67. #ifdef DEBUG
  68. #define DP(a) kprintf a
  69. #else
  70. #define DP(a)
  71. #endif
  72.  
  73. #define exit_buf u.u_jmp_buf
  74. extern struct ExecBase *SysBase;
  75.  
  76. /*
  77.  * Note: I kept the partition into startup and _main(), although in this
  78.  *       case, both functions could be done in one function, since this is
  79.  *       a library, and the user can't override _main anyway but globally...
  80.  */
  81.  
  82. int
  83. ix_startup (char *aline, int alen,
  84.         int expand, char *wb_default_window, u_int main, int *real_errno)
  85. {
  86.   struct Process    *me        = (struct Process *) SysBase->ThisTask;
  87.   int            exit_val;
  88.   struct WBStartup    *wb_msg;
  89.  
  90.   /*
  91.    * The following code to reset the fpu might not be necessary, BUT since
  92.    * a CLI shell doesn't spawn a new process when executing a command - it 
  93.    * insteads calls the command like a subroutine - it depends on the Shell
  94.    * whether the fpu is setup correctly. And I don't like to depend on any
  95.    * thing ;-)
  96.    */
  97.  
  98.   if (SysBase->AttnFlags & AFF_68881)
  99.     /* reset fpu into a defined state */
  100.     asm volatile ("
  101.     moveml    a5/a6,sp@@-
  102.     lea    pc@@(Lreset_fpu-.+2),a5
  103.     movel    4:w,a6
  104.     jsr    a6@@(-30)        | Supervisor()
  105.     bra    Lafter_reset_fpu
  106.  
  107. Lreset_fpu:
  108.     clrl    sp@@-
  109.     frestore sp@@+
  110.     rte
  111.  
  112. Lafter_reset_fpu:
  113.     moveml    sp@@+,a5/a6");
  114.  
  115.   /* first deal with WB messages, since those HAVE to be answered properly,
  116.    * even if we should fail later (memory, whatever..) */
  117.  
  118.   if (! me->pr_CLI)
  119.     {
  120.       /* we have been started by Workbench. Get the StartupMsg */
  121.       WaitPort (& me->pr_MsgPort);
  122.       wb_msg = (struct WBStartup *) GetMsg (& me->pr_MsgPort);
  123.       /* further processing in _main () */
  124.     }
  125.   else
  126.     {
  127.       /* for usage by sys_exit() for example */
  128.       u.u_argline = aline;
  129.       u.u_arglinelen = alen;
  130.     }
  131.   
  132.   u.u_expand_cmd_line = expand;
  133.   if (real_errno) u.u_errno = real_errno;
  134.  
  135. DP(("ix_startup(start): sp = $%lx\n",({int res;asm("movel sp,%0" : "=g" (res));res;})));
  136.  
  137.   exit_val = setjmp (exit_buf);
  138.  
  139.   if (! exit_val)
  140.     {
  141.       /* from now on it's save to allow signals */
  142.       syscall (SYS_sigsetmask, 0);
  143.  
  144.       /* the first time thru call the program */
  145.       exit_val = me->pr_CLI ? syscall (SYS__main, aline, alen, main)
  146.                 : syscall (SYS__main, wb_msg, wb_default_window, main);
  147.     }
  148.   else
  149.     /* in this case we came from a longjmp-call */
  150.     exit_val --;
  151.  
  152.   ix_remove_sigwinch ();
  153.  
  154.   /* if started from workbench, Forbid(), since on reply WB will deallocate
  155.    * our task... */
  156.   if (! me->pr_CLI)
  157.     {
  158.       Forbid ();
  159.       ReplyMsg ((struct Message *) wb_msg);
  160.     }
  161.  
  162. DP(("ix_startup(end): sp = $%lx\n",({int res;asm("movel sp,%0" : "=g" (res));res;})));
  163.  
  164.   return exit_val;
  165. }
  166.  
  167. /* this just jumps right back into ix_startup() */
  168. void
  169. _exit (int retcode)
  170. {
  171.   longjmp (exit_buf, retcode + 1);
  172. }
  173. @
  174.  
  175.  
  176. 1.2
  177. log
  178. @remove SIGWINCH handler before returning
  179. @
  180. text
  181. @d19 1
  182. a19 1
  183.  *  $Id: ix_startup.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  184. d22 3
  185. d40 1
  186. a51 1
  187.   struct ExecBase     *SysBase    = *(void **)4;
  188. @
  189.  
  190.  
  191. 1.1
  192. log
  193. @Initial revision
  194. @
  195. text
  196. @d19 1
  197. a19 1
  198.  *  $Id$
  199. d21 4
  200. a24 1
  201.  *  $Log$
  202. d114 2
  203. @
  204.