diff --git a/build-aux/build.sh.in b/build-aux/build.sh.in index b8900b1b..2a2cb3d0 100644 --- a/build-aux/build.sh.in +++ b/build-aux/build.sh.in @@ -102,7 +102,8 @@ fi ) if test -n "$M2_PLANET" && (test "$mes_cpu" == "x86" \ - || test "$mes_cpu" == "arm"); then + || test "$mes_cpu" == "x86_64" \ + || test "$mes_cpu" == "arm" ); then ( . ${srcdest}build-aux/trace.sh if [ -z "$V" -o "$V" = 0 ]; then diff --git a/build-aux/cflags.sh b/build-aux/cflags.sh index da98b4cb..e19bd1dc 100644 --- a/build-aux/cflags.sh +++ b/build-aux/cflags.sh @@ -18,16 +18,20 @@ case "$mes_cpu" in arm) + cc_cpu=arm stage0_cpu=armv7l ;; x86_64) + cc_cpu=x86_64 stage0_cpu=amd64 ;; x86) + cc_cpu=i386 stage0_cpu=x86 ;; *) stage0_cpu=$mes_cpu + cc_cpu=$mes_cpu ;; esac diff --git a/build-aux/config.sh.in b/build-aux/config.sh.in index ae4c1ce7..a919f141 100644 --- a/build-aux/config.sh.in +++ b/build-aux/config.sh.in @@ -97,6 +97,7 @@ export CC export DIFF export SHELL export V +export cc_cpu export colors export compiler export courageous diff --git a/build-aux/export.make b/build-aux/export.make index 3bfb0bff..05b85611 100644 --- a/build-aux/export.make +++ b/build-aux/export.make @@ -1,5 +1,5 @@ # GNU Mes --- Maxwell Equations of Software -# Copyright © 2018 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2023 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -43,6 +43,7 @@ export moduledir export sysconfdir export bootstrap +export cc_cpu export compiler export courageous export mes_system diff --git a/include/mes/lib-mini.h b/include/mes/lib-mini.h index eb994f79..48d91362 100644 --- a/include/mes/lib-mini.h +++ b/include/mes/lib-mini.h @@ -41,7 +41,7 @@ for that by multiplying with M2_PTR_SIZE when using (char) pointers. */ #if __M2__ -#define M2_PTR_SIZE 4 +#define M2_PTR_SIZE sizeof (void*) #else #define M2_PTR_SIZE 1 #endif diff --git a/include/mes/mes.h b/include/mes/mes.h index 0323b2dc..c189ab69 100644 --- a/include/mes/mes.h +++ b/include/mes/mes.h @@ -57,7 +57,7 @@ struct scm for that by multiplying with M2_CELL_SIZE when using cell pointers. */ #if __M2__ -#define M2_CELL_SIZE 12 +#define M2_CELL_SIZE sizeof (struct scm) #else #define M2_CELL_SIZE 1 #endif diff --git a/kaem.arm b/kaem.arm index 4e973a1f..4357c62b 100644 --- a/kaem.arm +++ b/kaem.arm @@ -19,6 +19,7 @@ # Usage: # kaem --verbose --strict +cc_cpu=arm mes_cpu=arm stage0_cpu=armv7l kaem --verbose --strict diff --git a/kaem.run b/kaem.run index 1179aa23..d4d51b54 100644 --- a/kaem.run +++ b/kaem.run @@ -19,6 +19,7 @@ # Usage: # kaem --verbose --strict +cc_cpu=${cc_cpu:-i386} mes_cpu=${mes_cpu:-x86} stage0_cpu=${stage0_cpu:-x86} @@ -27,6 +28,7 @@ mkdir -p m2 M2-Planet \ --debug \ --architecture ${stage0_cpu} \ + -D __${cc_cpu}__=1 \ -D __linux__=1 \ -f include/mes/config.h \ -f include/mes/lib-mini.h \ diff --git a/kaem.x86 b/kaem.x86 index 60ab6e6b..caea7f87 100644 --- a/kaem.x86 +++ b/kaem.x86 @@ -19,6 +19,7 @@ # Usage: # kaem --verbose --strict +cc_cpu=i386 mes_cpu=x86 stage0_cpu=x86 kaem --verbose --strict diff --git a/kaem.x86_64 b/kaem.x86_64 new file mode 100644 index 00000000..b20aecc3 --- /dev/null +++ b/kaem.x86_64 @@ -0,0 +1,25 @@ +#! /bin/sh +# Copyright © 2022 Jan (janneke) Nieuwenhuizen +# +# This file is part of GNU Mes. +# +# GNU Mes is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Mes is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Mes. If not, see . + +# Usage: +# kaem --verbose --strict + +cc_cpu=x86_64 +mes_cpu=x86_64 +stage0_cpu=amd64 +kaem --verbose --strict diff --git a/lib/linux/x86_64-mes-m2/_exit.c b/lib/linux/x86_64-mes-m2/_exit.c new file mode 100644 index 00000000..3396ebb7 --- /dev/null +++ b/lib/linux/x86_64-mes-m2/_exit.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2020,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include "mes/lib-mini.h" + +void +_exit (int status) +{ + asm ("mov____$i32,%rax SYS_exit"); + asm ("mov____0x8(%rbp),%rdi !-8"); + asm ("syscall"); +} diff --git a/lib/linux/x86_64-mes-m2/_write.c b/lib/linux/x86_64-mes-m2/_write.c new file mode 100644 index 00000000..25b0faed --- /dev/null +++ b/lib/linux/x86_64-mes-m2/_write.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2020,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include "mes/lib-mini.h" + +void +_write (int filedes, void const *buffer, size_t size) +{ + asm ("mov____$i32,%rax SYS_write"); + asm ("mov____0x8(%rbp),%rdi !-8"); + asm ("mov____0x8(%rbp),%rsi !-16"); + asm ("mov____0x8(%rbp),%rdx !-24"); + asm ("syscall"); +} diff --git a/lib/linux/x86_64-mes-m2/crt1.M1 b/lib/linux/x86_64-mes-m2/crt1.M1 new file mode 100644 index 00000000..5a792ff2 --- /dev/null +++ b/lib/linux/x86_64-mes-m2/crt1.M1 @@ -0,0 +1,56 @@ +### GNU Mes --- Maxwell Equations of Software +### Copyright © 2017,2018,2019,2022,2023 Jan (janneke) Nieuwenhuizen +### +### This file is part of GNU Mes. +### +### GNU Mes is free software; you can redistribute it and/or modify it +### under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 3 of the License, or (at +### your option) any later version. +### +### GNU Mes is distributed in the hope that it will be useful, but +### WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with GNU Mes. If not, see . + +:_start + push___%rbp + mov____%rsp,%rbp + + ;; mes c lib io + mov____$i8,%rax !0 + movl___%eax,0x32 &GLOBAL___stdin + mov____$i8,%rax !1 + movl___%eax,0x32 &GLOBAL___stdout + mov____$i8,%rax !2 + movl___%eax,0x32 &GLOBAL___stderr + + ;; M2-Planet pushes forward + mov____%rbp,%rax ;argc + add____$i8,%rax !8 + mov____(%rax),%rax + push___%rax + + mov____%rbp,%rax ;argv + add____$i8,%rax !16 + push___%rax + + mov____%rbp,%rax ;envp + add____$i8,%rax !8 + mov____(%rax),%rax + add____$i8,%rax !0x03 + shl____$i8,%rax !0x03 + add____%rbp,%rax + push___%rax + + ;; mes c lib environ + mov____%rax,0x32 &GLOBAL_environ + + call32 %FUNCTION_main + + mov____%rax,%rdi + mov____$i32,%rax SYS_exit + syscall diff --git a/lib/linux/x86_64-mes-m2/crt1.c b/lib/linux/x86_64-mes-m2/crt1.c new file mode 100644 index 00000000..da4c4824 --- /dev/null +++ b/lib/linux/x86_64-mes-m2/crt1.c @@ -0,0 +1,34 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include "mes/lib-mini.h" + +int __stdin; +int __stdout; +int __stderr; +char **environ; +int main (int argc, char **argv, char **envp); + +/* FIXME: this is going to be called `FUNCTION__start' */ +//#int +//#_start () +//#{ +//# .. +//#} diff --git a/lib/linux/x86_64-mes-m2/syscall.c b/lib/linux/x86_64-mes-m2/syscall.c new file mode 100644 index 00000000..0675be0b --- /dev/null +++ b/lib/linux/x86_64-mes-m2/syscall.c @@ -0,0 +1,137 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018,2020,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +long +__sys_call (long sys_call) +{ + asm ("mov____0x8(%rbp),%rax !-8"); + asm ("syscall"); +} + +long +__sys_call1 (long sys_call, long one) +{ + asm ("mov____0x8(%rbp),%rax !-8"); + asm ("mov____0x8(%rbp),%rdi !-16"); + asm ("syscall"); +} + +long +__sys_call2 (long sys_call, long one, long two) +{ + asm ("mov____0x8(%rbp),%rax !-8"); + asm ("mov____0x8(%rbp),%rdi !-16"); + asm ("mov____0x8(%rbp),%rsi !-24"); + asm ("syscall"); +} + +long +__sys_call3 (long sys_call, long one, long two, long three) +{ + asm ("mov____0x8(%rbp),%rax !-8"); + asm ("mov____0x8(%rbp),%rdi !-16"); + asm ("mov____0x8(%rbp),%rsi !-24"); + asm ("mov____0x8(%rbp),%rdx !-32"); + asm ("syscall"); +} + +long +__sys_call4 (long sys_call, long one, long two, long three, long four) +{ + asm ("mov____0x8(%rbp),%rax !-8"); + asm ("mov____0x8(%rbp),%rdi !-16"); + asm ("mov____0x8(%rbp),%rsi !-24"); + asm ("mov____0x8(%rbp),%rdx !-32"); + asm ("mov____0x8(%rbp),%r10 !-40"); + asm ("syscall"); +} + +long +_sys_call (long sys_call) +{ + long r = __sys_call (sys_call); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} + +long +_sys_call1 (long sys_call, long one) +{ + long r = __sys_call1 (sys_call, one); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} + +long +_sys_call2 (long sys_call, long one, long two) +{ + long r = __sys_call2 (sys_call, one, two); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} + +long +_sys_call3 (long sys_call, long one, long two, long three) +{ + long r = __sys_call3 (sys_call, one, two, three); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} + +long +_sys_call4 (long sys_call, long one, long two, long three, long four) +{ + long r = __sys_call4 (sys_call, one, two, three, four); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} diff --git a/lib/m2/x86_64/ELF-x86_64.hex2 b/lib/m2/x86_64/ELF-x86_64.hex2 new file mode 100644 index 00000000..32ccc7c7 --- /dev/null +++ b/lib/m2/x86_64/ELF-x86_64.hex2 @@ -0,0 +1,74 @@ +### Copyright (C) 2016 Jeremiah Orians +### Copyright (C) 2017 Jan Nieuwenhuizen +### This file is part of M2-Planet. +### +### M2-Planet is free software: you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### M2-Planet is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with M2-Planet. If not, see . + +### stage0's hex2 format +### !