x86_64: lib: Use __init_io.
* lib/linux/x86_64-mes-gcc/crt1.c (_start): Replace manual initialization of __stdin, __stdout, __stderr, and environ with __init_io (). * lib/linux/x86_64-mes-m2/crt1.M1 (_start): Likewise. * lib/linux/x86_64-mes-mescc/crt1.c (_start): Likewise.
This commit is contained in:
parent
1e898ea312
commit
88eb90dd38
|
@ -24,7 +24,7 @@
|
||||||
// let's try _main first
|
// let's try _main first
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib-mini.h>
|
||||||
int main (int argc, char *argv[]);
|
int main (int argc, char *argv[], char *envp[]);
|
||||||
|
|
||||||
// gcc x86_64 calling convention:
|
// gcc x86_64 calling convention:
|
||||||
// rdi, rsi, rdx, rcx, r8, r9, <stack0>, <stack1>
|
// rdi, rsi, rdx, rcx, r8, r9, <stack0>, <stack1>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2018,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib-mini.h>
|
||||||
// int main (int argc, char *argv[]);
|
int main (int argc, char *argv[], char *envp[]);
|
||||||
|
|
||||||
// gcc x86_64 calling convention:
|
// gcc x86_64 calling convention:
|
||||||
// rdi, rsi, rdx, rcx, r8, r9, <stack0>, <stack1>
|
// rdi, rsi, rdx, rcx, r8, r9, <stack0>, <stack1>
|
||||||
|
@ -29,38 +29,14 @@ void
|
||||||
_start ()
|
_start ()
|
||||||
{
|
{
|
||||||
asm (
|
asm (
|
||||||
"mov $0,%%eax\n\t"
|
"mov %rbp,%rax\n\t"
|
||||||
"mov %%eax,%0\n"
|
"add $8,%rax\n\t"
|
||||||
: "=r" (__stdin)
|
"mov (%rax),%rax\n\t"
|
||||||
: //no inputs ""
|
"add $3,%rax\n\t"
|
||||||
);
|
"shl $3,%rax\n\t"
|
||||||
|
"add %rbp,%rax\n\t"
|
||||||
|
"mov %rax,%rdx\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 %%rbp,%%rax\n\t"
|
|
||||||
"add $8,%%rax\n\t"
|
|
||||||
"mov (%%rax),%%rax\n\t"
|
|
||||||
"add $3,%%rax\n\t"
|
|
||||||
"shl $3,%%rax\n\t"
|
|
||||||
"add %%rbp,%%rax\n\t"
|
|
||||||
"mov %%rax,%0\n\t"
|
|
||||||
"mov %%rax,%%rdx\n\t"
|
|
||||||
: "=r" (environ)
|
|
||||||
: //no inputs ""
|
|
||||||
);
|
|
||||||
asm (
|
|
||||||
"mov %rbp,%rax\n\t"
|
"mov %rbp,%rax\n\t"
|
||||||
"add $16,%rax\n\t"
|
"add $16,%rax\n\t"
|
||||||
"mov %rax,%rsi\n\t"
|
"mov %rax,%rsi\n\t"
|
||||||
|
@ -69,6 +45,8 @@ _start ()
|
||||||
"add $8,%rax\n\t"
|
"add $8,%rax\n\t"
|
||||||
"mov (%rax),%rax\n\t"
|
"mov (%rax),%rax\n\t"
|
||||||
"mov %rax,%rdi\n\t"
|
"mov %rax,%rdi\n\t"
|
||||||
|
|
||||||
|
"call __init_io\n\t"
|
||||||
"call main\n\t"
|
"call main\n\t"
|
||||||
|
|
||||||
"mov %rax,%rdi\n\t"
|
"mov %rax,%rdi\n\t"
|
||||||
|
|
|
@ -20,14 +20,6 @@
|
||||||
push___%rbp
|
push___%rbp
|
||||||
mov____%rsp,%rbp
|
mov____%rsp,%rbp
|
||||||
|
|
||||||
;; mes c lib io
|
|
||||||
mov____$i8,%rax !0
|
|
||||||
movl___%eax,0x32 &GLOBAL___stdin
|
|
||||||
mov____$i8,%rax !1
|
|
||||||
movl___%eax,0x32 &GLOBAL___stdout
|
|
||||||
mov____$i8,%rax !2
|
|
||||||
movl___%eax,0x32 &GLOBAL___stderr
|
|
||||||
|
|
||||||
;; M2-Planet pushes forward
|
;; M2-Planet pushes forward
|
||||||
mov____%rbp,%rax ;argc
|
mov____%rbp,%rax ;argc
|
||||||
add____$i8,%rax !8
|
add____$i8,%rax !8
|
||||||
|
@ -46,9 +38,7 @@
|
||||||
add____%rbp,%rax
|
add____%rbp,%rax
|
||||||
push___%rax
|
push___%rax
|
||||||
|
|
||||||
;; mes c lib environ
|
call32 %FUNCTION___init_io
|
||||||
mov____%rax,0x32 &GLOBAL_environ
|
|
||||||
|
|
||||||
call32 %FUNCTION_main
|
call32 %FUNCTION_main
|
||||||
|
|
||||||
mov____%rax,%rdi
|
mov____%rax,%rdi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2018,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -24,15 +24,6 @@ int main (int argc, char *argv[], char *envp[]);
|
||||||
int
|
int
|
||||||
_start ()
|
_start ()
|
||||||
{
|
{
|
||||||
asm ("mov____$i8,%rax !0");
|
|
||||||
asm ("movl___%eax,0x32 &__stdin");
|
|
||||||
|
|
||||||
asm ("mov____$i8,%rax !1");
|
|
||||||
asm ("movl___%eax,0x32 &__stdout");
|
|
||||||
|
|
||||||
asm ("mov____$i8,%rax !2");
|
|
||||||
asm ("movl___%eax,0x32 &__stderr");
|
|
||||||
|
|
||||||
#if 0 //MES_CCAMD64
|
#if 0 //MES_CCAMD64
|
||||||
asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu
|
asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,8 +36,6 @@ _start ()
|
||||||
asm ("shl____$i8,%rax !0x03");
|
asm ("shl____$i8,%rax !0x03");
|
||||||
asm ("add____%rbp,%rax");
|
asm ("add____%rbp,%rax");
|
||||||
|
|
||||||
// FIXME: 64-bit addresses...
|
|
||||||
asm ("mov____%rax,0x32 &environ");
|
|
||||||
#if 0 //MES_CCAMD64
|
#if 0 //MES_CCAMD64
|
||||||
asm ("mov____%rax,%rdx"); // amd
|
asm ("mov____%rax,%rdx"); // amd
|
||||||
#else
|
#else
|
||||||
|
@ -70,6 +59,7 @@ _start ()
|
||||||
asm ("push___%rax"); // bootstrap
|
asm ("push___%rax"); // bootstrap
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
__init_io ();
|
||||||
main ();
|
main ();
|
||||||
|
|
||||||
asm ("mov____%rax,%rdi");
|
asm ("mov____%rax,%rdi");
|
||||||
|
|
Loading…
Reference in a new issue