public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Initialize the jvt CSR
@ 2024-01-05  3:07 Hau Hsu
  2024-01-05  6:49 ` Kito Cheng
  0 siblings, 1 reply; 6+ messages in thread
From: Hau Hsu @ 2024-01-05  3:07 UTC (permalink / raw)
  To: hau.hsu, newlib, kito.cheng

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.  */
+.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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] RISC-V: Initialize the jvt CSR
  2024-01-05  3:07 [PATCH] RISC-V: Initialize the jvt CSR Hau Hsu
@ 2024-01-05  6:49 ` Kito Cheng
  0 siblings, 0 replies; 6+ messages in thread
From: Kito Cheng @ 2024-01-05  6:49 UTC (permalink / raw)
  To: Hau Hsu; +Cc: newlib

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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] RISC-V: Initialize the jvt CSR
  2023-09-25  5:36 Hau Hsu
  2023-09-25  6:17 ` Kito Cheng
@ 2023-09-29  2:26 ` Kito Cheng
  1 sibling, 0 replies; 6+ messages in thread
From: Kito Cheng @ 2023-09-29  2:26 UTC (permalink / raw)
  To: Hau Hsu; +Cc: newlib

On Mon, Sep 25, 2023 at 1:37 PM Hau Hsu via Newlib
<newlib@sourceware.org> 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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] RISC-V: Initialize the jvt CSR
  2023-09-25  6:17 ` Kito Cheng
@ 2023-09-27  1:17   ` Hau Hsu
  0 siblings, 0 replies; 6+ messages in thread
From: Hau Hsu @ 2023-09-27  1:17 UTC (permalink / raw)
  To: Newlib; +Cc: Kito Cheng

[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]

We found a potential ISA conflict when compiling the crt0.S with zcd extension.
We already have a new patch under testing.
I'll send it after it is verified.

Best,

Hau Hsu
Software Engineer
hau.hsu@sifive.com




> Kito Cheng <kito.cheng@gmail.com> 於 2023年9月25日 下午2:17 寫道:
> 
> LGTM 
> 
> Hau Hsu via Newlib <newlib@sourceware.org <mailto:newlib@sourceware.org>> 於 2023年9月25日 週一 06:37 寫道:
>> 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
>> +  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
>> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] RISC-V: Initialize the jvt CSR
  2023-09-25  5:36 Hau Hsu
@ 2023-09-25  6:17 ` Kito Cheng
  2023-09-27  1:17   ` Hau Hsu
  2023-09-29  2:26 ` Kito Cheng
  1 sibling, 1 reply; 6+ messages in thread
From: Kito Cheng @ 2023-09-25  6:17 UTC (permalink / raw)
  To: Hau Hsu; +Cc: Newlib

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

LGTM

Hau Hsu via Newlib <newlib@sourceware.org> 於 2023年9月25日 週一 06:37 寫道:

> 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
> +  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
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] RISC-V: Initialize the jvt CSR
@ 2023-09-25  5:36 Hau Hsu
  2023-09-25  6:17 ` Kito Cheng
  2023-09-29  2:26 ` Kito Cheng
  0 siblings, 2 replies; 6+ messages in thread
From: Hau Hsu @ 2023-09-25  5:36 UTC (permalink / raw)
  To: hau.hsu, newlib, kito.cheng

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
+  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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-05  6:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05  3:07 [PATCH] RISC-V: Initialize the jvt CSR Hau Hsu
2024-01-05  6:49 ` Kito Cheng
  -- strict thread matches above, loose matches on Subject: below --
2023-09-25  5:36 Hau Hsu
2023-09-25  6:17 ` Kito Cheng
2023-09-27  1:17   ` Hau Hsu
2023-09-29  2:26 ` Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).