123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /*
- * Copyright (C) 2018 bzt (bztsrc@github)
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
- .section ".text.boot"
- .global _start
- _start:
- // save arguments in registers (we will need them later for the new kernel)
- // I choosed x10-x13 because instructions generated from C by gcc does not
- // touch them. You can check that with "aarch64-elf-objdump -d kernel8.elf"
- mov x10, x0
- mov x11, x1
- mov x12, x2
- mov x13, x3
- // IMPORTANT: because of a change in firmware, this code will only run on the
- // BSP core, therefore there's no need to check the cpu's id. A spin-loop on a
- // non-relocated address would be otherwise bad, thanks for the heads up @mrvn
- // See https://github.com/raspberrypi/tools/blob/master/armstubs/armstub8.S
- // relocate our code from load address to link address
- ldr x1, =0x80000
- ldr x2, =_start
- ldr w3, =__loader_size
- 1: ldr x4, [x1], #8
- str x4, [x2], #8
- sub w3, w3, #1
- cbnz w3, 1b
- // set top of stack just before our code (stack grows to a lower address per AAPCS64)
- ldr x1, =_start
- mov sp, x1
- // clear bss
- ldr x1, =__bss_start
- ldr w2, =__bss_size
- 3: cbz w2, 4f
- str xzr, [x1], #8
- sub w2, w2, #1
- cbnz w2, 3b
- // jump to relocated C code, should not return
- 4: bl main-1024
- // for failsafe, halt this core too
- b 1b
|