From aa97000027994ff868238bd434b32e3d383cd017 Mon Sep 17 00:00:00 2001 From: Janneke Nieuwenhuizen Date: Wed, 3 May 2023 22:04:37 +0200 Subject: [PATCH] riscv64: lib: Use __init_io. * lib/linux/riscv64-mes-gcc/crt1.c (_start): Replace manual initialization of __stdin, __stdout, __stderr, and environ with __init_io (). * lib/linux/riscv64-mes-mescc/crt1.c (_start): Likewise. --- lib/linux/riscv64-mes-gcc/crt1.c | 34 +++++------------------------- lib/linux/riscv64-mes-mescc/crt1.c | 18 ++-------------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/lib/linux/riscv64-mes-gcc/crt1.c b/lib/linux/riscv64-mes-gcc/crt1.c index e0a2e22e..3f3d7ce8 100644 --- a/lib/linux/riscv64-mes-gcc/crt1.c +++ b/lib/linux/riscv64-mes-gcc/crt1.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019,2020,2023 Jan (janneke) Nieuwenhuizen * Copyright © 2019,2020 Danny Milosavljevic * Copyright © 2021 W. J. van der Laan * @@ -21,7 +21,7 @@ */ #include -//int main (int argc, char *argv[], char *envp[]); +int main (int argc, char *argv[], char *envp[]); /* gcc will generate the following preamble: @@ -42,42 +42,18 @@ _start () "andi sp, sp, ~15\n\t" // make sure sp conforms to ABI alignment ); - asm ( - "li t0, 0\n\t" - "mv %0, t0\n" - : "=r" (__stdin) - : //no inputs "" - ); - - asm ( - "li t0, 1\n\t" - "mv %0, t0\n" - : "=r" (__stdout) - : //no inputs "" - ); - - asm ( - "li t0, 2\n\t" - "mv %0, t0\n" - : "=r" (__stderr) - : //no inputs "" - ); - // environ is &argv[argc + 1] asm ( "lw t0, 0(s0)\n\t" "addi t1, s0, 8\n\t" "addi t0, t0, 1\n\t" "slli t0, t0, 3\n\t" - "add %0, t1, t0\n\t" - : "=r" (environ) - : //no inputs "" - ); + "add t0, t1, t0\n\t" - asm ( "lw a0, 0(s0)\n\t" // a0 argc "addi a1, s0, 8\n\t" // a1 argv - "mv a2, %0\n\t" // a2 envp + "mv a2, t0\n\t" // a2 envp + "jal __init_io\n\t" "jal main\n\t" "li a7, 93\n\t" // SYS_exit diff --git a/lib/linux/riscv64-mes-mescc/crt1.c b/lib/linux/riscv64-mes-mescc/crt1.c index 9acff4a4..b9761126 100644 --- a/lib/linux/riscv64-mes-mescc/crt1.c +++ b/lib/linux/riscv64-mes-mescc/crt1.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2023 Jan (janneke) Nieuwenhuizen * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. @@ -30,20 +30,6 @@ int main (int argc, char *argv[], char *envp[]); int _start () { - asm ("li_____%t0,$i16_0000 @0"); - asm ("li_____%t1,$i32 &__stdin"); - asm ("sw_____%t0,0(%t1)"); - - asm ("li_____%t0,$i16_0000 @1"); - asm ("srai___%t0,16"); - asm ("li_____%t1,$i32 &__stdout"); - asm ("sw_____%t0,0(%t1)"); - - asm ("li_____%t0,$i16_0000 @2"); - asm ("srai___%t0,16"); - asm ("li_____%t1,$i32 &__stderr"); - asm ("sw_____%t0,0(%t1)"); - // environ is &argv[argc + 1] asm ("mv_____%t1,%fp"); asm ("addi___%t1,%t1,$i8_8 !0x1"); // 0x10 to skip over pushed fp+ra, 0x8 to skip over argc @@ -55,12 +41,12 @@ _start () asm ("add____%t0,%t0,%t1"); asm ("push___%t0"); // envp asm ("push___%t1"); // argv - asm ("li_____%t1,$i32 &environ"); asm ("sd_____%t0,0(%t1)"); asm ("addi___%t5,%fp,$i8_0 !0x1"); // 0x10 to skip over pushed fp+ra asm ("ld_____%t0,0(%t5)"); asm ("push___%t0"); // argc + __init_io (); main (); asm ("mv_____%a0,%t0");