RISC-V: Initialize the jvt CSR

Message ID 20240105030709.4179529-1-hau.hsu@sifive.com
State New
Headers
Series RISC-V: Initialize the jvt CSR |

Commit Message

Hau Hsu Jan. 5, 2024, 3:07 a.m. UTC
  Set symbol '__jvt_base$' as weak. So if the symbol is not set in the
linker script, the address would be 0. We initialize jvt CSR only if
the address is not 0.

Also use csr number directly instead of using symbolic name to prevent the
backward incompatible issue.

psabi reference:
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/2d770815dc9a8b11e61ea1abd487cb25ee56ad5e/riscv-elf.adoc#table-jump-relaxation
---
 libgloss/riscv/crt0.S | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Kito Cheng Jan. 5, 2024, 6:49 a.m. UTC | #1
On Fri, Jan 5, 2024 at 11:07 AM Hau Hsu <hau.hsu@sifive.com> wrote:
>
> Set symbol '__jvt_base$' as weak. So if the symbol is not set in the
> linker script, the address would be 0. We initialize jvt CSR only if
> the address is not 0.
>
> Also use csr number directly instead of using symbolic name to prevent the
> backward incompatible issue.
>
> psabi reference:
> https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/2d770815dc9a8b11e61ea1abd487cb25ee56ad5e/riscv-elf.adoc#table-jump-relaxation
> ---
>  libgloss/riscv/crt0.S | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
> index 7a4e4e32c..187ca4a56 100644
> --- a/libgloss/riscv/crt0.S
> +++ b/libgloss/riscv/crt0.S
> @@ -26,6 +26,19 @@ _start:
>    addi  gp, gp, %pcrel_lo(1b)
>  .option pop
>
> +  /* Initialize jvt CSR (reg addr: 0x0017) */
> +  .weak __jvt_base$
> +  lla a0, __jvt_base$
> +  beqz a0, .Ljvt_init_end
> +  /* Enable zicsr to set jvt.
> +     Also need to exclude conflict extensions.  */

^^^ comment seems not in sync with the code?

> +.option push
> +.option norelax
> +.option arch, +zicsr
> +  csrw 0x17, a0
> +.option pop
> +.Ljvt_init_end:
> +
>    # Clear the bss segment
>    la      a0, __bss_start
>    la      a2, _end
> --
> 2.37.1
>
  

Patch

diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
index 7a4e4e32c..187ca4a56 100644
--- a/libgloss/riscv/crt0.S
+++ b/libgloss/riscv/crt0.S
@@ -26,6 +26,19 @@  _start:
   addi  gp, gp, %pcrel_lo(1b)
 .option pop
 
+  /* Initialize jvt CSR (reg addr: 0x0017) */
+  .weak __jvt_base$
+  lla a0, __jvt_base$
+  beqz a0, .Ljvt_init_end
+  /* Enable zicsr to set jvt.
+     Also need to exclude conflict extensions.  */
+.option push
+.option norelax
+.option arch, +zicsr
+  csrw 0x17, a0
+.option pop
+.Ljvt_init_end:
+
   # Clear the bss segment
   la      a0, __bss_start
   la      a2, _end