prt0.as 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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-ARM target.
  16. #
  17. /* At this entry point, most registers' values are unspecified, except:
  18. sp The stack contains the arguments and environment:
  19. 0(sp) argc
  20. 4(sp) argv[0]
  21. ...
  22. (4*argc)(sp) NULL
  23. (4*(argc+1))(sp) envp[0]
  24. ...
  25. NULL
  26. */
  27. /*
  28. In our entry point we should save pointers to cmd line arguments
  29. and environment vars, then pass control to libc startup code.
  30. It will call "PASCALMAIN" via alias "main".
  31. */
  32. .text
  33. .globl _fpc_start
  34. .type _fpc_start,#function
  35. _fpc_start:
  36. /* Get GOT */
  37. ldr r3,.L_GOT1
  38. .LPIC1:
  39. add r3,pc,r3
  40. /* Clear the frame pointer since this is the outermost frame. */
  41. mov fp, #0
  42. /* Save initial stackpointer */
  43. ldr ip,.L__stkptr
  44. ldr ip,[r3, ip]
  45. str sp,[ip]
  46. mov r0,sp
  47. /* Pop argc off the stack and save a pointer to argv */
  48. ldmia r0!, {r1}
  49. ldr ip,.Loperatingsystem_parameter_argc
  50. ldr ip,[r3, ip]
  51. str r1,[ip]
  52. ldr ip,.Loperatingsystem_parameter_argv
  53. ldr ip,[r3, ip]
  54. str r0,[ip]
  55. /* calc envp */
  56. add r1,r1,#1
  57. add r1,r0,r1,LSL #2
  58. ldr ip,.Loperatingsystem_parameter_envp
  59. ldr ip,[r3, ip]
  60. str r1,[ip]
  61. /* Finally go to libc startup code. It will call "PASCALMAIN" via alias "main" */
  62. ldr ip,.L_start
  63. ldr ip,[r3, ip]
  64. bx ip
  65. .L_GOT1:
  66. .long _GLOBAL_OFFSET_TABLE_-.LPIC1-8
  67. .L__stkptr:
  68. .word __stkptr(GOT)
  69. .L_start:
  70. .word _start(GOT)
  71. .Loperatingsystem_parameter_argc:
  72. .word operatingsystem_parameter_argc(GOT)
  73. .Loperatingsystem_parameter_argv:
  74. .word operatingsystem_parameter_argv(GOT)
  75. .Loperatingsystem_parameter_envp:
  76. .word operatingsystem_parameter_envp(GOT)
  77. /* --------------------------------------------------------- */
  78. .globl _haltproc
  79. .type _haltproc,#function
  80. _haltproc:
  81. .globl _haltproc_eabi
  82. .type _haltproc_eabi,#function
  83. _haltproc_eabi:
  84. /* Simply call libc exit(). _haltproc has the same declaration as exit. */
  85. blx exit
  86. /* --------------------------------------------------------- */
  87. .data
  88. /* Define a symbol for the first piece of initialized data. */
  89. .globl __data_start
  90. __data_start:
  91. .long 0
  92. .weak data_start
  93. data_start = __data_start
  94. /* --------------------------------------------------------- */
  95. .bss
  96. .comm __stkptr,4
  97. .comm operatingsystem_parameter_envp,4
  98. .comm operatingsystem_parameter_argc,4
  99. .comm operatingsystem_parameter_argv,4