home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_exec_entry.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  4.0 KB  |  184 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.47.19;    author amiga;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    92.07.04.19.13.42;    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 function for programs invoked by an ixemul shell
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @call main thru exit, or no atexit handlers will be called!
  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_exec_entry.c,v 1.2 1992/07/04 19:13:42 mwild Exp $
  54.  *
  55.  *  $Log: ix_exec_entry.c,v $
  56.  *  Revision 1.2  1992/07/04  19:13:42  mwild
  57.  *  add SIGWINCH handler installation/removal
  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. int
  77. ix_exec_entry (int argc, char **argv, char **environ, int *real_errno, 
  78.            int (*main)(int, char **, char **))
  79. {
  80.   struct Process    *me        = (struct Process *) SysBase->ThisTask;
  81.   int            exit_val;
  82.  
  83.   /* we're coming from another process here, either after vfork() or from a
  84.    * process that wants to `replace' itself with this program. Thus the fpu
  85.    * is probably already initialized to some bogous state. That's why we
  86.    * HAVE to restore it into a default state here. */
  87.  
  88.   if (SysBase->AttnFlags & AFF_68881)
  89.     /* reset fpu into a defined state */
  90.     asm volatile ("
  91.     moveml    a5/a6,sp@@-
  92.     lea    pc@@(Lreset_fpu-.+2),a5
  93.     movel    4:w,a6
  94.     jsr    a6@@(-30)        | Supervisor()
  95.     bra    Lafter_reset_fpu
  96.  
  97. Lreset_fpu:
  98.     clrl    sp@@-
  99.     frestore sp@@+
  100.     rte
  101.  
  102. Lafter_reset_fpu:
  103.     moveml    sp@@+,a5/a6");
  104.  
  105.  
  106. DP(("ix_exec_entry: argc = %ld, argv = $%lx\n", argc, argv));
  107.  
  108.   /* a program started by ix_exec_entry() must have some ix'like shell
  109.      around, that takes care of printing exit-states, so don't print them
  110.      again in sig_exit() */
  111.   u.u_argline = 0;
  112.   u.u_arglinelen = 0;
  113.   
  114.   if (real_errno) u.u_errno = real_errno;
  115.  
  116.   exit_val = setjmp (exit_buf);
  117.  
  118.   if (! exit_val)
  119.     {
  120.       /* install the signal mask that was active before execve() was called */
  121.       syscall (SYS_sigsetmask, u.u_oldmask);
  122.  
  123.       /* this is not really the right thing to do, the user should call
  124.          ix_get_vars2 () to initialize environ to the address of the variable
  125.          in the calling program. However, this setting guarantees that 
  126.          the user area entry is valid for getenv() calls. */
  127.       u.u_environ = &environ;
  128.  
  129.       ix_install_sigwinch ();
  130.  
  131.       /* the first time thru call the program */
  132.       exit (main (argc, argv, environ));
  133.       /* not reached! */
  134.     }
  135.   else
  136.     /* in this case we came from a longjmp-call */
  137.     exit_val --;
  138.  
  139.   ix_remove_sigwinch ();
  140.  
  141. DP(("ix_exec_entry(end): sp = $%lx\n",({int res;asm("movel sp,%0" : "=g" (res));res;})));
  142.  
  143.   return exit_val;
  144. }
  145. @
  146.  
  147.  
  148. 1.2
  149. log
  150. @add SIGWINCH handler installation/removal
  151. @
  152. text
  153. @d19 1
  154. a19 1
  155.  *  $Id: ix_exec_entry.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  156. d22 3
  157. d40 1
  158. a45 1
  159.   struct ExecBase     *SysBase    = *(void **)4;
  160. d98 2
  161. a99 1
  162.       exit_val = main (argc, argv, environ);
  163. @
  164.  
  165.  
  166. 1.1
  167. log
  168. @Initial revision
  169. @
  170. text
  171. @d19 1
  172. a19 1
  173.  *  $Id$
  174. d21 4
  175. a24 1
  176.  *  $Log$
  177. d71 4
  178. a74 2
  179.   /* for usage by sys_exit() for example */
  180.   u.u_argline = (char *) argv;
  181. d92 2
  182. d100 2
  183. @
  184.