prt0.as 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* Clear the frame pointer since this is the outermost frame. */
  45. xorl %ebp,%ebp
  46. /* Save initial stackpointer */
  47. movl %esp,__stkptr
  48. /* First locate the start of the environment variables */
  49. /* Get argc in ecx */
  50. movl (%esp),%ecx
  51. /* Save argc */
  52. movl %ecx,operatingsystem_parameter_argc
  53. /* Get argv pointer in ebx */
  54. leal 4(%esp),%ebx
  55. /* Save argv */
  56. movl %ebx,operatingsystem_parameter_argv
  57. /* The start of the environment is: esp+ecx*4+12 */
  58. leal 12(%esp,%ecx,4),%eax
  59. /* Save envp */
  60. movl %eax,operatingsystem_parameter_envp
  61. /* Finally go to libc startup code. It will call "PASCALMAIN" via alias "main" */
  62. jmp _start
  63. /* --------------------------------------------------------- */
  64. .globl _haltproc
  65. .type _haltproc,@function
  66. _haltproc:
  67. movzwl operatingsystem_result,%ebx
  68. pushl %ebx
  69. /* Call libc exit() */
  70. call exit
  71. /* --------------------------------------------------------- */
  72. .data
  73. /* Define a symbol for the first piece of initialized data. */
  74. .globl __data_start
  75. __data_start:
  76. .long 0
  77. .weak data_start
  78. data_start = __data_start
  79. /* --------------------------------------------------------- */
  80. .bss
  81. .comm __stkptr,4
  82. .comm operatingsystem_parameter_envp,4
  83. .comm operatingsystem_parameter_argc,4
  84. .comm operatingsystem_parameter_argv,4