Re: [PATCH] RISC-V: Initialize the jvt CSR

Kito Cheng <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CA+yXCZDZaYcyD7gaKuyYTFX40e==St7CZLeCxvQOcqDSF8rw5w@mail.gmail.com>
On Mon, Sep 25, 2023 at 1:37 PM Hau Hsu via Newlib
<[email protected]> wrote:
>
> We 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.
>
> psabi reference:
> https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/2d770815dc9a8b11e61ea1abd487cb25ee56ad5e/riscv-elf.adoc#table-jump-relaxation
> ---
>  libgloss/riscv/crt0.S | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
> index 7a4e4e32c..4744ba039 100644
> --- a/libgloss/riscv/crt0.S
> +++ b/libgloss/riscv/crt0.S
> @@ -26,6 +26,16 @@ _start:
>    addi  gp, gp, %pcrel_lo(1b)
>  .option pop
>
> +  /* Initialize jvt CSR */
> +  .weak __jvt_base$
> +.option push
> +.option arch, +zcmt, +zicsr

I guess I am little concerned about the backward compatibility, zcmt
isn't supported by trunk binutils even, so maybe we should just +zicsr
to make sure csrw is usable, and use csr number directly instead of
using symbolic name to prevent the backward incompatible issue.

> +  lla a0, __jvt_base$
> +  beqz a0, .Ljvt_init_end
> +  csrw jvt, a0
> +.Ljvt_init_end:
> +.option pop
> +
>    # Clear the bss segment
>    la      a0, __bss_start
>    la      a2, _end
> --
> 2.42.0
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.