Start support for aarch64 compiled with gcc
This commit is contained in:
parent
c38a9966de
commit
c6d6ba92d4
51
lib/linux/aarch64-mes-gcc/_exit.c
Normal file
51
lib/linux/aarch64-mes-gcc/_exit.c
Normal 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__
|
60
lib/linux/aarch64-mes-gcc/_write.c
Normal file
60
lib/linux/aarch64-mes-gcc/_write.c
Normal 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*
|
154
lib/linux/aarch64-mes-gcc/crt1.c
Normal file
154
lib/linux/aarch64-mes-gcc/crt1.c
Normal 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__
|
19
lib/linux/aarch64-mes-gcc/crti.c
Normal file
19
lib/linux/aarch64-mes-gcc/crti.c
Normal 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/>.
|
||||||
|
*/
|
19
lib/linux/aarch64-mes-gcc/crtn.c
Normal file
19
lib/linux/aarch64-mes-gcc/crtn.c
Normal 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/>.
|
||||||
|
*/
|
31
lib/linux/aarch64-mes-gcc/exit-42.S
Normal file
31
lib/linux/aarch64-mes-gcc/exit-42.S
Normal 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
|
40
lib/linux/aarch64-mes-gcc/hello-mes.S
Normal file
40
lib/linux/aarch64-mes-gcc/hello-mes.S
Normal 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:
|
66
lib/linux/aarch64-mes-gcc/syscall-internal.c
Normal file
66
lib/linux/aarch64-mes-gcc/syscall-internal.c
Normal 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);
|
||||||
|
}
|
276
lib/linux/aarch64-mes-gcc/syscall.c
Normal file
276
lib/linux/aarch64-mes-gcc/syscall.c
Normal 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
|
7
lib/linux/aarch64-mes/elf64-0exit-42.hex2
Normal file
7
lib/linux/aarch64-mes/elf64-0exit-42.hex2
Normal 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
|
75
lib/linux/aarch64-mes/elf64-0header.hex2
Normal file
75
lib/linux/aarch64-mes/elf64-0header.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
|
||||||
|
|
||||||
|
&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
|
Loading…
Reference in a new issue