si_prc.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Michael Van Canneyt, Peter Vreman,
  4. & Daniel Mantione, members of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. Linux ELF startup code for Free Pascal
  13. %rdx Contains a function pointer to be registered with `atexit'.
  14. This is how the dynamic linker arranges to have DT_FINI
  15. functions called for shared libraries that have been loaded
  16. before this code runs.
  17. %rsp The stack contains the arguments and environment:
  18. 0(%rsp) argc
  19. 8(%rsp) argv[0]
  20. ...
  21. (8*argc)(%rsp) NULL
  22. (8*(argc+1))(%rsp) envp[0]
  23. ...
  24. NULL
  25. }
  26. {$asmmode gas}
  27. {$L abitag.o}
  28. procedure PASCALMAIN; external name 'PASCALMAIN';
  29. {******************************************************************************
  30. Process start/halt
  31. ******************************************************************************}
  32. var
  33. dlexitproc: pointer;
  34. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  35. asm
  36. popq %rsi { Pop the argument count. }
  37. movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
  38. movq %rsi,(%rax)
  39. movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
  40. movq %rsp,(%rax) { argv starts just at the current stack top. }
  41. leaq 8(,%rsi,8),%rax
  42. addq %rsp,%rax
  43. movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rsi
  44. movq %rax,(%rsi)
  45. andq $0xfffffffffffffff0,%rsp { Align the stack to a 16 byte boundary to follow the ABI. }
  46. { Save initial stackpointer }
  47. movq initialstkptr@GOTPCREL(%rip),%rax
  48. movq %rsp,(%rax)
  49. xorq %rbp, %rbp
  50. call PASCALMAIN
  51. end;
  52. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  53. asm
  54. movq dlexitproc@GOTPCREL(%rip),%rax
  55. movq %rdx,(%rax)
  56. jmp _FPC_proc_start
  57. end;
  58. procedure _FPC_proc_haltproc(e: longint); assembler; public name '_haltproc';
  59. var
  60. code: longint;
  61. asm
  62. movl %edi,code
  63. movq dlexitproc@GOTPCREL(%rip),%rax
  64. movq (%rax),%rdx
  65. testq %rdx,%rdx
  66. jz .Lhaltproc
  67. call *%rdx
  68. .Lhaltproc:
  69. movl $231,%eax { exit_group call }
  70. movl code,%edi
  71. syscall
  72. jmp .Lhaltproc
  73. end;