home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / amiga / normal / okstartup_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  2.4 KB  |  102 lines

  1. /* Startup_c.c */
  2. /* Thu Jun 24 18:05:36 1993 GM TabSize=4
  3.    additional startup code, C part
  4.  
  5.    No Bugs known
  6.  
  7.    Does not handle commandline-parsing,
  8.  
  9.    CLI: argc gets d0 (len) and argv a0 (arguements)
  10.  
  11.    WB : argc gets 0, argv ptr to WBStartupMessage.
  12.         No window is opened,  _stdin and _stdout get zero. Test for this !
  13.  
  14.    Thu Sep 23 18:19:55 1993 GM: cleanup
  15. */
  16.  
  17. #include <exec/types.h>
  18. #include <exec/libraries.h>
  19. #include <exec/execbase.h>
  20. #include <libraries/dosextens.h>
  21. #include <dos/dos.h>
  22. #include <inline/exec.h>
  23. #include <inline/dos.h>
  24. #include <workbench/startup.h>
  25.  
  26. extern struct ExecBase *SysBase;
  27. extern struct WBStartup    *WBenchMsg;
  28.  
  29. extern int main(ULONG,ULONG);
  30.  
  31. /* called by assember-startup-code */
  32.  
  33. int _main(UBYTE *reg_a0, ULONG reg_d0)
  34. {
  35.   struct Process    *me        = (struct Process *) SysBase->ThisTask;
  36.   int                exit_val;
  37.  
  38.   /*
  39.    * The following code to reset the fpu might not be necessary, BUT since
  40.    * a CLI shell doesn't spawn a new process when executing a command - it
  41.    * insteads calls the command like a subroutine - it depends on the Shell
  42.    * whether the fpu is setup correctly. And I don't like to depend on any
  43.    * thing ;-)
  44.    */
  45.  
  46.   if (SysBase->AttnFlags & AFF_68881)
  47.     /* reset fpu into a defined state */
  48.     asm volatile ("
  49.     moveml    a5/a6,sp@-
  50.     lea    pc@(Lreset_fpu),a5
  51.     addl    #2,a5        | needed due to a bug in as
  52.                         | or:    lea    pc@(Lreset_fpu-.+2),a5
  53.     movel    4:w,a6
  54.     jsr    a6@(-30)        | Supervisor()
  55.     bra    Lafter_reset_fpu
  56.  
  57. Lreset_fpu:
  58.     clrl    sp@-
  59.     frestore sp@+
  60.     rte
  61.  
  62. Lafter_reset_fpu:
  63.     moveml    sp@+,a5/a6");
  64.  
  65.   /* first deal with WB messages, since those HAVE to be answered properly,
  66.    * even if we should fail later (memory, whatever..) */
  67.  
  68.   if (! me->pr_CLI)
  69.   {
  70.       /* we have been started by Workbench. Get the StartupMsg */
  71.  
  72.       WaitPort (& me->pr_MsgPort);
  73.       WBenchMsg = (struct WBStartup *) GetMsg (& me->pr_MsgPort);
  74.  
  75.       /* Workbench programs expect to have their CD where the executed
  76.        * program lives. */
  77.  
  78.       if (WBenchMsg->sm_ArgList)
  79.         {
  80.           CurrentDir (WBenchMsg->sm_ArgList->wa_Lock);
  81.         }
  82.  
  83.       /* argc==0: this means, that argv is really a WBenchMsg, not a vector */
  84.  
  85.         exit_val=main(0L, (ULONG)WBenchMsg);
  86.     }
  87.     else
  88.     {
  89.         /* We have a CLI-Start here. Since we don't want to blow up
  90.             the startup, the original d0/a0 values are passed to main.
  91.             There further things have to be done if necessary */
  92.  
  93.         exit_val=main(reg_d0, (ULONG)reg_a0);
  94.     }
  95.  
  96.  
  97.     /* exit is called by the caller */
  98.  
  99.   return exit_val;
  100. }
  101.  
  102.