* [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives
@ 2017-05-02 12:47 Laurent Alfonsi
2017-05-17 7:57 ` Laurent Alfonsi
[not found] ` <CAOox84tB-ZBizQ5gpAMAry4A0gkfzwyipT5pJmum=NtL=n9mkw@mail.gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Laurent Alfonsi @ 2017-05-02 12:47 UTC (permalink / raw)
To: newlib
[-- Attachment #1: Type: text/plain, Size: 288 bytes --]
All,
There's currently a problem in ARM & AArch64 crt0 on the GetCommandLine
semihosting invocation.
I am proposing this patch to fix the issue.
Tested with versions : gcc 5.4, binutils 2.26, qemu-arm / qemu-aarch64
2.5.0.
Would it be ok to commit ?
Regards,
Laurent Alfonsi
[-- Attachment #2: 0001-ARM-AArch64-Fix-GetCmdLine-semihosting-directives.patch --]
[-- Type: text/x-patch, Size: 3419 bytes --]
From 12968a3744777fe4daac6a03cb76303e952664cc Mon Sep 17 00:00:00 2001
From: Laurent ALFONSI <laurent.alfonsi@st.com>
Date: Tue, 18 Apr 2017 17:50:16 +0200
Subject: [PATCH] ARM/AArch64: Fix GetCmdLine semihosting directives
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:
- libgloss/arm/crt0.S : Arguments passed to the AngelSWI_Reason_GetCmdLine
semihosting invocation are placed into .data section instead of .text
- libgloss/aarch64/crt0.S : Idem for aarch64 AngelSVC_Reason_GetCmdLine
semihosting.
---
libgloss/aarch64/crt0.S | 11 +++++++----
libgloss/arm/crt0.S | 9 ++++++---
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/libgloss/aarch64/crt0.S b/libgloss/aarch64/crt0.S
index fdfc174..42673fb 100644
--- a/libgloss/aarch64/crt0.S
+++ b/libgloss/aarch64/crt0.S
@@ -166,11 +166,12 @@
/* Fetch and parse the command line. */
#ifdef ARM_RDI_MONITOR
- adr x1, .Lcmdline /* Command line descriptor. */
+ ldr x1, .Lcmdline /* Command line descriptor. */
mov w0, #AngelSVC_Reason_GetCmdLine
AngelSVCAsm AngelSVC
#endif
ldr x8, .Lcmdline
+ ldr x8, [x8]
mov x0, #0 /* argc */
mov x1, sp /* argv */
@@ -267,9 +268,8 @@ FUNCTION (_cpu_init_reset):
.Lenvp:
GEN_DWORD env
.Lcmdline:
- GEN_DWORD CommandLine
- .dword 511
-
+ GEN_DWORD AngelSVCArgs
+
/* Workspace for Angel calls. */
.data
.align 3
@@ -287,3 +287,6 @@ StackBase: GEN_DWORD __stack
StackLimit: .dword 0
env: .dword 0 /* Dummy environment array */
CommandLine: .space 512,0 /* Maximum length of 511 chars handled. */
+AngelSVCArgs:
+ GEN_DWORD CommandLine
+ .dword 511
diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index 78bc467..709b71c 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -294,9 +294,10 @@ __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 */
AngelSWIAsm AngelSWI
ldr r1, .LC30
+ ldr r1, [r1]
#endif
/* Parse string at r1 */
movs r0, #0 /* count of arguments so far */
@@ -503,8 +504,7 @@ change_back:
#endif
#ifdef ARM_RDI_MONITOR
.LC30:
- .word CommandLine
- .word 511
+ .word AngelSWIArgs
.LC31:
.word __end__
@@ -517,6 +517,9 @@ HeapLimit: .word 0
__stack_base__: .word 0
StackLimit: .word 0
CommandLine: .space 512,0 /* Maximum length of 511 chars handled. */
+AngelSWIArgs:
+ .word CommandLine
+ .word 511
#endif
#ifdef __pe__
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives
2017-05-02 12:47 [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives Laurent Alfonsi
@ 2017-05-17 7:57 ` Laurent Alfonsi
[not found] ` <CAOox84tB-ZBizQ5gpAMAry4A0gkfzwyipT5pJmum=NtL=n9mkw@mail.gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Alfonsi @ 2017-05-17 7:57 UTC (permalink / raw)
To: newlib
Ping ?
Regards
Laurent
On 05/02/17 14:46, Laurent Alfonsi wrote:
> All,
>
> There's currently a problem in ARM & AArch64 crt0 on the
> GetCommandLine semihosting invocation.
> I am proposing this patch to fix the issue.
>
> Tested with versions : gcc 5.4, binutils 2.26, qemu-arm / qemu-aarch64
> 2.5.0.
>
> Would it be ok to commit ?
>
> Regards,
> Laurent Alfonsi
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives
[not found] ` <CAOox84tB-ZBizQ5gpAMAry4A0gkfzwyipT5pJmum=NtL=n9mkw@mail.gmail.com>
@ 2017-05-18 14:14 ` Laurent Alfonsi
0 siblings, 0 replies; 3+ messages in thread
From: Laurent Alfonsi @ 2017-05-18 14:14 UTC (permalink / raw)
To: Jeff Johnston; +Cc: Newlib
[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]
Hi Jeff,
I regenerated the patch on top of master branch.
I can now apply using git am. Sorry about that.
I re-validated again on newlib master + gcc 5.4, binutils 2.26, qemu-arm
/ qemu-aarch64 2.5.0 / afm.
Regards,
Laurent
On 05/17/17 22:18, Jeff Johnston wrote:
> Hi Laurent,
>
> I have no issues. I would have expected someone from the group of arm
> maintainers here to
> have commented. That said, I cannot apply the patch using git am nor
> patch -u -p1. Could you try recreating the patch?
> There is mention of trailing white-space in the errors in addition to
> mentioning that the patch will not apply.
>
> Regards,
>
> -- Jeff J.
>
>
> On Tue, May 2, 2017 at 8:46 AM, Laurent Alfonsi
> <laurent.alfonsi@st.com <mailto:laurent.alfonsi@st.com>> wrote:
>
> All,
>
> There's currently a problem in ARM & AArch64 crt0 on the
> GetCommandLine semihosting invocation.
> I am proposing this patch to fix the issue.
>
> Tested with versions : gcc 5.4, binutils 2.26, qemu-arm /
> qemu-aarch64 2.5.0.
>
> Would it be ok to commit ?
>
> Regards,
> Laurent Alfonsi
>
>
>
[-- Attachment #2: 0001-ARM-AArch64-Fix-GetCmdLine-semihosting-directives.patch --]
[-- Type: text/x-patch, Size: 3395 bytes --]
From 4b06ee8a7d5b3e0b134dd7e5f5d11ead2f223b26 Mon Sep 17 00:00:00 2001
From: Laurent ALFONSI <laurent.alfonsi@st.com>
Date: Tue, 18 Apr 2017 17:50:16 +0200
Subject: [PATCH] ARM/AArch64: Fix GetCmdLine semihosting directives
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:
- libgloss/arm/crt0.S : Arguments passed to the AngelSWI_Reason_GetCmdLine
semihosting invocation are placed into .data section instead of .text
- libgloss/aarch64/crt0.S : Idem for aarch64 AngelSVC_Reason_GetCmdLine
semihosting.
---
libgloss/aarch64/crt0.S | 10 ++++++----
libgloss/arm/crt0.S | 9 ++++++---
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/libgloss/aarch64/crt0.S b/libgloss/aarch64/crt0.S
index ae6264d..ed4dafc 100644
--- a/libgloss/aarch64/crt0.S
+++ b/libgloss/aarch64/crt0.S
@@ -156,10 +156,11 @@
bl FUNCTION (_init)
/* Fetch and parse the command line. */
- adr x1, .Lcmdline /* Command line descriptor. */
+ ldr x1, .Lcmdline /* Command line descriptor. */
mov w0, #AngelSVC_Reason_GetCmdLine
AngelSVCAsm AngelSVC
ldr x8, .Lcmdline
+ ldr x8, [x8]
mov x0, #0 /* argc */
mov x1, sp /* argv */
@@ -239,9 +240,7 @@ FUNCTION (_cpu_init_hook):
.Lenvp:
GEN_DWORD env
.Lcmdline:
- GEN_DWORD CommandLine
- .dword 255
-
+ GEN_DWORD AngelSVCArgs
/* Workspace for Angel calls. */
.data
.align 3
@@ -258,3 +257,6 @@ StackBase: .dword 0
StackLimit: .dword 0
env: .dword 0 /* Dummy environment array */
CommandLine: .space 256,0 /* Maximum length of 255 chars handled. */
+AngelSVCArgs:
+ GEN_DWORD CommandLine
+ .dword 255
diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index 35c306b..48f3d6b 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -296,9 +296,10 @@ __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 */
AngelSWIAsm AngelSWI
ldr r1, .LC30
+ ldr r1, [r1]
#endif
/* Parse string at r1 */
movs r0, #0 /* count of arguments so far */
@@ -505,8 +506,7 @@ change_back:
#endif
#ifdef ARM_RDI_MONITOR
.LC30:
- .word CommandLine
- .word 255
+ .word AngelSWIArgs
.LC31:
.word __end__
@@ -519,6 +519,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__
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-18 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 12:47 [PATCH] ARM / AArch64: Fix GetCmdLine semihosting directives Laurent Alfonsi
2017-05-17 7:57 ` Laurent Alfonsi
[not found] ` <CAOox84tB-ZBizQ5gpAMAry4A0gkfzwyipT5pJmum=NtL=n9mkw@mail.gmail.com>
2017-05-18 14:14 ` Laurent Alfonsi
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).