prt0.as 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 1999-2004 by Michael Van Canneyt, Peter Vreman,
  4. # & Daniel Mantione, members of the Free Pascal development team.
  5. #
  6. # See the file COPYING.FPC, included in this distribution,
  7. # for details about the copyright.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. #**********************************************************************}
  14. #
  15. # Linux ELF startup code for Free Pascal
  16. #
  17. # The code in this file is the default startup code, it is used unless
  18. # libc is linked in, profiling is enabled or you are compiling a shared
  19. # library.
  20. #
  21. /*
  22. %a1 Contains a function pointer to be registered with `atexit'.
  23. This is how the dynamic linker arranges to have DT_FINI
  24. functions called for shared libraries that have been loaded
  25. before this code runs.
  26. %sp The stack contains the arguments and environment:
  27. 0(%sp) argc
  28. 4(%sp) argv[0]
  29. ...
  30. (4*argc)(%sp) NULL
  31. (4*(argc+1))(%sp) envp[0]
  32. ...
  33. NULL
  34. */
  35. .text
  36. .globl _start
  37. .type _start,@function
  38. _start:
  39. /* Clear the frame pointer. The ABI suggests this be done, to mark
  40. the outermost frame obviously. */
  41. sub.l %fp, %fp
  42. /* Extract the arguments as encoded on the stack. */
  43. move.l (%sp), %d0
  44. move.l %d0, operatingsystem_parameter_argc
  45. lea.l 4(%sp), %a0
  46. move.l %a0, operatingsystem_parameter_argv
  47. lea.l 8(%sp,%d0.l*4), %a0
  48. move.l %a0, operatingsystem_parameter_envp
  49. move.l %sp, __stkptr
  50. # move.l 8(%sp), %d0
  51. # move.l %d0, operatingsystem_parameter_envp
  52. # move.l 4(%sp), %d0
  53. # move.l %d0, operatingsystem_parameter_argv
  54. # move.l (%sp), %d0
  55. # move.l %d0, operatingsystem_parameter_argc
  56. jbsr PASCALMAIN
  57. illegal /* Crash if somehow `exit' does return. */
  58. .file "prt0.as"
  59. .text
  60. .globl __entry
  61. __entry:
  62. jsr PASCALMAIN
  63. .globl _haltproc
  64. .type _haltproc,@function
  65. _haltproc:
  66. move.l #1,%d0
  67. move.l operatingsystem_result,%d1
  68. trap #0
  69. bras _haltproc
  70. .bss
  71. .type __stkptr,@object
  72. .size __stkptr,4
  73. .global __stkptr
  74. __stkptr:
  75. .skip 4
  76. .type operatingsystem_parameters,@object
  77. .size operatingsystem_parameters,12
  78. operatingsystem_parameters:
  79. .skip 3*4
  80. .global operatingsystem_parameter_envp
  81. .global operatingsystem_parameter_argc
  82. .global operatingsystem_parameter_argv
  83. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  84. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  85. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  86. .section .note.GNU-stack,"",%progbits