Commit graph

2411 commits

Author SHA1 Message Date
Artemis Tosini 63e731a01f
Fixes for __sys_call on aarch64-mes-gcc 2023-11-05 21:03:04 +00:00
Artemis Tosini 84491f3bd9
Merge remote-tracking branch 'upstream/wip-riscv' into aarch64 2023-11-05 20:40:14 +00:00
Artemis Tosini 67780639e9
Fix typos in aarch64-mes-gcc 2023-11-05 20:33:24 +00:00
Artemis Tosini b88b0184ab
Initial hex2 tests pass on aarch64 2023-11-05 20:28:40 +00:00
Artemis Tosini 5ad5f854f0
Add aarch64 0hello-mes 2023-11-05 20:21:06 +00:00
Janneke Nieuwenhuizen 38fbcbe2e2 DRAFT doc: Add ANNOUNCE-0.25.
* doc/announce/ANNOUNCE-0.24: Typo.
* doc/announce/ANNOUNCE-0.25: New file.
2023-11-05 14:52:17 +01:00
Janneke Nieuwenhuizen fb39bb2139 Add .mailmap.
* .mailmap: New file.
2023-11-05 14:52:17 +01:00
Janneke Nieuwenhuizen 02be9e2449 DRAFT doc: Update `NEWS'.
* NEWS (Changes in 0.25 since 0.24.2): New section.
2023-11-05 14:52:17 +01:00
Janneke Nieuwenhuizen be77e181a8 DRAFT doc: Update `AUTHORS'.
* AUTHORS: Mention RISC-V port.
* mes/module/mes/repl.mes (welcome): Add Wladimir van der Laan and
Andrius Štikonas.
2023-11-05 14:52:17 +01:00
Janneke Nieuwenhuizen e1dcb133cf DRAFT doc: Update `README'.
* README: Updates for 0.25.
2023-11-05 14:52:17 +01:00
Ekaitz Zarraga b71e5d1e2c build: Add support for TCC in RISC-V.
For RISC-V TCC needs a modified libc because it doesn't support Extended
Assembly. This change enables that kind of behavior, letting us select
the TCC library when it is present.

* build-aux/bootstrap.sh.in: Add a block to build-source-lib for TCC.
* build-aux/configure-lib.sh: Guard TCC to remove repeated definitions
from its libc.
* build-aux/install.sh.in: Make it install TCC's library, too
2023-11-05 14:51:31 +01:00
Ekaitz Zarraga f9efe47257 lib: Add missing (empty) crt files for RISC-V.
These are needed by the build scripts, but in RISC-V being empty is
enough.

* lib/linux/riscv64-mes-gcc/crti.c,
lib/linux/riscv64-mes-gcc/crtn.c,
lib/linux/riscv64-mes-tcc/crti.c,
lib/linux/riscv64-mes-tcc/crtn.c: New files.
2023-11-05 14:45:38 +01:00
Janneke Nieuwenhuizen 6bc27ab3a0 DRAFT doc: Bump mescc-tools requirement to 1.5.0.
* doc/mes.texi (Requirements): Update M2-Planet version to 1.5.0.
(Bootstrap Requirements): Likewise.
* INSTALL (Other GNU/Linux): Likewise.
2023-11-05 10:25:59 +01:00
Janneke Nieuwenhuizen a556c9158b 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-11-05 10:25:59 +01:00
Janneke Nieuwenhuizen c06ed439ad build: Bump stage0 versions.
* configure (main): Bump mescc-tools to 1.5.0, m2-planet to 1.11.0.
2023-11-05 10:25:59 +01:00
Janneke Nieuwenhuizen ae12aeac49 guix: m2-planet: Update to 1.11.0.
* guix/git/mes.scm (m2-planet): Update to 1.11.0.
2023-11-05 10:25:59 +01:00
Janneke Nieuwenhuizen 40cdd8aef1 guix: mescc-tools: Update to 1.5.0.
* guix/git/mes.scm (mescc-tools): Update to 1.5.0.
2023-11-05 10:25:59 +01:00
Janneke Nieuwenhuizen 6f5aeed75a DRAFT mescc: Hide assign size ERROR as WARNING behind MESCC_DEBUG.
* module/mescc/compile.scm (expr->register): Only output inexplicable
size warning when MESCC_DEBUG environment variable is set.
2023-11-05 10:25:59 +01:00
Ekaitz Zarraga 607f86247d configure.sh: Add 64 bit to RISCV-64.
* configure.sh: Add 64 bit for mes_cpu == riscv64.
2023-11-05 09:45:31 +01:00
Andrius Štikonas 542f015135 lib: Fix va_start macro to work for 64-bit arches.
* include/stdarg.h (va_start): Fix to point to correct location.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 9387d36f75 DRAFT test: Move 17-compare-rotated to XFAIL in riscv64.
* build-aux/check-mescc.sh: Add XFAIL block for riscv64 and add
17-compare-rotated in it.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 5d6041b780 DRAFT test: 16-cast.c: Fix for riscv64.
RISC-V64 has `unsigned char` for `char`, so it failed to build. In amd64
`char` is `signed char`, so the code wasn't portable. We have to be
explicit about the sign of the `char`.

* lib/test/scaffold/16-cast.c: Add `signed` to `char`.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 90a1684b89 lib: Add setjmp/longjmp for riscv64.
Note about the -tcc file:

    HAVE_FLOAT_ASM defines if there's assembly support for float
    instructions.

    HAVE_FLOAT defines if there's floating point arithmetic support.

    This is important for TinyCC because the assembler and the C
    compiler are split. TinyCC can HAVE_FLOAT but no assembler support
    for them.

* lib/riscv64-mes-gcc/setjmp.c,
lib/riscv64-mes-tcc/setjmp.c: New files.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 1637419a5c guix: Add riscv64 support.
* guix/git/mes.scm (mes)[supported-systems]: Add riscv64-linux.
[native-inputs]: Add riscv64 cross-compiler toolchain.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 6d784aa5ae lib: int8_t set to signed char instead of char.
`char` signedness is not defined by C standard.  In some architectures
it's `unsigned` by default (RISC-V), so it's better to be explicit to
avoid problems.

* include/stdint.h (int8_t): Use `signed char` instead of `char`.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 596df500b6 DRAFT lib: define va_* for bootstrappable tcc in riscv.
Bootstrappable TCC needs some extra definitions that upstream TCC
obtains from `tccdefs.h` in its codebase, which is also injected in the
binary using a weird trick (see `c2str` in tcc's codebase).

* include/stdarg.h: Add definitions for variable length arguments.
2023-11-05 09:45:31 +01:00
Ekaitz Zarraga 3539ee92a7 lib: Use GCC compatible stdarg.h for TINYCC.
* include/stdarg.h: Include __TINYC__ in the GCC style argument control
via __builtin* family.
2023-11-05 09:45:31 +01:00
Andrius Štikonas f49689d31a DRAFT riscv64: Fix arguments of main function in tcc.
* lib/linux/riscv64-mes-tcc/crt1.c

Co-authored-by: Ekaitz Zarraga <ekaitz@elenq.tech>.
2023-11-05 09:45:31 +01:00
Andrius Štikonas 958da104e5 DRAFT 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 10054b2f17 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 47cffc5d2a 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 85f97b6881 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 72ec66bd86 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 63beaa3dfe 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-11-05 09:45:31 +01:00
Ekaitz Zarraga a99a274992 lib: Make objdump work on binaries in riscv64
* lib/linux/riscv64-mes/elf32-header.hex2: Fix header sizes for objdump.
2023-11-05 09:45:31 +01:00
Janneke Nieuwenhuizen 4a0bb97d70 Revert "crt1: Move main declaration to mes/lib-mini.h."
This reverts commit 5b55627e0ccf7c798284a380a20a2eb4d6b9c4c0.
2023-11-05 09:45:31 +01:00
Janneke Nieuwenhuizen ad6c02076f 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-11-05 09:45:31 +01:00
Ekaitz Zarraga 1fb7ade93c 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-11-05 09:40:38 +01:00
Janneke Nieuwenhuizen 0637c13c72 lib/tests: 76-pointer-arithmetic: Cater for RISC-V64.
* lib/tests/scaffold/76-pointer-arithmetic.c (struct
foo)[__riscv_xlen==64]: Add __align.
2023-11-05 09:40:38 +01:00
Janneke Nieuwenhuizen 2609211a3f 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-11-05 09:40:38 +01:00
Andrius Štikonas 16f4fc3263 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-11-05 09:40:38 +01:00
Andrius Štikonas e5c556699c build: Ignore /m2 build directory.
* .gitignore: Add /m2.
2023-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 4b3e6344e8 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 20d92bec90 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen f2009e70f9 gnu: Update main prototype.
* lib/gnu/x86-mes-gcc/crt1.c (main): Add parameters.
2023-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen aa97000027 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 368ddbcd4f 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 3502ad4f73 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 88eb90dd38 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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen 1e898ea312 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-11-05 09:40:37 +01:00