Commit Graph

2385 Commits

Author SHA1 Message Date
Andrius Štikonas a34f255f40 riscv64: Fix arguments of main function in tcc.
* lib/linux/riscv64-mes-tcc/crt1.c
2023-10-06 19:54:40 +01:00
Andrius Štikonas eea9f759ee riscv64: simplify assembly constructs not supported by tcc.
At the moment tcc does not support assembler instructions
with C expression operands. As a workaround read values
directly from stack.

* lib/linux/riscv64-mes-tcc/_exit.c
* lib/linux/riscv64-mes-tcc/_write.c
* lib/linux/riscv64-mes-tcc/syscall.c
2023-10-04 23:23:05 +01:00
Janneke Nieuwenhuizen 44de0ec1c4 squash! riscv64: add support for tcc 2023-09-21 18:10:25 +02:00
Ekaitz 72758d48d8 riscv64: add support for tcc
Adapted from -gcc but make assembly match tcc style assembly where the
offsets are received as an extra input argument:

  sw a0, 9(t0)

Becomes:

  sw a0, t0, 9

* lib/linux/riscv64-mes-tcc/_exit.c,
lib/linux/riscv64-mes-tcc/_write.c,
lib/linux/riscv64-mes-tcc/crt1.c,
lib/linux/riscv64-mes-tcc/exit-42.S,
lib/linux/riscv64-mes-tcc/hello-mes.S,
lib/linux/riscv64-mes-tcc/syscall-internal.c,
lib/linux/riscv64-mes-tcc/syscall.c: New files.
2023-09-21 18:07:48 +02:00
Janneke Nieuwenhuizen 98f37a5bdb squash! mescc: Fix switch statements' fallthrough 2023-09-17 07:44:16 +02:00
Janneke Nieuwenhuizen 6ec2715f74 Revert "squash! mescc: Fix switch statements' fallthrough --support mes"
This reverts commit ef4f4bb25a.
2023-09-17 07:41:03 +02:00
Janneke Nieuwenhuizen c65ce2798b Revert "squash! squash! mescc: Fix switch statements' fallthrough --support mes"
This reverts commit 3266f6a834.
2023-09-17 07:41:01 +02:00
Janneke Nieuwenhuizen 3266f6a834 squash! squash! mescc: Fix switch statements' fallthrough --support mes 2023-09-16 17:38:48 +02:00
Janneke Nieuwenhuizen ef4f4bb25a squash! mescc: Fix switch statements' fallthrough --support mes 2023-09-16 08:19:02 +02:00
Ekaitz 1ec88d0109 mescc: Fix switch statements' fallthrough
Flattens case structures as nyacc is giving consecutive cases as a
nested block like:

    (case testA
      (case testB
        (case testC BODY)))

We convert to:

    ((case testA (expr-stmt))
     (case testB (expr-stmt))
     (case testC BODY))

And then treat them as independent cases. For the fallthrough we just
add a jump to each case's body right before its clause (each of the case
blocks is responsible of adding its own jump to its body):

        // This doesn't have it because it's the first
    CASE1:
        testA
    CASE1_BODY:

        goto CASE2_BODY
    CASE2:
        testB
    CASE2_BODY:

        goto CASE3_BODY
    CASE3:
        testB
    CASE3_BODY:

This enables complex fallthrough schemes comparing to what was done
before.

* module/mescc/compile.scm
  (ast->info)[switch]{flatten-cases}: New variable.
  (ast->info)[switch]{statements}: Use flatten-cases on it.
  (switch->expr): Remove unneeded matchers and add jumps to body.
* build-aux/check-mescc.sh(xfail-tests): Remove
  lib/tests/scaffold/66-local-char-array.c
2023-09-13 13:48:33 +02:00
Ekaitz 7ae03cc19b lib/tests: 44-switch-body-fallthrough-not-default.c: Add test.
This test detects if the fallthrough in a switch statement falls to the
next case (good) or to the default case (bad).

* lib/tests/scaffold/44-switch-body-fallthrough-not-default.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:11 +02:00
Ekaitz c989f9c56a lib/tests: 50-compare-rotated-weird.c: Add test for RV reloc
We detected the value in off64 in the test is not -1 as it should but 56
ones. This is because the rotation is applied as unsigned even with the
signed cast. This breaks many things in tcc.

* lib/tests/scaffold/50-compare-rotated-weird.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:11 +02:00
Ekaitz 4e9f08e2af mescc: Add support for signed rotation.
* module/mescc/compile.scm (expr->register)[rshift, assn-expr]: Add
signed right-rotation support.
* lib/arm-mes/arm.M1 (asr): Add instruction.
* lib/x86-mes/x86.M1 (sar): Add instruction.
* lib/x86_64-mes/x86_64.M1 (sar): Add instruction.
* module/mescc/armv4/as.scm (armv4:r0>>r1-signed): New procedure.
(armv4:instructions): Register it.
* module/mescc/i386/as.scm (i386:r0>>r1-signed): New procedure.
(i386:instructions): Register it.
* module/mescc/riscv64/as.scm (riscv64:r0>>r1-signed): New procedure.
(riscv64:instructions): Register it.
* module/mescc/x86_64/as.scm (x86_64:r0>>r1-signed): New procedure.
(x86_64:instructions): Register it.
(
2023-09-12 11:04:11 +02:00
Ekaitz efa2ff9474 XXX lib: Make objdump work on binaries in riscv64
XXX: do the same for other architectures

* lib/linux/riscv64-mes/elf32-header.hex2: Fix header sizes for objdump.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 0f0a510c43 Revert "crt1: Move main declaration to mes/lib-mini.h."
This reverts commit 5b55627e0ccf7c798284a380a20a2eb4d6b9c4c0.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 376f8a43d0 crt1: Move main declaration to mes/lib-mini.h.
* include/mes/lib-mini.h (main): New declaration.
lib/freebsd/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/freebsd/x86-mes-mescc/crt1.c (main): Remove declaration.
lib/gnu/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/arm-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/arm-mes-m2/crt1.c (main): Remove declaration.
lib/linux/arm-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-m2/crt1.c (main): Remove declaration.
lib/linux/riscv64-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/x86-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/x86-mes-m2/crt1.c (main): Remove declaration.
lib/linux/x86-mes-mescc/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-gcc/crt0.c (main): Remove declaration.
lib/linux/x86_64-mes-gcc/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-m2/crt1.c (main): Remove declaration.
lib/linux/x86_64-mes-mescc/crt1.c (main): Remove declaration.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen fdf147fa59 DRAFT doc: Add ANNOUNCE-0.25.
* doc/announce/ANNOUNCE-0.24: Typo.
* doc/announce/ANNOUNCE-0.25: New file.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 7317a2f5a8 Add .mailmap.
* .mailmap: New file.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 84785b16f7 DRAFT doc: Update `NEWS'.
* NEWS (Changes in 0.25 since 0.24.2): New section.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 8b0f2e29db DRAFT doc: Update `AUTHORS'.
* AUTHORS: Mention RISC-V port.
* mes/module/mes/repl.mes (welcome): Add Wladimir van der Laan and
Andrius Štikonas.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen c7981c0c9e DRAFT doc: Update `README'.
* README: Updates for 0.25.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen ed12d52f1a DRAFT doc: Bump M2-Planet requirement to 1.11.0.
* doc/mes.texi (Requirements): Update M2-Planet version to 1.11.0.
(Bootstrap Requirements): Likewise.
* INSTALL (Other GNU/Linux): Likewise.
2023-09-12 11:04:11 +02:00
Ekaitz b12f56c922 mescc: Initialize missing struct fields to 0.
This is a follow-up to commits
    7a8a2fc517
    mescc: x86_64 support: Refactor to abstracted assembly, add x86_64.

and

    c9ba7a619b
    mescc: Refactor variable declaration.

There was a debug "22" leaking in compile.scm.  It should be a "0".

* module/mescc/compile.scm (init-local): Replace "22" with "0".
* lib/tests/scaffold/7v-struct-initialize-zeroes.c: New test.
* build-aux/check-mescc.sh (tcc_tests): Add it.
(xfail-tests): Remove lib/tests/scaffold/72-typedef-struct-def-local.c.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen c5fbf9a06c lib/tests: 76-pointer-arithmetic: Cater for RISC-V64.
* lib/tests/scaffold/76-pointer-arithmetic.c (struct
foo)[__riscv_xlen==64]: Add __align.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 7980716681 riscv64: lib/tests: Skip 70-extern.c for gcc.
* build-aux/check-mescc.sh (xfail_tests)[gcc && riscv64]: Add
lib/tests/scaffold/70-extern.c.
2023-09-12 11:04:11 +02:00
Andrius Štikonas e42cf58d14 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-09-12 11:04:11 +02:00
Andrius Štikonas c009e6a191 build: Ignore /m2 build directory.
* .gitignore: Add /m2.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 60c4c193ef guix: m2-planet: Update to 0.10.0-1-c82fb8c353.
* guix/git/mes.scm (m2-planet)[source]: Update to
0.10.0-1-c82fb8c3530e93fd49efe60da785ffff827ea4d.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 6bcc8813cf doc: Update `PORTING'.
* PORTING (Setup environment): Use nyacc 1.00.2.  Prefer git-minimal
over git to avoid dependencies on subversion and graphic libraries.  Add
riscv64-linux example.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 03ef0cabc4 gnu: Update main prototype.
* lib/gnu/x86-mes-gcc/crt1.c (main): Add parameters.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 02bc7e62ee 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.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 826c517ad0 arm: lib: Use __init_io.
* lib/linux/arm-mes-gcc/crt1.c (_start): Replace manual initialization
of __stdin, __stdout, __stderr, and environ with __init_io ().
* lib/linux/arm-mes-m2/crt1.M1 (_start): Likewise.
* lib/linux/arm-mes-mescc/crt1.c (_start): Likewise.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 4ca7029115 freebsd: lib: Use __init_io.
* * lib/freebsd/x86-mes-gcc/crt1.c (_start): Replace manual initialization
of __stdin, __stdout, __stderr, and environ with __init_io ().
* lib/freebsd/x86-mes-mescc/crt1.c (_start): Likewise.
* lib/freebsd/x86-mes-gcc/_write.c (SYS_exit): Remove.
(SYS_write): New define.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen a65981af98 x86_64: lib: Use __init_io.
* lib/linux/x86_64-mes-gcc/crt1.c (_start): Replace manual initialization
of __stdin, __stdout, __stderr, and environ with __init_io ().
* lib/linux/x86_64-mes-m2/crt1.M1 (_start): Likewise.
* lib/linux/x86_64-mes-mescc/crt1.c (_start): Likewise.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen afe3831e66 x86: lib: Use __init_io.
* build-aux/configure-lib.sh (libc_mini_shared_SOURCES): Add init_io.c.
* include/mes/lib-mini.h (__init_io): Declare it.
* lib/linux/x86-mes-gcc/crt1.c (_start): Replace manual initialization
of __stdin, __stdout, __stderr, and environ with __init_io ().
* lib/linux/x86-mes-m2/crt1.M1 (_start): Likewise.
* lib/linux/x86-mes-mescc/crt1.c (_start): Likewise.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen df15c0ecd7 core: Remove duplicate environment initialization.
* src/mes.c (init): Remove envp parameter.  Remove environment initialization.
(main): Remove envp parameter.  Update caller.
2023-09-12 11:04:11 +02:00
Jan (janneke) Nieuwenhuizen d40520af55 riscv64: Cater for M2-Planet.
* kaem.riscv64: New file.

* lib/linux/riscv64-mes-m2/crt1.M1,
lib/m2/riscv64/ELF-riscv64.hex2,
lib/m2/riscv64/riscv64_defs.M1: New files, imported from M2Lib.c
* lib/linux/riscv64-mes-m2/_exit.c,
lib/linux/riscv64-mes-m2/_write.c,
lib/linux/riscv64-mes-m2/crt1.c,
lib/linux/riscv64-mes-m2/syscall.c: New files, adapted for M2-Planet
calling convention from ...
* lib/linux/riscv64-mes-mescc: ...here
* kaem.run: Move fcntl.h up.  Include signal.h.
* build-aux/build.sh.in: Also allow kaem build for riscv64.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen 14ef14edf5 scaffold: Add env.
* scaffold/env.c,
scaffold/env.kaem: New files.
* build-aux/build.sh.in: Use them.
2023-09-12 11:04:11 +02:00
Jan (janneke) Nieuwenhuizen 96aec42a89 guix: mescc-tools: Add RISCV architectures.
This is a follow-up to commit
    79da3fc3e2
    guix: mescc-tools: Update to 1.4.0

* guix/git/mes.scm (mescc-tools)[supported-systems]: Add riscv32-linux
and riscv64-linux.
2023-09-12 11:04:11 +02:00
Jan (janneke) Nieuwenhuizen 3c767a3bf9 mescc: Use size 8 for stack.
Reported by  W. J. van der Laan <laanwj@protonmail.com>.

* module/mescc/x86_64/as.scm (x86_64:function-locals): Oops, use size 8.
2023-09-12 11:04:11 +02:00
W. J. van der Laan 310620eef9 lib: Linux riscv64-mes-mescc support.
* 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: New files.  These add support for
building for riscv64-mes-mescc and make it self-hosting.
2023-09-12 11:04:11 +02:00
W. J. van der Laan 9d5613e0af lib: Base riscv64-mes-mescc support.
* lib/riscv64-mes-mescc/setjmp.c: New file.
(setjmp, longjmp): Implement for RV64.
2023-09-12 11:04:11 +02:00
W. J. van der Laan 58fb0c78f2 lib: Add RISCV64 instruction macros for M1.
* lib/riscv64-mes/riscv64.M1: New file.  Add set of instruction macros
for RV64.  These are all potentially needed by the code generation.  I
have made no effort yet to minimize the list of instructions for mes+tcc
compile.
2023-09-12 11:04:11 +02:00
W. J. van der Laan dc6af19506 mescc: RISC-V64 code generation.
* mes/module/mescc/mescc.mes: Import riscv64 code generation modules.
* mes/module/mescc/riscv64/as.mes: Imports for as.mes.
* mes/module/mescc/riscv64/info.mes: Imports for info.mes.
* module/mescc/mescc.scm (replace-suffix, arch-get, arch-get-info,
arch-get-machine, arch-get-m1-macros, .E?, .s?, .o?): Handle riscv64 and
some stubs for riscv32.
(arch-get-defines): Add defines for riscv32 and riscv64.
* module/mescc/riscv64/as.scm: New file: Code generator module for RISC-V64.
* module/mescc/riscv64/info.scm: New file: Architecture info for RISC-V64.
* build-aux/build-guile.sh (SCM_FILES): Add them.
2023-09-12 11:04:11 +02:00
W. J. van der Laan 9044e13309 lib: Make stdarg work for GCC on RISC-V64.
* include/stdarg.h: GCC on RISC-V always passes arguments in registers.
Implementing these macros without the use of built-ins would be very
involved. So use those for now to make printf etc work.
2023-09-12 11:04:11 +02:00
W. J. van der Laan fa3e83691d lib/tests: Take RISC-V into account in size conditionals.
* lib/tests/scaffold/76-pointer-arithmetic.c (main): Use the right sizes
in the test for RISC-V architectures.
* lib/tests/scaffold/7k-for-each-elem.c (main): Same.
* lib/tests/scaffold/85-sizeof.c: Same.
2023-09-12 11:04:10 +02:00
W. J. van der Laan f24b1e467c lib: General Linux RISC-V64 syscall support.
* include/linux/riscv32/kernel-stat.h,
include/linux/riscv64/kernel-stat.h: New files.
* include/fcntl.h (AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_REMOVEDIR): Add
necessary constants.
* include/stdint.h: Integer size defines for RISC-V.
* include/sys/stat.h: "stat" struct for RISC-V.
* lib/linux/_open3.c (_open3)[!SYS_open]: Use SYS_openat.
* lib/linux/access.c (access)[!SYS_access]: Use SYS_faccessat.
* lib/linux/chmod.c (chmod)[!SYS_chmod]: Use SYS_fchmodat.
* lib/linux/dup2.c (dup2)[!SYS_dup2]: Use if SYS_dup3.
* lib/linux/fork.c (fork)[!SYS_fork]: Use SYS_clone.
* lib/linux/getdents.c (getdents)[!SYS_getdents]: Use SYS_getdents64.
* lib/linux/link.c (link)[!SYS_link]: Use SYS_linkat.
* lib/linux/lstat.c (lstat)[!SYS_lstat]: Use SYS_newfstatat.
* lib/linux/mkdir.c (mkdir)[!SYS_mkdir]: Use SYS_mkdirat.
* lib/linux/mknod.c (mknod)[!SYS_mknod]: Use SYS_mknodat.
* lib/linux/pipe.c (pipe)[!SYS_pipe]: Use SYS_pipe2.
* lib/linux/readlink.c (readlink)[!SYS_readlinkat]: Use SYS_readlinkat.
* lib/linux/rename.c (rename)[!SYS_rename]: Use SYS_renameat2.
* lib/linux/rmdir.c (rmdir)[!SYS_rmdir]: Use SYS_unlinkat.
* lib/linux/signal.c (_restorer_for_siginfo): Remove unused function
that causes compilation issue.
* lib/linux/stat.c (stat)[!SYS_stat]: Use SYS_newfstatat.
* lib/linux/symlink.c (symlink)[!SYS_symlinkat]: Use SYS_symlink.
* lib/linux/unlink.c (unlink)[!SYS_unlink]: Use SYS_unlinkat.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 9ce2b56743 lib: Add _sys_call_5 for Linux RISC-V64.
* include/linux/syscall.h (_sys_call5): Declare 5-argument syscall needed
for SYS_renameat2, currently only used on RISC-V64.
* lib/linux/riscv64-mes-gcc/syscall.c (__sys_call5, _sys_call5):
Implement it.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 32d7171835 lib: Linux riscv64-mes-gcc support.
* lib/linux/riscv64-mes-gcc/_exit.c,
lib/linux/riscv64-mes-gcc/_write.c,
lib/linux/riscv64-mes-gcc/crt1.c,
lib/linux/riscv64-mes-gcc/syscall-internal.c,
lib/linux/riscv64-mes-gcc/syscall.c: New files to make it possible
to compile mes for riscv64-mes-gcc.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 8af58676b9 lib: Base riscv64-mes-gcc support (dummy setjmp).
* lib/riscv64-mes-gcc/setjmp.c: New file.
(setjmp, longjmp): Add dummy implementations. Implementing these for gcc
would be very involved, and does not seem necessary to get mescc to
work.
2023-09-12 11:04:10 +02:00