public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][Newlib] arm: Fix the SP used in setting stack limit for standalone application.
@ 2023-03-03 12:45 Srinath Parvathaneni
  2023-03-03 13:34 ` Richard Earnshaw
  0 siblings, 1 reply; 2+ messages in thread
From: Srinath Parvathaneni @ 2023-03-03 12:45 UTC (permalink / raw)
  To: newlib; +Cc: Richard Earnshaw


[-- Attachment #1.1: Type: text/plain, Size: 831 bytes --]

Hi,

When the processor by default starts in USER mode, in __stack_init
function of crt0.s the stack limit register is not getting set
correctly for standalone application. This is because the register r3
used to set this stack limit register is not updated with correct stack
pointer value. This patch fixes this issue and updates r3 with correct
stack pointer value.

Regression tested on arm-none-eabi target for newlib and newlib-nano and found
no regressions.

Ok for newlib master?

Regards,
Srinath.

libgloss/ChangeLog:

2023-03-03  Srinath Parvathaneni<srinath.parvathaneni@arm.com>

	* arm/crt0.S (__stack_init): Update r3 value before mode checking.

newlib/ChangeLog:

2023-03-03  Srinath Parvathaneni<srinath.parvathaneni@arm.com>

	* libc/sys/arm/crt0.S (__stack_init): Update r3 value before mode
         checking.

[-- Attachment #2: stack_limit.patch --]
[-- Type: text/plain, Size: 1384 bytes --]

diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index 78515180bf06f1da37669e4c7e6608c76e1b096d..79ae1e2511783d6b834bd1ac278316ae04ea2ec8 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -149,13 +149,12 @@
 #if (__ARM_ARCH_PROFILE != 'M')
 	/* Following code is compatible for both ARM and Thumb ISA.  */
 	mrs	r4, CPSR
+	mov	r3, sp /* Save input SP value.  */
 	/* Test mode bits - in User of all are 0.  */
 	tst	r4, #(CPSR_M_MASK)
 	/* "eq" means r4 AND #0x0F is 0.  */
 	beq	.Lskip_cpu_modes
 
-	mov	r3, sp /* Save input SP value.  */
-
 	/* FIQ mode, interrupts disabled.  */
 	mov	r1, #(CPSR_M_FIQ|CPSR_M_32BIT|CPSR_I_MASK|CPSR_F_MASK)
 	msr	CPSR_c, r1
diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S
index 6b01d8a88b77f44b1ba495aa1f69156f12749527..121246cfaf1ea197c271e434fe0c05a3aba8fb6a 100644
--- a/newlib/libc/sys/arm/crt0.S
+++ b/newlib/libc/sys/arm/crt0.S
@@ -149,13 +149,12 @@
 #if (__ARM_ARCH_PROFILE != 'M')
 	/* Following code is compatible for both ARM and Thumb ISA.  */
 	mrs	r4, CPSR
+	mov	r3, sp /* Save input SP value.  */
 	/* Test mode bits - in User of all are 0.  */
 	tst	r4, #(CPSR_M_MASK)
 	/* "eq" means r4 AND #0x0F is 0.  */
 	beq	.Lskip_cpu_modes
 
-	mov	r3, sp /* Save input SP value.  */
-
 	/* FIQ mode, interrupts disabled.  */
 	mov	r1, #(CPSR_M_FIQ|CPSR_M_32BIT|CPSR_I_MASK|CPSR_F_MASK)
 	msr	CPSR_c, r1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][Newlib] arm: Fix the SP used in setting stack limit for standalone application.
  2023-03-03 12:45 [PATCH][Newlib] arm: Fix the SP used in setting stack limit for standalone application Srinath Parvathaneni
@ 2023-03-03 13:34 ` Richard Earnshaw
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Earnshaw @ 2023-03-03 13:34 UTC (permalink / raw)
  To: Srinath Parvathaneni, newlib; +Cc: Richard Earnshaw

I've tweaked the commit message and pushed (we don't use ChangeLog files 
in newlib).

R.

On 03/03/2023 12:45, Srinath Parvathaneni wrote:
> Hi,
> 
> When the processor by default starts in USER mode, in __stack_init
> function of crt0.s the stack limit register is not getting set
> correctly for standalone application. This is because the register r3
> used to set this stack limit register is not updated with correct stack
> pointer value. This patch fixes this issue and updates r3 with correct
> stack pointer value.
> 
> Regression tested on arm-none-eabi target for newlib and newlib-nano and 
> found
> no regressions.
> 
> Ok for newlib master?
> 
> Regards,
> Srinath.
> 
> libgloss/ChangeLog:
> 
> 2023-03-03  Srinath Parvathaneni<srinath.parvathaneni@arm.com>
> 
>      * arm/crt0.S (__stack_init): Update r3 value before mode checking.
> 
> newlib/ChangeLog:
> 
> 2023-03-03  Srinath Parvathaneni<srinath.parvathaneni@arm.com>
> 
>      * libc/sys/arm/crt0.S (__stack_init): Update r3 value before mode
>          checking.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-03 13:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 12:45 [PATCH][Newlib] arm: Fix the SP used in setting stack limit for standalone application Srinath Parvathaneni
2023-03-03 13:34 ` Richard Earnshaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).