si_prc.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. procedure PASCALMAIN; external name 'PASCALMAIN';
  27. {******************************************************************************
  28. Process start/halt
  29. ******************************************************************************}
  30. var
  31. dlexitproc: pointer;
  32. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  33. asm
  34. popq %rsi { Pop the argument count. }
  35. movq %rsi,operatingsystem_parameter_argc
  36. movq %rsp,operatingsystem_parameter_argv { argv starts just at the current stack top. }
  37. leaq 8(,%rsi,8),%rax
  38. addq %rsp,%rax
  39. movq %rax,operatingsystem_parameter_envp
  40. andq $0xfffffffffffffff0,%rsp { Align the stack to a 16 byte boundary to follow the ABI. }
  41. { Save initial stackpointer }
  42. movq %rsp,__stkptr
  43. xorq %rbp, %rbp
  44. call PASCALMAIN
  45. end;
  46. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  47. asm
  48. movq %rdx,dlexitproc
  49. jmp _FPC_proc_start
  50. end;
  51. procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
  52. asm
  53. movq dlexitproc,%rdx
  54. testq %rdx,%rdx
  55. jz .Lhaltproc
  56. call *%rdx
  57. .Lhaltproc:
  58. movl $231,%eax { exit_group call }
  59. movzwl operatingsystem_result,%edi
  60. syscall
  61. jmp .Lhaltproc
  62. { We need this stuff to make gdb behave itself, otherwise
  63. gdb will chokes with SIGILL when trying to debug apps.
  64. }
  65. .section ".note.ABI-tag", "a"
  66. .align 4
  67. .long 1f - 0f
  68. .long 3f - 2f
  69. .long 1
  70. 0: .asciz "GNU"
  71. 1: .align 4
  72. 2: .long 0
  73. .long 2,4,0
  74. 3: .align 4
  75. .section .note.GNU-stack,"",@progbits
  76. end;