Commit Graph

2375 Commits

Author SHA1 Message Date
Ekaitz 42cb302c85 WIP setjmp/longjmp 2023-10-16 12:14:47 +02:00
Ekaitz af4fabcd64 guix: add riscv64 support
* guix/git/mes.scm (mes): Add riscv64-linux to supported systems and add
  riscv64 cross-compiler toolchain
2023-10-14 11:36:55 +02:00
Ekaitz 4dcedfdb8e 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-10-13 21:31:20 +02:00
Ekaitz 925db84523 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-10-11 19:58:27 +02:00
Ekaitz c288c35657 lib: Use GCC compatible stdarg.h in TINYCC
* include/stdarg.h: Include __TINYC__ in the GCC style argument control
via __builtin* family
2023-10-09 00:51:17 +02:00
Andrius Štikonas 267a132ca9 riscv64: Fix arguments of main function in tcc.
* lib/linux/riscv64-mes-tcc/crt1.c
2023-10-06 23:49:56 +02:00
Andrius Štikonas b5eb0e34c6 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-06 23:49:56 +02:00
Ekaitz a04b558074 riscv64: add support for tcc
* 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. 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
2023-09-21 15:51:20 +02:00
Janneke Nieuwenhuizen 07ae24e40d squash! mescc: Fix switch statements' fallthrough 2023-09-17 12:55:19 +02:00
Janneke Nieuwenhuizen 9506777449 Revert "squash! mescc: Fix switch statements' fallthrough --support mes"
This reverts commit ef4f4bb25a.
2023-09-17 12:55:19 +02:00
Janneke Nieuwenhuizen eac61918dd Revert "squash! squash! mescc: Fix switch statements' fallthrough --support mes"
This reverts commit 3266f6a834.
2023-09-17 12:55:19 +02:00
Janneke Nieuwenhuizen 1de4454036 squash! squash! mescc: Fix switch statements' fallthrough --support mes 2023-09-17 12:55:19 +02:00
Janneke Nieuwenhuizen a258c212da squash! mescc: Fix switch statements' fallthrough --support mes 2023-09-17 12:55:19 +02:00
Ekaitz f75cf7bfb9 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:06:18 +02:00
Ekaitz 16746c17c7 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-11 23:43:26 +02:00
Ekaitz c0c2556c2b 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 (r0>>r1-signed): Add variable.
* module/mescc/i386/as.scm (r0>>r1-signed): Add variable.
* module/mescc/riscv64/as.scm (r0>>r1-signed): Add variable.
* module/mescc/x86_64/as.scm (r0>>r1-signed): Add variable.
2023-09-11 17:20:45 +02:00
Ekaitz 81e35e6c30 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-11 15:46:56 +02:00
Ekaitz 51947d5a32 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-11 14:23:41 +02:00
Ekaitz 72860f56ae XXX lib: Make objdump work on binaries in x86-linux.
XXX: do the same for other architectures

* lib/linux/x86-mes/elf32-header.hex2: Fix header sizes for objdump.
2023-09-11 14:23:41 +02:00
Ekaitz d4d413e5c5 lib: Make objdump work on binaries in amd64
XXX: do the same for other architectures

* lib/linux/x86_64-mes/elf64-header.hex2: Fix header sizes until objdump
    stops complaining.
2023-09-11 14:23:41 +02:00
Ekaitz ba15a28de0 tests: add comparison against rotated number test.
* lib/tests/scaffold/17-compare-rotated.c: Add file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-11 14:23:41 +02:00
Ekaitz 863e055e3e tests: add simple casting test.
* lib/tests/scaffold/16-cast.c: Add file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-11 14:23:41 +02:00
Janneke Nieuwenhuizen 3a71a8edb2 DRAFT test: Add 68-truncate-shift.
* lib/tests/scaffold/68-truncate-shift.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-11 14:23:41 +02:00
Janneke Nieuwenhuizen 6b477daae4 HACK mescc: Consider truncate after each shift operation.
XXX For every binop / binop* operation?  We need tests?

* module/mescc/compile.scm (expr->register): After lshift and rshift,
use convert-r0.

Instead of truncating on size of first operand, truncate on largest of
default/int or size of first operand
2023-09-11 14:23:22 +02:00
Ekaitz 1f14a62e0a tests: make tests/vector.test compatible with guile
* tests/vector.test (make-vector): Don't rely in string comparison.
* mes/module/mes/type-0.mes (unspecified?): Add function.
2023-08-24 21:28:25 +02:00
Ekaitz 71934c9356 mes: make scm.mes compatible with guile
* mes/module/mes/scm.mes (iota): Throw exception when n < 0
* tests/scm.test: import (mes catch)
* tests/scm.test ("iota -1"): Rewrite with exception handling
2023-08-24 19:12:25 +02:00
Ekaitz e0e560895d mes: fix %program not defined error in guile
* module/mes/guile.scm (%program): define and export
2023-08-24 15:16:03 +02:00
Ekaitz f22a8f40a9 build: Fix broken test script
* build-aux/check-mescc.sh (tcc_tests): fix variable name
2023-08-24 14:35:06 +02:00
Ekaitz e0a7b14da5 mescc: initialize missing struct fields to 0
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.
* build-aux/check-mescc.sh (xfail-tests): Remove
  lib/tests/scaffold/72-typedef-struct-def-local.c
2023-08-22 16:30:15 +02:00
Janneke Nieuwenhuizen 1b4d36b869 DRAFT doc: Add ANNOUNCE-0.25.
* doc/announce/ANNOUNCE-0.24: Typo.
* doc/announce/ANNOUNCE-0.25: New file.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen d6616a27c0 Add .mailmap.
* .mailmap: New file.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 43de253d92 DRAFT doc: Update `NEWS'.
* NEWS (Changes in 0.25 since 0.24.2): New section.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen a8e307df36 DRAFT doc: Update `AUTHORS'.
* AUTHORS: Mention RISC-V port.
* mes/module/mes/repl.mes (welcome): Add Wladimir van der Laan and
Andrius Štikonas.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 780bc1e7d8 DRAFT doc: Update `README'.
* README: Updates for 0.25.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 325a84c213 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 6c64ceb3e5 lib/tests: 76-pointer-arithmetic: Cater for RISC-V64.
* lib/tests/scaffold/76-pointer-arithmetic.c (struct
foo)[__riscv_xlen==64]: Add __align.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 2986d6c59d 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-07-17 09:06:32 +02:00
Andrius Štikonas 01991aff74 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-07-17 09:06:32 +02:00
Andrius Štikonas 7133cda8ed build: Ignore /m2 build directory.
* .gitignore: Add /m2.
2023-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 44aa21cfb8 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen eb9fa90bd4 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 65152f5dad 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 20e6bb2b4f 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen abb4bb8ce3 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 0a8e432c68 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen 92484fc0b4 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen f176c0de5b core: Remove duplicate environment initialization.
* src/mes.c (init): Remove envp parameter.  Remove environment initialization.
(main): Remove envp parameter.  Update caller.
2023-07-17 09:06:32 +02:00
Jan (janneke) Nieuwenhuizen 061d681f69 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-07-17 09:06:32 +02:00
Janneke Nieuwenhuizen fe89526d65 scaffold: Add env.
* scaffold/env.c,
scaffold/env.kaem: New files.
* build-aux/build.sh.in: Use them.
2023-07-17 09:06:32 +02:00
Jan (janneke) Nieuwenhuizen 7dcd3d1b2c 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-07-17 09:06:32 +02:00