diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index eb320a66..22d0fe89 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -1,7 +1,7 @@ #! /bin/sh # GNU Mes --- Maxwell Equations of Software -# Copyright © 2019,2020,2021 Jan (janneke) Nieuwenhuizen +# Copyright © 2019,2020,2021,2023 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -30,6 +30,7 @@ fi . ./config.sh libc_mini_shared_SOURCES=" +lib/mes/__init_io.c lib/mes/eputs.c lib/mes/oputs.c " diff --git a/include/mes/lib-mini.h b/include/mes/lib-mini.h index 48d91362..d02751d2 100644 --- a/include/mes/lib-mini.h +++ b/include/mes/lib-mini.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2020,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2020,2022,2023 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -51,6 +51,7 @@ extern int __stdin; extern int __stdout; extern int __stderr; +void __init_io (); int eputs (char const *s); int puts (char const *s); int oputs (char const *s); diff --git a/lib/linux/x86-mes-gcc/crt1.c b/lib/linux/x86-mes-gcc/crt1.c index 74cfe066..7c5ba6f8 100644 --- a/lib/linux/x86-mes-gcc/crt1.c +++ b/lib/linux/x86-mes-gcc/crt1.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019,2023 Jan (janneke) Nieuwenhuizen * Copyright © 2021 Paul Dersey * * This file is part of GNU Mes. @@ -20,45 +20,21 @@ */ #include -//int main (int argc, char *argv[], char *envp[]); +int main (int argc, char *argv[], char *envp[]); // *INDENT-OFF* void _start () { asm ( - "mov $0,%%eax\n\t" - "mov %%eax,%0\n" - : "=r" (__stdin) - : //no inputs "" - ); + "mov %ebp,%eax\n\t" + "add $4,%eax\n\t" + "mov (%eax),%eax\n\t" + "add $3,%eax\n\t" + "shl $2,%eax\n\t" + "add %ebp,%eax\n\t" + "push %eax\n\t" - 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" - "mov (%%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" @@ -68,6 +44,7 @@ _start () "mov (%eax),%eax\n\t" "push %eax\n\t" + "call __init_io\n\t" "call main\n\t" "mov %eax,%ebx\n\t" diff --git a/lib/linux/x86-mes-m2/crt1.M1 b/lib/linux/x86-mes-m2/crt1.M1 index a337b168..934b9e62 100644 --- a/lib/linux/x86-mes-m2/crt1.M1 +++ b/lib/linux/x86-mes-m2/crt1.M1 @@ -1,5 +1,5 @@ ### GNU Mes --- Maxwell Equations of Software -### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen +### Copyright © 2017,2018,2019,2023 Jan (janneke) Nieuwenhuizen ### ### This file is part of GNU Mes. ### @@ -19,22 +19,8 @@ :_start push___%ebp mov____%esp,%ebp - sub____$i32,%esp %0x1054 - mov____$i8,%eax !0 - mov____%eax,0x32 &GLOBAL___stdin - mov____$i8,%eax !1 - mov____%eax,0x32 &GLOBAL___stdout - mov____$i8,%eax !2 - mov____%eax,0x32 &GLOBAL___stderr - mov____%ebp,%eax - add____$i8,%eax !4 - mov____(%eax),%eax - add____$i8,%eax !3 - shl____$i8,%eax !0x02 - add____%ebp,%eax - mov____%eax,0x32 &GLOBAL_environ - mov____%esp,%edi ; M2-Planet calling convention pushes forward + ;; M2-Planet calling convention pushes forward mov____%ebp,%eax ; argc add____$i8,%eax !4 mov____(%eax),%eax @@ -44,10 +30,16 @@ add____$i8,%eax !8 push___%eax - mov____0x32,%eax &GLOBAL_environ - push___%eax + mov____%ebp,%eax ; envp + add____$i8,%eax !4 + mov____(%eax),%eax + add____$i8,%eax !3 + shl____$i8,%eax !0x02 + add____%ebp,%eax + mov____%eax,%ebx + push___%ebx - mov____%edi,%ebp ; M2-Planet calling convention + call32 %FUNCTION___init_io call32 %FUNCTION_main add____$i8,%esp !0x0 test___%eax,%eax diff --git a/lib/linux/x86-mes-mescc/crt1.c b/lib/linux/x86-mes-mescc/crt1.c index 05f189d1..a184e99c 100644 --- a/lib/linux/x86-mes-mescc/crt1.c +++ b/lib/linux/x86-mes-mescc/crt1.c @@ -19,41 +19,29 @@ */ #include "mes/lib-mini.h" - int main (int argc, char *argv[], char *envp[]); int _start () { - asm ("mov____$i8,%eax !0"); - asm ("mov____%eax,0x32 &__stdin"); - - asm ("mov____$i8,%eax !1"); - asm ("mov____%eax,0x32 &__stdout"); - - asm ("mov____$i8,%eax !2"); - asm ("mov____%eax,0x32 &__stderr"); - - asm ("mov____%ebp,%eax"); + asm ("mov____%ebp,%eax"); //environ asm ("add____$i8,%eax !4"); - asm ("mov____(%eax),%eax"); asm ("add____$i8,%eax !3"); - asm ("shl____$i8,%eax !0x02"); asm ("add____%ebp,%eax"); - asm ("mov____%eax,0x32 &environ"); asm ("push___%eax"); - asm ("mov____%ebp,%eax"); + asm ("mov____%ebp,%eax"); // argv asm ("add____$i8,%eax !8"); asm ("push___%eax"); - asm ("mov____%ebp,%eax"); + asm ("mov____%ebp,%eax"); // argc asm ("add____$i8,%eax !4"); asm ("mov____(%eax),%eax"); asm ("push___%eax"); + __init_io (); main (); asm ("mov____%eax,%ebx");