From c086f67cecc8be1e68da8ed4f2ec2a96d2382b21 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 10 Jun 2018 16:03:18 +0200 Subject: [PATCH] mescc: Support less-patched tcc/gcc: Add crti and crtn. * lib/crt0.c[__MESC__]: Support MesCC. * lib/crti.c: New file. * lib/crtn.c: New file. * build-aux/build-mes-gcc.sh: Build them. --- build-aux/build-mes-gcc.sh | 2 ++ build-aux/build-mes.sh | 3 +++ lib/crt0.c | 36 ++++++++++++++++++++++++++++++++++++ lib/crti.c | 19 +++++++++++++++++++ lib/crtn.c | 19 +++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 lib/crti.c create mode 100644 lib/crtn.c diff --git a/build-aux/build-mes-gcc.sh b/build-aux/build-mes-gcc.sh index 2dca41f1..58c24cb7 100755 --- a/build-aux/build-mes-gcc.sh +++ b/build-aux/build-mes-gcc.sh @@ -64,6 +64,8 @@ C32FLAGS=${C32FLAGS-" ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt0 ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crt1 +ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crti +ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/crtn ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libc ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes-gcc.sh lib/libgetopt diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 02d47ba7..a7ca9ab5 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -97,7 +97,10 @@ if [ -d "$MES_SEED" ]; then fi PREPROCESS=1 +ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/crt0 ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/crt1 +ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/crti +ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/crtn ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libc ARCHDIR=1 NOLINK=1 sh build-aux/cc-mes.sh lib/libgetopt diff --git a/lib/crt0.c b/lib/crt0.c index 08cbbc80..5a34f358 100644 --- a/lib/crt0.c +++ b/lib/crt0.c @@ -26,6 +26,8 @@ char **environ = 0; int _main (int argc, char *argv[]); +#if __GNUC__ + void _start () { @@ -59,3 +61,37 @@ _start () : ); } + +#elif __MESC__ + +int +_start () +{ + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !4"); + + asm ("movzbl_(%eax),%eax"); + asm ("add____$i8,%eax !3"); + + asm ("shl____$i8,%eax !0x02"); + asm ("add____%ebp,%eax"); + asm ("mov____%eax,0x32 &environ"); + + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !8"); + asm ("push___%eax"); + + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !4"); + asm ("movzbl_(%eax),%eax"); + asm ("push___%eax"); + + _main (); + + asm ("mov____%eax,%ebx"); + asm ("mov____$i32,%eax %1"); + asm ("int____$0x80"); + asm ("hlt"); +} + +#endif diff --git a/lib/crti.c b/lib/crti.c new file mode 100644 index 00000000..1038f49d --- /dev/null +++ b/lib/crti.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ diff --git a/lib/crtn.c b/lib/crtn.c new file mode 100644 index 00000000..1038f49d --- /dev/null +++ b/lib/crtn.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */