cprt0.as 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. //Copyright 2001, QNX Software Systems Ltd. All Rights Reserved
  3. //
  4. // QNX has kindly released this source code under the QNX open
  5. // Community license, expressly to be used with the
  6. // Free Pascal runtime library
  7. //
  8. .extern main
  9. .extern exit
  10. .extern _fini
  11. .extern _init
  12. .extern atexit
  13. .extern errno
  14. .extern operatingsystem_parameter_argc
  15. .extern operatingsystem_parameter_argv
  16. .extern operatingsystem_parameter_envp
  17. .text
  18. .byte 'N', 'I', 'A', 'M' /* Used by debugger for setting a break point */
  19. .long main
  20. #if defined(VARIANT_wcc)
  21. .globl _cstart_
  22. _cstart_:
  23. jmp _CMain
  24. .type _cstart_,@function
  25. .size _cstart_,.-_cstart_
  26. #else
  27. .globl _start
  28. _start:
  29. #if defined(__PIC__)
  30. // call 1f
  31. //1: popl %ebx
  32. // addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx
  33. // call _CMain@PLT
  34. //#else
  35. /* Stash EDX to EBX */
  36. movl %edx,%ebx
  37. /* Call _init_libc -- need to extract argc, argv, env and auxv first */
  38. // argc
  39. movl 0(%esp),%esi
  40. movl 0(%esp), %eax
  41. movl %eax, operatingsystem_parameter_argc
  42. // argv
  43. leal 4(%esp),%ecx
  44. movl %ecx, operatingsystem_parameter_argv
  45. // envp
  46. leal (%ecx,%esi,4),%eax
  47. // auxv vector pointer
  48. leal 4(%eax),%edi
  49. // pointer to environment
  50. leal 8(%eax),%edx
  51. movl %edx, operatingsystem_parameter_envp
  52. cmpl $0,4(%eax)
  53. je .Ldoneargv
  54. .align 4
  55. // Scan for auxv
  56. .Lloop:
  57. movl (%edx),%eax
  58. addl $4,%edx
  59. testl %eax,%eax
  60. jne .Lloop
  61. .Ldoneargv:
  62. pushl %ebx
  63. pushl %edx
  64. pushl %edi
  65. pushl %ecx
  66. pushl %esi
  67. call _init_libc
  68. // Leave the args on the stack, we'll just pass them to main()
  69. pushl $_fini
  70. call atexit
  71. addl $4,%esp
  72. call _init
  73. .Lmain:
  74. movl $0,errno
  75. call PASCALMAIN
  76. pushl %eax
  77. call exit
  78. //#endif
  79. int $3 /* Should never get here.... */
  80. .type _start,@function
  81. .size _start,.-_start
  82. #endif