si_prc.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  33. asm
  34. { First locate the start of the environment variables }
  35. popl %ecx { Get argc in ecx }
  36. movl %esp,%ebx { Esp now points to the arguments }
  37. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+4 }
  38. andl $0xfffffff8,%esp { Align stack }
  39. movl %eax,operatingsystem_parameter_envp
  40. movl %ecx,operatingsystem_parameter_argc
  41. movl %ebx,operatingsystem_parameter_argv
  42. fninit { initialize fpu }
  43. fwait
  44. fldcw Default8087CW
  45. { Initialize gs for thread local storage }
  46. // movw %ds,%ax
  47. // movw %ax,%gs
  48. { Save initial stackpointer }
  49. movl %esp,initialstkptr
  50. xorl %ebp,%ebp
  51. call PASCALMAIN
  52. end;
  53. procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
  54. asm
  55. .Lhaltproc:
  56. movl syscall_nr_exit_group,%eax
  57. {$if sizeof(ExitCode)=2}
  58. movzwl ExitCode,%ebx
  59. {$else}
  60. mov ExitCode,%ebx
  61. {$endif}
  62. int $0x80
  63. movl syscall_nr_exit,%eax
  64. {$if sizeof(ExitCode)=2}
  65. movzwl ExitCode,%ebx
  66. {$else}
  67. mov ExitCode,%ebx
  68. {$endif}
  69. int $0x80
  70. jmp .Lhaltproc
  71. end;