Re: [PATCH] Arm Initialize SP for Cortex-R in semihosting case

Alexander Fedotov <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAN8C2Cr0ZwUokw2Lr-cArEBuGVDMm8H9pjMXTxEZ3aTqF-uSqA@mail.gmail.com>
Patch updated. Forgot to move .Lstack in previous version.

Alex

On Wed, Jan 23, 2019 at 1:40 PM Alexander Fedotov <[email protected]> wrote:
>
> Since Cortex-R cores doesn't have NVIC and therefore no hardware stack
> pointer initialization we have to force SP initialized by default
> value and then override if optional value is passed over HeapInfo
>
> Alex



-- 
Best regards,
AF
0001-Initialize-Stack-Pointer-by-default-value-in-semihos.patch (application/octet-stream, 1.8 KB)
From bec21732094b5675fe38703dde319a375d79282b Mon Sep 17 00:00:00 2001
From: Alexander Fedotov <[email protected]>
Date: Wed, 23 Jan 2019 13:33:14 +0300
Subject: [PATCH] Initialize Stack Pointer by default value in semihosting case
 and then override if optional value is passed

---
 libgloss/arm/crt0.S | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index 48f3d6b1d..7eba06910 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -148,11 +148,15 @@
 	      to skip setting sp/sl to 0 here.
 	    - Considering M-profile processors, We might want to initialize
 	      sp by the first entry of vector table and return 0 to SYS_HEAPINFO
-	      semihosting call, which will be skipped here. */
+	      semihosting call, which will be skipped here.
+	    - Considering R-profile processors there is no automatic SP init by hardware
+	      so we need to initialize it by default value. */
+	ldr	r3, .Lstack
 	cmp	r1, #0
 	beq	.LC26
-	mov	sp, r1
+	mov	r3, r1
 .LC26:
+	mov	sp, r3
 	cmp	r2, #0
 	beq	.LC27
 	/*  allow slop for stack overflow handling and small frames */
@@ -464,8 +468,6 @@ change_back:
 #else
 	.word	0x80000			/* Top of RAM on the PIE board.  */
 #endif
-.Lstack:	
-	.word	__stack
 .Lhwinit:	
 	.word	FUNCTION (hardware_init_hook)
 .Lswinit:
@@ -478,12 +480,16 @@ change_back:
 	   and only if, a normal version of the same symbol isn't provided
 	   e.g. by a linker script or another object file.) */	
 
-	.weak __stack
 	.weak FUNCTION (hardware_init_hook) 
 	.weak FUNCTION (software_init_hook)
 #endif
 	
 #endif
+
+.Lstack:
+	.word	__stack
+	.weak	__stack
+
 #if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__)
 	/* Protect against unhandled exceptions.  */
 	.cantunwind
-- 
2.20.1.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.