prt0.as 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 4(%sp,%d0.l*4), %a0
  48. move.l %a0, operatingsystem_parameter_envp
  49. # move.l 8(%sp), %d0
  50. # move.l %d0, operatingsystem_parameter_envp
  51. # move.l 4(%sp), %d0
  52. # move.l %d0, operatingsystem_parameter_argv
  53. # move.l (%sp), %d0
  54. # move.l %d0, operatingsystem_parameter_argc
  55. jbsr PASCALMAIN
  56. illegal /* Crash if somehow `exit' does return. */
  57. .file "prt0.as"
  58. .text
  59. .globl __entry
  60. __entry:
  61. jsr PASCALMAIN
  62. .globl _haltproc
  63. .type _haltproc,@function
  64. _haltproc:
  65. move.l #1,%d0
  66. move.l operatingsystem_result,%d1
  67. trap #0
  68. bras _haltproc
  69. .bss
  70. .type __stkptr,@object
  71. .size __stkptr,4
  72. .global __stkptr
  73. __stkptr:
  74. .skip 4
  75. .type operatingsystem_parameters,@object
  76. .size operatingsystem_parameters,12
  77. operatingsystem_parameters:
  78. .skip 3*4
  79. .global operatingsystem_parameter_envp
  80. .global operatingsystem_parameter_argc
  81. .global operatingsystem_parameter_argv
  82. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  83. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  84. .set operatingsystem_parameter_argv,operatingsystem_parameters+8