Browse Source

Assure address of PC at startup.

Ein Terakawa 5 years ago
parent
commit
23605f5b35
1 changed files with 19 additions and 0 deletions
  1. 19 0
      riscv-rt/asm.S

+ 19 - 0
riscv-rt/asm.S

@@ -12,6 +12,25 @@
 .global _start
 
 _start:
+    /* Jump to the absolute address defined by the linker script. */
+    // for 32bit
+    .if __riscv_xlen == 32
+    lui ra, %hi(_abs_start)
+    jr %lo(_abs_start)(ra)
+    .endif
+
+    // for 64bit
+    .if __riscv_xlen == 64
+1:
+    auipc ra, %pcrel_hi(1f)
+    ld ra, %pcrel_lo(1b)(ra)
+    jr ra
+    .align  3
+1:
+    .dword _abs_start
+    .endif
+
+_abs_start:
     .cfi_startproc
     .cfi_undefined ra