This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: mis-handling of arm semihosting in libgloss/arm/crt0.S
- From: Nick Clifton <nickc at redhat dot com>
- To: Can Finner <can dot finner at gmail dot com>
- Cc: newlib at sources dot redhat dot com
- Date: Thu, 16 Jun 2011 10:20:53 +0100
- Subject: Re: mis-handling of arm semihosting in libgloss/arm/crt0.S
- References: <4DF787CB.70309@redhat.com> <BANLkTimZ+44p1JOvrf4M=8AMvKr1Rj-xRQ@mail.gmail.com>
Hi Can,
Actually it is "RealView compilation Tools developer guide", section 8.1.2.
you can find it as DUI0203J at arm infocenter website
http://infocenter.arm.com/help/index.jsp
Thanks - that was the reference that I needed.
Seems your reply is off list, so I put newlib in cc.
Oops, sorry, I forgot that.
Anyway, you are correct, the wrong software interrupt instruction is
being used when crt0.S is built for ARMv[67]-M architectures. Please
could you try out the attached patch which I think should fix things,
and let me know how you get on ?
Cheers
Nick
Index: libgloss/arm/crt0.S
===================================================================
RCS file: /cvs/src/src/libgloss/arm/crt0.S,v
retrieving revision 1.8
diff -u -3 -p -r1.8 crt0.S
--- libgloss/arm/crt0.S 6 Oct 2008 20:55:19 -0000 1.8
+++ libgloss/arm/crt0.S 16 Jun 2011 09:16:36 -0000
@@ -18,7 +18,7 @@
/* .text is used instead of .section .text so it works with arm-aout too. */
.text
-#if defined(__thumb2__)
+#if defined __thumb2__ || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_6M__
.syntax unified
.thumb
.macro FUNC_START name
@@ -46,27 +46,37 @@
/* Start by setting up a stack */
#ifdef ARM_RDP_MONITOR
/* Issue Demon SWI to read stack info */
- swi SWI_GetEnv /* Returns command line in r0 */
- mov sp,r1 /* and the highest memory address in r1 */
+ AngelSWIAsm SWI_GetEnv /* Returns command line in r0 */
+ mov sp, r1 /* and the highest memory address in r1 */
+#if defined __ARM_ARCH_7M__ || defined __ARM_ARCH_6M__
+ ldr r1, .LC2 /* stack limit is at end of data */
+ adds r1, #128 /* allow slop for stack overflow handling */
+ adds r1, #128
+ mov sl, r1
+#else
ldr sl, .LC2 /* stack limit is at end of data */
add sl, sl, #256 /* allow slop for stack overflow handling */
/* and small frames */
+#endif
#else
#ifdef ARM_RDI_MONITOR
/* Issue Angel SWI to read stack info */
- mov r0, #AngelSWI_Reason_HeapInfo
+ movs r0, #AngelSWI_Reason_HeapInfo
adr r1, .LC0 /* point at ptr to 4 words to receive data */
-#if defined(__thumb2__)
- bkpt AngelSWI
-#else
- /* We are always in ARM mode for startup */
- AngelSWIAsm AngelSWI_ARM
-#endif
+ AngelSWIAsm AngelSWI
ldr r0, .LC0 /* point at values read */
+#if defined __ARM_ARCH_7M__ || defined __ARM_ARCH_6M__
+ ldr r1, [r0, #8]
+ mov sp, r1
+ ldr r0, [r0, #12]
+ adds r0, #128
+ adds r0, #128 /* allow slop for stack overflow handling */
+ mov sl, r0 /* and small frames */
+#else
ldr sp, [r0, #8]
ldr sl, [r0, #12]
- add sl, sl, #256 /* allow slop for stack overflow handling */
- /* and small frames */
+ adds sl, #256
+#endif
#else
/* Set up the stack pointer to a fixed value */
/* Changes by toralf:
@@ -138,16 +148,16 @@
#endif
#endif
/* Zero the memory in the .bss section. */
- mov a2, #0 /* Second arg: fill value */
+ movs a2, #0 /* Second arg: fill value */
mov fp, a2 /* Null frame pointer */
mov r7, a2 /* Null frame pointer for Thumb */
ldr a1, .LC1 /* First arg: start of memory block */
ldr a3, .LC2
- sub a3, a3, a1 /* Third arg: length of block */
+ subs a3, a3, a1 /* Third arg: length of block */
-#if defined(__thumb__) && !defined(__thumb2__)
+#if defined(__thumb__) && !defined(__thumb2__) && ! defined __ARM_ARCH_7M__ && ! defined __ARM_ARCH_6M__
/* Enter Thumb mode.... */
add a4, pc, #1 /* Get the address of the Thumb block */
bx a4 /* Go there and start Thumb decoding */
@@ -192,16 +202,16 @@ __change_mode:
bl FUNCTION (initialise_monitor_handles)
#ifdef ARM_RDP_MONITOR
- swi SWI_GetEnv /* sets r0 to point to the command line */
+ AngelSWIAsm SWI_GetEnv /* sets r0 to point to the command line */
mov r1, r0
#else
- mov r0, #AngelSWI_Reason_GetCmdLine
+ movs r0, #AngelSWI_Reason_GetCmdLine
adr r1, .LC30 /* Space for command line */
AngelSWIAsm AngelSWI
ldr r1, .LC30
#endif
/* Parse string at r1 */
- mov r0, #0 /* count of arguments so far */
+ movs r0, #0 /* count of arguments so far */
/* Push a NULL argument onto the end of the list. */
#ifdef __thumb__
push {r0}
@@ -212,7 +222,7 @@ __change_mode:
/* Skip leading blanks */
#ifdef __thumb__
ldrb r3, [r1]
- add r1, #1
+ adds r1, #1
#else
ldrb r3, [r1], #1
#endif
@@ -232,8 +242,8 @@ __change_mode:
b .LC22
.LC21:
- mov r2, #' ' /* terminator type */
- sub r1, r1, #1 /* adjust back to point at start char */
+ movs r2, #' ' /* terminator type */
+ subs r1, r1, #1 /* adjust back to point at start char */
.LC22:
#else
cmpne r3, #'\''
@@ -248,11 +258,11 @@ __change_mode:
#else
stmfd sp!, {r1}
#endif
- add r0, r0, #1
+ adds r0, r0, #1
.LC11:
#ifdef __thumb__
ldrb r3, [r1]
- add r1, #1
+ adds r1, #1
#else
ldrb r3, [r1], #1
#endif
@@ -260,33 +270,33 @@ __change_mode:
beq .LC12
cmp r2, r3 /* reached terminator? */
bne .LC11
- mov r2, #0
- sub r3, r1, #1
+ movs r2, #0
+ subs r3, r1, #1
strb r2, [r3] /* terminate the arg string */
b .LC10
.LC12:
mov r1, sp /* point at stacked arg pointers */
- /* We've now got the stacked args in order reverse the */
+ /* We've now got the stacked args in reverse order. */
#ifdef __thumb__
mov r2, r0
- lsl r2, #2
+ lsls r2, #2
add r2, sp
mov r3, sp
.LC15: cmp r2, r3
bls .LC14
- sub r2, #4
+ subs r2, r2, #4
ldr r4, [r2]
ldr r5, [r3]
str r5, [r2]
str r4, [r3]
- add r3, #4
+ adds r3, r3, #4
b .LC15
.LC14:
/* Ensure doubleword stack alignment. */
mov r4, sp
- mov r5, #7
- bic r4, r5
+ movs r5, #7
+ bics r4, r5
mov sp, r4
#else
add r2, sp, r0, LSL #2 /* End of args */
@@ -320,19 +330,21 @@ __change_mode:
bl FUNCTION (exit) /* Should not return. */
#if defined(__thumb__) && !defined(__thumb2__)
+#if ! defined __ARM_ARCH_7M__ && ! defined __ARM_ARCH_6M__
/* Come out of Thumb mode. This code should be redundant. */
mov a4, pc
bx a4
.code 32
+#endif
.global change_back
change_back:
/* Halt the execution. This code should never be executed. */
/* With no debug monitor, this probably aborts (eventually).
With a Demon debug monitor, this halts cleanly.
With an Angel debug monitor, this will report 'Unknown SWI'. */
- swi SWI_Exit
+ AngelSWIAsm SWI_Exit
#endif
/* For Thumb, constants must be after the code since only
Index: libgloss/arm/swi.h
===================================================================
RCS file: /cvs/src/src/libgloss/arm/swi.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 swi.h
--- libgloss/arm/swi.h 25 Dec 2006 23:05:24 -0000 1.3
+++ libgloss/arm/swi.h 16 Jun 2011 09:16:36 -0000
@@ -33,8 +33,8 @@
#else
#define AngelSWI AngelSWI_ARM
#endif
-/* For Thumb-2 code use the BKPT instruction instead of SWI. */
-#ifdef __thumb2__
+/* For ARMv6-M or ARMv7-M code use the BKPT instruction instead of SWI. */
+#if defined __ARM_ARCH_7M__ || defined __ARM_ARCH_6M__
#define AngelSWIInsn "bkpt"
#define AngelSWIAsm bkpt
#else