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.
This commit is contained in:
parent
368ddbcd4f
commit
aa97000027
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019,2020,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||
*
|
||||
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <mes/lib-mini.h>
|
||||
//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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
||||
*
|
||||
* 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");
|
||||
|
|
Loading…
Reference in a new issue