prt0.as 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. |
  2. | This file is part of the Free Pascal run time library.
  3. | Copyright (c) 2005-2014 by Karoly Balogh
  4. |
  5. | Startup code for Amiga/m68k RTL
  6. |
  7. | See the file COPYING.FPC, included in this distribution,
  8. | for details about the copyright.
  9. |
  10. | This program is distributed in the hope that it will be useful,
  11. | but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. |
  14. .text
  15. .align 4
  16. | This symbol is required for lineinfo support!
  17. .globl __EXESTART
  18. __EXESTART:
  19. .globl _start
  20. .globl start
  21. _start:
  22. start:
  23. movem.l d0-d7/a0-a6,-(sp)
  24. | Get ExecBase
  25. move.l 0x4,a6
  26. move.l a6,_ExecBase
  27. | Get current stacksize
  28. move #0,a1 | nil
  29. jsr -294(a6) | FindTask()
  30. move.l d0,a0
  31. move.l 62(a0),d1 | SPUpper
  32. sub.l 58(a0),d1 | SPLower
  33. | Check if we need a new stack
  34. | Only allocate a new stack if the system-provided
  35. | stack is smaller than the one set compile time
  36. move.l __stklen,d0 | Also an argument for AllocVec() below
  37. cmp.l d0,d1
  38. blt _allocStack
  39. move.l d1,__stklen | Store the new stack size
  40. moveq.l #0,d0
  41. move.l d0,stackArea | Clear the stackArea pointer for exit test
  42. move.l sp,stackPtr | Store the stackPointer for restoration
  43. bra _noAllocStack
  44. _allocStack:
  45. | Allocating new stack
  46. moveq.l #0,d1 | MEMF_ANY
  47. jsr -684(a6) | AllocVec()
  48. tst.l d0
  49. beq __exit
  50. move.l d0,stackArea
  51. | Setting up StackSwap structure, and do the StackSwap
  52. lea stackSwap,a0
  53. move.l d0,(a0) | Bottom of the stack
  54. add.l __stklen,d0
  55. move.l d0,4(a0) | Top of the stack
  56. move.l d0,8(a0) | Initial stackpointer
  57. jsr -732(a6) | StackSwap()
  58. _noAllocStack:
  59. jsr PASCALMAIN
  60. .globl _haltproc
  61. _haltproc:
  62. | Check if we need to release a stack
  63. tst.l stackArea
  64. bne _freeStack
  65. move.l stackPtr,sp
  66. bra __exit
  67. _freeStack:
  68. | Swapping the stack back
  69. move.l _ExecBase,a6
  70. lea stackSwap,a0
  71. jsr -732(a6) | StackSwap()
  72. | Freeing up stack area
  73. move.l stackArea,a1
  74. jsr -690(a6) | FreeVec()
  75. __exit:
  76. movem.l (sp)+,d0-d7/a0-a6
  77. move.l operatingsystem_result,d0
  78. rts
  79. .bss
  80. .globl _ExecBase
  81. .globl SysBase
  82. .balign 4
  83. SysBase:
  84. _ExecBase:
  85. .skip 4
  86. .globl stackArea
  87. .balign 4
  88. stackArea:
  89. .skip 4
  90. .globl stackPtr
  91. .balign 4
  92. stackPtr:
  93. .skip 4
  94. .globl stackSwap
  95. .balign 4
  96. stackSwap:
  97. .skip 12