Commit Graph

2359 Commits

Author SHA1 Message Date
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
Jan (janneke) Nieuwenhuizen e415635663 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-07-17 09:06:32 +02:00
W. J. van der Laan 252d55d2b8 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-07-17 09:06:32 +02:00
W. J. van der Laan 8fa8bb6f76 lib: Base riscv64-mes-mescc support.
* lib/riscv64-mes-mescc/setjmp.c: New file.
(setjmp, longjmp): Implement for RV64.
2023-07-17 09:06:32 +02:00
W. J. van der Laan ff2b2f6ae6 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-07-17 09:06:32 +02:00
W. J. van der Laan 760f7bc891 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-07-17 09:06:32 +02:00
W. J. van der Laan a5a1ffa6a4 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-07-17 09:06:32 +02:00
W. J. van der Laan 9aa5d71950 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-07-17 09:06:32 +02:00
W. J. van der Laan a9fac33bcb 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-07-17 09:06:32 +02:00
W. J. van der Laan f33eef1100 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-07-17 09:06:32 +02:00
W. J. van der Laan 5801038749 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-07-17 09:06:32 +02:00
W. J. van der Laan 6a77115f54 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-07-17 09:06:32 +02:00
W. J. van der Laan ec2b5b8618 lib: Add RISC-V64 Linux syscall numbers header.
* include/linux/riscv64/syscall.h: New file: list relevant syscall
number constants.
2023-07-17 09:06:32 +02:00
Jan (janneke) Nieuwenhuizen 48bea0ef8a lib: Document syscalls.
* include/linux/SYSCALLS: New file.
2023-07-17 09:06:32 +02:00
W. J. van der Laan e495d0c4a8 lib: Make Linux scaffold work for RISC-V64.
* lib/linux/riscv64-mes-gcc/exit-42.S,
lib/linux/riscv64-mes-gcc/hello-mes.S,
lib/linux/riscv64-mes/elf64-0exit-42.hex2,
lib/linux/riscv64-mes/elf64-0header.hex2,
lib/linux/riscv64-mes/elf64-0hello-mes.hex2,
lib/linux/riscv64-mes/elf64-body-exit-42.hex2,
lib/linux/riscv64-mes/elf64-body-hello-mes.hex2,
lib/linux/riscv64-mes/elf64-footer-single-main.hex2,
lib/linux/riscv64-mes/elf64-header.hex2: New files.  Makes basic
scaffold pass on RISC-V64.
2023-07-17 09:06:32 +02:00
W. J. van der Laan 1de2efef97 core: Add RISC-V architecture detection.
* src/mes.c(mes_environment)[__riscv_xlen == 32]: Set
architecture to riscv32.
[__riscv_xlen == 64]: Set architecture to riscv64.

xlen
2023-07-17 09:06:32 +02:00
W. J. van der Laan be06e18507 configure: Recognize RISC-V architectures.
* configure (main): Classify "riscv64" as 64 bit, allow "redhat" OS
(somewhat tangential, but important for Fedora RISC-V), allow
"riscv32-linux-mes" and "riscv64-linux-mes" as system.
2023-07-17 09:06:32 +02:00