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
Janneke Nieuwenhuizen
68f3db77cf
core: Remove duplicate environment initialization.
...
* src/mes.c (init): Remove envp parameter. Remove environment initialization.
(main): Remove envp parameter. Update caller.
2023-11-05 09:40:37 +01:00
Jan (janneke) Nieuwenhuizen
141688a865
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-11-05 09:40:37 +01:00
Janneke Nieuwenhuizen
c6d0604e0c
scaffold: Add env.
...
* scaffold/env.c,
scaffold/env.kaem: New files.
* build-aux/build.sh.in: Use them.
2023-11-05 09:40:37 +01:00
Jan (janneke) Nieuwenhuizen
465787b721
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-11-05 09:40:37 +01:00
Jan (janneke) Nieuwenhuizen
794935b75d
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-11-05 09:40:37 +01:00
W. J. van der Laan
a1bc54bce8
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-11-05 09:40:37 +01:00
W. J. van der Laan
e7aac5e8ba
lib: Base riscv64-mes-mescc support.
...
* lib/riscv64-mes-mescc/setjmp.c: New file.
(setjmp, longjmp): Implement for RV64.
2023-11-05 09:40:37 +01:00
W. J. van der Laan
8f0cb67078
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-11-05 09:40:37 +01:00
W. J. van der Laan
d0b1be6a5d
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-11-05 09:40:37 +01:00
W. J. van der Laan
c8dfa47e10
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-11-05 09:40:37 +01:00
W. J. van der Laan
9d7360cca6
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-11-05 09:39:29 +01:00
W. J. van der Laan
04e6fdad13
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-11-05 09:39:29 +01:00
W. J. van der Laan
e07d1052aa
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-11-05 09:39:29 +01:00
W. J. van der Laan
f5d6a7b100
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-11-05 09:39:29 +01:00
W. J. van der Laan
6051a6e91e
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-11-05 09:39:29 +01:00
W. J. van der Laan
2eb0085ba0
lib: Add RISC-V64 Linux syscall numbers header.
...
* include/linux/riscv64/syscall.h: New file: list relevant syscall
number constants.
2023-11-05 09:39:29 +01:00
Jan (janneke) Nieuwenhuizen
9ae3426c96
lib: Document syscalls.
...
* include/linux/SYSCALLS: New file.
2023-11-05 09:39:29 +01:00
W. J. van der Laan
2848cf6a18
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-11-05 09:39:29 +01:00
W. J. van der Laan
bf5e8b245e
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-11-05 09:39:29 +01:00
W. J. van der Laan
5d64961c83
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-11-05 09:39:29 +01:00
W. J. van der Laan
edf397038a
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-11-05 09:39:29 +01:00
Ekaitz Zarraga
acfead04ed
DRAFT lib: Make objdump work on binaries in x86-linux.
...
* lib/linux/x86-mes/elf32-header.hex2: Fix header sizes for objdump.
2023-11-05 09:39:06 +01:00
Ekaitz Zarraga
1120073d8d
DRAFT lib: Make objdump work on binaries in x86_64-linux.
...
* lib/linux/x86_64-mes/elf64-header.hex2: Fix header sizes for objdump.
2023-11-05 09:39:00 +01:00
Janneke Nieuwenhuizen
83f26445b0
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-11-05 09:38:57 +01:00
Janneke Nieuwenhuizen
592a612777
DRAFT mescc: Consider truncate after each shift operation.
...
* module/mescc/compile.scm (expr->register): After lshift and rshift,
use convert-r0. Tuncate on largest of default/int or size of first
operand.
2023-11-05 09:38:53 +01:00
Andrius Štikonas
05e945c0a8
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-11-05 09:36:26 +01:00
Andrius Štikonas
2e13faa3c2
mescc: Fix hex2:immediate8 to work with mes/m2-compiled mes.
...
* module/mescc/M1.scm (hex2:immediate8): Remove mesc? exception.
(mesc?): Remove.
2023-11-05 09:36:26 +01:00
Janneke Nieuwenhuizen
516b5849f2
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-11-05 09:36:26 +01:00
Janneke Nieuwenhuizen
f32b5f5510
core: Avoid displaying truncated 64bit values.
...
* src/display.c (display_helper): Use `ltoa' instead of `itoa'.
2023-11-05 09:36:26 +01:00
Andrius Štikonas
1650f0caae
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-11-05 09:36:26 +01:00
Andrius Štikonas
3a514386c5
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-11-05 09:36:26 +01:00
Janneke Nieuwenhuizen
73acbc37b1
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-11-05 09:36:26 +01:00
Jan (janneke) Nieuwenhuizen
189ea8eb9d
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-11-05 09:36:26 +01:00
Janneke Nieuwenhuizen
002dc6253a
build: Generate reproducible doc/version.texi.
...
* build-aux/GNUmakefile.in (doc/version.texi): Use timestamp from git.
2023-11-05 09:36:11 +01:00
Janneke Nieuwenhuizen
b6bad13883
build: Help help2man generate reproducible man-pages.
...
* build-aux/GNUmakefile.in (SOURCE_DATE_EPOCH): New variable.
2023-11-05 09:36:11 +01:00