prt0.as 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Start-up code for Free Pascal Compiler, not in a shared library,
  3. not linking with C library.
  4. Written by Edmund Grimley Evans in 2015 and released into the public domain.
  5. */
  6. .text
  7. .align 2
  8. .globl _dynamic_start
  9. .type _dynamic_start, function
  10. _dynamic_start:
  11. 1:
  12. auipc x5,%pcrel_hi(__dl_fini)
  13. sd x10, %pcrel_lo(1b)(x5)
  14. jal x0, _start
  15. .globl _start
  16. .type _start, function
  17. _start:
  18. .option push
  19. .option norelax
  20. 1: auipc gp, %pcrel_hi(__bss_start+0x800)
  21. addi gp, gp, %pcrel_lo(1b)
  22. .option pop
  23. /* Get argc, argv, envp */
  24. ld x5,(x2)
  25. addi x6,x2,8
  26. addi x7,x5,1
  27. slli x7,x7,3
  28. add x7,x6,x7
  29. /* Save argc, argv, envp, and initial stack pointer */
  30. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_argc)
  31. sw x5,%pcrel_lo(1b)(x8)
  32. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_argv)
  33. sd x6,%pcrel_lo(1b)(x8)
  34. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_envp)
  35. sd x7,%pcrel_lo(1b)(x8)
  36. 1:auipc x5,%pcrel_hi(__stkptr)
  37. addi x6, x2, 0
  38. sd x6,%pcrel_lo(1b)(x5)
  39. /* Initialise FP to zero */
  40. addi x8,x0,0
  41. /* Call main */
  42. jal x1, PASCALMAIN
  43. .globl _haltproc
  44. .type _haltproc,function
  45. _haltproc:
  46. 1:auipc x10,%pcrel_hi(__dl_fini)
  47. ld x10,%pcrel_lo(1b)(x10)
  48. beq x10,x0,.Lexit
  49. jalr x1,x10
  50. .Lexit:
  51. 1:auipc x10,%pcrel_hi(operatingsystem_result)
  52. ld x10,%pcrel_lo(1b)(x10)
  53. addi x17, x0, 94
  54. ecall
  55. jal x0, _haltproc
  56. /* Define a symbol for the first piece of initialized data. */
  57. .data
  58. .align 4
  59. .globl __data_start
  60. __data_start:
  61. .quad 0
  62. .weak data_start
  63. data_start = __data_start
  64. .bss
  65. .align 4
  66. .comm __dl_fini,8
  67. .comm __stkptr,8
  68. .comm operatingsystem_parameter_envp,8
  69. .comm operatingsystem_parameter_argc,4
  70. .comm operatingsystem_parameter_argv,8
  71. .section .note.GNU-stack,"",%progbits