cprt0.as 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. .text
  15. .byte 'N', 'I', 'A', 'M' /* Used by debugger for setting a break point */
  16. .long main
  17. #if defined(VARIANT_wcc)
  18. .globl _cstart_
  19. _cstart_:
  20. jmp _CMain
  21. .type _cstart_,@function
  22. .size _cstart_,.-_cstart_
  23. #else
  24. .globl _start
  25. _start:
  26. #if defined(__PIC__)
  27. // call 1f
  28. //1: popl %ebx
  29. // addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx
  30. // call _CMain@PLT
  31. //#else
  32. /* Stash EDX to EBX */
  33. movl %edx,%ebx
  34. /* Call _init_libc -- need to extract argc, argv, env and auxv first */
  35. // argc
  36. movl 0(%esp),%esi
  37. movl 0(%esp), %eax
  38. movl %eax, U_SYSTEM_ARGC
  39. // argv
  40. leal 4(%esp),%ecx
  41. movl %ecx, U_SYSTEM_ARGV
  42. // envp
  43. leal (%ecx,%esi,4),%eax
  44. // auxv vector pointer
  45. leal 4(%eax),%edi
  46. // pointer to environment
  47. leal 8(%eax),%edx
  48. movl %edx, U_SYSTEM_ENVP
  49. cmpl $0,4(%eax)
  50. je .Ldoneargv
  51. .align 4
  52. // Scan for auxv
  53. .Lloop:
  54. movl (%edx),%eax
  55. addl $4,%edx
  56. testl %eax,%eax
  57. jne .Lloop
  58. .Ldoneargv:
  59. pushl %ebx
  60. pushl %edx
  61. pushl %edi
  62. pushl %ecx
  63. pushl %esi
  64. call _init_libc
  65. // Leave the args on the stack, we'll just pass them to main()
  66. pushl $_fini
  67. call atexit
  68. addl $4,%esp
  69. call _init
  70. .Lmain:
  71. movl $0,errno
  72. call PASCALMAIN
  73. pushl %eax
  74. call exit
  75. //#endif
  76. int $3 /* Should never get here.... */
  77. .type _start,@function
  78. .size _start,.-_start
  79. #endif