First work at getting mes to compile on aarch64
This commit is contained in:
parent
a3455191be
commit
2f28361d24
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,6 +17,7 @@
|
||||||
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
# along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
.direnv/
|
.direnv/
|
||||||
|
m2/
|
||||||
|
|
||||||
*-
|
*-
|
||||||
*~
|
*~
|
||||||
|
|
52
include/linux/aarch64/kernel-stat.h
Normal file
52
include/linux/aarch64/kernel-stat.h
Normal 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
|
87
include/linux/aarch64/syscall.h
Normal file
87
include/linux/aarch64/syscall.h
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* -*-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 */
|
||||||
|
#define SYS_exit 93
|
||||||
|
#define SYS_write 64
|
||||||
|
#define SYS_clone 220
|
||||||
|
#define SYS_read 63
|
||||||
|
#define SYS_openat 56
|
||||||
|
#define SYS_wait4 260
|
||||||
|
#define SYS_execve 221
|
||||||
|
#define SYS_fchmod 52
|
||||||
|
#define SYS_faccessat 48
|
||||||
|
#define SYS_brk 234
|
||||||
|
#define SYS_ioctl 29
|
||||||
|
#define SYS_fsync 82
|
||||||
|
#define SYS_getcwd 17
|
||||||
|
#define SYS_dup 23
|
||||||
|
#define SYS_dup3 24
|
||||||
|
#define SYS_unlinkat 35
|
||||||
|
#define SYS_gettimeofday 169
|
||||||
|
#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 */
|
0
lib/aarch64-mes/aarch64.M1
Normal file
0
lib/aarch64-mes/aarch64.M1
Normal file
32
lib/linux/aarch64-mes-m2/_exit.c
Normal file
32
lib/linux/aarch64-mes-m2/_exit.c
Normal 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");
|
||||||
|
}
|
30
lib/linux/aarch64-mes-m2/_write.c
Normal file
30
lib/linux/aarch64-mes-m2/_write.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* -*-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 ("POP_X2");
|
||||||
|
asm ("POP_X1");
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("SET_X8_TO_SYS_WRITE");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
73
lib/linux/aarch64-mes-m2/crt1.M1
Normal file
73
lib/linux/aarch64-mes-m2/crt1.M1
Normal 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
|
34
lib/linux/aarch64-mes-m2/crt1.c
Normal file
34
lib/linux/aarch64-mes-m2/crt1.c
Normal 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 ()
|
||||||
|
//#{
|
||||||
|
//# ..
|
||||||
|
//#}
|
167
lib/linux/aarch64-mes-m2/syscall.c
Normal file
167
lib/linux/aarch64-mes-m2/syscall.c
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
/* -*-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 ("POP_X8");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call1 (int sys_call, int one)
|
||||||
|
{
|
||||||
|
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("POP_X8");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call2 (int sys_call, int one, int two)
|
||||||
|
{
|
||||||
|
asm ("POP_X1");
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("POP_X8");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call3 (int sys_call, int one, int two, int three)
|
||||||
|
{
|
||||||
|
asm ("POP_X2");
|
||||||
|
asm ("POP_X1");
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("POP_X8");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||||
|
{
|
||||||
|
asm ("POP_X3");
|
||||||
|
asm ("POP_X2");
|
||||||
|
asm ("POP_X1");
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("POP_X8");
|
||||||
|
asm ("SYSCALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
|
||||||
|
{
|
||||||
|
asm ("POP_X5");
|
||||||
|
asm ("POP_X4");
|
||||||
|
asm ("POP_X3");
|
||||||
|
asm ("POP_X2");
|
||||||
|
asm ("POP_X1");
|
||||||
|
asm ("POP_X0");
|
||||||
|
asm ("POP_X8");
|
||||||
|
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;
|
||||||
|
}
|
75
lib/m2/aarch64/ELF-aarch64.hex2
Normal file
75
lib/m2/aarch64/ELF-aarch64.hex2
Normal 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
|
169
lib/m2/aarch64/aarch64_defs.M1
Normal file
169
lib/m2/aarch64/aarch64_defs.M1
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
## 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_X2 428640f8
|
||||||
|
DEFINE POP_X3 438640f8
|
||||||
|
DEFINE POP_X4 448640f8
|
||||||
|
DEFINE POP_X5 458640f8
|
||||||
|
DEFINE POP_X8 488640f8
|
||||||
|
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_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
|
Loading…
Reference in a new issue