Add ARM C runtime library.
* lib/linux/arm-mes/crt1.c: New file. * lib/linux/arm-mes/mes.c: New file. * lib/linux/arm-mes/mini.c: New file. * lib/linux/libc-mini.c: Use them.
This commit is contained in:
parent
394db05c9b
commit
3aaf8774a8
|
@ -0,0 +1,70 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,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/>.
|
||||
*/
|
||||
|
||||
#include "mes/lib-mini.h"
|
||||
|
||||
int main (int argc, char *argv[], char *envp[]);
|
||||
|
||||
void /* must not return */
|
||||
_start ()
|
||||
{
|
||||
/*
|
||||
|
||||
sp+1 argv
|
||||
sp -> argc
|
||||
|
||||
environ = &argv[argc + 1]
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* stdin = 0 */
|
||||
|
||||
asm ("!0 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdin");
|
||||
|
||||
/* stdout = 1 */
|
||||
|
||||
asm ("!1 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdout");
|
||||
|
||||
/* stderr = 2 */
|
||||
|
||||
asm ("!2 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stderr");
|
||||
|
||||
/* Add "environ" to main's arguments */
|
||||
|
||||
asm ("!0 ldr____%r0,(%sp,#$i8)"); /* "argc" */
|
||||
asm ("!4 ldr____%r1,(%sp,#$i8)"); /* "argv" */
|
||||
asm ("add____%r2,%r0,%r1,lsl#4"); /* "environ": argv + argc */
|
||||
asm ("!4 add____%r2,$i8"); /* "environ": argv + argc + 1 */
|
||||
|
||||
asm ("push___%r2");
|
||||
asm ("push___%r1");
|
||||
asm ("push___%r0");
|
||||
|
||||
main ();
|
||||
|
||||
//asm ("mov____%r0,%r0");
|
||||
asm ("SYS_exit mov____$i8,%r7");
|
||||
asm ("swi____$0");
|
||||
asm ("hlt");
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017 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/>.
|
||||
*/
|
||||
|
||||
void
|
||||
_exit ()
|
||||
{
|
||||
asm ("SYS_exit mov____$i8,%r7");
|
||||
asm ("!8 mov____0x8(%ebp),%r0");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
void
|
||||
_write ()
|
||||
{
|
||||
asm ("SYS_write mov____$i8,%r7");
|
||||
asm ("!8 mov____0x8(%ebp),%r0");
|
||||
asm ("!12 mov____0x8(%ebp),%r1");
|
||||
asm ("!16 mov____0x8(%ebp),%r2");
|
||||
asm ("swi____$0");
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,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/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <linux/x86/syscall.h>
|
||||
|
||||
int
|
||||
__sys_call (int sys_call)
|
||||
{
|
||||
asm ("!8 mov____0x8(%ebp),%r7");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call1 (int sys_call, int one)
|
||||
{
|
||||
asm ("!8 mov____0x8(%ebp),%r7");
|
||||
asm ("!12 mov____0x8(%ebp),%r0");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call2 (int sys_call, int one, int two)
|
||||
{
|
||||
asm ("!8 mov____0x8(%ebp),%r7");
|
||||
asm ("!12 mov____0x8(%ebp),%r0");
|
||||
asm ("!16 mov____0x8(%ebp),%r1");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call3 (int sys_call, int one, int two, int three)
|
||||
{
|
||||
asm ("!8 mov____0x8(%ebp),%r7");
|
||||
asm ("!12 mov____0x8(%ebp),%r0");
|
||||
asm ("!16 mov____0x8(%ebp),%r1");
|
||||
asm ("!20 mov____0x8(%ebp),%r2");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||
{
|
||||
asm ("!8 mov____0x8(%ebp),%r7");
|
||||
asm ("!12 mov____0x8(%ebp),%r0");
|
||||
asm ("!16 mov____0x8(%ebp),%r1");
|
||||
asm ("!20 mov____0x8(%ebp),%r2");
|
||||
asm ("!24 mov____0x8(%ebp),%r3");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue