ARM: Mes C Library: Support gcc-sans-libc.
* lib/linux/arm-mes-gcc/crt1.c: New file. * lib/linux/arm-mes-gcc/mini.c: New file. * lib/linux/arm-mes-gcc/syscall.c: New file. * lib/arm-mes-gcc/setjmp.c: New file.
This commit is contained in:
parent
92d60477c5
commit
bfe710d2a2
|
@ -0,0 +1,54 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 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 <setjmp.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
longjmp (jmp_buf env, int val)
|
||||||
|
{
|
||||||
|
val = val == 0 ? 1 : val;
|
||||||
|
// *INDENT-OFF*
|
||||||
|
#if 1
|
||||||
|
#warning LONGJMP not implemented
|
||||||
|
#else
|
||||||
|
asm (
|
||||||
|
"mov 0x8(%ebp),%ebp\n\t" // env*
|
||||||
|
|
||||||
|
"mov 0x4(%ebp),%ebx\n\t" // env->__pc
|
||||||
|
"mov 0x8(%ebp),%esp\n\t" // env->__sp
|
||||||
|
"mov 0x0(%ebp),%ebp\n\t" // env->__bp
|
||||||
|
"jmp *%ebx\n\t" // jmp *PC
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
// *INDENT-ON*
|
||||||
|
// not reached
|
||||||
|
exit (42);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
setjmp (jmp_buf env)
|
||||||
|
{
|
||||||
|
long *p = (long *) &env;
|
||||||
|
env[0].__bp = p[-2];
|
||||||
|
env[0].__pc = p[-1];
|
||||||
|
env[0].__sp = (long) &env;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 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 <mes/lib-mini.h>
|
||||||
|
//int main (int argc, char *argv[], char *envp[]);
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
void
|
||||||
|
_start ()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
asm (
|
||||||
|
"mov $0,%%eax\n\t"
|
||||||
|
"mov %%eax,%0\n"
|
||||||
|
: "=r" (__stdin)
|
||||||
|
: //no inputs ""
|
||||||
|
);
|
||||||
|
|
||||||
|
asm (
|
||||||
|
"mov $1,%%eax\n\t"
|
||||||
|
"mov %%eax,%0\n"
|
||||||
|
: "=r" (__stdout)
|
||||||
|
: //no inputs ""
|
||||||
|
);
|
||||||
|
|
||||||
|
asm (
|
||||||
|
"mov $2,%%eax\n\t"
|
||||||
|
"mov %%eax,%0\n"
|
||||||
|
: "=r" (__stderr)
|
||||||
|
: //no inputs ""
|
||||||
|
);
|
||||||
|
asm (
|
||||||
|
"mov %%ebp,%%eax\n\t"
|
||||||
|
"add $4,%%eax\n\t"
|
||||||
|
"movzbl (%%eax),%%eax\n\t"
|
||||||
|
"add $3,%%eax\n\t"
|
||||||
|
"shl $2,%%eax\n\t"
|
||||||
|
"add %%ebp,%%eax\n\t"
|
||||||
|
"mov %%eax,%0\n\t"
|
||||||
|
"push %%eax\n\t"
|
||||||
|
: "=r" (environ)
|
||||||
|
: //no inputs ""
|
||||||
|
);
|
||||||
|
asm (
|
||||||
|
"mov %ebp,%eax\n\t"
|
||||||
|
"add $8,%eax\n\t"
|
||||||
|
"push %eax\n\t"
|
||||||
|
|
||||||
|
"mov %ebp,%eax\n\t"
|
||||||
|
"add $4,%eax\n\t"
|
||||||
|
"movzbl (%eax),%eax\n\t"
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
asm (
|
||||||
|
"mov r2, $0\n\t"
|
||||||
|
"push {r2}\n\t"
|
||||||
|
"mov r1, $0\n\t"
|
||||||
|
"push {r1}\n\t"
|
||||||
|
"mov r0, $1\n\t"
|
||||||
|
"push {r0}\n\t"
|
||||||
|
"bl main\n\t"
|
||||||
|
"mov r7, $1\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"wfi \n\t"
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2016,2017,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 "mes/lib-mini.h"
|
||||||
|
|
||||||
|
#define SYS_exit "0x01"
|
||||||
|
#define SYS_write "0x04"
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
void
|
||||||
|
_exit (int code)
|
||||||
|
{
|
||||||
|
asm (
|
||||||
|
"mov r7, $"SYS_exit"\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
: // no outputs "=" (r)
|
||||||
|
: "r" (code)
|
||||||
|
: "r0"//, "r7" // error: r7 cannot be used in asm here
|
||||||
|
);
|
||||||
|
// not reached
|
||||||
|
_exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
_write (int filedes, void const *buffer, size_t size)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, $"SYS_write"\n\t"
|
||||||
|
"mov r0, %1\n\t"
|
||||||
|
"mov r1, %2\n\t"
|
||||||
|
"mov r3, %3\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov %0, r0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (filedes), "r" (buffer), "r" (size)
|
||||||
|
: "r0", "r1", "r2"//, "r7"
|
||||||
|
);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
// *INDENT-ON*
|
|
@ -0,0 +1,164 @@
|
||||||
|
/* -*-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 <errno.h>
|
||||||
|
#include <linux/x86/syscall.h>
|
||||||
|
|
||||||
|
// *INDENT-OFF*
|
||||||
|
long
|
||||||
|
_sys_call (long sys_call)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call)
|
||||||
|
: "r0" // , "r7" // error: r7 cannot be used in asm here
|
||||||
|
);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
_sys_call1 (long sys_call, long one)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"mov r0, %2\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call), "r" (one)
|
||||||
|
: "r0"
|
||||||
|
);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
_sys_call2 (long sys_call, long one, long two)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"mov r0, %2\n\t"
|
||||||
|
"mov r1, %3\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call), "r" (one), "r" (two)
|
||||||
|
: "r0", "r1"
|
||||||
|
);
|
||||||
|
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;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"mov r0, %2\n\t"
|
||||||
|
"mov r1, %3\n\t"
|
||||||
|
"mov r2, %4\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call), "r" (one), "r" (two), "r" (three)
|
||||||
|
: "r0", "r1", "r2"
|
||||||
|
);
|
||||||
|
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;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"mov r0, %2\n\t"
|
||||||
|
"mov r1, %3\n\t"
|
||||||
|
"mov r2, %4\n\t"
|
||||||
|
"mov r3, %5\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call), "r" (one), "r" (two), "r" (three), "r" (four)
|
||||||
|
: "r0", "r1", "r2", "r3"
|
||||||
|
);
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
errno = -r;
|
||||||
|
r = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errno = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||||
|
{
|
||||||
|
long r;
|
||||||
|
asm (
|
||||||
|
"mov r7, %1\n\t"
|
||||||
|
"mov r0, %2\n\t"
|
||||||
|
"mov r1, %3\n\t"
|
||||||
|
"mov r2, %4\n\t"
|
||||||
|
"mov r3, %5\n\t"
|
||||||
|
"mov r4, %6\n\t"
|
||||||
|
"mov r5, %7\n\t"
|
||||||
|
"swi $0\n\t"
|
||||||
|
"mov r0, %0\n\t"
|
||||||
|
: "=r" (r)
|
||||||
|
: "r" (sys_call), "r" (one), "r" (two), "r" (three), "r" (four), "r" (five), "r" (six)
|
||||||
|
: "r0", "r1", "r2", "r3", "r4", "r5"
|
||||||
|
);
|
||||||
|
return r;
|
||||||
|
}
|
Loading…
Reference in New Issue