mescc: Put _start at top of mlibc.

* mlibc/libc-mes.c (_start): Move to top.
* mlibc/mini-libc-mes.c (_start): Likewise.
* module/mes/elf-util.mes (function-prefix): Update for _start == 0.
  (function-offset): Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2017-06-11 13:01:46 +02:00
parent 01b4c0846b
commit 4479540aed
3 changed files with 80 additions and 71 deletions

View file

@ -19,6 +19,42 @@
*/
int g_stdin = 0;
char **g_environment;
int _env ();
int exit ();
int main(int,char*[]);
int
_start ()
{
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x08"); // add $0x8,%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x83 0xc0 0x03"); // add $0x3,%eax
asm (".byte 0xc1 0xe0 0x02"); // shl $0x2,%eax
asm (".byte 0x01 0xe8"); // add %ebp,%eax
asm (".byte 0x50"); // push %eax
g_environment = _env ();
asm (".byte 0x58");
int r = main ();
exit (r);
}
char **
_env (char **e)
{
return e;
}
void
exit ()
@ -352,37 +388,3 @@ printf (char const* format, int va_args)
}
return 0;
}
char **g_environment;
char **
_env (char **e)
{
return e;
}
int main(int,char*[]);
int
_start ()
{
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x08"); // add $0x8,%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x83 0xc0 0x03"); // add $0x3,%eax
asm (".byte 0xc1 0xe0 0x02"); // shl $0x2,%eax
asm (".byte 0x01 0xe8"); // add %ebp,%eax
asm (".byte 0x50"); // push %eax
g_environment = _env ();
asm (".byte 0x58");
int r = main ();
exit (r);
}

View file

@ -19,6 +19,47 @@
*/
int g_stdin = 0;
char **g_environment;
int _env ();
int exit ();
int main(int,char*[]);
int
_start ()
{
#if 0
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x08"); // add $0x8,%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x83 0xc0 0x03"); // add $0x3,%eax
asm (".byte 0xc1 0xe0 0x02"); // shl $0x2,%eax
asm (".byte 0x01 0xe8"); // add %ebp,%eax
asm (".byte 0x50"); // push %eax
g_environment = _env ();
asm (".byte 0x58");
int r = main ();
exit (r);
#else
int r = main ();
exit (r);
#endif
}
char **
_env (char **e)
{
return e;
}
void
exit ()
@ -54,37 +95,3 @@ eputs (char const* s)
write (2, s, i);
return 0;
}
char **g_environment;
char **
_env (char **e)
{
return e;
}
int main(int,char*[]);
int
_start ()
{
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x08"); // add $0x8,%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x50"); // push %eax
asm (".byte 0x89 0xe8"); // mov %ebp,%eax
asm (".byte 0x83 0xc0 0x04"); // add $0x4,%eax
asm (".byte 0x0f 0xb6 0x00"); // movzbl (%eax),%eax
asm (".byte 0x83 0xc0 0x03"); // add $0x3,%eax
asm (".byte 0xc1 0xe0 0x02"); // shl $0x2,%eax
asm (".byte 0x01 0xe8"); // add %ebp,%eax
asm (".byte 0x50"); // push %eax
g_environment = _env ();
asm (".byte 0x58");
int r = main ();
exit (r);
}

View file

@ -70,21 +70,21 @@
;; FIXME
;;(member name (reverse functions) (lambda (a b) (equal? (car b) name)))
(let* ((x functions)
(x (if (and (pair? x) (equal? (caar x) "exit")) (reverse x) x)))
(x (if (and (pair? x) (equal? (caar x) "_start")) (reverse x) x)))
(member name x (lambda (a b) (equal? (car b) name)))))
(define function-offset
(let ((cache '()))
(lambda (name functions)
(or (assoc-ref cache name)
(let* ((functions (if (and (pair? functions) (equal? (caar functions) "exit")) functions (reverse functions)))
(let* ((functions (if (and (pair? functions) (equal? (caar functions) "_start")) functions (reverse functions)))
(prefix (and=> (function-prefix name functions) cdr))
(offset (and prefix
(if (null? prefix) 0
(+ (length (functions->text (list (car prefix)) '() 0 0 0))
(if (null? (cdr prefix)) 0
(function-offset (caar prefix) functions)))))))
(if (and offset (or (equal? name "exit") (> offset 0))) (set! cache (assoc-set! cache name offset)))
(if (and offset (or (equal? name "_start") (> offset 0))) (set! cache (assoc-set! cache name offset)))
(or offset 0))))))
(define label-offset