si_prc.inc 2.4 KB

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