head	1.3;
access;
symbols
	version39-41:1.2;
locks;
comment	@ *  @;


1.3
date	92.08.09.20.47.19;	author amiga;	state Exp;
branches;
next	1.2;

1.2
date	92.07.04.19.13.42;	author mwild;	state Exp;
branches;
next	1.1;

1.1
date	92.05.14.19.55.40;	author mwild;	state Exp;
branches;
next	;


desc
@startup function for programs invoked by an ixemul shell
@


1.3
log
@call main thru exit, or no atexit handlers will be called!
@
text
@/*
 *  This file is part of ixemul.library for the Amiga.
 *  Copyright (C) 1991, 1992  Markus M. Wild
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Id: ix_exec_entry.c,v 1.2 1992/07/04 19:13:42 mwild Exp $
 *
 *  $Log: ix_exec_entry.c,v $
 *  Revision 1.2  1992/07/04  19:13:42  mwild
 *  add SIGWINCH handler installation/removal
 *
 * Revision 1.1  1992/05/14  19:55:40  mwild
 * Initial revision
 *
 */

#define KERNEL
#include "ixemul.h"

#ifdef DEBUG
#define DP(a) kprintf a
#else
#define DP(a)
#endif

#define exit_buf u.u_jmp_buf
extern struct ExecBase 	*SysBase;

int
ix_exec_entry (int argc, char **argv, char **environ, int *real_errno, 
	       int (*main)(int, char **, char **))
{
  struct Process	*me		= (struct Process *) SysBase->ThisTask;
  int			exit_val;

  /* we're coming from another process here, either after vfork() or from a
   * process that wants to `replace' itself with this program. Thus the fpu
   * is probably already initialized to some bogous state. That's why we
   * HAVE to restore it into a default state here. */

  if (SysBase->AttnFlags & AFF_68881)
    /* reset fpu into a defined state */
    asm volatile ("
	moveml	a5/a6,sp@@-
	lea	pc@@(Lreset_fpu-.+2),a5
	movel	4:w,a6
	jsr	a6@@(-30)		| Supervisor()
	bra	Lafter_reset_fpu

Lreset_fpu:
	clrl	sp@@-
	frestore sp@@+
	rte

Lafter_reset_fpu:
	moveml	sp@@+,a5/a6");


DP(("ix_exec_entry: argc = %ld, argv = $%lx\n", argc, argv));

  /* a program started by ix_exec_entry() must have some ix'like shell
     around, that takes care of printing exit-states, so don't print them
     again in sig_exit() */
  u.u_argline = 0;
  u.u_arglinelen = 0;
  
  if (real_errno) u.u_errno = real_errno;

  exit_val = setjmp (exit_buf);

  if (! exit_val)
    {
      /* install the signal mask that was active before execve() was called */
      syscall (SYS_sigsetmask, u.u_oldmask);

      /* this is not really the right thing to do, the user should call
         ix_get_vars2 () to initialize environ to the address of the variable
         in the calling program. However, this setting guarantees that 
         the user area entry is valid for getenv() calls. */
      u.u_environ = &environ;

      ix_install_sigwinch ();

      /* the first time thru call the program */
      exit (main (argc, argv, environ));
      /* not reached! */
    }
  else
    /* in this case we came from a longjmp-call */
    exit_val --;

  ix_remove_sigwinch ();

DP(("ix_exec_entry(end): sp = $%lx\n",({int res;asm("movel sp,%0" : "=g" (res));res;})));

  return exit_val;
}
@


1.2
log
@add SIGWINCH handler installation/removal
@
text
@d19 1
a19 1
 *  $Id: ix_exec_entry.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
d22 3
d40 1
a45 1
  struct ExecBase 	*SysBase	= *(void **)4;
d98 2
a99 1
      exit_val = main (argc, argv, environ);
@


1.1
log
@Initial revision
@
text
@d19 1
a19 1
 *  $Id$
d21 4
a24 1
 *  $Log$
d71 4
a74 2
  /* for usage by sys_exit() for example */
  u.u_argline = (char *) argv;
d92 2
d100 2
@
