arm: lib: Use __init_io.
* lib/linux/arm-mes-gcc/crt1.c (_start): Replace manual initialization of __stdin, __stdout, __stderr, and environ with __init_io (). * lib/linux/arm-mes-m2/crt1.M1 (_start): Likewise. * lib/linux/arm-mes-mescc/crt1.c (_start): Likewise.
This commit is contained in:
parent
3502ad4f73
commit
368ddbcd4f
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019,2020,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
#include <mes/lib-mini.h>
|
||||
//int main (int argc, char *argv[], char *envp[]);
|
||||
int main (int argc, char *argv[], char *envp[]);
|
||||
|
||||
/* Note: GCC automatically emits a preable in order to set up the
|
||||
frame pointer: "push {fp}" "add fp, sp, 0"
|
||||
|
@ -30,27 +30,6 @@ frame pointer: "push {fp}" "add fp, sp, 0"
|
|||
void
|
||||
_start ()
|
||||
{
|
||||
asm (
|
||||
"mov r0,#0\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stdin)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
asm (
|
||||
"mov r0,#1\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stdout)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
asm (
|
||||
"mov r0,#2\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stderr)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
/* environ = argv + argc + 1 */
|
||||
asm (
|
||||
"ldr r0,[fp,#4]\n\t" /* r0 = argc */
|
||||
|
@ -61,14 +40,10 @@ _start ()
|
|||
"push {r2}\n\t" /* envp */
|
||||
"push {r1}\n\t" /* argv */
|
||||
"push {r0}\n\t" /* argc */
|
||||
"mov %0,r2\n\t"
|
||||
: "=r" (environ)
|
||||
: //no inputs ""
|
||||
);
|
||||
asm (
|
||||
"ldr r0,[sp]\n\t" /* argc */
|
||||
"ldr r1,[sp, #4]\n\t" /* argv */
|
||||
"ldr r2,[sp, #8]\n\t" /* envp */
|
||||
"bl __init_io\n\t"
|
||||
"bl main\n\t"
|
||||
"mov r7, #1\n\t"
|
||||
"swi #0\n\t"
|
||||
|
@ -79,31 +54,6 @@ _start ()
|
|||
void
|
||||
_start ()
|
||||
{
|
||||
#if 0
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
#endif
|
||||
|
||||
int *in = &__stdin;
|
||||
int *out = &__stdout;
|
||||
int *err = &__stderr;
|
||||
char ***env = &environ;
|
||||
|
||||
#if 0
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
*in = 0x22;
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
*out = 0x33;
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
*err = 0x44;
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
*env = 0x55;
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
#endif
|
||||
|
||||
/* environ = argv + argc + 1 */
|
||||
__asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12]
|
||||
__asm__ (".int 0xe28b1010\n"); //add r1, fp, #16
|
||||
|
@ -118,34 +68,11 @@ _start ()
|
|||
__asm__ (".int 0xe52d0004\n"); //push {r0} ; (str r0, [sp, #-4]!)
|
||||
__asm__ (".int 0xe1a02002\n"); //mov r2, r2
|
||||
|
||||
// *in = 0;
|
||||
__asm__ (".int 0xe3a01000\n"); //mov r1, #0
|
||||
__asm__ (".int 0xe51b0004\n"); //ldr r0, [fp, #-4]
|
||||
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
|
||||
// *out = 1;
|
||||
__asm__ (".int 0xe3a01001\n"); //mov r1, #1
|
||||
__asm__ (".int 0xe51b0008\n"); //ldr r0, [fp, #-8]
|
||||
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
|
||||
// *err = 2;
|
||||
__asm__ (".int 0xe3a01002\n"); //mov r1, #2
|
||||
__asm__ (".int 0xe51b000c\n"); //ldr r0, [fp, #-12]
|
||||
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
|
||||
// *env = [sp, #8]
|
||||
__asm__ (".int 0xe59d1008\n"); //ldr r1, [sp, #8]
|
||||
__asm__ (".int 0xe51b0010\n"); //ldr r0, [fp, #-16]
|
||||
__asm__ (".int 0xe5801000\n"); //str r1, [r0]
|
||||
__asm__ (".int 0xe320f000\n"); //nop {0}
|
||||
|
||||
// setup argc, argv, envp parameters in registers
|
||||
__asm__ (".int 0xe59d0000\n"); //ldr r0, [sp]
|
||||
__asm__ (".int 0xe59d1004\n"); //ldr r1, [sp, #4]
|
||||
__asm__ (".int 0xe59d2008\n"); //ldr r2, [sp, #8]
|
||||
__init_io ();
|
||||
main ();
|
||||
|
||||
__asm__ (".int 0xe3a07001\n"); //mov r7, #1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright © 2022,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
###
|
||||
### This file is part of GNU Mes.
|
||||
###
|
||||
|
@ -32,21 +32,10 @@
|
|||
'0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = BP + OFFSET
|
||||
{R0} PUSH_ALWAYS ; Put envp on the stack
|
||||
|
||||
mov____%r0,0x32 &GLOBAL_environ
|
||||
|
||||
;; Stack offset
|
||||
!4 BP ADD BP ARITH_ALWAYS ; Fix BP
|
||||
|
||||
;;^~FUNCTION___init_io CALL_ALWAYS ; Setup for FILE*
|
||||
|
||||
;; Initialize MesCC lib file descriptors.
|
||||
!0 mov____$i8,%r0
|
||||
mov____%r0,0x32 &GLOBAL___stdin
|
||||
!1 mov____$i8,%r0
|
||||
mov____%r0,0x32 &GLOBAL___stdout
|
||||
!2 mov____$i8,%r0
|
||||
mov____%r0,0x32 &GLOBAL___stderr
|
||||
|
||||
^~FUNCTION___init_io CALL_ALWAYS ; Init libc
|
||||
^~FUNCTION_main CALL_ALWAYS ; Jump right into main
|
||||
|
||||
SYS_exit mov____$i8,%r7
|
||||
|
|
|
@ -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,2023 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
#include "mes/lib-mini.h"
|
||||
|
||||
int main (int argc, char *argv[], char *envp[]);
|
||||
|
||||
void /* must not return */
|
||||
|
@ -36,21 +35,6 @@ environ = &argv[argc + 1]
|
|||
HOWEVER, the function entry already allocated space for locals on the stack (after saving lr and fp, which moved sp again). Hence, use fp instead of sp.
|
||||
*/
|
||||
|
||||
/* stdin = 0 */
|
||||
|
||||
asm ("!0 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdin");
|
||||
|
||||
/* stdout = 1 */
|
||||
|
||||
asm ("!1 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdout");
|
||||
|
||||
/* stderr = 2 */
|
||||
|
||||
asm ("!2 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stderr");
|
||||
|
||||
/* Add "environ" to main's arguments */
|
||||
|
||||
asm ("!8 ldr____%r0,(%fp,+#$i8)"); /* "argc" */
|
||||
|
@ -63,10 +47,7 @@ HOWEVER, the function entry already allocated space for locals on the stack (aft
|
|||
asm ("push___%r1"); /* argv */
|
||||
asm ("push___%r0"); /* argc */
|
||||
|
||||
/* environ = r2 */
|
||||
|
||||
asm ("mov____%r2,0x32 &environ");
|
||||
|
||||
__init_io ();
|
||||
main ();
|
||||
|
||||
asm ("SYS_exit mov____$i8,%r7");
|
||||
|
|
Loading…
Reference in a new issue