prt0.as 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 2018 by Yuriy Sydorov 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-aarch64 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. 8(sp) argv[0]
  21. ...
  22. (8*argc)(sp) NULL
  23. (8*(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. .file "prt0.as"
  33. .text
  34. .align 2
  35. .globl _fpc_start
  36. .type _fpc_start,#function
  37. _fpc_start:
  38. /* Clear the frame pointer since this is the outermost frame. */
  39. mov x29,#0
  40. /* Save initial stackpointer and slightly adjust it */
  41. adrp x14,:got:__stkptr
  42. ldr x14,[x14,#:got_lo12:__stkptr]
  43. mov x0,sp
  44. add x1,x0,#-64
  45. str x1,[x14]
  46. /* Get argc off the stack and save a pointer to argv */
  47. ldr w1,[x0]
  48. adrp x14,:got:operatingsystem_parameter_argc
  49. ldr x14,[x14,#:got_lo12:operatingsystem_parameter_argc]
  50. str w1,[x14]
  51. adrp x14,:got:operatingsystem_parameter_argv
  52. ldr x14,[x14,#:got_lo12:operatingsystem_parameter_argv]
  53. add x0,x0,#8
  54. str x0,[x14]
  55. /* calc envp */
  56. add x1,x1,#1
  57. add x1,x0,x1,LSL #3
  58. adrp x14,:got:operatingsystem_parameter_envp
  59. ldr x14,[x14,#:got_lo12:operatingsystem_parameter_envp]
  60. str x1,[x14]
  61. /* Finally go to libc startup code. It will call "PASCALMAIN" via alias "main" */
  62. b _start
  63. /* --------------------------------------------------------- */
  64. .globl _haltproc
  65. .type _haltproc,#function
  66. _haltproc:
  67. /* Simply call libc exit(). _haltproc has the same declaration as exit. */
  68. bl exit
  69. /* --------------------------------------------------------- */
  70. .data
  71. /* Define a symbol for the first piece of initialized data. */
  72. .globl __data_start
  73. __data_start:
  74. .long 0
  75. .weak data_start
  76. data_start = __data_start
  77. /* --------------------------------------------------------- */
  78. .bss
  79. .comm __stkptr,8
  80. .comm operatingsystem_parameter_envp,8
  81. .comm operatingsystem_parameter_argc,4
  82. .comm operatingsystem_parameter_argv,8