x86: lib: Use __init_io.
* build-aux/configure-lib.sh (libc_mini_shared_SOURCES): Add init_io.c. * include/mes/lib-mini.h (__init_io): Declare it. * lib/linux/x86-mes-gcc/crt1.c (_start): Replace manual initialization of __stdin, __stdout, __stderr, and environ with __init_io (). * lib/linux/x86-mes-m2/crt1.M1 (_start): Likewise. * lib/linux/x86-mes-mescc/crt1.c (_start): Likewise.
This commit is contained in:
parent
68f3db77cf
commit
1e898ea312
|
@ -1,7 +1,7 @@
|
|||
#! /bin/sh
|
||||
|
||||
# GNU Mes --- Maxwell Equations of Software
|
||||
# Copyright © 2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
# Copyright © 2019,2020,2021,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
#
|
||||
# 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
|
||||
"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2016,2017,2018,2020,2022,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2021 Paul Dersey <pdersey@gmail.com>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
|
@ -20,45 +20,21 @@
|
|||
*/
|
||||
|
||||
#include <mes/lib-mini.h>
|
||||
//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"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright © 2017,2018,2019,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
###
|
||||
### 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
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue