si_prc.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Stack layout at program start:
  14. nil
  15. envn
  16. ....
  17. .... ENVIRONMENT VARIABLES
  18. env1
  19. env0
  20. nil
  21. argn
  22. ....
  23. .... COMMAND LINE OPTIONS
  24. arg1
  25. arg0
  26. argc <--- esp
  27. }
  28. procedure PASCALMAIN; external name 'PASCALMAIN';
  29. {******************************************************************************
  30. Process start/halt
  31. ******************************************************************************}
  32. {$asmmode ATT}
  33. var
  34. dlexitproc: pointer;
  35. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  36. asm
  37. { First locate the start of the environment variables }
  38. popl %ecx { Get argc in ecx }
  39. movl %esp,%ebx { Esp now points to the arguments }
  40. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+4 }
  41. andl $0xfffffff8,%esp { Align stack }
  42. movl %eax,operatingsystem_parameter_envp
  43. movl %ecx,operatingsystem_parameter_argc
  44. movl %ebx,operatingsystem_parameter_argv
  45. movl %edx, dlexitproc
  46. fninit { initialize fpu }
  47. fwait
  48. fldcw Default8087CW
  49. { Initialize gs for thread local storage }
  50. // movw %ds,%ax
  51. // movw %ax,%gs
  52. { Save initial stackpointer }
  53. movl %esp,initialstkptr
  54. xorl %ebp,%ebp
  55. call PASCALMAIN
  56. end;
  57. procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
  58. asm
  59. .Lhaltproc:
  60. movl dlexitproc,%eax
  61. testl %eax,%eax
  62. je .Lnodlexitproc
  63. call *%eax
  64. .Lnodlexitproc:
  65. movl syscall_nr_exit_group,%eax
  66. {$if sizeof(ExitCode)=2}
  67. movzwl ExitCode,%ebx
  68. {$else}
  69. mov ExitCode,%ebx
  70. {$endif}
  71. int $0x80
  72. movl syscall_nr_exit,%eax
  73. {$if sizeof(ExitCode)=2}
  74. movzwl ExitCode,%ebx
  75. {$else}
  76. mov ExitCode,%ebx
  77. {$endif}
  78. int $0x80
  79. jmp .Lhaltproc
  80. end;