crt0-efi-ia32.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. _start:
  35. pushl %ebp
  36. movl %esp,%ebp
  37. pushl 12(%ebp) # copy "image" argument
  38. pushl 8(%ebp) # copy "systab" argument
  39. call 0f
  40. 0: popl %eax
  41. movl %eax,%ebx
  42. addl $ImageBase-0b,%eax # %eax = ldbase
  43. addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC
  44. pushl %ebx # pass _DYNAMIC as second argument
  45. pushl %eax # pass ldbase as first argument
  46. call _relocate
  47. popl %ebx
  48. popl %ebx
  49. testl %eax,%eax
  50. jne .exit
  51. call efi_main # call app with "image" and "systab" argument
  52. .exit: leave
  53. ret
  54. // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
  55. .data
  56. dummy: .long 0
  57. #define IMAGE_REL_ABSOLUTE 0
  58. .section .reloc
  59. .long dummy // Page RVA
  60. .long 10 // Block Size (2*4+2)
  61. .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy