crt0-efi-x86_64.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* crt0-efi-x86_64.S - x86_64 EFI startup code.
  2. Copyright (C) 1999 Hewlett-Packard Co.
  3. Contributed by David Mosberger <[email protected]>.
  4. Copyright (C) 2005 Intel Co.
  5. Contributed by Fenghua Yu <[email protected]>.
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the following
  14. disclaimer in the documentation and/or other materials
  15. provided with the distribution.
  16. * Neither the name of Hewlett-Packard Co. nor the names of its
  17. contributors may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  20. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  21. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24. BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  29. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. SUCH DAMAGE.
  32. */
  33. .text
  34. .align 4
  35. .globl _start
  36. _start:
  37. subq $8, %rsp
  38. pushq %rcx
  39. pushq %rdx
  40. 0:
  41. lea ImageBase(%rip), %rdi
  42. lea _DYNAMIC(%rip), %rsi
  43. popq %rcx
  44. popq %rdx
  45. pushq %rcx
  46. pushq %rdx
  47. call _relocate
  48. popq %rdi
  49. popq %rsi
  50. call efi_main
  51. addq $8, %rsp
  52. .exit:
  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, "a"
  59. label1:
  60. .long dummy-label1 // Page RVA
  61. .long 10 // Block Size (2*4+2)
  62. .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy