bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH master] mescc: Mes C Library: Add crt1, mini.


From: Danny Milosavljevic
Subject: [PATCH master] mescc: Mes C Library: Add crt1, mini.
Date: Wed, 3 Jun 2020 00:49:53 +0200

* lib/linux/arm-mes-mescc/crt1.c: New file.
* lib/linux/arm-mes-mescc/mini.c: New file.
---
 lib/linux/arm-mes-mescc/crt1.c | 75 ++++++++++++++++++++++++++++++++++
 lib/linux/arm-mes-mescc/mini.c | 38 +++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 lib/linux/arm-mes-mescc/crt1.c
 create mode 100644 lib/linux/arm-mes-mescc/mini.c

diff --git a/lib/linux/arm-mes-mescc/crt1.c b/lib/linux/arm-mes-mescc/crt1.c
new file mode 100644
index 00000000..ffaca8ae
--- /dev/null
+++ b/lib/linux/arm-mes-mescc/crt1.c
@@ -0,0 +1,75 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017,2018 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/>.
+ */
+
+#include "mes/lib-mini.h"
+
+int main (int argc, char *argv[], char *envp[]);
+
+void /* must not return */
+_start ()
+{
+/*
+
+sp+1    argv UNROLLED ON STACK
+sp   -> argc
+
+environ = &argv[argc + 1]
+
+HOWEVER, the function entry already allocated space for locals on the stack 
(after saving lr and fp, which moved sp again).  Hence, use fp instead of sp.
+*/
+
+  /* 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 ("!8 ldr____%r0,(%fp,+#$i8)"); /* "argc" */
+  asm ("mov____%fp,%r1");
+  asm ("!12 add____%r1,$i8"); /* argv */
+  asm ("add____%r2,%r1,%r0,lsl#2"); /* "environ": argv + argc */
+  asm ("!4 add____%r2,$i8"); /* "environ": argv + argc + 1 */
+
+  asm ("push___%r2"); /* environ */
+  asm ("push___%r1"); /* argv */
+  asm ("push___%r0"); /* argc */
+
+  /* environ = r2 */
+
+  asm ("mov____%r2,0x32 &environ");
+
+  main ();
+
+  asm ("SYS_exit mov____$i8,%r7");
+  asm ("swi____$0");
+  asm ("hlt");
+}
diff --git a/lib/linux/arm-mes-mescc/mini.c b/lib/linux/arm-mes-mescc/mini.c
new file mode 100644
index 00000000..6ea2d5a3
--- /dev/null
+++ b/lib/linux/arm-mes-mescc/mini.c
@@ -0,0 +1,38 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2016,2017 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 ()
+{
+  asm ("SYS_exit mov____$i8,%r7");
+  asm ("!8 ldr____%r0,(%fp,+#$i8)");
+  asm ("swi____$0");
+}
+
+void
+_write ()
+{
+  asm ("SYS_write mov____$i8,%r7");
+  asm ("!8 ldr____%r0,(%fp,+#$i8)");
+  asm ("!12 ldr____%r1,(%fp,+#$i8)");
+  asm ("!16 ldr____%r2,(%fp,+#$i8)");
+  asm ("swi____$0");
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]