home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / lattice / crt0.s < prev    next >
Text File  |  1993-05-23  |  2KB  |  115 lines

  1.     INCLUDE    inc.i
  2.     
  3. ;
  4. ; Initilization code; this is common to both 16 and 32 bit libraries,
  5. ; so be careful!
  6. ;
  7.     XDATA
  8.     xref    __app        ; short, declared in crtinit.c
  9.     xref    __base        ; BASEPAGE *, declared in crtinit.c
  10.     xref    __heapbase    ; void *
  11.     xref    __stksize    ; long, declared by user or in stack.c
  12.     
  13.     XFUNC
  14.     IF    _REGARG
  15.     xref    @_acc_main
  16.     xref    @_crtinit
  17.     ELSE
  18.     xref    __acc_main
  19.     xref    __crtinit
  20.     ENDC
  21.     
  22.     IF    _BASREL
  23.     XFAR
  24.     xref    __LinkerDB
  25.     ENDC
  26. ;
  27. ; Assumption: basepage is passed in a0 for accessories; for programs
  28. ; a0 is always 0.
  29.  
  30.     TEXT
  31.     xdef    __start
  32. __start
  33.     IF    _BASREL
  34.     lea    __LinkerDB,a4
  35.     ENDC
  36.     sub.l    a6,a6        ; clear a6 for debuggers
  37.     cmp.w    #0,a0        ; test if acc or program
  38.     beq.s    __startprg    ; if a program, go elsewhere
  39.     tst.l    36(a0)        ; also test parent basepage pointer
  40.     bne.s    __startprg    ; for acc's, it must be 0
  41.     move.l    a0,__base    ; acc basepage is in A0
  42.     move.l    __heapbase,sp    ; stack must be set from heap
  43.     add.l    __stksize,sp
  44.     IF    _REGARG
  45.     bra    @_acc_main
  46.     ELSE
  47.     bra    __acc_main    ; function is in crtinit.c
  48.     ENDC
  49. ;
  50. ; program startup code: doesn't actually do much, other than push
  51. ; the basepage onto the stack and call _start1 in crtinit.c
  52. ;
  53. __startprg:
  54.     move.l    4(sp),a0    ; get basepage
  55.     move.l    a0,__base    ; save it
  56.     move.l    4(a0),d0    ; get _base->p_hitpa
  57.     and.l    #$fffffffe,d0    ; round off
  58.     move.l    d0,sp        ; set stack (temporarily)
  59.     IF    _REGARG
  60.     bra    @_crtinit
  61.     ELSE
  62.     bra    __crtinit    ; in crtinit.c
  63.     ENDC
  64.  
  65. ;
  66. ; _setstack: changes the stack pointer; called as
  67. ;     void setstack( void *newsp )
  68. ; called from crtinit.c once the new stack size has been decided upon
  69. ;
  70. ; WARNING WARNING WARNING: after you do this, local variables may no longer
  71. ; be accessible!
  72. ; destroys a1 and a7
  73.  
  74.     XFUNC
  75.     IF    _REGARG
  76.     xdef    @_setstack
  77. @_setstack:
  78.     ELSE
  79.     xdef    __setstack
  80. __setstack:
  81.     ENDC
  82.     
  83.     TEXT
  84.     move.l    (sp)+,a1    ; save return address
  85.     IF    _REGARG
  86.     move.l    a0,sp        ; new stack pointer - from register
  87.     ELSE
  88.     move.l    (sp)+,sp    ; new stack pointer - from stack
  89.     ENDC
  90.     subq.l    #4,sp        ; fixup for tidy upon return
  91.     jmp    (a1)        ; back to caller
  92.  
  93. ;
  94. ; interfaces for gprof: for crt0.s, does nothing, but for gcrt0.s branches
  95. ; to the appropriate subroutines
  96. ;
  97.     XFUNC
  98.     IF    _REGARG
  99.     xdef    @_monstartup
  100.     xdef    @_moncontrol
  101.     xdef    @__mcleanup
  102. @_monstartup:
  103. @_moncontrol:
  104. @__mcleanup:
  105.     ELSE
  106.     xdef     __monstartup
  107.     xdef    __moncontrol
  108.     xdef     ___mcleanup
  109. __monstartup:
  110. __moncontrol:
  111. ___mcleanup:
  112.     ENDC
  113.     rts
  114.     end
  115.