From 3502ad4f73408a7c4ad636b3f50e203acbaf946a Mon Sep 17 00:00:00 2001 From: Janneke Nieuwenhuizen Date: Wed, 3 May 2023 22:15:38 +0200 Subject: [PATCH] freebsd: lib: Use __init_io. * * lib/freebsd/x86-mes-gcc/crt1.c (_start): Replace manual initialization of __stdin, __stdout, __stderr, and environ with __init_io (). * lib/freebsd/x86-mes-mescc/crt1.c (_start): Likewise. * lib/freebsd/x86-mes-gcc/_write.c (SYS_exit): Remove. (SYS_write): New define. --- lib/freebsd/x86-mes-gcc/_write.c | 4 +-- lib/freebsd/x86-mes-gcc/crt1.c | 44 ++++++++------------------------ lib/freebsd/x86-mes-mescc/crt1.c | 14 ++-------- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/lib/freebsd/x86-mes-gcc/_write.c b/lib/freebsd/x86-mes-gcc/_write.c index 54cfaf80..e9e7a0ba 100644 --- a/lib/freebsd/x86-mes-gcc/_write.c +++ b/lib/freebsd/x86-mes-gcc/_write.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2019,2020,2023 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -20,7 +20,7 @@ #include "mes/lib-mini.h" -#define SYS_exit "0x01" +#define SYS_write "0x04" // *INDENT-OFF* ssize_t diff --git a/lib/freebsd/x86-mes-gcc/crt1.c b/lib/freebsd/x86-mes-gcc/crt1.c index 151d0279..f282fbf2 100644 --- a/lib/freebsd/x86-mes-gcc/crt1.c +++ b/lib/freebsd/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 * * This file is part of GNU Mes. * @@ -19,45 +19,20 @@ */ #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 "" - ); - - 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 $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" "mov %ebp,%eax\n\t" "add $8,%eax\n\t" "push %eax\n\t" @@ -67,6 +42,7 @@ _start () "mov (%eax),%eax\n\t" "push %eax\n\t" + "call __init_io\n\t" "call main\n\t" "push %eax\n\t" diff --git a/lib/freebsd/x86-mes-mescc/crt1.c b/lib/freebsd/x86-mes-mescc/crt1.c index 83cde649..cb2ea878 100644 --- a/lib/freebsd/x86-mes-mescc/crt1.c +++ b/lib/freebsd/x86-mes-mescc/crt1.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018,2019,2021 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019,2021,2023 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,21 +19,11 @@ */ #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 ("add____$i8,%eax !4"); @@ -42,7 +32,6 @@ _start () asm ("shl____$i8,%eax !0x02"); asm ("add____%ebp,%eax"); - asm ("mov____%eax,0x32 &environ"); asm ("push___%eax"); asm ("mov____%ebp,%eax"); @@ -54,6 +43,7 @@ _start () asm ("mov____(%eax),%eax"); asm ("push___%eax"); + __init_io (); main (); asm ("mov____%eax,%ebx");