ARM: Add fake asm for setjmp.c.

* lib/arm-mes-gcc/setjmp.c (longjmp, setjmp)[__TINYC__]: Add fake asm.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-11-22 22:21:16 +01:00
parent e5573ec23c
commit 4f66055f3b
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -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,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org> * Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
@ -22,6 +22,7 @@
#include <setjmp.h> #include <setjmp.h>
#include <stdlib.h> #include <stdlib.h>
#if !__TINYC__
void void
__attribute__ ((noinline)) __attribute__ ((noinline))
longjmp (jmp_buf env, int val) longjmp (jmp_buf env, int val)
@ -42,7 +43,31 @@ longjmp (jmp_buf env, int val)
// *INDENT-ON* // *INDENT-ON*
// not reached // not reached
} }
#else //__TINYC__
__asm__ (".global longjmp\n");
__asm__ ("longjmp:\n");
__asm__ (".int 0xe52db004\n"); //push {fp} ; (str fp, [sp, #-4]!)
__asm__ (".int 0xe28db000\n"); //add fp, sp, #0
__asm__ (".int 0xe24dd00c\n"); //sub sp, sp, #12
__asm__ (".int 0xe50b0008\n"); //str r0, [fp, #-8]
__asm__ (".int 0xe50b100c\n"); //str r1, [fp, #-12]
__asm__ (".int 0xe51b3008\n"); //ldr r3, [fp, #-8]
__asm__ (".int 0xe51b200c\n"); //ldr r2, [fp, #-12]
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
__asm__ (".int 0xe1a01002\n"); //mov r1, r2
__asm__ (".int 0xe3510000\n"); //cmp r1, #0
__asm__ (".int 0x03a01001\n"); //moveq r1, #1
__asm__ (".int 0xe490d004\n"); //ldr sp, [r0], #4
__asm__ (".int 0xe490e004\n"); //ldr lr, [r0], #4
__asm__ (".int 0xe8b00ff0\n"); //ldm r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
#if HAVE_FLOAT
// TODO: If using VFP, vldmia r0!, {d8-d15}
#endif
__asm__ (".int 0xe1a00001\n"); //mov r0, r1
__asm__ (".int 0xe12fff1e\n"); //bx lr
#endif //__TINYC__
#if !__TINYC__
int int
__attribute__ ((noinline)) __attribute__ ((noinline))
setjmp (jmp_buf env) setjmp (jmp_buf env)
@ -60,3 +85,25 @@ setjmp (jmp_buf env)
// *INDENT-ON* // *INDENT-ON*
return 0; return 0;
} }
#else //__TINYC__
__asm__ (".global setjmp\n");
__asm__ ("setjmp:\n");
__asm__ (".int 0xe52db004\n"); //push {fp} ; (str fp, [sp, #-4]!)
__asm__ (".int 0xe28db000\n"); //add fp, sp, #0
__asm__ (".int 0xe24dd00c\n"); //sub sp, sp, #12
__asm__ (".int 0xe50b0008\n"); //str r0, [fp, #-8]
__asm__ (".int 0xe51b3008\n"); //ldr r3, [fp, #-8]
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
__asm__ (".int 0xe480d004\n"); //str sp, [r0], #4
__asm__ (".int 0xe480e004\n"); //str lr, [r0], #4
__asm__ (".int 0xe28bd000\n"); //add sp, fp, #0
__asm__ (".int 0xe49db004\n"); //pop {fp} ; (ldr fp, [sp], #4)
__asm__ (".int 0xe8a00ff0\n"); //stmia r0!, {r4, r5, r6, r7, r8, r9, sl, fp}
#if HAVE_FLOAT
// TODO: If using VFP, vstmia r0!, {d8-d15}
#endif
__asm__ (".int 0xe1a0b00d\n"); //mov fp, sp
__asm__ (".int 0xe3a03000\n"); //mov r3, #0
__asm__ (".int 0xe1a00003\n"); //mov r0, r3
__asm__ (".int 0xe12fff1e\n"); //bx lr
#endif //__TINYC__