crt0-efi-ia32.S 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* crt0-efi-ia32.S - x86 EFI startup code.
  2. Copyright (C) 1999 Hewlett-Packard Co.
  3. Contributed by David Mosberger <[email protected]>.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. * Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above
  11. copyright notice, this list of conditions and the following
  12. disclaimer in the documentation and/or other materials
  13. provided with the distribution.
  14. * Neither the name of Hewlett-Packard Co. nor the names of its
  15. contributors may be used to endorse or promote products derived
  16. from this software without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  18. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  19. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  22. BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  23. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  27. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. SUCH DAMAGE.
  30. */
  31. .text
  32. .align 4
  33. .globl _start
  34. .type _start,%function
  35. _start:
  36. pushl %ebp
  37. movl %esp,%ebp
  38. pushl 12(%ebp) # copy "image" argument
  39. pushl 8(%ebp) # copy "systab" argument
  40. call 0f
  41. 0: popl %eax
  42. movl %eax,%ebx
  43. addl $ImageBase-0b,%eax # %eax = ldbase
  44. addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC
  45. pushl %ebx # pass _DYNAMIC as second argument
  46. pushl %eax # pass ldbase as first argument
  47. call _relocate
  48. popl %ebx
  49. popl %ebx
  50. testl %eax,%eax
  51. jne .exit
  52. call _entry # call app with "image" and "systab" argument
  53. .exit: leave
  54. ret
  55. // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
  56. .data
  57. dummy: .4byte 0
  58. #define IMAGE_REL_ABSOLUTE 0
  59. .section .reloc
  60. .4byte dummy // Page RVA
  61. .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits
  62. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  63. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  64. #if defined(__ELF__) && defined(__linux__)
  65. .section .note.GNU-stack,"",%progbits
  66. #endif