From f49689d31a3abbd95055670dbdd56722fdd3c5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 6 Oct 2023 22:51:27 +0100 Subject: [PATCH] DRAFT riscv64: Fix arguments of main function in tcc. * lib/linux/riscv64-mes-tcc/crt1.c Co-authored-by: Ekaitz Zarraga . --- lib/linux/riscv64-mes-tcc/crt1.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/linux/riscv64-mes-tcc/crt1.c b/lib/linux/riscv64-mes-tcc/crt1.c index 0fe6c686..b91e9dfe 100644 --- a/lib/linux/riscv64-mes-tcc/crt1.c +++ b/lib/linux/riscv64-mes-tcc/crt1.c @@ -45,7 +45,21 @@ _start () "addi a1, s0, 8\n\t" // a1 argv "mv a2, t0\n\t" // a2 envp + // Push arguments to stack + "addi sp, sp, -32\n\t" + "sd sp, a0, 8\n\t" // argc + "sd sp, a1, 16\n\t" // argv + "sd sp, a2, 24\n\t" // envp + + "jal ra, __init_io\n\t" + + // Recover stack + "ld a0, sp, 8\n\t" // a0 argc + "ld a1, sp, 16\n\t" // a0 argc + "ld a2, sp, 24\n\t" // a0 argc + "addi sp, sp, 32\n\t" + "jal ra, main\n\t" "li a7, 93\n\t" // SYS_exit