From 29acdfa2a7cbc0d6de102c3cec8ca4909c6e5af0 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 3 Sep 2017 08:18:18 +0200 Subject: [PATCH] mescc: Tinycc support: refactor _start. * mlibc/libc-mes.c (_start): Refactor. (_env): Remove. * stage0/x86.M1: --- mlibc/libc-mes.c | 46 ++++++++++++++++++++-------------------------- stage0/x86.M1 | 1 + 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/mlibc/libc-mes.c b/mlibc/libc-mes.c index d4f985a3..35b76770 100644 --- a/mlibc/libc-mes.c +++ b/mlibc/libc-mes.c @@ -23,42 +23,36 @@ int g_stdin = 0; char **g_environment; -int _env (); -int exit (); -int main(int,char*[]); +int main (int,char*[]); int _start () { - asm ("mov____%ebp,%eax"); // mov %ebp,%eax - asm ("add____$i8,%eax !8"); // add $0x8,%eax - asm ("push___%eax"); // push %eax + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !4"); - asm ("mov____%ebp,%eax"); // mov %ebp,%eax - asm ("add____$i8,%eax !4"); // add $0x4,%eax - asm ("movzbl_(%eax),%eax"); // movzbl (%eax),%eax - asm ("push___%eax"); // push %eax + asm ("movzbl_(%eax),%eax"); + asm ("add____$i8,%eax !3"); - asm ("mov____%ebp,%eax"); // mov %ebp,%eax - asm ("add____$i8,%eax !4"); // add $0x4,%eax + asm ("shl____$i8,%eax !0x02"); + asm ("add____%ebp,%eax"); + asm ("mov____%eax,0x32 &g_environment"); - asm ("movzbl_(%eax),%eax"); // movzbl (%eax),%eax - asm ("add____$i8,%eax !3"); // add $0x3,%eax + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !8"); + asm ("push___%eax"); - asm ("shl____$i8,%eax !0x02"); // shl $0x2,%eax - asm ("add____%ebp,%eax"); // add %ebp,%eax - asm ("push___%eax"); // push %eax + asm ("mov____%ebp,%eax"); + asm ("add____$i8,%eax !4"); + asm ("movzbl_(%eax),%eax"); + asm ("push___%eax"); - g_environment = _env (); - asm ("pop____%eax"); // pop %eax - int r = main (); - exit (r); -} + main (); -char ** -_env (char **e) -{ - return e; + asm ("mov____%eax,%ebx"); + asm ("mov____$i32,%eax %1"); + asm ("int____$0x80"); + asm ("hlt"); } void diff --git a/stage0/x86.M1 b/stage0/x86.M1 index 8543a12f..1b88cbfe 100644 --- a/stage0/x86.M1 +++ b/stage0/x86.M1 @@ -49,6 +49,7 @@ DEFINE cmp____$i8,0x32(%ebp) 83bd DEFINE cmp____$i8,0x8(%ebp) 837d DEFINE cmp____%al,%dl 38c2 DEFINE cmp____%edx,%eax 39d0 +DEFINE hlt f4 DEFINE idiv___%ebx f7fb DEFINE int____$0x80 cd80 DEFINE je32 0f84