home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / pgp_mip / pgpsendmail / source / rcs / c.asm,v next >
Encoding:
Text File  |  1993-10-12  |  44.4 KB  |  1,361 lines

  1. head    1.6;
  2. access;
  3. symbols;
  4. locks
  5.         simons:1.6; strict;
  6. comment @ * @;
  7.  
  8.  
  9. 1.6
  10. date    93.09.14.23.13.22;      author simons;  state Stab;
  11. branches;
  12. next    1.5;
  13.  
  14. 1.5
  15. date    93.09.14.22.24.41;      author simons;  state Exp;
  16. branches;
  17. next    1.4;
  18.  
  19. 1.4
  20. date    93.09.14.22.16.07;      author simons;  state Exp;
  21. branches;
  22. next    1.3;
  23.  
  24. 1.3
  25. date    93.09.14.21.58.36;      author simons;  state Exp;
  26. branches;
  27. next    1.2;
  28.  
  29. 1.2
  30. date    93.09.14.20.20.03;      author simons;  state Exp;
  31. branches;
  32. next    1.1;
  33.  
  34. 1.1
  35. date    93.09.14.20.18.32;      author simons;  state Exp;
  36. branches;
  37. next    ;
  38.  
  39.  
  40. desc
  41. @This is a replacement for the standard startup module, usually
  42. linked to C programs. This one is modified to fit better with
  43. my _main().
  44. @
  45.  
  46.  
  47. 1.6
  48. log
  49. @Startup code crashed the machine when the command was started without
  50. parameters.
  51. @
  52. text
  53. @**
  54. **      $Filename: c.asm $
  55. **      $Revision: 1.5 $
  56. **      $Date: 1993/09/14 22:24:41 $
  57. **
  58. **      This is a replacement for the standard startup module, usually
  59. **      linked to C programs. This one is modified to fit better with
  60. **      my _main().
  61. **
  62. **      © Copyright 1993 Peter Simons, Germany
  63. **        All Rights Reserved
  64. **
  65. **      $Id: c.asm,v 1.5 1993/09/14 22:24:41 simons Exp simons $
  66. **
  67. ** ------------------------------ log history -----------------------------
  68. ** $Log: c.asm,v $
  69. ** Revision 1.5  1993/09/14  22:24:41  simons
  70. ** Deleted some Workbench related code to make the startup more efficient.
  71. **
  72. ** Revision 1.4  1993/09/14  22:16:07  simons
  73. ** If started from Workbench, the startup-code returns immediatly.
  74. **
  75. ** Revision 1.3  1993/09/14  21:58:36  simons
  76. ** The pseudo opcode EVEN is unknown to asm, replaced it.
  77. ** Changed the line-parameter for _main() to the shell commandline
  78. ** without programname and the terminating return, for usage with my
  79. ** modified __main().
  80. **
  81. ** Revision 1.2  1993/09/14  20:20:03  simons
  82. ** Added RCSId string.
  83. **
  84. ** Revision 1.1  1993/09/14  20:18:32  simons
  85. ** Initial revision
  86. **
  87. ** --------------------------------- flags --------------------------------
  88. ** Use the following command line to make c.o
  89. ** asm -u -isc:Assembler_Include/ c.a
  90. **
  91. ** Use the following command line to make cres.o
  92. ** asm -u -isc:Assembler_Include/ -dRESIDENT -ocres.o c.a
  93. **
  94. ** Use the following command line to make catch.o (standard GURU catcher)
  95. ** asm -u -isc:Assembler_Include/ -dCATCH -ocatch.o c.a
  96. **
  97. ** Use the following command line to make catchnr.o (GURU catcher w/out requester)
  98. ** asm -u -isc:Assembler_Include/ -dCATCH -dNOREQ -ocatchnr.o c.a
  99. **
  100. ** Use the following command line to make catchres.o (resident GURU catcher)
  101. ** asm -u -isc:Assembler_Include/ -dCATCH -dRESIDENT -ocatchres.o c.a
  102. **
  103. ** Use the following command line to make catchresnr.o (resi GURU catcher w/out req)
  104. ** asm -u -isc:Assembler_Include/ -dCATCH -dRESIDENT -dNOREQ -ocatchresnr.o c.a
  105. **
  106.  
  107.         IFD  CATCH
  108.           IFND NOREQ
  109. AUTOREQ         set        1
  110.           ENDC
  111.         ENDC
  112.  
  113.         INCLUDE        "exec/types.i"
  114.         INCLUDE        "exec/alerts.i"
  115.         INCLUDE        "exec/nodes.i"
  116.         INCLUDE        "exec/lists.i"
  117.         INCLUDE        "exec/ports.i"
  118.         INCLUDE        "exec/libraries.i"
  119.         INCLUDE        "exec/tasks.i"
  120.         INCLUDE        "exec/memory.i"
  121.         INCLUDE        "exec/execbase.i"
  122.         INCLUDE        "libraries/dos.i"
  123.         INCLUDE        "libraries/dosextens.i"
  124.         INCLUDE        "workbench/startup.i"
  125.         INCLUDE        "Offsets.i"
  126.  
  127.         IFD   CATCH
  128.         INCLUDE        "intuition/intuition.i"
  129. VERSION  equ    1
  130. REVISION equ    0
  131.         ENDC
  132.  
  133. MEMFLAGS        EQU        MEMF_CLEAR+MEMF_PUBLIC
  134. AbsExecBase     EQU        4
  135.  
  136. ;;;
  137. ;;;   Stack map.
  138. ;;;
  139.       OFFSET  0
  140.            ds.b    4
  141. savereg    ds.b    13*4
  142. stackbtm   ds.b    4
  143.  
  144.  
  145.  
  146. ; some usefull macros:
  147.  
  148. callsys macro
  149.         CALLLIB _LVO\1
  150.         endm
  151.  
  152.         xdef        _XCEXIT                * exit(code) is standard way to leave C.
  153.         xdef        @@_XCEXIT
  154.  
  155.         xref        LinkerDB        * linker defined base value
  156.         xref        _BSSBAS                * linker defined base of BSS
  157.         xref        _BSSLEN                * linker defined length of BSS
  158.         xref        __stack
  159.  
  160.        IFD          RESIDENT
  161.         xref        RESLEN
  162.         xref        RESBASE
  163.         xref        NEWDATAL
  164.        ENDC
  165.  
  166. *       library references
  167.  
  168.         section text,code
  169.  
  170.         xref    __main                  * Name of C program to start with.
  171.         xref    _MemCleanup             * Free all allocated memory
  172.         xref    __fpinit                * initialize floating point
  173.         xref    __fpterm                * terminate floating point
  174.  
  175. start:
  176.         movem.l d1-d6/a0-a6,-(a7)       * save registers
  177.  
  178.         move.l  a0,a2                   * save command pointer
  179.         move.l  d0,d2                   * and command length
  180.         lea     LinkerDB,a4             * load base register
  181.         move.l  AbsExecBase.W,a6
  182.  
  183. *---------- check if started from CLI
  184.                 move.l  ThisTask(a6),A3
  185.                 tst.l   pr_CLI(A3)
  186.                 bne.s   fromcli
  187.                 movem.l (SP)+,d1-d6/a0-a6
  188.                 rts
  189. fromcli:
  190.  
  191.         IFND        RESIDENT
  192.         lea     _BSSBAS,a3              * get base of BSS
  193.         moveq   #0,d1
  194.         move.l  #_BSSLEN,d0             * get length of BSS in longwords
  195.         bra.s   clr_lp                  * and clear for length given
  196. clr_bss move.l  d1,(a3)+
  197. clr_lp  dbf     d0,clr_bss
  198.         move.l  a7,_StackPtr(A4)        * Save stack ptr
  199.         move.l  a6,SysBase(A4)
  200.  
  201. *------ get the size of the stack, if CLI use cli_DefaultStack
  202.         move.l        ThisTask(a6),A3
  203.         move.l        pr_CLI(A3),d0
  204.         lsl.l         #2,d0
  205.         move.l        d0,a0
  206.         move.l        cli_DefaultStack(a0),d0
  207.         lsl.l         #2,d0              * # longwords -> # bytes
  208.  
  209. *------ Set __base for stack checking
  210.         move.l       a7,d1
  211.         sub.l        d0,d1               * get top of stack
  212.         add.l        #128,D1             * allow for parms overflow
  213.         move.l       D1,__base(A4)       * save for stack checking
  214.  
  215.         cmp.l         __stack(a4),d0
  216.         bcc.s        nochange
  217.  
  218. *-- current stack is not as big as __stack says it needs
  219. *-- to be. Allocate a new one.
  220.         move.l        __stack(a4),d0
  221.         add.l         #128,d0           * extra room
  222.         move.l        d0,newstacksize(a4)
  223.  
  224.         move.l        #MEMFLAGS,d1
  225.         callsys       AllocMem
  226.         tst.l         d0
  227.         beq.w         return
  228.  
  229.         move.l        d0,newstack(a4)
  230.         add.l         #128,d0           * extra room
  231.         move.l        d0,__base(a4)
  232.  
  233.         add.l         __stack(a4),d0
  234.         move.l        d0,a7
  235.  
  236. nochange:
  237.         ENDC
  238.  
  239.  
  240.  
  241.         IFD        RESIDENT
  242.         move.l        d2,-(a7)
  243.         movem.l       a0-a2,-(a7)
  244.  
  245. *------ get the size of the stack, if CLI use cli_DefaultStack
  246.         move.l        ThisTask(a6),A3
  247.         move.l        pr_CLI(A3),d1
  248.         lsl.l         #2,d1
  249.         move.l        d1,a0
  250.         move.l        cli_DefaultStack(a0),d1
  251.         lsl.l         #2,d1             * # longwords -> # bytes
  252.         moveq        #0,d2              * use d2 as flag for newstack or not
  253.         move.l       #RESLEN,d0
  254.         cmp.l        __stack(a4),d1     * This a4 is in the original
  255.                                         * set of data
  256.         bcc.s        nochange
  257.         move.l        __stack(a4),d1
  258.         add.l        d1,d0              * increase size of mem for new stack
  259.         moveq        #1,d2              * set flag
  260.  
  261. nochange:
  262.         move.l        d1,a3             * save stacksize to set up stack checking
  263.         move.l        #MEMFLAGS,d1
  264.         callsys       AllocMem
  265.         tst.l         d0
  266.         bne.s         ok1
  267.         movem.l       (a7)+,d2/a0-a2
  268.         bra.w         return
  269.  
  270. ok1:    move.l        d0,a0
  271.         move.l        d0,a2             * a2 now has difference
  272.  
  273.         move.l        d0,a1
  274.         move.l        #NEWDATAL,d0
  275.         sub.l         #RESBASE,a4
  276.  
  277.                                         * copy data over
  278. cpy:    move.l        (a4)+,(a0)+
  279.         subq.l        #1,d0
  280.         bne.s         cpy
  281.  
  282.                                         * a4 now points at number of relocs
  283.         move.l        (a4)+,d0
  284. reloc:  beq.s         nreloc
  285.         move.l        a1,a0
  286.         add.l         (a4)+,a0          * a0 now has add of reloc
  287.         add.l         (a0),a2
  288.         move.l        a2,(a0)
  289.         move.l        a1,a2             * restore offset
  290.         subq.l        #1,d0
  291.         bra.s         reloc
  292.  
  293. nreloc: move.l        a1,a4             * set up new base register
  294.         add.l         #RESBASE,a4
  295.  
  296.         move.l        #RESLEN,realdatasize(a4)
  297.         movem.l       (a7)+,a0-a2
  298.  
  299.         move.l        a6,SysBase(A4)
  300.         tst.b         d2
  301.         movem.l       (a7)+,d2          * restore d2
  302.         movem.l       a7,_StackPtr(A4)  * Save stack ptr (movem doesn't
  303.                                         * change flags
  304.         beq.s         nochg2
  305.  
  306. *------ set up new stack
  307.         move.l       a4,d0
  308.         sub.l        #RESBASE,d0
  309.         add.l        #RESLEN,d0
  310.         add.l        __stack(a4),d0     * here a4 will be pointing at the
  311.                                         * new data, but __stack will be the
  312.                                         * same if all goes well
  313.         sub.l        #128,d0            * 128 down for good measure
  314.         move.l       d0,a7
  315.         move.l       __stack(a4),d0
  316.         move.l       d0,4(a7)            * fill in size of new stack
  317.         add.l        d0,realdatasize(a4) * need to know how much to free later
  318.  
  319. nochg2:
  320. *------ Set __base for stack checking
  321.         move.l       a7,d1
  322.         sub.l        a3,d1               * get top of stack
  323.         add.l        #128,D1             * allow for parms overflow
  324.         move.l       D1,__base(A4)       * save for stack checking
  325.  
  326.         ENDC
  327.  
  328.  
  329.  
  330.         ifd     CATCH
  331.         move.w  AttnFlags(a6),Environment+2(a4) * save copy for dump
  332.         endc
  333.  
  334.  
  335.  
  336. clrwb:
  337.         clr.l        _WBenchMsg(A4)
  338.  
  339. *-----  clear any pending signals
  340.         moveq         #0,d0
  341.         move.l        #$00003000,d1
  342.         callsys       SetSignal
  343.  
  344.  
  345.         move.l        ThisTask(a6),A3
  346.  
  347.         ifd        CATCH
  348.         move.l        A3,TaskID(a4)
  349.  
  350. *------ initialize exception handler
  351. *------ Remember to preserve the old handler first
  352.         move.l        TC_TRAPDATA(a3),oldtrapdata(A4)
  353.         move.l        TC_TRAPCODE(a3),d0              ; check current exception
  354.         move.l        d0,oldtrapcode(A4)
  355.  
  356.         move.l        d0,a1
  357.         callsys TypeOfMem
  358.         tst.l d0
  359.         bne.s        1$                               * somebody else (debugger?) has vector
  360.  
  361.         move.l        #Exception,TC_TRAPCODE(a3)      * install pointers to code
  362.         move.l        a4,TC_TRAPDATA(a3)              * ...and data
  363. 1$:
  364.         ifd         AUTOREQ
  365. *------ attempt to open Intuition library:
  366.         bsr.w                openIntui
  367.         endc
  368.         endc
  369.  
  370.  
  371. *------ attempt to open DOS library:
  372.         lea           DOSName(PC),A1
  373.         moveq.l       #0,D0
  374.         callsys       OpenLibrary
  375.         move.l        D0,DOSBase(A4)
  376.         bne.s         ok2
  377.         moveq.l       #100,d0
  378.         bra.w         exit2
  379.  
  380. ok2:
  381.  
  382.         move.l        pr_CurrentDir(A3),__curdir(A4)
  383.  
  384. *=======================================================================
  385. *====== CLI Startup Code ===============================================
  386. *=======================================================================
  387. *
  388. * Entry: D2 = command length
  389. *        A2 = Command pointer
  390. fromCLI:
  391.         ifd        CATCH
  392.         moveq         #-1,d0
  393.         move.l        d0,Starter(a4)        * non-zero means CLI
  394.         move.l        a5,StackTop(a4)
  395.         endc
  396.  
  397. *------ find command name:
  398.         move.l      pr_CLI(a3),a0
  399.         add.l       a0,a0                   * bcpl pointer conversion
  400.         add.l       a0,a0
  401.         move.l      cli_CommandName(a0),a1
  402.  
  403.         IFD         CATCH
  404.         IFND        AUTOREQ
  405.         move.l      cli_StandardOutput(a0),GConsole(a4)   * save output fh
  406.         ENDC
  407.         ENDC
  408.  
  409.         add.l       a1,a1                   * bcpl pointer conversion
  410.         add.l       a1,a1
  411.  
  412. *------ collect parameters:
  413.         move.l      d2,d0                   * get command line length
  414.         moveq.l     #0,d1
  415.         move.b      (a1)+,d1
  416.         move.l      a1,_ProgramName(A4)
  417.         add.l       d1,d0                   * add length of command name
  418.         addq.l      #7,d0                   * allow for space after command, quotes
  419.                                             * and null terminator, as well as
  420.         andi.w      #$fffc,D0               * force to long word boundary
  421.         move.l      d0,Commandlen(a4)
  422.  
  423.         movem.l d1/a1,-(a7)
  424.         move.l      #MEMFLAGS,d1
  425.         callsys     AllocMem
  426.         movem.l     (a7)+,d1/a1
  427.         tst.l       d0
  428.         bne.s       ok_copy
  429.  
  430.         move.l      #1000,d0                * what should the return code be for out of mem?
  431.         move.l      d0,-(a7)                * put a return code on the stack
  432.         beq.w       nodofree                * Was exitToDOS
  433.  
  434. ok_copy:
  435.         move.l      d0,a0
  436.         move.l      d0,Commandbuf(a4)
  437.  
  438. *------ copy command line into memory
  439.                 move.l  a0,a1
  440.                 subq.w  #2,d2
  441.                 bmi.b   no_cmd_line
  442. copy_line:      move.b  (a2)+,(a1)+
  443.                 dbra    d2,copy_line
  444. no_cmd_line:    clr.b   (a1)+
  445.                 pea     (a0)
  446.  
  447. *=============================================
  448. *------ common code --------
  449. *=============================================
  450.  
  451. main    jsr        __fpinit(PC)              * Initialize floating point
  452.         jsr        __main(PC)                * call C entrypoint
  453.         moveq.l    #0,d0                     * set successful status
  454.         bra.s      exit2
  455. *
  456.  
  457. XCEXIT:
  458. _XCEXIT:
  459.         move.l     4(SP),d0                  * extract return code
  460. @@XCEXIT:
  461. @@_XCEXIT:
  462. exit2:
  463.         movea.l    _StackPtr(a4),a7          * restore stack ptr
  464.         move.l     d0,-(a7)
  465.         move.l     _ONEXIT(A4),d0            * exit trap function?
  466.         beq.s      exit3
  467.         move.l     d0,a0
  468.         jsr        (a0)
  469. exit3:
  470.         jsr        __fpterm(PC)              * clean up any floating point
  471.         jsr        _MemCleanup(PC)           * cleanup leftover memory alloc.
  472.  
  473.         ifnd       RESIDENT
  474. *------ free the stack if we allocated one
  475.         move.l     newstacksize(a4),d0
  476.         beq.s      exit4
  477.         move.l     newstack(a4),a1
  478.         move.l     AbsExecBase.W,A6
  479.         callsys    FreeMem
  480.         endc
  481.  
  482. exit4:
  483. exitToDOS:
  484.         move.l     AbsExecBase.W,a6
  485.  
  486. *------ Restore the original exception handler
  487.         ifd    CATCH
  488.         move.l        ThisTask(a6),A3
  489.         move.l        oldtrapdata(A4),TC_TRAPDATA(a3)
  490.         move.l        oldtrapcode(A4),TC_TRAPCODE(a3) * check current exception
  491.          ifd         AUTOREQ
  492.           move.l        IntuiBase(a4),a1
  493.           callsys         CloseLibrary                * close Intuition library
  494.          endc
  495.         ENDC
  496.  
  497. *------ free the command line buffer
  498.         move.l     Commandlen(a4),d0
  499.         beq.s      nodofree
  500.         move.l     Commandbuf(a4),a1
  501.         callsys    FreeMem
  502.  
  503. *------ this rts sends us back to DOS:
  504. nodofree:
  505.         move.l     DOSBase(A4),a1
  506.         callsys    CloseLibrary              * close Dos library
  507.  
  508.         IFD        RESIDENT
  509.         move.l     realdatasize(a4),d0
  510.         move.l     a4,a1
  511.         sub.l      #RESBASE,a1
  512.         callsys    FreeMem
  513.         ENDC
  514.         move.l     (a7)+,d0
  515.  
  516. return:
  517.         movem.l    (a7)+,d1-d6/a0-a6
  518.         rts
  519.  
  520. DOSName dc.b    'dos.library',0
  521. RCSId   dc.b    '$Id: c.asm,v 1.5 1993/09/14 22:24:41 simons Exp simons $'
  522.         dc.w    0
  523.  
  524.         ifd        CATCH
  525. *-----------------------------------------------------------------------
  526. *        Open the Intuition library:
  527.  
  528. openIntui:
  529.         lea        IntuiName(PC),A1
  530.         moveq.l    #0,D0
  531.         callsys    OpenLibrary
  532.         move.l     D0,IntuiBase(A4)
  533.         beq.s      noDOS
  534.         rts
  535.  
  536. *-----------------------------------------------------------------------
  537. noDOS:
  538.                 moveq.l #100,d0
  539.                 bra.w   exit2
  540.  
  541.  
  542. IntuiName  dc.b        'intuition.library',0
  543.  
  544. *-----------------------------------------------------------------------
  545. *        The Exception Handler - catches GURUs and exits (semi)cleanly
  546. Exception:
  547.         movem.l    a0,-(a7)
  548.         move.l     AbsExecBase.W,a0
  549.         move.l     ThisTask(a0),a0
  550.         move.l     TC_TRAPDATA(a0),a0        * ...and data
  551.         move.l     (sp)+,ADump(a0)           * save a0
  552.         move.l     d0,ADump+4(a0)            * and d0
  553.  
  554.         move.l     (a7)+,d0                  * get exception # from stack
  555.         move.l     d0,GURUNum(a0)            * and save it
  556.         cmpi.l     #3,d0                     * ADDRESS or BUS error?
  557.         bgt.s      1$                        * no, skip adjustment
  558.         btst       #0,Environment+3(a0)      * is it 68010 or 68020?
  559.         bne.s      1$                        * 0 means NO
  560.         addq.l     #8,a7                     * adjust for 68000
  561. 1$:
  562.         move.l     2(a7),d0                  * get PC at crash
  563.         move.l     d0,GURUAddr(a0)           * and save it
  564.         move.l     ADump+4(a0),d0            * restore a0 and d0
  565.         move.l     ADump(a0),a0
  566.         move.l     #GURUExit,2(a7)           * use our own exit point
  567.         rte
  568.  
  569. *-----------------------------------------------------------------------
  570. *        The Exception exit routine - write 'PGTB' IFF chunk to file
  571. *        'SnapShot.TB' in current directory, then exit to system.
  572.  
  573. GURUExit:
  574.         movem.l    d0-d7/a0-a7,-(sp)         * save all registers
  575.         move.l     AbsExecBase.W,a6          * make sure we are working with Exec
  576.         callsys    GetCC                     * safe way - works with all CPUs
  577.         move.l     ThisTask(a6),a3
  578.         move.l     TC_TRAPDATA(a3),a4        * make sure we have a valid # in a4
  579.         move.l     d0,Flags(a4)              * save area
  580.         movem.l    (sp)+,d0-d7
  581.         movem.l    d0-d7,DDump(a4)           * save data reg contents
  582.         movem.l    (sp)+,d0-d7
  583.         movem.l    d0-d7,ADump(a4)           * save address reg contents
  584.         tst.l      StackPtr(a4)              * if there's something there
  585.         bne        GExit1                    * ...we've been here before!
  586.         lea        TempStore(a4),a0          * calculate addr of TempStore
  587.         move.l     a0,TempAddr(a4)           * ...and save for later access
  588.         move.l     A7Store(a4),d0            * make sure we have proper TOS
  589.         move.l     d0,StackPtr(a4)           * ...and save it
  590.         moveq      #0,d0
  591.         move.l     _ProgramName(a4),a0       * find length of program name
  592.  
  593.         ifd        AUTOREQ
  594.         move.l     a0,PName(a4)
  595.         endc
  596.  
  597.         subq.l     #1,a0
  598.         move.b     (a0),d0
  599.         addq.l     #4,d0                     * adjust for shift
  600.         lsr.l      #2,d0
  601.         move.l     d0,NameLen(a4)            * store length
  602.         add.l      d0,FAILlen(a4)            * and sub-chunk total
  603.  
  604.         moveq      #0,d0                     * clear d0 for use
  605.         lea        VBlankFrequency(a6),a0    * set up a0 to find correct data
  606.         move.b     (a0)+,d0                  * get just in case
  607.         move.l     d0,VBlankFreq(a4)         * ...so we can figure what
  608.         move.b     (a0),d0                   * ...type of machine
  609.         move.l     d0,PowerSupFreq(a4)       * ...we're working on
  610.  
  611.         lea        start-4(pc),a0            * get seglist ptr
  612.         moveq      #-1,d0                    * always at least 1
  613. 2$:
  614.         addq.l     #1,d0
  615.         move.l     (a0),d1                   * find end of list
  616.         beq.s      3$
  617.         lsl.l      #2,d1                     * BPTR!!!!!
  618.         move.l     d1,a0
  619.         bra.s      2$
  620. 3$:
  621.         add.l      d0,SegCount(a4)           * store # of seglist pointers
  622.         lsl.l      #1,d0                     * multiply by 2 for longword count
  623.         add.l      d0,FAILlen(a4)            * and sub-chunk length
  624.  
  625.         move.l     StackTop(a4),d0           * get top of stack
  626.         sub.l      StackPtr(a4),d0           * find number of bytes used
  627.         addq.l     #4,d0                     * adjust for longword conversion
  628.         lsr.l      #2,d0                     * convert from bytes to long
  629.         move.l     d0,StackLen(a4)           * and save
  630.         add.l      d0,s2len(a4)              * and sub-chunk total
  631.  
  632.         move.l     a5,-(sp)                  * save a5 for later
  633.         callsys    Forbid                    * don't let 'em change while we ask
  634.         move.l     MemList+LH_HEAD(a6),d0    * first node in MemList
  635. checkchip:
  636.         move.l     d0,a5                     * move node address to address reg
  637.         move.w     MH_ATTRIBUTES(a5),d4      * get node attributes
  638.         btst       #MEMB_CHIP,d4             * is it chip?
  639.         beq.s      checkfast                 * no, go on
  640.         lea        chipAvail(a4),a3
  641.         bsr.w      AddIt
  642. checkfast:
  643.         btst       #MEMB_FAST,d4             * is it fast?
  644.         beq.s      next                      * no, go on
  645.         lea        fastAvail(a4),a3
  646.         bsr.w      AddIt
  647. next:
  648.         move.l     LN_SUCC(a5),d0            * get address of next node
  649.         bne.s      checkchip                 * ...and loop back if valid
  650.         callsys    Permit                    * allow others access again
  651.         move.l     #MEMF_CHIP+MEMF_LARGEST,d1 * to find largest hunk in chip ram
  652.         callsys    AvailMem
  653.         move.l     d0,chipLargest(a4)         * store
  654.         move.l     #MEMF_FAST+MEMF_LARGEST,d1 * to find largest hunk in fast ram
  655.         callsys    AvailMem
  656.         move.l     d0,fastLargest(a4)        * store
  657.         move.l     (sp)+,a5                  * and restore a5
  658.  
  659.         ifd        AUTOREQ
  660.         moveq      #0,d0                     * PosFlag
  661.         move.l     d0,d1                     * NegFlag
  662.         move.l     d0,a0                     * 0 means use current window
  663.         lea        IText1(a4),a1             * Body Text
  664.         lea        IText5(a4),a2             * Positive Gadget Text
  665.         lea        IText6(a4),a3             * Negative Gadget Text
  666.         moveq      #1,d2
  667.         lsl.l      #8,d2                     * quick way to set Width
  668.         moveq      #76,d3                    * Height
  669.         move.l     IntuiBase(a4),a6          * get intuition library pointer
  670.         jsr        -$15c(A6)                 * callsys       AutoRequest
  671.         move.l     AbsExecBase.W,a6
  672.         tst.l      d0                        * save SnapShot?
  673.         beq.w      GExit2                    * no, just exit
  674.         endc
  675.  
  676.         move.l     DOSBase(a4),a6
  677.         lea        DumpName(a4),a0           * get name of output file
  678.         move.l     a0,d1
  679.         move.l     #MODE_NEWFILE,d2          * create new file
  680.         callsys    Open
  681.         bne.s      4$
  682.         lea        DumpPath(a4),a0           * if error in current dir, try DF1:
  683.         move.l     a0,d1
  684.         move.l     #MODE_NEWFILE,d2
  685.         callsys    Open
  686.         bne.s      4$
  687.         move.b     #'0',DumpPath+2(a4)       * still error?  Try DF0:
  688.         lea        DumpPath(a4),a0
  689.         move.l     a0,d1
  690.         move.l     #MODE_NEWFILE,d2
  691.         callsys    Open
  692.  
  693.         ifnd        AUTOREQ
  694.         bne.s      4$                        * if no error, continue (finally!)
  695.         move.l     GConsole(a4),d1
  696.         beq.w      GExit2
  697.         lea        failmsg(a4),a0
  698.         move.l     a0,d2
  699.         move.l     #23,d3
  700.         callsys    Write
  701.         endc
  702.  
  703.         bra.w      GExit2                    * else, print msg & DIE gracefully
  704. 4$:
  705.         move.l     d0,d5                     * save file handle for Write
  706.         move.l     d0,fp(a4)                 * ...and in a safe place for later
  707.         move.l     d5,d1                     * get file handle
  708.         lea        PGTB(a4),a0               * first part of fixed
  709.         move.l     a0,d2
  710.         move.l     #chunk_len_1,d3           * length of first
  711.         callsys    Write                     * ...since it gets written over
  712.  
  713.         move.l     d5,d1                     * get file handle
  714.         move.l     _ProgramName(a4),d2       * get address of program name
  715.         move.l     NameLen(a4),d3            * get # longs in program name
  716.         lsl.l      #2,d3                     * ..and convert to bytes
  717.         callsys    Write
  718.  
  719.         move.l     d5,d1                     * get file handle
  720.         lea        Environment(a4),a0        * second part of fixed
  721.         move.l     a0,d2
  722.         move.l     #chunk_len_2,d3           * length of second part
  723.         callsys    Write
  724.  
  725.         lea        start-8(pc),a0            * address of seglist (size of seg)
  726.         move.l     (a0)+,d0                  * segsize
  727.         move.l     d0,TempStore+4(a4)        * save it
  728.         move.l     a0,TempStore(a4)          * store first number
  729.         move.l     SegCount(a4),d4
  730. 5$:
  731.         move.l     d5,d1                     * get file handle
  732.         move.l     TempAddr(a4),d2           * address of write buffer
  733.         moveq      #TempSize,d3              * size of segment pointer
  734.         callsys    Write
  735.         move.l     TempStore(a4),a0          * retrieve pointer
  736.         move.l     (a0),d0                   * get next seg pointer
  737.         lsl.l      #2,d0                     * adjust
  738.         move.l     d0,TempStore(a4)          * ..and save
  739.         move.l     d0,a0
  740.         beq.b      donesegs                  * last segment?
  741.         move.l     -4(a0),d0                 * get segsize
  742.         move.l     d0,TempStore+4(a4)        * ...and save it
  743.         subq.l     #1,d4                     * done yet?
  744.         bne.s      5$                        * no, do next
  745.  
  746. donesegs:
  747.         tst.l      _FMEM(a4)                 * do they want memory reported?
  748.         beq.s      55$                       * no, forget it
  749.         move.l     d5,d1
  750.         lea        subFMEM(a4),a0
  751.         move.l     a0,d2
  752.         move.l     #FMEMlen,d3
  753.         callsys    Write
  754.  
  755. 55$:
  756.         move.l     d5,d1                     * (get the idea?)
  757.         lea        subREGS(a4),a0            * third part of fixed
  758.         move.l     a0,d2
  759.         move.l     #chunk_len_3,d3           * length of third
  760.         callsys    Write
  761.  
  762.         move.l     StackLen(a4),d0           * get length of stack used
  763.         cmpi.l     #2048,d0                  * > 8k ?
  764.         bgt.s      6$                        * yes, dump two chunks
  765.         move.l     d5,d1
  766.         lea        STAK2(a4),a0              * whole stack chunk
  767.         move.l     a0,d2
  768.         moveq      #STAK2len,d3              * length of fixed part
  769.         callsys    Write
  770.  
  771.         move.l     d5,d1
  772.         move.l     StackPtr(a4),d2           * address of stack
  773.         move.l     StackLen(a4),d3           * get # longwords on stack
  774.         lsl.l      #2,d3                     * ..and convert to bytes
  775.         callsys    Write
  776.         bra.s      7$
  777. 6$:
  778.         move.l     d5,d1
  779.         lea        STAK3(a4),a0              * top4k chunk
  780.         move.l     a0,d2
  781.         moveq      #STAK3len,d3              * length of fixed part
  782.         callsys    Write
  783.  
  784.         move.l     d5,d1
  785.         move.l     StackTop(a4),d2           * find top of stack
  786.         sub.l      #4096,d2                  * find top-4k
  787.         move.l     #4096,d3                  * # bytes to write
  788.         callsys    Write
  789.  
  790.         move.l     d5,d1
  791.         lea        STAK4(a4),a0              * bottom4k chunk
  792.         move.l     a0,d2
  793.         moveq      #STAK4len,d3              * length of fixed part
  794.         callsys    Write
  795.  
  796.         move.l     d5,d1
  797.         move.l     StackPtr(a4),d2           * current stack address
  798.         move.l     #4096,d3                  * # bytes to write
  799.         callsys    Write
  800. 7$:
  801.         move.l     _STAKOffset(a4),d3
  802.         beq.s      8$
  803.         lsr.l      #2,d3
  804.         addq.l     #1,d3
  805.         move.l     d3,_STAKOffset(a4)
  806.         addq.l     #1,d3
  807.         move.l     d5,d1
  808.         lea        STAK5(a4),a0
  809.         move.l     a0,d2
  810.         moveq      #STAK5len,d3
  811.         callsys    Write
  812.  
  813.         move.l     d5,d1
  814.         move.l     StackPtr(a4),d2
  815.         move.l     _STAKOffset(a4),d3
  816.         subq.l     #1,d3
  817.         move.l     StackLen(a4),d4
  818.         cmp.l      d3,d4
  819.         bge.s      75$
  820.         move.l     StackLen(a4),d3
  821. 75$:
  822.         lsl.l      #2,d3
  823.         callsys    Write
  824. 8$:
  825.         tst.l      _ONGURU(A4)               * user GURU function?
  826.         beq.s      9$
  827.         move.l     d5,-(sp)
  828.         move.l     d5,d1
  829.         lea        UDAT(a4),a0
  830.         move.l     a0,d2
  831.         move.l     #UDATlen,d3
  832.         callsys    Write
  833.         move.l     d5,d1
  834.         moveq      #0,d2                     * zero offset
  835.         moveq      #1,d3                     * ...from EOF
  836.         callsys    Seek
  837.         move.l     d0,SeekStore(a4)
  838.         move.l     _ONGURU(a4),a0
  839.         jsr        (a0)
  840.         addq.l     #4,sp
  841. 9$:
  842.         move.l     fp(a4),d5
  843.         move.l     d5,d1
  844.         moveq      #0,d2                     * offset from EOF
  845.         moveq      #1,d3                     * OFFSET_END
  846.         callsys    Seek                      * Seek returns OLD position
  847.         move.l     d0,d1
  848.         andi.l     #3,d1                     * did user write even longwords?
  849.         beq.s      10$                       * Yep!        Nice Human.
  850.         move.l     d1,d6                     * Nope, save for later.
  851.         clr.l      TempStore(a4)             * clear temp storage
  852.         move.l     d5,d1
  853.         move.l     TempAddr(a4),d2
  854.         moveq      #4,d3
  855.         sub.l      d6,d3                     * find how many NULLs to pad
  856.         callsys    Write
  857.         bra.s      9$
  858. 10$:
  859.         tst.l      SeekStore(a4)             * did we write UDAT?
  860.         beq.s      11$                       * nope!
  861.         sub.l      SeekStore(a4),d0          * find length of UDAT section
  862.         lsr.l      #2,d0                     * adjust to longwords
  863.         move.l     d0,TempStore(a4)          * save UDAT length for write
  864.         move.l     d5,d1
  865.         move.l     SeekStore(a4),d2          * find where to write it
  866.         subq.l     #4,d2
  867.         moveq      #-1,d3                    * OFFSET_BEGINNING
  868.         callsys    Seek
  869.         move.l     d5,d1
  870.         move.l     TempAddr(a4),d2
  871.         move.l     #4,d3
  872.         callsys    Write                     * write length of UDAT field to file
  873. 11$:
  874.         move.l     d5,d1
  875.         moveq      #0,d2                     * offset to 'Length' field
  876.         moveq      #1,d3                     * OFFSET_END
  877.         callsys    Seek                      * make sure we are at end of file
  878.         move.l     d5,d1
  879.         moveq      #4,d2                     * offset to 'Length' field
  880.         moveq      #-1,d3                    * OFFSET_BEGINNING
  881.         callsys    Seek
  882.         subq.l     #8,d0                     * adjust total length
  883.         lsr.l      #2,d0                     * adjust to longwords
  884.         move.l     d0,TempStore(a4)          * save for write
  885.         move.l     d5,d1
  886.         move.l     TempAddr(a4),d2
  887.         move.l     #4,d3
  888.         callsys    Write                     * write 'Length' field
  889. GExit1:
  890.         move.l     fp(a4),d1
  891.         beq.s      GExit2
  892.         move.l     DOSBase(a4),a6
  893.         callsys    Close
  894.  
  895.         ifnd        AUTOREQ
  896.         move.l      GConsole(a4),d1
  897.         beq.s       GExit2
  898.         lea         success(a4),a0
  899.         move.l      a0,d2
  900.         move.l      #32,d3
  901.         callsys     Write
  902.         endc
  903.  
  904. GExit2:
  905.         move.l       TaskID(a4),a6
  906.         move.l       AbsExecBase.W,a6
  907.         moveq        #$47,d0
  908.         bra.w        exit2
  909.  
  910. *-----------------------------------------------------------------------
  911. * AddIt:        routine to add memory parts to variables
  912.  
  913. AddIt:
  914.         move.l       MH_FREE(a5),d0
  915.         add.l        d0,(a3)                 * add to available
  916.         move.l       MH_UPPER(a5),d0
  917.         sub.l        MH_LOWER(a5),d0
  918.         add.l        d0,4(a3)                * add to Max section
  919.         rts
  920.         endc
  921.  
  922.  
  923.         IFD     CATCH
  924.         section __MERGED,DATA
  925. _ONGURU        dc.l        0
  926. IntuiBase      dc.l        0
  927. TaskID         dc.l        0
  928. oldtrapcode    dc.l        0
  929. oldtrapdata    dc.l        0
  930.  
  931.         ifnd        AUTOREQ
  932. GConsole        dc.l        0
  933. failmsg         dc.b        7,'Can''t write SnapShot!',10
  934. success         dc.b        7,'GURU caught; SnapShot written!',10
  935.         endc
  936.  
  937.         cnop        0,4
  938. _FMEM           dc.l        0
  939. fp              dc.l        0                  * save SnapShot file pointer
  940. DumpPath        dc.b        'DF1:'
  941. DumpName        dc.b        'SnapShot.TB',0
  942. SeekStore       dc.l        0
  943. TempAddr        dc.l        0                  * Storage for &TempStore
  944. TempStore       dc.l        0,0                * Temporary storage for BPTR -> APTR
  945. TempSize        equ        *-TempStore
  946.  
  947.         cnop        0,4
  948.         ifd        AUTOREQ
  949. TAttr:                                         * Text attributes for font
  950.         dc.l        TName                      * name of font
  951.         dc.w        TOPAZ_EIGHTY               * font size
  952.         dc.b        FS_NORMAL                  * font style
  953.         dc.b        FPF_ROMFONT                * font preferences
  954. TName:
  955.         dc.b        'topaz.font',0
  956.         cnop        0,4
  957.  
  958. IText1:                                        * Text definitions for AutoReq call
  959.         dc.b        3,0,RP_JAM1,0              * front & back pens, drawmode and filler byte
  960.         dc.w        6,4                        * XY origin relative to container TopLeft
  961.         dc.l        TAttr                      * font pointer or NULL for default
  962.         dc.l        ITextText1                 * pointer to text
  963.         dc.l        IText2                     * next IntuiText structure
  964. ITextText1:
  965.         dc.b        'Program:',0
  966.         cnop 0,4
  967. IText2:
  968.         dc.b        3,0,RP_JAM1,0
  969.         dc.w        78,4
  970.         dc.l        TAttr
  971. PName   dc.l        0
  972.         dc.l        IText3
  973.         cnop        0,4
  974. IText3:
  975.         dc.b        3,0,RP_JAM1,0
  976.         dc.w        55,16
  977.         dc.l        TAttr
  978.         dc.l        ITextText3
  979.         dc.l        IText4
  980. ITextText3:
  981.         dc.b        'I caught a GURU!',0
  982.         cnop 0,4
  983. IText4:
  984.         dc.b        3,0,RP_JAM1,0
  985.         dc.w        20,28
  986.         dc.l        TAttr
  987.         dc.l        ITextText4
  988.         dc.l        0
  989. ITextText4:
  990.         dc.b        'Should I make a SnapShot?',0
  991.         cnop 0,4
  992. IText5:
  993.         dc.b        3,0,RP_JAM2,0
  994.         dc.w        6,3
  995.         dc.l        TAttr
  996.         dc.l        ITextText5
  997.         dc.l        0
  998. ITextText5:
  999.         dc.b        'YES',0
  1000.         cnop 0,4
  1001. IText6:
  1002.         dc.b        3,0,RP_JAM2,0
  1003.         dc.w        6,3
  1004.         dc.l        TAttr
  1005.         dc.l        ITextText6
  1006.         dc.l        0
  1007. ITextText6:
  1008.         dc.b        'NO',0
  1009.         endc
  1010.  
  1011.         cnop 0,4
  1012.  
  1013. *--------------------------------------------------------------------------
  1014. * New IFF chunk format -
  1015. *        PGTB = Program Traceback, header for chunk
  1016. *        FAIL = reason for and environment of crash
  1017. *        REGS = registers at time of crash, including PC and CCR
  1018. *        VERS = version, revision, name of this program
  1019. *        STAK = ENTIRE stack at time of crash or, alternately,
  1020. *                the top and bottom 4k if the stack used is > 8k
  1021. *        UDAT = optional user data dump (if _ONGURU is set to a
  1022. *                function pointer in the user's program)
  1023. *--------------------------------------------------------------------------
  1024.  
  1025. PGTB            dc.b        'PGTB'
  1026. Length          dc.l        0                * length of chunk (in longwords)
  1027.  
  1028. subFAIL         dc.b        'FAIL'
  1029. FAILlen         dc.l        9
  1030. NameLen         dc.l        0                * length of program name
  1031. chunk_len_1     equ         *-PGTB
  1032. Environment     dc.l        0                * CPU (, Math)
  1033. VBlankFreq      dc.l        0                *        PAL = 50, NTSC = 60 (approx.)
  1034. PowerSupFreq    dc.l        0                * Europe = 50,        USA = 60 (approx.)
  1035. Starter         dc.l        0                * 0 = WB, -1 = CLI
  1036. GURUNum         dc.l        0                * cause of crash (GURU #)
  1037. SegCount        dc.l        1                * # hunks in seglist
  1038. chunk_len_2     equ         *-Environment
  1039.  
  1040. subFMEM         dc.b        'FMEM'           * FMEM - free memory at crash
  1041.                 dc.l        6
  1042. chipAvail       dc.l        0                * available chip memory
  1043. chipMax         dc.l        0                *        maximum chip memory
  1044. chipLargest     dc.l        0                *        largest chip memory
  1045. fastAvail       dc.l        0                * available fast memory
  1046. fastMax         dc.l        0                *        maximum fast memory
  1047. fastLargest     dc.l        0                *        largest fast memory
  1048. FMEMlen         equ         *-subFMEM
  1049.  
  1050. subREGS         dc.b        'REGS'           * REGS - register storage field
  1051. REGSlen         dc.l        18
  1052. GURUAddr        dc.l        0                * PC at time of crash
  1053. Flags           dc.l        0                * Condition Code Register (CCR)
  1054. DDump           dc.l        0,0,0,0,0,0,0,0  * data registers
  1055. ADump           dc.l        0,0,0,0,0,0,0    * address registers
  1056. A7Store         dc.l        0
  1057.  
  1058. subVERS         dc.b        'VERS'           * VERS - program version field
  1059.                 dc.l        6
  1060.                 dc.l        VERSION          * version #
  1061.                 dc.l        REVISION         * revision #
  1062.                 dc.l        3                * length of name of program
  1063.                 IFD        RESIDENT
  1064.                 dc.b        'catchres.o',0,0 * name
  1065.                 ENDC
  1066.                 IFND        RESIDENT
  1067.                 dc.b        'catch.o   ',0,0 * name
  1068.                 ENDC
  1069.  
  1070. subSTAK         dc.b        'STAK'           * STAK - stack field
  1071. STAKlen         dc.l        4
  1072. Type            dc.l        0                * 0 = Info
  1073. StackTop        dc.l        0                * top of stack pointer
  1074. StackPtr        dc.l        0                * current Stack Pointer
  1075. StackLen        dc.l        0                * # bytes used on stack
  1076. chunk_len_3     equ         *-subREGS
  1077.  
  1078. STAK2           dc.b        'STAK'
  1079. s2len           dc.l        1                * length of subtype
  1080.                 dc.l        1                * 1 = whole stack
  1081. STAK2len        equ         *-STAK2
  1082.  
  1083. STAK3           dc.b        'STAK'
  1084.                 dc.l        1025
  1085.                 dc.l        2                * 2 = top 4k of stack
  1086. STAK3len        equ         *-STAK3
  1087.  
  1088. STAK4           dc.b        'STAK'
  1089.                 dc.l        1025
  1090.                 dc.l        3                * 3 = bottom 4k of stack
  1091. STAK4len        equ         *-STAK4
  1092.  
  1093. STAK5           dc.b        'STAK'
  1094. _STAKOffset     dc.l        0
  1095.                 dc.l        4                * 4 = user defined amount
  1096. STAK5len        equ         *-STAK5
  1097.  
  1098. UDAT            dc.b        'UDAT'
  1099.                 dc.l        0
  1100. UDATlen         equ         *-UDAT
  1101.         endc
  1102.  
  1103.  
  1104.  
  1105.         section __MERGED,BSS
  1106.  
  1107.         xref    DOSBase
  1108.  
  1109.         xdef    NULL,SysBase,_WBenchMsg
  1110.         xdef    __curdir
  1111.         xdef    _OSERR,_FPERR,_SIGFPE,_ONERR,_ONEXIT,_ONBREAK
  1112.         xdef    _SIGINT
  1113.         xdef    _ProgramName,_StackPtr,__base
  1114.         ifd        CATCH
  1115.         xdef        _ONGURU,_FMEM,_STAKOffset
  1116.         endc
  1117.  
  1118.  
  1119.  
  1120. NULL         ds.b    4
  1121. __base       ds.b    4                   * base of stack
  1122. _OSERR       ds.b    4
  1123. _FPERR       ds.b    4
  1124. _SIGFPE      ds.b    4
  1125. _SIGINT      ds.b    4
  1126. _ONERR       ds.b    4
  1127. _ONEXIT      ds.b    4
  1128. _ONBREAK     ds.b    4
  1129. __curdir     ds.b    4
  1130. SysBase      ds.b    4
  1131. _WBenchMsg   ds.b    4
  1132. _StackPtr    ds.b    4
  1133. _ProgramName ds.b    4
  1134. Commandbuf   ds.b    4
  1135. Commandlen   ds.b    4
  1136.  
  1137.         ifd        RESIDENT
  1138. realdatasize ds.b    4                   * size of memory allocated for data +
  1139.                                          * possible stack
  1140.         endc
  1141.         ifnd       RESIDENT
  1142. newstack     ds.b    4                   * pointer to new stack (if needed)
  1143. newstacksize ds.b    4                   * size of new stack
  1144.         endc
  1145.  
  1146.              END
  1147. @
  1148.  
  1149.  
  1150. 1.5
  1151. log
  1152. @Deleted some Workbench related code to make the startup more efficient.
  1153. @
  1154. text
  1155. @d3 2
  1156. a4 2
  1157. **      $Revision: 1.4 $
  1158. **      $Date: 1993/09/14 22:16:07 $
  1159. d13 1
  1160. a13 1
  1161. **      $Id: c.asm,v 1.4 1993/09/14 22:16:07 simons Exp simons $
  1162. d17 3
  1163. d389 1
  1164. d392 1
  1165. a392 1
  1166.                 clr.b   (a1)+
  1167. d469 1
  1168. a469 1
  1169. RCSId   dc.b    '$Id: c.asm,v 1.4 1993/09/14 22:16:07 simons Exp simons $'
  1170. @
  1171.  
  1172.  
  1173. 1.4
  1174. log
  1175. @If started from Workbench, the startup-code returns immediatly.
  1176. @
  1177. text
  1178. @d3 2
  1179. a4 2
  1180. **      $Revision: 1.3 $
  1181. **      $Date: 1993/09/14 21:58:36 $
  1182. d13 1
  1183. a13 1
  1184. **      $Id: c.asm,v 1.3 1993/09/14 21:58:36 simons Exp simons $
  1185. d17 3
  1186. a146 1
  1187. *------                                 if WB use a7 - TC_SPLOWER
  1188. a148 1
  1189.         beq.s         fromwb
  1190. d152 1
  1191. a152 7
  1192.         lsl.l         #2,d0             * # longwords -> # bytes
  1193.         bra.s         dostack
  1194.  
  1195. fromwb:
  1196.         move.l        a7,d0
  1197.         sub.l         TC_SPLOWER(a3),d0
  1198. dostack:
  1199. a190 1
  1200. *------                                 if WB use a7 - TC_SPLOWER
  1201. a192 1
  1202.         beq.s         fromwb
  1203. a196 6
  1204.         bra.s         dostack
  1205.  
  1206. fromwb:
  1207.         move.l        a7,d1
  1208.         sub.l         TC_SPLOWER(a3),d1
  1209. dostack:
  1210. a326 1
  1211. *------ are we running as a son of Workbench?
  1212. a327 2
  1213.         tst.l         pr_CLI(A3)
  1214.         beq.w         fromWorkbench
  1215. a389 38
  1216.                 bra.s   main                    ; call C entrypoint
  1217.  
  1218. *=======================================================================
  1219. *====== Workbench Startup Code =========================================
  1220. *=======================================================================
  1221.  
  1222. fromWorkbench:
  1223.  
  1224.         ifd        CATCH
  1225.         move.l     TC_SPUPPER(a3),StackTop(a4)  * set top of stack
  1226.         endc
  1227.  
  1228.  
  1229. *------ we are now set up.  wait for a message from our starter
  1230.         lea        pr_MsgPort(A3),a0         * our process base
  1231.         callsys    WaitPort
  1232.         lea        pr_MsgPort(A3),a0         * our process base
  1233.         callsys    GetMsg
  1234.         move.l     d0,_WBenchMsg(a4)
  1235.         move.l     d0,-(SP)
  1236.  
  1237.         move.l     d0,a2                     * get first argument
  1238.         move.l     sm_ArgList(a2),d0
  1239.         beq.s      do_main
  1240.         move.l     DOSBase(a4),a6
  1241.         move.l     d0,a0
  1242.         move.l     wa_Lock(a0),d1
  1243.         callsys    DupLock
  1244.         move.l     d0,__curdir(A4)
  1245.         move.l     d0,d1
  1246.         callsys    CurrentDir
  1247.  
  1248. do_main:
  1249.         move.l     _WBenchMsg(A4),a0         * get address of workbench message
  1250.         move.l     a0,-(a7)                  * push argv
  1251.         pea        NULL(a4)                  * push argc
  1252.         move.l     sm_ArgList(a0),a0         * get address of arguments
  1253.         move.l     wa_Name(a0),_ProgramName(A4) * get name of program
  1254. a426 17
  1255. *------ if we ran from CLI, skip workbench cleanup:
  1256.         tst.l      _WBenchMsg(A4)
  1257.         beq.s      exitToDOS
  1258.         move.l     DOSBase(A4),a6
  1259.         move.l     __curdir(a4),d1
  1260.         beq.s      done_5
  1261.         callsys    UnLock
  1262. done_5:
  1263. *------ return the startup message to our parent
  1264. *       we forbid so workbench can't UnLoadSeg() us
  1265. *       before we are done:
  1266.         move.l     AbsExecBase.W,A6
  1267.         callsys    Forbid
  1268.         move.l     _WBenchMsg(a4),a1
  1269.         callsys    ReplyMsg
  1270.         bra.s      nodofree
  1271.  
  1272. d465 1
  1273. a465 1
  1274. RCSId   dc.b    '$Id: c.asm,v 1.3 1993/09/14 21:58:36 simons Exp simons $'
  1275. @
  1276.  
  1277.  
  1278. 1.3
  1279. log
  1280. @The pseudo opcode EVEN is unknown to asm, replaced it.
  1281. Changed the line-parameter for _main() to the shell commandline
  1282. without programname and the terminating return, for usage with my
  1283. modified __main().
  1284. @
  1285. text
  1286. @d3 2
  1287. a4 2
  1288. **      $Revision: 1.2 $
  1289. **      $Date: 1993/09/14 20:20:03 $
  1290. d13 1
  1291. a13 1
  1292. **      $Id: c.asm,v 1.2 1993/09/14 20:20:03 simons Exp simons $
  1293. d17 6
  1294. d125 7
  1295. d536 1
  1296. a536 1
  1297. RCSId   dc.b    '$Id: c.asm,v 1.2 1993/09/14 20:20:03 simons Exp simons $'
  1298. @
  1299.  
  1300.  
  1301. 1.2
  1302. log
  1303. @Added RCSId string.
  1304. @
  1305. text
  1306. @d3 2
  1307. a4 2
  1308. **      $Revision: 1.1 $
  1309. **      $Date: 1993/09/14 20:18:32 $
  1310. d13 1
  1311. a13 1
  1312. **      $Id: c.asm,v 1.1 1993/09/14 20:18:32 simons Exp simons $
  1313. d17 3
  1314. d371 1
  1315. a371 1
  1316.         movem.l     d1/a1,-(a7)
  1317. d387 7
  1318. a393 18
  1319.         move.l     d2,d0                    * get command line length
  1320.         subq.l     #1,d0
  1321.         add.l      d1,d2
  1322.  
  1323. copy_line:
  1324.         move.b     0(A2,D0.W),2(A0,D2.W)    * copy command line to stack
  1325.         subq.l     #1,d2
  1326.         dbf        d0,copy_line
  1327.         move.b     #' ',2(a0,d2.w)          * add space between command and parms
  1328.         subq.l     #1,d2
  1329.         move.b     #'"',2(a0,d2.w)          * add end quote
  1330.  
  1331. copy_cmd:
  1332.         move.b     0(a1,d2.w),1(a0,d2.w)    * copy command name to stack
  1333.         dbf        d2,copy_cmd
  1334.         move.b     #'"',(a0)
  1335.         move.l     A0,-(A7)                 * push command line address
  1336.         bra.s      main                     * call C entrypoint
  1337. d523 2
  1338. a524 2
  1339. RCSId   dc.b    '$Id$',0
  1340.         EVEN
  1341. @
  1342.  
  1343.  
  1344. 1.1
  1345. log
  1346. @Initial revision
  1347. @
  1348. text
  1349. @d3 2
  1350. a4 2
  1351. **      $Revision$
  1352. **      $Date$
  1353. d13 1
  1354. a13 1
  1355. **      $Id$
  1356. d16 3
  1357. a18 1
  1358. ** $Log$
  1359. d531 2
  1360. @
  1361.