public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Align libgloss/arm and libc/sys/arm sources: Fix GetCmdLine semihosting directives
Date: Mon, 05 Aug 2019 12:02:00 -0000	[thread overview]
Message-ID: <20190805120205.65873.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=37e80fbb1c329ab39d154a78fa6d99f28d220dfe

commit 37e80fbb1c329ab39d154a78fa6d99f28d220dfe
Author: Alexander Fedotov <alfedotov@gmail.com>
Date:   Fri Aug 2 07:33:43 2019 -0500

    Align libgloss/arm and libc/sys/arm sources: Fix GetCmdLine semihosting directives
    
    Applied changes from the commit 9b11672:
    
    	When simulating arm code, the target program startup code (crt0) uses
    	semihosting invocations to get the command line from the simulator. The
    	simulator returns the command line and its size into the area passed in
    	parameter. (ARM 32-bit specifications :
    	http://infocenter.arm.com/help/topic/com.arm.doc.dui0058d/DUI0058.pdf
    	chapter "5.4.19 SYS_GET_CMDLINE").
    
    	The memory area pointed by the semihosting register argument is located
    	in .text section (usually not writtable (RX)).
    
    	If we run this code on a simulator that respects this rights properties
    	(qemu user-mode for instance), the command line will not be written to
    	the .text program memory, in particular the length of the string. The
    	program runs with an empty command line. This problem hasn't been seen
    	earlier probably because qemu user-mode is not so much used, but this can
    	happen with another simulator that refuse to write in a read-only segment.
    
    	With this modification, the command line can be correctly passed to the
    	target program.
    
    	Changes:
    	- newlib/libc/sys/arm/crt0.S : Arguments passed to the
    	AngelSWI_Reason_GetCmdLine semihosting invocation are placed into .data
    	section instead of .text

Diff:
---
 newlib/libc/sys/arm/crt0.S | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S
index 9c26242..40bbc3d 100644
--- a/newlib/libc/sys/arm/crt0.S
+++ b/newlib/libc/sys/arm/crt0.S
@@ -393,13 +393,14 @@ __change_mode:
 	movs	r1, r0
 #else
 	movs	r0, #AngelSWI_Reason_GetCmdLine
-	adr	r1, .LC30	/* Space for command line.  */
+	ldr	r1, .LC30	/* Space for command line.  */
 #ifdef THUMB_VXM
 	bkpt	AngelSWI
 #else
  	AngelSWIAsm	AngelSWI
 #endif
 	ldr	r1, .LC30
+	ldr	r1, [r1]
 #endif
 	/*  Parse string at r1.  */
 	movs	r0, #0		/* Count of arguments so far.  */
@@ -586,8 +587,7 @@ change_back:
 #endif
 #ifdef ARM_RDI_MONITOR
 .LC30:
-	.word	CommandLine
-	.word	255
+	.word	AngelSWIArgs
 .LC31:
 	.word	__end__
 
@@ -600,6 +600,9 @@ HeapLimit:	.word	0
 __stack_base__:	.word	0
 StackLimit:	.word	0
 CommandLine:	.space	256,0	/*  Maximum length of 255 chars handled.  */
+AngelSWIArgs:
+	.word	CommandLine
+	.word	255
 #endif
 	
 #ifdef __pe__


                 reply	other threads:[~2019-08-05 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190805120205.65873.qmail@sourceware.org \
    --to=rearnsha@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).