Commit Graph

2365 Commits

Author SHA1 Message Date
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
W. J. van der Laan 33f23d652b lib: Add RISC-V64 Linux syscall numbers header.
* include/linux/riscv64/syscall.h: New file: list relevant syscall
number constants.
2023-09-12 11:04:10 +02:00
Jan (janneke) Nieuwenhuizen b9647b874c lib: Document syscalls.
* include/linux/SYSCALLS: New file.
2023-09-12 11:04:10 +02:00
W. J. van der Laan 95cfc38772 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-09-12 11:04:10 +02:00
W. J. van der Laan 3752e735d2 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-09-12 11:04:10 +02:00
W. J. van der Laan 3267daedbf 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-09-12 11:04:10 +02:00
W. J. van der Laan 55b42018db mescc: Add r0-cmp-r1 instruction.
This instruction is used to compare two registers and set the flags
accordingly. In current architectures this is the same as r0-r1, but for
RISCV it will be different.  RISC-V does not have condition flags so
(until a better solution) we are going to emulate them there.

* module/mescc/armv4/as.scm (armv4:instructions): Add r0-cmp-r1 as alias
of r0-r1.
* module/mescc/i386/as.scm: Same.
* module/mescc/x86_64/as.scm: Same.
* module/mescc/compile.scm (expr->register): Make use of the new
r0-cmp-r1 instruction.
2023-09-12 11:04:10 +02:00
Ekaitz 0b5053e4b7 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-12 11:04:02 +02:00
Ekaitz 190cafbfb1 XXX lib: Make objdump work on binaries in x86_64-linux.
XXX: do the same for other architectures

* lib/linux/x86_64-mes/elf64-header.hex2: Fix header sizes for objdump.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen 6117207d72 squash! HACK mescc: Consider truncate after each shift operation.
Instead of truncating on size of first operand, truncate on largest of
default/int or size of first operand
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen bc4339815f 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-12 11:04:02 +02:00
Janneke Nieuwenhuizen 57b60fc794 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.
2023-09-12 11:04:02 +02:00
Andrius Štikonas 08b1e9fefe mescc: Do not overflow M1 64bit immediates.
M1 immediates are limited to 31-bit before they become negative.

* module/mescc/x86_64/as.scm (x86_64:value->r, x86_64:r-cmp-value,
x86_64:r-long-mem-add, x86_64:r-and): Limit M1 immediate to #x80000000.

* lib/tests/scaffold/67-m1-overflow-check.c: New test.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:02 +02:00
Andrius Štikonas abf677a8c3 mescc: Fix hex2:immediate8 to work with mes/m2-compiled mes.
* module/mescc/M1.scm (hex2:immediate8): Remove mesc? exception.
(mesc?): Remove.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen 1b87616349 guix: m2-planet: Update to 1.10.0-0.754c5de.
For 64bit platforms, this fix is essential

    85dd953 Add padding when loading global ints on 64-bit arches.

* guix/git/mes.scm (m2-planet): Update to latest git.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen 7f3f05f856 core: Avoid displaying truncated 64bit values.
* src/display.c (display_helper): Use `ltoa' instead of `itoa'.
2023-09-12 11:04:02 +02:00
Andrius Štikonas 76e6217725 lib: Fix x86_64 M2 elf header to work with debug info.
* lib/m2/x86_64/ELF-x86_64.hex2: Fix e_shoff, e_shentsize, e_shstrndx.
2023-09-12 11:04:02 +02:00
Andrius Štikonas 6d92ad4323 kaem: Pass --64 to blood_elf on 64-bit arches.
* kaem.run (blood_elf_flag): New variable with dummy default value to
support kaem from mescc-tools 1.4.0.
* kaem.x86_64 (blood_elf_flag): New variable.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen 996b55046c m2: Add new style x86_64 defines to support M2-Planet 1.11.0.
* lib/m2/x86_64/x86_64_defs.M1: Add new M1 defines.
2023-09-12 11:04:02 +02:00
Jan (janneke) Nieuwenhuizen c8294803cd x86_64: build: Cater for M2-Planet.
* build-aux/cflags.sh: Set cc_cpu.
* build-aux/config.sh.in (cc_cpu): Export.
* build-aux/export.make (cc_cpu): Likewise.
* kaem.arm (cc_cpu): New variable.
* kaem.x86 (cc_cpu): New variable.
* kaem.run (cc_cpu): New variable.  Define __<cc_cpu>__.
* scaffold/argv.kaem (cc_cpu): Likewise.  Define __linux__
* scaffold/global-array.kaem (cc_cpu): Likewise.
* scaffold/hello.kaem (cc_cpu): Likewise.
* scaffold/local-array.kaem (cc_cpu): Likewise.
* scaffold/local-static-array.kaem (cc_cpu): Likewise.
* scaffold/main.kaem (cc_cpu): Likewise.
* scaffold/read.kaem (cc_cpu): Likewise.
* kaem.x86_64: New file.
lib/m2/x86_64/ELF-x86_64.hex2,
lib/m2/x86_64/x86_64_defs.M1: New files, imported from M2Libc.
lib/linux/x86_64-mes-m2/_exit.c,
lib/linux/x86_64-mes-m2/_write.c,
lib/linux/x86_64-mes-m2/crt1.M1,
lib/linux/x86_64-mes-m2/crt1.c,
lib/linux/x86_64-mes-m2/syscall.c: New files, adapted for M2-Planet
calling convention from ...
* lib/linux/x86_64-mes-mescc: ... here.
* build-aux/build.sh.in: Also allow kaem build for x86_64.
* include/mes/lib-mini.h[__M2__]: Define as sizeof (void*).
* include/mes/mes.h[__M2__](M2_CELL_SIZE): Define as sizeof (struct scm).
* lib/x86_64-mes/x86_64.M1 (add____$i8,%rbp, mov____%rdi,%rbp): New
defines.
* src/posix.c (TIME_UNITS_PER_SECOND): Cater for 64bit M2-Planet.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen 61956fb14c build: Generate reproducible doc/version.texi.
* build-aux/GNUmakefile.in (doc/version.texi): Use timestamp from git.
2023-09-09 14:05:28 +02:00