2021-04-23 17:20:27 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2023-05-03 20:04:37 +00:00
|
|
|
* Copyright © 2018,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2021-04-23 17:20:27 +00:00
|
|
|
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
|
riscv64: Port to word based mescc-tools.
* module/mescc/M1.scm (riscv:i-format, riscv:j-format, riscv:u-format):
New procedures for RISC-V instruction formats.
(info->M1): Use them to switch from !0xAB to M1
weird strings 'AB'.
* module/mescc/riscv64/as.scm,
lib/linux/riscv64-mes-m2/_exit.c
ib/linux/riscv64-mes-m2/_write.c,.
lib/linux/riscv64-mes-m2/crt1.M1,.
lib/linux/riscv64-mes-m2/syscall.c,.
lib/linux/riscv64-mes-mescc/_exit.c,.
lib/linux/riscv64-mes-mescc/_write.c,.
lib/linux/riscv64-mes-mescc/crt1.c,.
lib/linux/riscv64-mes-mescc/syscall-internal.c,.
lib/linux/riscv64-mes-mescc/syscall.c,.
lib/m2/riscv64/riscv64_defs.M1,.
lib/riscv64-mes-mescc/setjmp.c,.
lib/riscv64-mes/riscv64.M1: Switch to riscv64 word-based macros.
* lib/linux/open.c (open)[!SYS_open]: Add support using openat syscall.
* include/linux/riscv64/syscall.h (MAKESTRING, MAKESTRING2,
RISCV_SYSCALL): New macros.
2023-05-19 20:51:46 +00:00
|
|
|
* Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
|
2021-04-23 17:20:27 +00:00
|
|
|
*
|
|
|
|
* 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:43:53 +00:00
|
|
|
#include "linux/riscv64/syscall.h"
|
2021-04-23 17:20:27 +00:00
|
|
|
|
2023-08-27 10:53:37 +00:00
|
|
|
int main (int argc, char *argv[], char *envp[]);
|
|
|
|
|
2021-04-23 17:20:27 +00:00
|
|
|
/* mesc will generate the following preamble:
|
|
|
|
|
|
|
|
push ra
|
|
|
|
push fp
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
_start ()
|
|
|
|
{
|
riscv64: Port to word based mescc-tools.
* module/mescc/M1.scm (riscv:i-format, riscv:j-format, riscv:u-format):
New procedures for RISC-V instruction formats.
(info->M1): Use them to switch from !0xAB to M1
weird strings 'AB'.
* module/mescc/riscv64/as.scm,
lib/linux/riscv64-mes-m2/_exit.c
ib/linux/riscv64-mes-m2/_write.c,.
lib/linux/riscv64-mes-m2/crt1.M1,.
lib/linux/riscv64-mes-m2/syscall.c,.
lib/linux/riscv64-mes-mescc/_exit.c,.
lib/linux/riscv64-mes-mescc/_write.c,.
lib/linux/riscv64-mes-mescc/crt1.c,.
lib/linux/riscv64-mes-mescc/syscall-internal.c,.
lib/linux/riscv64-mes-mescc/syscall.c,.
lib/m2/riscv64/riscv64_defs.M1,.
lib/riscv64-mes-mescc/setjmp.c,.
lib/riscv64-mes/riscv64.M1: Switch to riscv64 word-based macros.
* lib/linux/open.c (open)[!SYS_open]: Add support using openat syscall.
* include/linux/riscv64/syscall.h (MAKESTRING, MAKESTRING2,
RISCV_SYSCALL): New macros.
2023-05-19 20:51:46 +00:00
|
|
|
asm ("rd_t1 rs1_fp mv");
|
|
|
|
asm ("rd_t1 rs1_t1 !0x18 addi"); // 0x10 to skip over pushed fp+ra, 0x8 to skip over argc
|
|
|
|
asm ("rd_t5 rs1_fp !0x10 addi"); // 0x10 to skip over pushed fp+ra
|
|
|
|
asm ("rd_t0 rs1_t5 ld");
|
|
|
|
asm ("rd_t0 rs1_t0 !1 addi");
|
|
|
|
asm ("rd_t5 !3 addi"); // skip over all arguments and the final NULL
|
|
|
|
asm ("rd_t0 rs1_t0 rs2_t5 sll");
|
|
|
|
asm ("rd_t0 rs1_t0 rs2_t1 add");
|
|
|
|
asm ("rd_sp rs1_sp !-8 addi"); // push envp onto stack
|
|
|
|
asm ("rs1_sp rs2_t0 sd");
|
|
|
|
asm ("rd_sp rs1_sp !-8 addi"); // push argv onto stack
|
|
|
|
asm ("rs1_sp rs2_t1 sd");
|
|
|
|
asm ("rd_t5 rs1_fp !0x10 addi"); // 0x10 to skip over pushed fp+ra
|
|
|
|
asm ("rd_t0 rs1_t5 ld");
|
|
|
|
asm ("rd_sp rs1_sp !-8 addi"); // push argc onto stack
|
|
|
|
asm ("rs1_sp rs2_t0 sd");
|
2021-04-23 17:20:27 +00:00
|
|
|
|
2023-05-03 20:04:37 +00:00
|
|
|
__init_io ();
|
2021-04-23 17:20:27 +00:00
|
|
|
main ();
|
|
|
|
|
riscv64: Port to word based mescc-tools.
* module/mescc/M1.scm (riscv:i-format, riscv:j-format, riscv:u-format):
New procedures for RISC-V instruction formats.
(info->M1): Use them to switch from !0xAB to M1
weird strings 'AB'.
* module/mescc/riscv64/as.scm,
lib/linux/riscv64-mes-m2/_exit.c
ib/linux/riscv64-mes-m2/_write.c,.
lib/linux/riscv64-mes-m2/crt1.M1,.
lib/linux/riscv64-mes-m2/syscall.c,.
lib/linux/riscv64-mes-mescc/_exit.c,.
lib/linux/riscv64-mes-mescc/_write.c,.
lib/linux/riscv64-mes-mescc/crt1.c,.
lib/linux/riscv64-mes-mescc/syscall-internal.c,.
lib/linux/riscv64-mes-mescc/syscall.c,.
lib/m2/riscv64/riscv64_defs.M1,.
lib/riscv64-mes-mescc/setjmp.c,.
lib/riscv64-mes/riscv64.M1: Switch to riscv64 word-based macros.
* lib/linux/open.c (open)[!SYS_open]: Add support using openat syscall.
* include/linux/riscv64/syscall.h (MAKESTRING, MAKESTRING2,
RISCV_SYSCALL): New macros.
2023-05-19 20:51:46 +00:00
|
|
|
asm ("rd_a0 rs1_t0 mv");
|
|
|
|
asm (RISCV_SYSCALL(SYS_exit));
|
2021-04-23 17:20:27 +00:00
|
|
|
asm ("ecall");
|
|
|
|
asm ("ebreak");
|
|
|
|
}
|