home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / utilities / dirutils / visualshell / src / crt0.asm < prev    next >
Assembly Source File  |  1991-12-18  |  4KB  |  175 lines

  1. ;:ts=8
  2. ;
  3. ; Initial startup routine for Aztec 'C' and ARP using RESIDENT.
  4. ; NB: This should allow access to all Aztec Features, math, etc.
  5. ;     Could be made smaller if only for CLI, only for Workbench,
  6. ;     Could be made smaller if only this or that.
  7. ;
  8. ; Created 02-18-88 by -+=SDB+=- from arpcrt0.s
  9. ; Copyright (c) 1988 by Scott Ballantyne, may be freely
  10. ; used by Arp Supporters/users.
  11. ; Use at your own risk.
  12. ;
  13. ; NB: References to the ___fromdisk__ long have to be handled carefully,
  14. ;     since they are somewhat shizophrenic, sometimes referring to copied
  15. ;     data, sometimes not.  Note that they should fine for the C code without
  16. ;     special handling as long as small model is used.
  17. ;
  18. ; 10-Mar-90:    Put together from resgeta4.s & arprescrt0.s for
  19. ;        Aztec 5.0 release.
  20.  
  21.     include "exec/types.i"
  22.     include "exec/execbase.i"
  23.     include "exec/tasks.i"
  24.     include "exec/alerts.i"
  25.     include "libraries/arpbase.i"
  26.  
  27. call    macro
  28.     xref    _LVO\1
  29.     jsr    _LVO\1(a6)
  30.     endm
  31.  
  32.     entry    .begin
  33.     public    .begin
  34.     public    _geta4
  35.  
  36. *    If you need more or less stack, change the first number below
  37. *    For example, if your program only needs 4000 bytes of stack, the
  38. *    line below would read:
  39. *    RESIDENT 4000,__H2_end-__H1_org,loaded
  40.  
  41. .begin
  42.     RESIDENT 14096,__H2_end-__H1_org,loaded
  43.  
  44.     move.l    a4,a3            ; copy base
  45.     add.l    #32766,a4        ; bias
  46.     bra.s    clonedata        ; and copy the data segment only
  47.  
  48. loaded:
  49.     moveq    #-1,d7            ; flag not resident (start if from disk)
  50.     far    data
  51.     move.l    d7,___fromdisk__    ; needs to be set for _geta4
  52.     near    data
  53.  
  54.     bsr.s    _geta4            ; set up data base register
  55.  
  56.     lea    __H1_end,a1
  57.     lea    __H2_org,a2
  58.     cmp.l    a1,a2            ; check if BSS and DATA together
  59.     bne.s    normal            ; this would actually be an error.
  60.  
  61.     move.w    #((__H2_end-__H2_org)/4)-1,d1
  62.     bmi.s    normal
  63.     moveq    #0,d2
  64.  
  65. clear_loop:
  66.     move.l    d2,(a1)+        ; clear out memory
  67.     dbra    d1,clear_loop
  68.     bra.s    normal
  69.  
  70. clonedata:
  71.     move.l    #((__H1_end-__H1_org)/4)-1,d1
  72.     bmi.s    normal
  73.     far    data
  74.     lea    __H1_end,a1
  75.     lea    __H2_org,a2
  76.     near    data
  77.     cmp.l    a1,a2
  78.     beq.s    clone_no_error
  79.     move.l    #500,d2            ; error, must be same hunk, so scram
  80.     bra.s    exit
  81.  
  82. clone_no_error:
  83.     far    data
  84.     lea    __H1_org,a1        ; clone data and bss
  85.     near    data
  86.  
  87. clone_loop:
  88.     move.l    (a1)+,(a3)+        ; a3 set to point to base
  89.     dbra    d1,clone_loop
  90.  
  91. normal:
  92.     move.l    sp,__savsp        ; save stack pointer
  93.     move.l    (4).w,a6        ; get Exec's library base pointer
  94.     move.l    a6,_SysBase        ; put where we can get it
  95.  
  96.     movem.l d0/a0,-(sp)        ; save CLI command parameters
  97.     lea    dos_name(pc),a1        ; get name of dos library
  98.     moveq    #0,d0            ; any version
  99.     call    OpenLibrary        ; open the library
  100.     move.l    d0,_DOSBase        ; set it up
  101.     movem.l (sp)+,d0/a0        ; restore CLI command parameters
  102.     tst.l    _DOSBase        ; check base ptr
  103.     bne.s    start_main        ; skip if okay
  104.  
  105.       move.l  #AG_OpenLib!AO_DOSLib,d7
  106.     call    Alert
  107.     move.l    #500,d2            ; set return code
  108.     bra.s    exit
  109.  
  110. start_main:
  111.     jsr    __main            ; call the startup stuff
  112.     move.l    d0,d2            ; remember return code
  113.  
  114.     move.l    _DOSBase,d0        ; lib still open?
  115.     beq.s    exit            ; nope
  116.     move.l    d0,a1
  117.     move.l    (4).w,a6
  118.     call    CloseLibrary        ; close it
  119.  
  120. exit:
  121.     move.l    d2,d0            ; set return code
  122.     rts                ; and return
  123.  
  124. _geta4:
  125.     movem.l d0-d1/a0-a1/a6,-(sp)    ; max safety here...
  126.     far    data
  127.     tst.l    ___fromdisk__
  128.     near    data
  129.     bne.s    1$
  130.  
  131.     move.l    (4).w,a6
  132.     sub.l    a1,a1
  133.     call    FindTask
  134.     move.l    d0,a0
  135.     lea    TC_MEMENTRY(a0),a0
  136.     lea    PMEM(pc),a1
  137.     call    FindName
  138.     tst.l    d0
  139.     beq.s    1$            ; not resident
  140.  
  141.     move.l    d0,a0
  142.     cmp.w    #2,pm_Num(a0)        ; check for data
  143.     bne.s    1$            ; resident, but no data allocated.
  144.     move.l    pm_Data(a0),a4        ; get data pointer
  145.     add.l    #32766,a4        ; bias 
  146.     bra.s    2$
  147. 1$    far    data
  148.     lea    __H1_org+32766,a4
  149.     near    data
  150. 2$    movem.l (sp)+,d0-d1/a0-a1/a6
  151.     rts
  152.  
  153. dos_name:
  154.     dc.b    'dos.library',0
  155.  
  156. PMEM    PMEM_NAME
  157.  
  158.     even
  159.  
  160.     far    data
  161.  
  162.     public    __main,__H0_org
  163.  
  164.     dseg
  165.     
  166.     public    _SysBase,_DOSBase,__savsp,___fromdisk__
  167.     public    __H1_org,__H1_end,__H2_org,__H2_end
  168.  
  169.     near    data
  170.  
  171. ___fromdisk__:
  172.     dc.l    0    ; default is resident
  173.  
  174.     end
  175.