start64.S 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * raspi/start64.S
  3. * https://gitlab.com/bztsrc/imgrecv
  4. *
  5. * Copyright (C) 2020 bzt (bztsrc@github)
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. .section ".text.boot"
  29. .global _start
  30. _start:
  31. // save arguments in registers (we will need them later for the new kernel)
  32. // I choosed x20-x23 because instructions generated from C by gcc does not
  33. // touch them. You can check that with "aarch64-elf-objdump -d kernel8.elf"
  34. mov x20, x0
  35. mov x21, x1
  36. mov x22, x2
  37. mov x23, x3
  38. // read cpu id, stop slave cores
  39. mrs x1, mpidr_el1
  40. and x1, x1, #3
  41. cbz x1, 2f
  42. // cpu id > 0, stop
  43. 1: wfe
  44. b 1b
  45. 2: // cpu id == 0
  46. // relocate our code from load address to link address
  47. ldr x1, =LOAD_ADDR
  48. mov x0, x1
  49. ldr x2, =_start
  50. mov sp, x2
  51. ldr w3, =__loader_size
  52. 1: ldr x4, [x1], #8
  53. str x4, [x2], #8
  54. sub w3, w3, #1
  55. cbnz w3, 1b
  56. // jump to relocated C code
  57. bl receiver-1024
  58. // restore registers and jump to new kernel's entry point
  59. mov x30, x0
  60. mov x0, x20
  61. mov x1, x21
  62. mov x2, x22
  63. mov x3, x23
  64. ret