1/* 2 * Copyright 2019, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12.section .text 13.global _start 14_start: 15 16/* 17 * RISC-V uses the gp (global pointer) to provide a link-time 18 * optimisation. It is kept in a location near the most-used symbols in 19 * the text segments for any particular section of code. 20 * 21 * This means that a single instruction can be used to jump to a small 22 * offset from the gp rather than 2 or more instructions to do a far 23 * jump to an absolute address. 24 * 25 * The initial location for this is only known at the final link stage 26 * before assembly of the static image. This code below uses a 27 * replacement from the linker to set the value of the gp. 28 * 29 * Relaxation must be disabled when this value is set, otherwise parts 30 * of this code may be optimised away. 31 * 32 * https://web.archive.org/web/20170828212605/https://www.sifive.com/blog/2017/08/28/all-aboard-part-3-linker-relaxation-in-riscv-toolchain/ 33 */ 34.option push 35.option norelax 361:auipc gp, %pcrel_hi(__global_pointer$) 37 addi gp, gp, %pcrel_lo(1b) 38.option pop 39 40 li s0, 0 41 li ra, 0 42 43 addi a0, sp, 0 44 jal ra, __sel4_start_c 45 46 /* should not return */ 471: 48 j 1b 49