prt0.as 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 2013 by Yury Sidorov and other
  4. # 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. # Program startup code for Free Pascal. Android-i386 target.
  16. #
  17. # Stack layout at program start:
  18. #
  19. # nil
  20. # envn
  21. # ....
  22. # .... ENVIRONMENT VARIABLES
  23. # env1
  24. # env0
  25. # nil
  26. # argn
  27. # ....
  28. # .... COMMAND LINE OPTIONS
  29. # arg1
  30. # arg0
  31. # argc <--- esp
  32. #
  33. /*
  34. In our entry point we should save pointers to cmd line arguments
  35. and environment vars, then pass control to libc startup code.
  36. It will call "PASCALMAIN" via alias "main".
  37. */
  38. .file "prt0.as"
  39. .text
  40. .align 4
  41. .globl _fpc_start
  42. .type _fpc_start,@function
  43. _fpc_start:
  44. /* GOT init */
  45. call fpc_geteipasebx
  46. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  47. /* Clear the frame pointer since this is the outermost frame. */
  48. xorl %ebp,%ebp
  49. /* Save initial stackpointer */
  50. movl __stkptr@GOT(%ebx),%eax
  51. movl %esp,(%eax)
  52. /* First locate the start of the environment variables */
  53. /* Get argc in ecx */
  54. movl (%esp),%ecx
  55. /* Save argc */
  56. movl operatingsystem_parameter_argc@GOT(%ebx),%eax
  57. movl %ecx,(%eax)
  58. /* Get argv pointer in edx */
  59. leal 4(%esp),%edx
  60. /* Save argv */
  61. movl operatingsystem_parameter_argv@GOT(%ebx),%eax
  62. movl %edx,(%eax)
  63. /* The start of the environment is: esp+ecx*4+12 */
  64. leal 12(%esp,%ecx,4),%edx
  65. /* Save envp */
  66. movl operatingsystem_parameter_envp@GOT(%ebx),%eax
  67. movl %edx,(%eax)
  68. /* Finally go to libc startup code. It will call "PASCALMAIN" via alias "main". */
  69. /* No need to align stack since it will aligned by libc. */
  70. jmp _start
  71. /* --------------------------------------------------------- */
  72. .globl _haltproc
  73. .type _haltproc,@function
  74. _haltproc:
  75. /* GOT init */
  76. call fpc_geteipasebx
  77. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  78. /* Jump to libc exit(). _haltproc has the same declaration as exit. */
  79. jmp exit@PLT
  80. /* --------------------------------------------------------- */
  81. .data
  82. /* Define a symbol for the first piece of initialized data. */
  83. .globl __data_start
  84. __data_start:
  85. .long 0
  86. .weak data_start
  87. data_start = __data_start
  88. /* --------------------------------------------------------- */
  89. .bss
  90. .comm __stkptr,4
  91. .comm operatingsystem_parameter_envp,4
  92. .comm operatingsystem_parameter_argc,4
  93. .comm operatingsystem_parameter_argv,4