2021-04-04 07:24:07 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2023-05-03 20:04:37 +00:00
|
|
|
* Copyright © 2017,2018,2019,2020,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2021-04-04 07:24:07 +00:00
|
|
|
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
|
|
|
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of GNU Mes.
|
|
|
|
*
|
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <mes/lib-mini.h>
|
2023-08-27 10:53:37 +00:00
|
|
|
int main (int argc, char *argv[], char *envp[]);
|
2021-04-04 07:24:07 +00:00
|
|
|
|
|
|
|
/* gcc will generate the following preamble:
|
|
|
|
|
|
|
|
addi sp,sp,-16
|
|
|
|
sd s0,8(sp)
|
|
|
|
addi s0,sp,16
|
|
|
|
*/
|
|
|
|
|
|
|
|
// *INDENT-OFF*
|
|
|
|
void
|
|
|
|
_start ()
|
|
|
|
{
|
|
|
|
asm (
|
|
|
|
".option push\n\t"
|
|
|
|
".option norelax\n\t"
|
|
|
|
"lla gp, __global_pointer$\n\t"
|
|
|
|
".option pop\n\t"
|
|
|
|
"andi sp, sp, ~15\n\t" // make sure sp conforms to ABI alignment
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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"
|
2023-05-03 20:04:37 +00:00
|
|
|
"add t0, t1, t0\n\t"
|
2021-04-04 07:24:07 +00:00
|
|
|
|
|
|
|
"lw a0, 0(s0)\n\t" // a0 argc
|
|
|
|
"addi a1, s0, 8\n\t" // a1 argv
|
2023-05-03 20:04:37 +00:00
|
|
|
"mv a2, t0\n\t" // a2 envp
|
|
|
|
"jal __init_io\n\t"
|
2021-04-04 07:24:07 +00:00
|
|
|
"jal main\n\t"
|
|
|
|
|
|
|
|
"li a7, 93\n\t" // SYS_exit
|
|
|
|
"ecall\n\t" // exit(return value from main)
|
|
|
|
|
|
|
|
"ebreak\n\t"
|
|
|
|
: //no outputs ""
|
|
|
|
: "r" (environ)
|
|
|
|
);
|
|
|
|
}
|