si_prc.inc 2.3 KB

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