crt0-efi-aarch64.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * crt0-efi-aarch64.S - PE/COFF header for AArch64 EFI applications
  3. *
  4. * Copright (C) 2014 Linaro Ltd. <[email protected]>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice and this list of conditions, without modification.
  11. * 2. The name of the author may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * Alternatively, this software may be distributed under the terms of the
  15. * GNU General Public License as published by the Free Software Foundation;
  16. * either version 2 of the License, or (at your option) any later version.
  17. */
  18. .text
  19. .align 12
  20. .globl _start
  21. .type _start,%function
  22. _start:
  23. stp x29, x30, [sp, #-32]!
  24. mov x29, sp
  25. stp x0, x1, [sp, #16]
  26. mov x2, x0
  27. mov x3, x1
  28. adr x0, ImageBase
  29. adrp x1, _DYNAMIC
  30. add x1, x1, #:lo12:_DYNAMIC
  31. bl _relocate
  32. cbnz x0, 0f
  33. ldp x0, x1, [sp, #16]
  34. bl _entry
  35. 0: ldp x29, x30, [sp], #32
  36. ret
  37. // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
  38. .data
  39. dummy: .4byte 0
  40. #define IMAGE_REL_ABSOLUTE 0
  41. .section .reloc, "a"
  42. label1:
  43. .4byte dummy-label1 // Page RVA
  44. .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits
  45. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  46. .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
  47. #if defined(__ELF__) && defined(__linux__)
  48. .section .note.GNU-stack,"",%progbits
  49. #endif