mescc: Mes C Library: Initialize streams in crt1.

* lib/linux/x86-mes-gcc/crt1.c: Initialize streams.
* lib/linux/x86-mes/crt1.c: Likewise.
* lib/linux/x86_64-mes-gcc/crt1.c: Likewise.
* lib/linux/x86_64-mes/crt1.c: Likewise.
* src/mes.c (main): Remove initialization of streams.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-24 12:31:44 +01:00
parent 3480813038
commit 5232cfe669
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
11 changed files with 78 additions and 18 deletions

View File

@ -21,11 +21,6 @@
#ifndef __MES_LIBMES_MINI_H
#define __MES_LIBMES_MINI_H
char **environ;
int g_stdin;
int g_stdout;
int g_stderr;
#if !WITH_GLIBC
#ifndef _SIZE_T
@ -64,18 +59,25 @@ int errno;
#endif //!WITH_LIBC
// CONSTANT STDIN 0
#ifndef STDIN
#define STDIN 0
#endif
// CONSTANT STDOUT 1
#ifndef STDOUT
#define STDOUT 1
#endif
// CONSTANT STDERR 2
#ifndef STDERR
#define STDERR 2
#endif
char **environ;
int g_stdin;
int g_stdout;
int g_stderr;
int eputs (char const* s);
int puts (char const* s);

View File

@ -40,8 +40,6 @@
#error both __GNU__ and _linux__ are undefined, choose one
#endif
int g_stdin = 0;
void _env ();
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

View File

@ -23,7 +23,7 @@
// instead of calling main, it seems to call either _main or ___main,
// let's try _main first
char **environ = 0;
#include <libmes-mini.h>
int _main (int argc, char *argv[]);
void

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -18,12 +18,32 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char **environ = 0;
#include <libmes-mini.h>
//int main (int argc, char *argv[], char *envp[]);
void
_start ()
{
asm (
"mov $0,%%eax\n\t"
"mov %%eax,%0\n"
: "=r" (g_stdin)
: //no inputs ""
);
asm (
"mov $1,%%eax\n\t"
"mov %%eax,%0\n"
: "=r" (g_stdout)
: //no inputs ""
);
asm (
"mov $2,%%eax\n\t"
"mov %%eax,%0\n"
: "=r" (g_stderr)
: //no inputs ""
);
asm (
"mov %%ebp,%%eax\n\t"
"add $4,%%eax\n\t"

View File

@ -18,12 +18,22 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char **environ = 0;
#include "libmes-mini.h"
int main (int argc, char *argv[], char *envp[]);
int
_start ()
{
asm ("mov____$i8,%eax !0");
asm ("mov____%eax,0x32 &g_stdin");
asm ("mov____$i8,%eax !1");
asm ("mov____%eax,0x32 &g_stdout");
asm ("mov____$i8,%eax !2");
asm ("mov____%eax,0x32 &g_stderr");
asm ("mov____%ebp,%eax");
asm ("add____$i8,%eax !4");

View File

@ -23,7 +23,7 @@
// instead of calling main, it seems to call either _main or ___main,
// let's try _main first
char **environ = 0;
#include <libmes-mini.h>
int main (int argc, char *argv[]);
// gcc x86_64 calling convention:

View File

@ -18,7 +18,7 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char **environ = 0;
#include <libmes-mini.h>
// int main (int argc, char *argv[]);
// gcc x86_64 calling convention:
@ -27,6 +27,26 @@ char **environ = 0;
void
_start ()
{
asm (
"mov $0,%%rax\n\t"
"mov %%rax,%0\n"
: "=r" (g_stdin)
: //no inputs ""
);
asm (
"mov $1,%%rax\n\t"
"mov %%rax,%0\n"
: "=r" (g_stdout)
: //no inputs ""
);
asm (
"mov $2,%%rax\n\t"
"mov %%rax,%0\n"
: "=r" (g_stderr)
: //no inputs ""
);
asm (
"mov %%rbp,%%rax\n\t"
"add $8,%%rax\n\t"

View File

@ -18,12 +18,21 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char **environ = 0;
int main (int argc, char *argv[]);
#include "libmes-mini.h"
int main (int argc, char *argv[], char *envp[]);
int
_start ()
{
asm ("mov____$i8,%rax !0");
asm ("mov____%rax,0x32 &g_stdin");
asm ("mov____$i8,%rax !1");
asm ("mov____%rax,0x32 &g_stdout");
asm ("mov____$i8,%rax !2");
asm ("mov____%rax,0x32 &g_stderr");
#if 0 //MES_CCAMD64
asm ("add____$i32,%rbp %0x80"); // FIXME: corresponds to x86_64/as.scm function-preamble-fu
#endif

View File

@ -82,6 +82,8 @@ DEFINE mov____$i32,(%eax) c700
DEFINE mov____$i32,0x32 c705
DEFINE mov____$i32,0x8(%eax) c740
DEFINE mov____$i32,0x8(%ebp) c745
DEFINE mov____$i8,%al b0
DEFINE mov____$i8,%eax b0
DEFINE mov____%al,(%ebx) 8803
DEFINE mov____%al,0x8(%ebp) 8845
DEFINE mov____%ax,(%ebx) 668903

View File

@ -82,6 +82,8 @@ DEFINE mov____$i32,0x8(%rbp) c745
DEFINE mov____$i64,%r15 49bf
DEFINE mov____$i64,%rax 48b8
DEFINE mov____$i64,%rdi 48bf
DEFINE mov____$i8,%al b0
DEFINE mov____$i8,%rax b0
DEFINE mov____%al,(%rdi) 8807
DEFINE mov____%al,0x32(%rbp) 8885
DEFINE mov____%al,0x8(%rbp) 8845

View File

@ -2286,9 +2286,6 @@ main (int argc, char *argv[])
STACK_SIZE = atoi (p);
if (p = getenv ("MES_MAX_STRING"))
MAX_STRING = atoi (p);
g_stdin = STDIN;
g_stdout = STDOUT;
g_stderr = STDERR;
SCM a = mes_environment (argc, argv);
a = mes_builtins (a);