diff --git a/build-aux/build-cc.sh b/build-aux/build-cc.sh index 723d7dbe..4ef6b474 100755 --- a/build-aux/build-cc.sh +++ b/build-aux/build-cc.sh @@ -47,10 +47,10 @@ trace "MSNARF vector.c" ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc.sh lib/libmes sh ${srcdest}build-aux/cc.sh src/mes -#ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crt0 +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crt0 ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crt1 -# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crti -# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crtn +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crti +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/crtn ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libgetopt diff --git a/build-aux/build-cc32.sh b/build-aux/build-cc32.sh index abcd0c5e..6f2385c9 100755 --- a/build-aux/build-cc32.sh +++ b/build-aux/build-cc32.sh @@ -45,10 +45,10 @@ trace "MSNARF posix.c" ${srcdest}build-aux/mes-snarf.scm --mes src/posix.c trace "MSNARF reader.c" ${srcdest}build-aux/mes-snarf.scm --mes src/reader.c trace "MSNARF vector.c" ${srcdest}build-aux/mes-snarf.scm --mes src/vector.c -ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/crt0 -ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/crt1 -ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/crti -ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/crtn +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crt0 +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crt1 +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crti +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/linux/x86-mes-gcc/crtn ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libc ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc32-mes.sh lib/libgetopt diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index 8517d2c8..55b6b292 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -114,7 +114,7 @@ if [ ! -d "$MES_SEED" ] \ fi MES_ARENA=100000000 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crt0 +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crt1 ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc-mini PREPROCESS= bash ${srcdest}build-aux/cc-mes.sh lib/x86-mes/exit-42 @@ -123,9 +123,9 @@ trace "TEST exit-42.out" { set +e; lib/x86-mes/exit-42.mes-out; r=$?; set -e; } [ $r != 42 ] && echo " => $r" && exit 1 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crt1 -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crti -ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/crtn +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crt0 +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crti +ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/linux/x86-mes/crtn ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libc ARCHDIR=1 NOLINK=1 bash ${srcdest}build-aux/cc-mes.sh lib/libgetopt diff --git a/lib/linux/x86-mes-gcc/crt0.c b/lib/linux/x86-mes-gcc/crt0.c new file mode 100644 index 00000000..d17fc92b --- /dev/null +++ b/lib/linux/x86-mes-gcc/crt0.c @@ -0,0 +1,60 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +// no clue what crt0.o is and why gcc-2.6.3 needs it + +// instead of calling main, it seems to call either _main or ___main, +// let's try _main first + +char **environ = 0; +int _main (int argc, char *argv[]); + +void +_start () +{ + 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" + : "=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" + "push %eax\n\t" + + "call _main\n\t" + + "mov %eax,%ebx\n\t" + "mov $1,%eax\n\t" + "int $0x80\n\t" + "hlt \n\t" + ); +} diff --git a/lib/linux/crt1.c b/lib/linux/x86-mes-gcc/crt1.c similarity index 71% rename from lib/linux/crt1.c rename to lib/linux/x86-mes-gcc/crt1.c index 8148f268..7bf73b62 100644 --- a/lib/linux/crt1.c +++ b/lib/linux/x86-mes-gcc/crt1.c @@ -21,40 +21,6 @@ char **environ = 0; int main (int argc, char *argv[]); -#if __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"); -} - -#else // !__MESC__ - void _start () { @@ -84,8 +50,6 @@ _start () "mov %eax,%ebx\n\t" "mov $1,%eax\n\t" "int $0x80\n\t" - "hlt \n\t" + "hlt \n\t" ); } - -#endif // !__MESC__ diff --git a/lib/linux/crti.c b/lib/linux/x86-mes-gcc/crti.c similarity index 100% rename from lib/linux/crti.c rename to lib/linux/x86-mes-gcc/crti.c diff --git a/lib/linux/crtn.c b/lib/linux/x86-mes-gcc/crtn.c similarity index 100% rename from lib/linux/crtn.c rename to lib/linux/x86-mes-gcc/crtn.c diff --git a/lib/linux/crt0.c b/lib/linux/x86-mes/crt0.c similarity index 68% rename from lib/linux/crt0.c rename to lib/linux/x86-mes/crt0.c index 46dd2d8c..0072dcd4 100644 --- a/lib/linux/crt0.c +++ b/lib/linux/x86-mes/crt0.c @@ -26,44 +26,6 @@ char **environ = 0; int _main (int argc, char *argv[]); -#if __GNUC__ - -void -_start () -{ - asm ( - "mov %%ebp,%%eax\n\t" - "addl $4,%%eax\n\t" - "movzbl (%%eax),%%eax\n\t" - "addl $3,%%eax\n\t" - "shl $2,%%eax\n\t" - "add %%ebp,%%eax\n\t" - "movl %%eax,%0\n\t" - : "=environ" (environ) - : //no inputs "" - ); - asm ( - "mov %%ebp,%%eax\n\t" - "addl $8,%%eax\n\t" - "push %%eax\n\t" - - "mov %%ebp,%%eax\n\t" - "addl $4,%%eax\n\t" - "movzbl (%%eax),%%eax\n\t" - "push %%eax\n\t" - - "call _main\n\t" - - "mov %%eax,%%ebx\n\t" - "mov $1,%%eax\n\t" - "int $0x80\n\t" - "hlt \n\t" - : - ); -} - -#elif __MESC__ - int _start () { @@ -93,5 +55,3 @@ _start () asm ("int____$0x80"); asm ("hlt"); } - -#endif diff --git a/lib/linux/x86-mes/crt1.c b/lib/linux/x86-mes/crt1.c new file mode 100644 index 00000000..cd5a581a --- /dev/null +++ b/lib/linux/x86-mes/crt1.c @@ -0,0 +1,52 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +char **environ = 0; +int main (int argc, char *argv[]); + +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"); +} diff --git a/lib/linux/x86-mes/crti.c b/lib/linux/x86-mes/crti.c new file mode 100644 index 00000000..e11c4684 --- /dev/null +++ b/lib/linux/x86-mes/crti.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ diff --git a/lib/linux/x86-mes/crtn.c b/lib/linux/x86-mes/crtn.c new file mode 100644 index 00000000..e11c4684 --- /dev/null +++ b/lib/linux/x86-mes/crtn.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ diff --git a/lib/linux/x86_64-mes-gcc/crt0.c b/lib/linux/x86_64-mes-gcc/crt0.c new file mode 100644 index 00000000..9fcbd800 --- /dev/null +++ b/lib/linux/x86_64-mes-gcc/crt0.c @@ -0,0 +1,62 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +// no clue what crt0.o is and why gcc-2.6.3 needs it + +// instead of calling main, it seems to call either _main or ___main, +// let's try _main first + +char **environ = 0; +int main (int argc, char *argv[]); + +// gcc x86_64 calling convention: +// rdi, rsi, rdx, rcx, r8, r9, , + +void +_start () +{ + asm ( + "movq %%rbp,%%rax\n\t" + "add $8,%%rax\n\t" + "movq (%%rax),%%rax\n\t" + "add $3,%%rax\n\t" + "shl $3,%%rax\n\t" + "add %%rbp,%%rax\n\t" + "mov %%rax,%0\n\t" + : "=r" (environ) + : //no inputs "" + ); + asm ( + "mov %rbp,%rax\n\t" + "add $16,%rax\n\t" + "mov %rax,%rsi\n\t" + + "mov %rbp,%rax\n\t" + "add $8,%rax\n\t" + "mov (%rax),%rax\n\t" + "mov %rax,%rdi\n\t" + "call _main\n\t" + + "mov %rax,%rdi\n\t" + "mov $0x3c,%rax\n\t" + "syscall \n\t" + "hlt \n\t" + ); +} diff --git a/lib/linux/x86_64-mes-gcc/crt1.c b/lib/linux/x86_64-mes-gcc/crt1.c index 701d75fa..2a5fca57 100644 --- a/lib/linux/x86_64-mes-gcc/crt1.c +++ b/lib/linux/x86_64-mes-gcc/crt1.c @@ -22,7 +22,7 @@ char **environ = 0; int main (int argc, char *argv[]); // gcc x86_64 calling convention: -// edi, esi, edx, ecx, r8d, r9d, , +// rdi, rsi, rdx, rcx, r8, r9, , void _start () diff --git a/lib/linux/x86_64-mes-gcc/crti.c b/lib/linux/x86_64-mes-gcc/crti.c new file mode 100644 index 00000000..e11c4684 --- /dev/null +++ b/lib/linux/x86_64-mes-gcc/crti.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ diff --git a/lib/linux/x86_64-mes-gcc/crtn.c b/lib/linux/x86_64-mes-gcc/crtn.c new file mode 100644 index 00000000..e11c4684 --- /dev/null +++ b/lib/linux/x86_64-mes-gcc/crtn.c @@ -0,0 +1,19 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * 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 . + */