Compare commits

...

10 commits

37 changed files with 1670 additions and 22 deletions

1
.gitignore vendored
View file

@ -17,6 +17,7 @@
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
.direnv/
m2/
*-
*~

3
configure vendored
View file

@ -538,7 +538,7 @@ Some influential environment variables:
(mes-cpu (cond ((member mes-cpu '("i386" "i486" "i586" "i686")) "x86")
((member mes-cpu '("arm" "armv4" "armv7l")) "arm")
(else mes-cpu)))
(mes-bits (if (member mes-cpu '("x86_64")) "64"
(mes-bits (if (member mes-cpu '("x86_64" "aarch64")) "64"
"32"))
(mes-libc (if system-libc? "system" "mes"))
(mes-kernel (car (filter
@ -578,6 +578,7 @@ Some influential environment variables:
(loop (read-line in 'concat))))))))
(when (and (not (member mes-system '("arm-linux-mes"
"aarch64-linux-mes"
"x86-linux-mes"
"x86_64-linux-mes")))
(not with-courage?))

View file

@ -22,11 +22,8 @@
in rec {
formatter = pkgs.nixfmt;
devShells.rustybar = pkgs.mkShellNoCC {
devShells.mes-m2 = pkgs.mkShellNoCC {
packages = with pkgs; [
perl
guile
gnumake
minimal-bootstrap.kaem
minimal-bootstrap.mescc-tools
];
@ -34,8 +31,25 @@
CC = "M2-Planet";
stage0_cpu = stage0Arch;
mes_cpu = mesArch;
shellHook = ''
export GUILE_LOAD_PATH=$PWD/mes/module:$PWD/module:${pkgs.minimal-bootstrap.mes.nyacc.guilePath}
'';
};
devShells.default = devShells.rustybar;
devShells.mes-guile = pkgs.mkShell {
packages = with pkgs; [
perl
guile
gnumake
minimal-bootstrap.mescc-tools
];
shellHook = ''
export GUILE_LOAD_PATH=$PWD/module:${pkgs.minimal-bootstrap.mes.nyacc.guilePath}
'';
};
devShells.default = devShells.mes-m2;
}));
}

View file

@ -0,0 +1,52 @@
/* -*-comment-start: "//";
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software;
* under the terms of the GNU General Public License as published by
* the Free Software Foundation;
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY;
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_LINUX_AARCH64_KERNEL_STAT_H
#define __MES_LINUX_AARCH64_KERNEL_STAT_H 1
// https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/stat.h
#include <arch/syscall.h>
// *INDENT-OFF*
struct stat
{
unsigned long st_dev;
unsigned long st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned int st_uid;
unsigned int st_gid;
unsigned long st_rdev;
unsigned long __pad1;
long st_size;
int st_blksize;
int __pad2;
long st_blocks;
long st_atime;
unsigned long st_atime_nsec;
long st_mtime;
unsigned long st_mtime_nsec;
long st_ctime;
unsigned long st_ctime_nsec;
unsigned int __unused4;
unsigned int __unused5;
};
#endif // __MES_LINUX_AARCH64_KERNEL_STAT_H

View file

@ -0,0 +1,105 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_LINUX_AARCH64_SYSCALL_H
#define __MES_LINUX_AARCH64_SYSCALL_H 1
/* See https://github.com/torvalds/linux/blob/v6.5/include/uapi/asm-generic/unistd.h */
/* libc */
// CONSTANT SYS_exit 93
#define SYS_exit 93
// CONSTANT SYS_write 64
#define SYS_write 64
// CONSTANT SYS_clone 220
#define SYS_clone 220
// CONSTANT SYS_read 63
#define SYS_read 63
// CONSTANT SYS_openat 56
#define SYS_openat 56
// CONSTANT SYS_wait4 260
#define SYS_wait4 260
// CONSTANT SYS_execve 221
#define SYS_execve 221
// CONSTANT SYS_fchmodat 53
#define SYS_fchmodat 53
// CONSTANT SYS_faccessat 48
#define SYS_faccessat 48
// CONSTANT SYS_brk 214
#define SYS_brk 214
// CONSTANT SYS_ioctl 29
#define SYS_ioctl 29
// CONSTANT SYS_fsync 82
#define SYS_fsync 82
// CONSTANT SYS_getcwd 17
#define SYS_getcwd 17
// CONSTANT SYS_dup 23
#define SYS_dup 23
// CONSTANT SYS_dup3 24
#define SYS_dup3 24
// CONSTANT SYS_unlinkat 35
#define SYS_unlinkat 35
// CONSTANT SYS_gettimeofday 169
#define SYS_gettimeofday 169
// CONSTANT SYS_clock_gettime 113
#define SYS_clock_gettime 113
/* libc+tcc */
#define SYS_close 0x06
#define SYS_lseek 0x13
#define SYS_rmdir 0x28
#define SYS_stat 0x6a
/* libc+gnu */
#define SYS_chdir 0x0c
#define SYS_link 0x09
#define SYS_getpid 0x14
#define SYS_getuid 0x18
#define SYS_kill 0x25
#define SYS_rename 0x26
#define SYS_mkdir 0x27
#define SYS_pipe 0x2a
#define SYS_getgid 0x2f
#define SYS_rt_sigaction 0xae
#define SYS_rt_sigreturn 0xad
#define SYS_fcntl 0x37
#define SYS_getrusage 0x4d
#define SYS_lstat 0x6b
#define SYS_setitimer 0x68
#define SYS_fstat 0x6c
#define SYS_nanosleep 0xa2
#define SYS_getdents 0x8d
/* bash */
#define SYS_setuid 0x17
#define SYS_setgid 0x2e
#define SYS_geteuid 0x31
#define SYS_getegid 0x32
#define SYS_getppid 0x40
/* make+WITH_GLIBC */
#define SYS_rt_sigprocmask 0xaf
/* tar */
#define SYS_symlink 0x53
#define SYS_readlink 0x55
#define SYS_mknod 0x0e
#endif /* __MES_LINUX_AARCH64_SYSCALL_H */

View file

View file

@ -26,7 +26,7 @@
int
_open3 (char const *file_name, int flags, int mask)
{
int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask);
int r = _sys_call4 (SYS_openat, (long) -100, (long) file_name, (int) flags, (int) mask);
if (r > 2)
{
__ungetc_clear (r);

View file

@ -0,0 +1,51 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "mes/lib-mini.h"
// *INDENT-OFF*
#if !__TINYC__
#define SYS_exit "93"
void
_exit (int code)
{
asm (
"mov x7, $"SYS_exit"\n\t"
"mov x0, %0\n\t"
"svc $0\n\t"
: // no outputs "=" (r)
: "r" (code)
: "x0", "x7"
);
// not reached
_exit (0);
}
#else //__TINYC__
#define SYS_exit 0x01
void
_exit (int code)
{
int c = SYS_exit;
__asm__ (".int 0xe51b7004\n"); //ldr r7, [fp, #-4] ; "c"
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12] ; code
__asm__ (".int 0xef000000\n"); //svc 0x00000000
}
#endif //__TINYC__

View file

@ -0,0 +1,60 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "mes/lib-mini.h"
// *INDENT-OFF*
#if !__TINYC__
#define SYS_write "64"
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
long r;
asm (
"mov x7, $"SYS_write"\n\t"
"mov x0, %1\n\t"
"mov x1, %2\n\t"
"mov x2, %3\n\t"
"svc $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (filedes), "r" (buffer), "r" (size)
: "r0", "r1", "r2", "r7"
);
return r;
}
#else //__TINYC__
#define SYS_write 0x04
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
long r;
int c = SYS_write;
__asm__ (".int 0xe51b7008\n"); //ldr r7, [fp, #-8] ; <c>
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12] ; filedes
__asm__ (".int 0xe59b1010\n"); //ldr r1, [fp, #16] ; buffer
__asm__ (".int 0xe59b2014\n"); //ldr r2, [fp, #20] ; size
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
// *INDENT-ON*

View file

@ -0,0 +1,154 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib-mini.h>
//int main (int argc, char *argv[], char *envp[]);
/* Note: GCC may or may not omit the frame pointer,
* depending on whether it thinks this is a leaf function.
*/
// *INDENT-OFF*
#if !__TINYC__
void
_start ()
{
asm (
"mov w0,#0\n\t"
"mov %0,w0\n"
: "=r" (__stdin)
: //no inputs ""
);
asm (
"mov w0,#1\n\t"
"mov %0,w0\n"
: "=r" (__stdout)
: //no inputs ""
);
asm (
"mov w0,#2\n\t"
"mov %0,w0\n"
: "=r" (__stderr)
: //no inputs ""
);
/* environ = argv + argc + 1 */
asm (
"ldr x0,[sp]\n\t" /* x0 = argc */
"add x1,sp,#8\n\t" /* x1 = &argv[0] */
"add x2,x0,#1\n\t" /* x2 = argc + 1 (skip zero word after argv) */
"lsl x2,#3\n\t" /* x2 = (argc + 1) << 3 */
"add x2,x2,x1\n\t" /* x2 = ((argc + 1) << 3) + &argv[0] */
"stp x1,x2,[sp,#0x10]!\n\t" /* argv, envp */
"stp xzr,x0,[sp,#0x10]!\n\t" /* 0, argc */
"mov %0,x2\n\t"
: "=r" (environ)
: //no inputs ""
);
asm (
"ldp xzr,x0,[sp],#0x10\n\t" /* 0, argc */
"ldp x1,x2,[sp],#0x10\n\t" /* argv, envp */
"bl main\n\t"
"mov x7, #93\n\t"
"svc #0\n\t"
"wfi \n\t"
);
}
#else //__TINYC__
void
_start ()
{
#if 0
__asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe320f000\n"); //nop {0}
#endif
int *in = &__stdin;
int *out = &__stdout;
int *err = &__stderr;
char ***env = &environ;
#if 0
__asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe320f000\n"); //nop {0}
*in = 0x22;
__asm__ (".int 0xe320f000\n"); //nop {0}
*out = 0x33;
__asm__ (".int 0xe320f000\n"); //nop {0}
*err = 0x44;
__asm__ (".int 0xe320f000\n"); //nop {0}
*env = 0x55;
__asm__ (".int 0xe320f000\n"); //nop {0}
#endif
/* environ = argv + argc + 1 */
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12]
__asm__ (".int 0xe28b1010\n"); //add r1, fp, #16
__asm__ (".int 0xe2802001\n"); //add r2, r0, #1
__asm__ (".int 0xe1a02102\n"); //lsl r2, r2, #2
__asm__ (".int 0xe0822001\n"); //add r2, r2, r1
// setup argc, argv, envp parameters on stack
__asm__ (".int 0xe52d2004\n"); //push {r2} ; (str r2, [sp, #-4]!)
__asm__ (".int 0xe52d1004\n"); //push {r1} ; (str r1, [sp, #-4]!)
__asm__ (".int 0xe52d0004\n"); //push {r0} ; (str r0, [sp, #-4]!)
__asm__ (".int 0xe1a02002\n"); //mov r2, r2
// *in = 0;
__asm__ (".int 0xe3a01000\n"); //mov r1, #0
__asm__ (".int 0xe51b0004\n"); //ldr r0, [fp, #-4]
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
__asm__ (".int 0xe320f000\n"); //nop {0}
// *out = 1;
__asm__ (".int 0xe3a01001\n"); //mov r1, #1
__asm__ (".int 0xe51b0008\n"); //ldr r0, [fp, #-8]
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
__asm__ (".int 0xe320f000\n"); //nop {0}
// *err = 2;
__asm__ (".int 0xe3a01002\n"); //mov r1, #2
__asm__ (".int 0xe51b000c\n"); //ldr r0, [fp, #-12]
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
__asm__ (".int 0xe320f000\n"); //nop {0}
// *env = [sp, #8]
__asm__ (".int 0xe59d1008\n"); //ldr r1, [sp, #8]
__asm__ (".int 0xe51b0010\n"); //ldr r0, [fp, #-16]
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
__asm__ (".int 0xe320f000\n"); //nop {0}
// setup argc, argv, envp parameters in registers
__asm__ (".int 0xe59d0000\n"); //ldr r0, [sp]
__asm__ (".int 0xe59d1004\n"); //ldr r1, [sp, #4]
__asm__ (".int 0xe59d2008\n"); //ldr r2, [sp, #8]
main ();
__asm__ (".int 0xe3a07001\n"); //mov r7, #1
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe320f003\n"); //wfi
__asm__ (".int 0xe320f000\n"); //nop {0}
}
#endif //__TINYC__

View file

@ -0,0 +1,19 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/

View file

@ -0,0 +1,19 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/

View file

@ -0,0 +1,31 @@
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** Commentary: */
/** Code: */
.text
.globl _start
_start:
mov x8, #93
mov x0, #42
svc #0
wfi

View file

@ -0,0 +1,40 @@
/*
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** Commentary: */
/** Code: */
.text
.globl _start
_start:
mov x8, #64
mov x0, #1
mov x1, hello
mov x2, $(end-hello)
svc #0
mov x8, #93
mov x0, xzr
svc #0
wfi
hello: .ascii "Hello, GNU Mes!\n"
end:

View file

@ -0,0 +1,66 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <linux/aarch64/syscall.h>
// *INDENT-OFF*
static long
__sys_call_internal (long sys_call)
{
long r;
asm (
"mov x7, %1\n\t"
"svc $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (sys_call)
: "x0", "x7"
);
return r;
}
static long
__sys_call2_internal (long sys_call, long one, long two)
{
long r;
asm (
"mov x7, %1\n\t"
"mov x0, %2\n\t"
"mov x1, %3\n\t"
"swi $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (sys_call), "r" (one), "r" (two)
: "x0", "x1", "x7"
);
return r;
}
// *INDENT-ON*
/* Returns < 0 on error (errno-like value from kernel), or 0 on success */
int
__raise (int signum)
{
long pid = __sys_call_internal (SYS_getpid);
if (pid < 0)
return pid;
else
return __sys_call2_internal (SYS_kill, pid, signum);
}

View file

@ -0,0 +1,276 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <linux/aarch64/syscall.h>
#if !__TINYC__
// *INDENT-OFF*
long
__sys_call (long sys_call)
{
long r;
asm (
"mov x7, %1\n\t"
"svc $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (sys_call)
: "x0", "x7"
);
return r;
}
#else //__TINYC__
long
__sys_call (long sys_call)
{
long r;
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
// __asm__ (".int 0xe1a00001\n"); //mov r0, r1
// __asm__ (".int 0xe1a01002\n"); //mov r1, r2
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
#if !__TINYC__
long
__sys_call1 (long sys_call, long one)
{
long r;
asm (
"mov x7, %1\n\t"
"mov x0, %2\n\t"
"svc $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (sys_call), "r" (one)
: "x0", "x7"
);
return r;
}
#else //__TINYC__
long
__sys_call1 (long sys_call, long one)
{
long r;
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
// __asm__ (".int 0xe1a01002\n"); //mov r1, r2
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
#if !__TINYC__
long
__sys_call2 (long sys_call, long one, long two)
{
long r;
asm (
"mov x7, %1\n\t"
"mov x0, %2\n\t"
"mov x1, %3\n\t"
"svc $0\n\t"
"mov %0, x0\n\t"
: "=r" (r)
: "r" (sys_call), "r" (one), "r" (two)
: "x0", "x1", "x7"
);
return r;
}
#else //__TINYC__
long
__sys_call2 (long sys_call, long one, long two)
{
long r;
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
// __asm__ (".int 0xe1a02003\n"); //mov r2, r3
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
#if !__TINYC__
long
__sys_call3 (long sys_call, long one, long two, long three)
{
long r;
asm (
"mov x7, %1\n\t"
"mov x0, %2\n\t"
"mov x1, %3\n\t"
"mov x2, %4\n\t"
"svc $0\n\t"
"mov %0, r0\n\t"
: "=r" (r)
: "r" (sys_call), "r" (one), "r" (two), "r" (three)
: "x0", "x1", "x2", "x7"
);
return r;
}
#else //__TINYC__
long
__sys_call3 (long sys_call, long one, long two, long three)
{
long r;
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
__asm__ (".int 0xe1a02003\n"); //mov r2, r3
// __asm__ (".int 0xe1a03004\n"); //mov r3, r4
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
#if !__TINYC__
long
__sys_call4 (long sys_call, long one, long two, long three, long four)
{
long r;
asm (
"mov x7, %1\n\t"
"mov x0, %2\n\t"
"mov x1, %3\n\t"
"mov x2, %4\n\t"
"mov x3, %5\n\t"
"svc $0\n\t"
"mov %0, r0\n\t"
: "=r" (r)
: "r" (sys_call), "r" (one), "r" (two), "r" (three), "r" (four)
: "x0", "x1", "x2", "x3", "x7"
);
return r;
}
#else //__TINYC__
long
__sys_call4 (long sys_call, long one, long two, long three, long four)
{
long r;
__asm__ (".int 0xe1a07000\n"); //mov r7, r0
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
__asm__ (".int 0xe1a02003\n"); //mov r2, r3
__asm__ (".int 0xe1a03004\n"); //mov r3, r4
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe50b0004\n"); //str r0, [fp, #-4]
return r;
}
#endif //__TINYC__
// *INDENT-ON*
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;
}
#if 0
long
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
{
long r = __sys_call6 (sys_call, one, two, three, four, five, six);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
#endif

View file

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
void
_exit ()
{
/* We're pretending to be x86 now, so I guess we get args from the stack
Use the weird calling convention m2libc uses */
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_TO_SYS_EXIT");
asm ("SYSCALL");
}

View file

@ -0,0 +1,41 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
void
_write ()
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_TO_SYS_WRITE");
asm ("SYSCALL");
}

View file

@ -0,0 +1,73 @@
### GNU Mes --- Maxwell Equations of Software
### Copyright (C) 2016 Jeremiah Orians
### Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
###
### 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 <http://www.gnu.org/licenses/>.
:_start
; sp has to be 16 byte aligned but we only want to deal with 8 byte registers,
; so use a normal register as sp
INIT_SP ; mov x18, sp
LDR_X0_[SP]
ADD_X1_SP_8
; M2-Planet also has a frame pointer, x17
SET_BP_FROM_SP ; mov x17, x18
; Separate out envp, get our args for main
PUSH_X0 ; argc
PUSH_X1 ; argv (yes, that's above the top of the stack)
SET_X1_TO_2 ; One word for argc, one word for a null pointer
ADD_X0_X1_X0
SET_X1_TO_8
MUL_X0_X1_X0
ADD_X0_BP_X0
PUSH_X0 ; envp
; Store envp to environ global
LOAD_W1_AHEAD
SKIP_32_DATA
&GLOBAL_environ
STR_X0_[X1]
; Set stdin, stdout, and stderr
SET_X0_TO_0
LOAD_W1_AHEAD
SKIP_32_DATA
&GLOBAL___stdin
STR_X0_[X1]
SET_X0_TO_1
LOAD_W1_AHEAD
SKIP_32_DATA
&GLOBAL___stdout
STR_X0_[X1]
SET_X0_TO_2
SKIP_32_DATA
&GLOBAL___stderr
STR_X0_[X1]
; Call our main function
LOAD_W16_AHEAD
SKIP_32_DATA
&FUNCTION_main
BLR_X16
; Exit
; Return from main is already in x0
SET_X8_TO_SYS_EXIT
SYSCALL

View file

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 ()
//#{
//# ..
//#}

View file

@ -0,0 +1,256 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <linux/aarch64/syscall.h>
int errno;
int
__sys_call (int sys_call)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SYSCALL");
}
int
__sys_call1 (int sys_call, int one)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL");
}
int
__sys_call2 (int sys_call, int one, int two)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL");
}
int
__sys_call3 (int sys_call, int one, int two, int three)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL");
}
int
__sys_call4 (int sys_call, int one, int two, int three, int four)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X3_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL");
}
int
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X5_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X4_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X3_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL");
}
int
_sys_call (int sys_call)
{
int r = __sys_call (sys_call);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call1 (int sys_call, int one)
{
int r = __sys_call1 (sys_call, one);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call2 (int sys_call, int one, int two)
{
int r = __sys_call2 (sys_call, one, two);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call3 (int sys_call, int one, int two, int three)
{
int r = __sys_call3 (sys_call, one, two, three);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call4 (int sys_call, int one, int two, int three, int four)
{
int r = __sys_call4 (sys_call, one, two, three, four);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
int
_sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{
int r = __sys_call6 (sys_call, one, two, three, four, five, six);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}

View file

@ -0,0 +1,7 @@
:ELF_text
a8 0b 80 d2 # mov x8, #93
40 05 80 d2 # mov x0, #42
01 00 00 d4 # svc #0
7f 20 03 d5 # wfi
:ELF_end

View file

@ -0,0 +1,75 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### Copyright (C) 2020 deesix <deesix@tuta.io>
### 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 <http://www.gnu.org/licenses/>.
### stage0's hex2 format
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
B7 00 # e_machine Indicating AArch64
01 00 00 00 # e_version Indicating original elf
&ELF_text 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text

View file

@ -27,5 +27,5 @@ access (char const *file_name, int how)
{
long long_file_name = cast_charp_to_long (file_name);
long long_how = cast_int_to_long (how);
return _sys_call2 (SYS_access, long_file_name, long_how);
return _sys_call4 (SYS_faccessat, -100, long_file_name, long_how, 0);
}

View file

@ -26,5 +26,5 @@ dup2 (int old, int new)
{
long long_old = old;
long long_new = new;
return _sys_call2 (SYS_dup2, long_old, long_new);
return _sys_call3 (SYS_dup3, long_old, long_new, 0);
}

View file

@ -24,5 +24,6 @@
int
fork ()
{
return _sys_call (SYS_fork);
/* We don't have a _sys_call5 but this works */
return _sys_call6 (SYS_clone, 17, 0, 0, 0, 0, 0);
}

View file

@ -26,5 +26,5 @@ int
unlink (char const *file_name)
{
long long_file_name = cast_charp_to_long (file_name);
return _sys_call1 (SYS_unlink, long_file_name);
return _sys_call3 (SYS_unlinkat, -100, long_file_name, 0);
}

View file

@ -0,0 +1,75 @@
### Copyright (C) 2016 Jeremiah Orians
### Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
### Copyright (C) 2020 deesix <deesix@tuta.io>
### 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 <http://www.gnu.org/licenses/>.
### stage0's hex2 format
### !<label> 1 byte relative
### $<label> 2 byte address
### @<label> 2 byte relative
### &<label> 4 byte address
### %<label> 4 byte relative
### if you wish to use this header, you need to add :ELF_end to the end of your
### M1 or hex2 files.
## ELF Header
:ELF_base
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
02 # e_ident[EI_CLASS] Indicating 64 bit
01 # e_ident[EI_DATA] Indicating little endianness
01 # e_ident[EI_VERSION] Indicating original elf
03 # e_ident[EI_OSABI] Set at 3 because FreeBSD is strict
00 # e_ident[EI_ABIVERSION] See above
00 00 00 00 00 00 00 # e_ident[EI_PAD]
02 00 # e_type Indicating Executable
B7 00 # e_machine Indicating AArch64
01 00 00 00 # e_version Indicating original elf
&_start 00 00 00 00 # e_entry Address of the entry point
%ELF_program_headers>ELF_base 00 00 00 00 # e_phoff Address of program header table
00 00 00 00 00 00 00 00 # e_shoff Address of section header table
00 00 00 00 # e_flags
40 00 # e_ehsize Indicating our 64 Byte header
38 00 # e_phentsize size of a program header table
01 00 # e_phnum number of entries in program table
00 00 # e_shentsize size of a section header table
00 00 # e_shnum number of entries in section table
00 00 # e_shstrndx index of the section names
:ELF_program_headers
:ELF_program_header__text
01 00 00 00 # ph_type: PT-LOAD = 1
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
00 00 00 00 00 00 00 00 # ph_offset
&ELF_base 00 00 00 00 # ph_vaddr
&ELF_base 00 00 00 00 # ph_physaddr
%ELF_end>ELF_base 00 00 00 00 # ph_filesz
%ELF_end>ELF_base 00 00 00 00 # ph_memsz
01 00 00 00 00 00 00 00 # ph_align
:ELF_text

View file

@ -0,0 +1,165 @@
## Copyright (C) 2020 deesix <deesix@tuta.io>
## Copyright (C) 2020 Sanne Wouda
## 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 <http://www.gnu.org/licenses/>.
DEFINE NULL 0000000000000000
# Stack (x18 as SP, 64 bits per element)
DEFINE PUSH_X0 408e1ff8
DEFINE PUSH_X1 418e1ff8
DEFINE PUSH_X16 508e1ff8
DEFINE PUSH_BP 518e1ff8
DEFINE PUSH_LR 5e8e1ff8
DEFINE POP_X0 408640f8
DEFINE POP_X1 418640f8
DEFINE POP_X16 508640f8
DEFINE POP_BP 518640f8
DEFINE POP_LR 5e8640f8
DEFINE INIT_SP f2030091 # mov x18, sp
# Jump/branch/call/return
DEFINE BR_X16 00021fd6
DEFINE BLR_X16 00023fd6
DEFINE RETURN c0035fd6
DEFINE CBZ_X0_PAST_BR a00000b4
DEFINE CBNZ_X0_PAST_BR a00000b5
DEFINE SKIP_INST_EQ 40000054
DEFINE SKIP_INST_NE 41000054
DEFINE SKIP_INST_LT 4b000054
DEFINE SKIP_INST_LE 4d000054
DEFINE SKIP_INST_GT 4c000054
DEFINE SKIP_INST_GE 4a000054
DEFINE SKIP_INST_LO 43000054
DEFINE SKIP_INST_LS 49000054
DEFINE SKIP_INST_HS 42000054
DEFINE SKIP_INST_HI 48000054
DEFINE SKIP_32_DATA 02000014
# Load literals (PC-relative)
DEFINE LOAD_W0_AHEAD 40000098
DEFINE LOAD_W1_AHEAD 41000018
DEFINE LOAD_W2_AHEAD 42000018
DEFINE LOAD_W16_AHEAD 50000018
# Load/store/dereference
DEFINE LDR_X0_[SP] 400240f9
DEFINE STR_X0_[X1] 200000f9
DEFINE STR_W0_[X1] 200000B9
DEFINE STRH_W0_[X1] 20000079
DEFINE STR_BYTE_W0_[X1] 20000039
DEFINE DEREF_X0 000040f9
DEFINE DEREF_X1 210040f9
DEFINE LDRH_W0_[X0] 00004079
DEFINE LDRSB_X0_[X0] 00008039
DEFINE LDRSH_X0_[X0] 00008079
DEFINE LDR_W0_[X0] 000040B9
DEFINE DEREF_X0_BYTE 00004039
DEFINE DEREF_X1_BYTE 21004039
# Move data between registers
DEFINE SET_X0_FROM_BP e00311aa
DEFINE SET_X1_FROM_X0 e10300aa
DEFINE SET_X1_FROM_SP e10312aa
DEFINE SET_X2_FROM_X0 e20300aa
DEFINE SET_X3_FROM_X0 e30300aa
DEFINE SET_X4_FROM_X0 e40300aa
DEFINE SET_X5_FROM_X0 e50300aa
DEFINE SET_X6_FROM_X0 e60300aa
DEFINE SET_X8_FROM_X0 e80300aa
DEFINE SET_X16_FROM_X0 f00300aa
DEFINE SET_X16_FROM_SP f00312aa
DEFINE SET_BP_FROM_X16 f10310aa
DEFINE SET_BP_FROM_SP f10312aa
# Move constant to register
DEFINE SET_X0_TO_0 000080d2
DEFINE SET_X0_TO_1 200080d2
DEFINE SET_X0_TO_2 400080d2
DEFINE SET_X0_TO_17 200280d2
DEFINE SET_X0_TO_MINUS_1 00008092
DEFINE SET_W0_TO_MINUS_1 00008012
DEFINE SET_X1_TO_0 010080d2
DEFINE SET_X1_TO_2 410080d2
DEFINE SET_X1_TO_8 010180d2
DEFINE SET_X2_TO_1 220080d2
DEFINE SET_X0_TO_FCNTL_H_AT_FDCWD 600c8092
# Arith/logic/relational
DEFINE ADD_X0_X1_X0 2000008b
DEFINE ADD_X0_BP_X0 2002008b
DEFINE ADD_X1_SP_8 41220091
DEFINE SUB_X0_X1_X0 200000cb
DEFINE SUB_X0_X0_X1 000001cb
DEFINE SUB_X0_8 002000d1
DEFINE SUB_X0_16 004000d1
DEFINE SUB_X0_24 006000d1
DEFINE MSUB_X0_X0_X2_X1 0084029b
DEFINE MUL_X0_X1_X0 207c009b
DEFINE SDIV_X0_X1_X0 200cc09a
DEFINE SDIV_X2_X1_X0 220cc09a
DEFINE UDIV_X0_X1_X0 2008c09a
DEFINE UDIV_X2_X1_X0 2208c09a
DEFINE LSHIFT_X0_X0_X2 0020c29a
DEFINE LSHIFT_X0_X1_X0 2020c09a
DEFINE LOGICAL_RSHIFT_X0_X1_X0 2024c09a
DEFINE ARITH_RSHIFT_X0_X1_X0 2028c09a
DEFINE MVN_X0 e00320aa
DEFINE AND_X0_X1_X0 2000008a
DEFINE OR_X0_X1_X0 200000aa
DEFINE XOR_X0_X1_X0 000001ca
DEFINE CMP_X1_X0 3f0000eb
# Syscall
DEFINE SET_X8_TO_SYS_BRK c81a80d2
DEFINE SET_X8_TO_SYS_CHDIR 280680d2
DEFINE SET_X8_TO_SYS_CLONE 881b80d2
DEFINE SET_X8_TO_SYS_CLOSE 280780d2
DEFINE SET_X8_TO_SYS_EXECVE a81b80d2
DEFINE SET_X8_TO_SYS_EXIT a80b80d2
DEFINE SET_X8_TO_SYS_FACCESSAT 080680d2
DEFINE SET_X8_TO_SYS_FCHDIR 480680d2
DEFINE SET_X8_TO_SYS_FCHMOD 880680d2
DEFINE SET_X8_TO_SYS_FCHMODAT a80680d2
DEFINE SET_X8_TO_SYS_GETCWD 280280d2
DEFINE SET_X8_TO_SYS_LSEEK c80780d2
DEFINE SET_X8_TO_SYS_MKDIR c88080d2
DEFINE SET_X8_TO_SYS_MKNOD 688080d2
DEFINE SET_X8_TO_SYS_OPENAT 080780d2
DEFINE SET_X8_TO_SYS_READ e80780d2
DEFINE SET_X8_TO_SYS_UNAME 081480d2
DEFINE SET_X8_TO_SYS_WAIT4 882080d2
DEFINE SET_X8_TO_SYS_WRITE 080880d2
DEFINE SET_X8_TO_SYS_UNLINK 488080d2
DEFINE SET_X8_TO_SYS_UMASK c81480d2
DEFINE SYSCALL 010000d4

View file

@ -27,5 +27,5 @@ chmod (char const *file_name, int mask)
{
long long_file_name = file_name;
long long_mask = mask;
return _sys_call2 (SYS_chmod, long_file_name, long_mask);
return _sys_call2 (SYS_fchmodat, -100, long_file_name, long_mask, 0);
}

View file

@ -27,7 +27,7 @@
int
open (char *file_name, int flags, int mask)
{
int r = _sys_call3 (SYS_open, file_name, flags, mask);
int r = _sys_call4 (SYS_openat, -100, file_name, flags, mask);
if (r > 2)
__ungetc_clear (r);
return r;

View file

@ -22,7 +22,7 @@
#include <string.h>
#include <stdlib.h>
// CONSTANT M2_PTR_SIZE 4
// CONSTANT M2_PTR_SIZE 8
#define M2_PTR_SIZE 1
char *

View file

@ -22,7 +22,7 @@
#include <string.h>
#include <stdlib.h>
// CONSTANT M2_PTR_SIZE 4
// CONSTANT M2_PTR_SIZE 8
#define M2_PTR_SIZE 1
int

View file

@ -32,7 +32,7 @@
int g_dump_filedes;
#define M2_CELL_SIZE 1U
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
char *
cell_bytes (struct scm *x)

View file

@ -27,10 +27,10 @@
#if __M2_PLANET__
#define M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
#else
#define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
#endif
struct scm *
@ -193,7 +193,7 @@ init_symbols () /*:((internal)) */
a = acons (cell_symbol_boot_module, cell_symbol_boot_module, a);
a = acons (cell_symbol_current_module, cell_symbol_current_module, a);
a = acons (cell_symbol_mes_version, make_string0 (MES_VERSION), a);
a = acons (cell_symbol_mes_version, make_string0 ("uwu"), a);
a = acons (cell_symbol_mes_datadir, make_string0 (g_datadir), a);
a = acons (cell_type_bytes, make_number (TBYTES), a);

View file

@ -25,7 +25,7 @@
#include <string.h>
#define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
int g_debug;

View file

@ -23,10 +23,10 @@
#if __M2_PLANET__
#define M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
#else
#define M2_CELL_SIZE 1
// CONSTANT M2_CELL_SIZE 12
// CONSTANT M2_CELL_SIZE 24
#endif
struct scm *