mescc: Mes C Library: ARM: _start: Inline fake asm.

* lib/linux/arm-mes-gcc/crt1.c (_start): Use inline fake asm.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-12-07 07:16:14 +01:00
parent 9711ed70ec
commit 4e7a6057aa
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -22,11 +22,11 @@
#include <mes/lib-mini.h> #include <mes/lib-mini.h>
//int main (int argc, char *argv[], char *envp[]); //int main (int argc, char *argv[], char *envp[]);
#if !__TINYC__
/* Note: GCC automatically emits a preable in order to set up the /* Note: GCC automatically emits a preable in order to set up the
frame pointer: "push {fp}" "add fp, sp, 0" frame pointer: "push {fp}" "add fp, sp, 0"
*/ */
// *INDENT-OFF* // *INDENT-OFF*
#if !__TINYC__
void void
_start () _start ()
{ {
@ -76,46 +76,81 @@ _start ()
); );
} }
#else //__TINYC__ #else //__TINYC__
__asm__ (".global _start\n"); void
__asm__ ("_start:\n"); _start ()
__asm__ (".int 0xe52db004\n"); //push {fp} ; (str fp, [sp, #-4]!) {
__asm__ (".int 0xe28db000\n"); //add fp, sp, #0 #if 0
__asm__ (".int 0xe3a00000\n"); //mov r0, #0 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe1a02000\n"); //mov r2, r0 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe3003000\n"); //movw r3, #0 #endif
__asm__ (".int 0xe3403000\n"); //movt r3, #0
__asm__ (".int 0xe5832000\n"); //str r2, [r3] int *in = &__stdin;
__asm__ (".int 0xe3a00001\n"); //mov r0, #1 int *out = &__stdout;
__asm__ (".int 0xe1a02000\n"); //mov r2, r0 int *err = &__stderr;
__asm__ (".int 0xe3003000\n"); //movw r3, #0 char ***env = &environ;
__asm__ (".int 0xe3403000\n"); //movt r3, #0
__asm__ (".int 0xe5832000\n"); //str r2, [r3] #if 0
__asm__ (".int 0xe3a00002\n"); //mov r0, #2 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe1a02000\n"); //mov r2, r0 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe3003000\n"); //movw r3, #0
__asm__ (".int 0xe3403000\n"); //movt r3, #0 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe5832000\n"); //str r2, [r3] *in = 0x22;
__asm__ (".int 0xe59b0004\n"); //ldr r0, [fp, #4] __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe28b1008\n"); //add r1, fp, #8 *out = 0x33;
__asm__ (".int 0xe2802001\n"); //add r2, r0, #1 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe1a02102\n"); //lsl r2, r2, #2 *err = 0x44;
__asm__ (".int 0xe0822001\n"); //add r2, r2, r1 __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe52d2004\n"); //push {r2} ; (str r2, [sp, #-4]!) *env = 0x55;
__asm__ (".int 0xe52d1004\n"); //push {r1} ; (str r1, [sp, #-4]!) __asm__ (".int 0xe320f000\n"); //nop {0}
__asm__ (".int 0xe52d0004\n"); //push {r0} ; (str r0, [sp, #-4]!) #endif
__asm__ (".int 0xe1a02002\n"); //mov r2, r2
__asm__ (".int 0xe3003000\n"); //movw r3, #0 /* environ = argv + argc + 1 */
__asm__ (".int 0xe3403000\n"); //movt r3, #0 __asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12]
__asm__ (".int 0xe5832000\n"); //str r2, [r3] __asm__ (".int 0xe28b1010\n"); //add r1, fp, #16
__asm__ (".int 0xe59d0000\n"); //ldr r0, [sp]
__asm__ (".int 0xe59d1004\n"); //ldr r1, [sp, #4] __asm__ (".int 0xe2802001\n"); //add r2, r0, #1
__asm__ (".int 0xe59d2008\n"); //ldr r2, [sp, #8] __asm__ (".int 0xe1a02102\n"); //lsl r2, r2, #2
__asm__ (".int 0xebfffffe\n"); //bl 0 <main> __asm__ (".int 0xe0822001\n"); //add r2, r2, r1
__asm__ (".int 0xe3a07001\n"); //mov r7, #1
__asm__ (".int 0xef000000\n"); //svc 0x00000000 // setup argc, argv, envp parameters on stack
__asm__ (".int 0xe320f003\n"); //wfi __asm__ (".int 0xe52d2004\n"); //push {r2} ; (str r2, [sp, #-4]!)
__asm__ (".int 0xe320f000\n"); //nop {0} __asm__ (".int 0xe52d1004\n"); //push {r1} ; (str r1, [sp, #-4]!)
__asm__ (".int 0xe28bd000\n"); //add sp, fp, #0 __asm__ (".int 0xe52d0004\n"); //push {r0} ; (str r0, [sp, #-4]!)
__asm__ (".int 0xe49db004\n"); //pop {fp} ; (ldr fp, [sp], #4) __asm__ (".int 0xe1a02002\n"); //mov r2, r2
__asm__ (".int 0xe12fff1e\n"); //bx lr
// *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]
main ();
__asm__ (".int 0xe3a07001\n"); //mov r7, #1
__asm__ (".int 0xef000000\n"); //svc 0x00000000
__asm__ (".int 0xe320f003\n"); //wfi
__asm__ (".int 0xe320f000\n"); //nop {0}
}
#endif //__TINYC__ #endif //__TINYC__