crt0-efi-x86_64.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. .type _start,%function
  37. _start:
  38. subq $8, %rsp
  39. pushq %rcx
  40. pushq %rdx
  41. 0:
  42. lea ImageBase(%rip), %rdi
  43. lea _DYNAMIC(%rip), %rsi
  44. popq %rcx
  45. popq %rdx
  46. pushq %rcx
  47. pushq %rdx
  48. call _relocate
  49. popq %rdi
  50. popq %rsi
  51. call _entry
  52. addq $8, %rsp
  53. .exit:
  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, "a"
  60. label1:
  61. .4byte dummy-label1 // Page RVA
  62. .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits
  63. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  64. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  65. #if defined(__ELF__) && defined(__linux__)
  66. .section .note.GNU-stack,"",%progbits
  67. #endif