libgloss: riscv: Fix envp parameter for main

Message ID fe866abd-d637-4b2b-b7f2-54e3a56a990b@edlinger-online.de
State New
Headers
Series libgloss: riscv: Fix envp parameter for main |

Commit Message

Bernd Edlinger April 11, 2024, 12:57 p.m. UTC
  The envp paramter is currently NULL when crt0.S calls main.
With this patch the envp parameter should now be set correctly.
Tested with riscv32 and riscv64: both gdb/sim and qemu do work.
---
 libgloss/riscv/crt0.S | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Corinna Vinschen April 12, 2024, 9:45 a.m. UTC | #1
On Apr 11 14:57, Bernd Edlinger wrote:
> The envp paramter is currently NULL when crt0.S calls main.
> With this patch the envp parameter should now be set correctly.
> Tested with riscv32 and riscv64: both gdb/sim and qemu do work.
> ---
>  libgloss/riscv/crt0.S | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
> index f1c5419a5..54443e412 100644
> --- a/libgloss/riscv/crt0.S
> +++ b/libgloss/riscv/crt0.S
> @@ -61,7 +61,9 @@ _start:
>  
>    lw      a0, 0(sp)                  # a0 = argc
>    addi    a1, sp, __SIZEOF_POINTER__ # a1 = argv
> -  li      a2, 0                      # a2 = envp = NULL
> +  slli    a2, a0, 1 + __SIZEOF_POINTER__ >> 2
> +  addi    a2, a2, __SIZEOF_POINTER__
> +  add     a2, a2, a1                 # a2 = envp
>    call    main
>    tail    exit
>    .size  _start, .-_start
> -- 
> 2.25.1

Pushed.

Thanks,
Corinna
  

Patch

diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
index f1c5419a5..54443e412 100644
--- a/libgloss/riscv/crt0.S
+++ b/libgloss/riscv/crt0.S
@@ -61,7 +61,9 @@  _start:
 
   lw      a0, 0(sp)                  # a0 = argc
   addi    a1, sp, __SIZEOF_POINTER__ # a1 = argv
-  li      a2, 0                      # a2 = envp = NULL
+  slli    a2, a0, 1 + __SIZEOF_POINTER__ >> 2
+  addi    a2, a2, __SIZEOF_POINTER__
+  add     a2, a2, a1                 # a2 = envp
   call    main
   tail    exit
   .size  _start, .-_start