home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / crt0.cpp < prev    next >
C/C++ Source or Header  |  1992-10-01  |  3KB  |  115 lines

  1. |
  2. | Initialization code; this is common to both 16 and 32 bit libraries,
  3. | so be careful!
  4. |
  5.     .globl    __app        | short, declared in crtinit.c
  6.     .globl    __base        | BASEPAGE *, declared in crtinit.c
  7.     .globl    __heapbase    | void *
  8.     .globl    __stksize    | long, declared by user or in stksiz.c
  9.  
  10. |
  11. | externs to pull ident strings of all used libraries into the
  12. | executable; if a library is not used, then the extern is
  13. | satisfied by a dummy in the library
  14.  
  15.     .globl    ___Ident_libg
  16.     .globl    ___Ident_curses
  17.     .globl    ___Ident_widget
  18.     .globl    ___Ident_gem
  19.     .globl    ___Ident_pml
  20.     .globl    ___Ident_gnulib
  21.  
  22. |
  23. | Assumption: basepage is passed in a0 for accessories; for programs
  24. | a0 is always 0.
  25.  
  26.     .text
  27.     .even
  28.     .globl    __start
  29. __start:
  30.  
  31. |
  32. | If compiled for base-relative, get address of data segment from
  33. | basepage and store data+32K in base register.  -- hyc
  34.  
  35. #ifdef __MBASE__
  36.  
  37. #define Base    __MBASE__@(__base)
  38. #define Heapbase    __MBASE__@(__heapbase)
  39. #define Stksize    __MBASE__@(__stksize)
  40.  
  41.     movl    a0, a1
  42.     cmpw    #0, a1        
  43.     jne    skip0
  44.     movl    sp@(4), a1
  45. skip0:    movl    a1@(16), __MBASE__
  46.     subw    #32768, __MBASE__    | 32K == -32K, so subtract to add
  47. #else
  48.  
  49. #define Base    __base
  50. #define Heapbase    __heapbase
  51. #define Stksize    __stksize
  52.  
  53. #endif
  54.     subl    a6, a6        | clear a6 for debuggers
  55.     cmpw    #0, a0        | test if acc or program
  56.     beq    __startprg    | if a program, go elsewhere
  57.     tstl    a0@(36)        | also test parent basepage pointer
  58.     bne    __startprg    | for accs, it must be 0
  59.     movel    a0, Base    | acc basepage is in A0
  60.     lea    a0@(252), sp    | use the command line as a temporary stack
  61.     jmp    __acc_main    | function is in crtinit.c
  62. |
  63. | program startup code: doesn''t actually do much, other than push
  64. | the basepage onto the stack and call _start1 in crtinit.c
  65. |
  66. __startprg:
  67.     movel    sp@(4), a0    | get basepage
  68.     movel    a0, Base    | save it
  69.     movel    a0@(4), d0    | get _base->p_hitpa
  70.     bclr    #0, d0        | round off
  71.     movel    d0, sp        | set stack (temporarily)
  72.     jmp    __crtinit    | in crtinit.c
  73.  
  74. |
  75. | _setstack: changes the stack pointer; called as
  76. |     void setstack( void *newsp )
  77. | called from crtinit.c once the new stack size has been decided upon
  78. |
  79. | WARNING WARNING WARNING: after you do this, local variables may no longer
  80. | be accessible!
  81. | destroys a0 and a7
  82.  
  83.     .globl    __setstack
  84. __setstack:
  85.     movel    sp@+, a0    | save return address
  86.     movel    sp@, sp        | new stack pointer
  87.     subql    #4, sp        | fixup for tidy upon return
  88.     jmp    a0@        | back to caller
  89.  
  90. |
  91. | interfaces for gprof: for crt0.o, does nothing, but for gcrt0.o branches
  92. | to the appropriate subroutines
  93. |
  94.     .globl     __monstartup
  95.     .globl    __moncontrol
  96.     .globl     ___mcleanup
  97.  
  98. #ifdef GCRT0
  99.     .globl    _monstartup
  100.     .globl    _moncontrol
  101.     .globl    __mcleanup
  102.  
  103. __monstartup:
  104.     jmp    _monstartup
  105. __moncontrol:
  106.     jmp    _moncontrol
  107. ___mcleanup:
  108.     jmp    __mcleanup
  109. #else
  110. __monstartup:
  111. __moncontrol:
  112. ___mcleanup:
  113.     rts
  114. #endif /* GCRT0 */
  115.