Skip to contentSkip to conversation

arm: add support for semihosting for ARMv7M targets

PATCH New Vadzim Dambrouski 2 participants 5 messages Oct 19, 2015 – Nov 10, 2015 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 arm: add support for semihosting for ARMv7M targets

If you enable CONFIG_SEMIHOSTING for STM32F429 target, you will get compile error looking like this:

arch/arm/lib/semihosting.c: In function 'smh_read':
{standard input}: Assembler messages:
{standard input}:34: Error: invalid swi expression
{standard input}:34: Error: value of 1193046 too large for field of 2 bytes at 0 scripts/Makefile.build:277: recipe for target 'arch/arm/lib/semihosting.o' failed

The source of the problem is "svc #0x123456" instruction. This instruction can not be encoded using Thumb2 instruction set used by ARMv7M CPUs. ARM documentation suggests using "bkpt #0xAB" instruction instead [1]. This patch fixes compile errors and adds support for semihosting for STM32F429 or any other ARMv7M target.
This change was sested on STM32F429-DISCOVERY board using OpenOCD and "smhload" u-boot command.

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bgbjhiea.html

---

 arch/arm/lib/semihosting.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/lib/semihosting.c +2 -0
index c3e964e..ed5e8e4 100644
@@ -31,6 +31,8 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
 	register long result asm("r0");
 #if defined(CONFIG_ARM64)
 	asm volatile ("hlt #0xf000" : "=r" (result) : "0"(sysnum), "r"(addr));
+#elif defined(CONFIG_CPU_V7M)
+	asm volatile ("bkpt #0xAB" : "=r" (result) : "0"(sysnum), "r"(addr));
 #else
 	/* Note - untested placeholder */
 	asm volatile ("svc #0x123456" : "=r" (result) : "0"(sysnum), "r"(addr));
Signature · 1 line
2.6.1
#1 lore raw

PATCH v3 2/2 arm: fix compile warnings when semihosting is enabled on ARMv7M target.

This patch fixes compile warnings like this:

warning: format '%lu' expects argument of type 'long unsigned int',
but argument 5 has type 'size_t'

In C99 standard you can use %zu modifier to print size_t values.

---

 arch/arm/lib/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/lib/semihosting.c +2 -2
index ed5e8e4..e32ad90 100644
@@ -92,7 +92,7 @@ static long smh_read(long fd, void *memp, size_t len)
 		size_t len;
 	} read;
 
-	debug("%s: fd %ld, memp %p, len %lu\n", __func__, fd, memp, len);
+	debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
 
 	read.fd = fd;
 	read.memp = memp;
@@ -106,7 +106,7 @@ static long smh_read(long fd, void *memp, size_t len)
 		 * hard to maintain partial read loops and such, just fail
 		 * with an error message.
 		 */
-		printf("%s: ERROR ret %ld, fd %ld, len %lu memp %p\n",
+		printf("%s: ERROR ret %ld, fd %ld, len %zu memp %p\n",
 		       __func__, ret, fd, len, memp);
 		return -1;
 	}
Signature · 1 line
2.6.1
#2 lore raw

PATCH v3 2/2 arm: fix compile warnings when semihosting is enabled on ARMv7M target.

Hello Vadzim,

Quoted 38 lines · Vadzim Dambrouski

This patch fixes compile warnings like this:

warning: format '%lu' expects argument of type 'long unsigned int',
but argument 5 has type 'size_t'

In C99 standard you can use %zu modifier to print size_t values.

---

 arch/arm/lib/semihosting.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/lib/semihosting.c +2 -2
index ed5e8e4..e32ad90 100644
@@ -92,7 +92,7 @@ static long smh_read(long fd, void *memp, size_t len)
 		size_t len;
 	} read;
 
-	debug("%s: fd %ld, memp %p, len %lu\n", __func__, fd, memp, len);
+	debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
 
 	read.fd = fd;
 	read.memp = memp;
@@ -106,7 +106,7 @@ static long smh_read(long fd, void *memp, size_t len)
 		 * hard to maintain partial read loops and such, just fail
 		 * with an error message.
 		 */
-		printf("%s: ERROR ret %ld, fd %ld, len %lu memp %p\n",
+		printf("%s: ERROR ret %ld, fd %ld, len %zu memp %p\n",
 		       __func__, ret, fd, len, memp);
 		return -1;
 	}
Signature · 1 line
2.6.1

Applied to u-boot-arm/master, thanks!

Amicalement,

Signature · 1 line
Albert.
#3 lore raw

PATCH v3 1/2 arm: add support for semihosting for ARMv7M targets

In reply to Vadzim Dambrouski

Hello Vadzim,

Quoted 17 lines · Vadzim Dambrouski

If you enable CONFIG_SEMIHOSTING for STM32F429 target, you will get compile error looking like this:

arch/arm/lib/semihosting.c: In function 'smh_read':
{standard input}: Assembler messages:
{standard input}:34: Error: invalid swi expression
{standard input}:34: Error: value of 1193046 too large for field of 2 bytes at 0 scripts/Makefile.build:277: recipe for target 'arch/arm/lib/semihosting.o' failed

The source of the problem is "svc #0x123456" instruction. This instruction can not be encoded using Thumb2 instruction set used by ARMv7M CPUs. ARM documentation suggests using "bkpt #0xAB" instruction instead [1]. This patch fixes compile errors and adds support for semihosting for STM32F429 or any other ARMv7M target.
This change was sested on STM32F429-DISCOVERY board using OpenOCD and "smhload" u-boot command.

Quoted 4 lines

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bgbjhiea.html

---

Can someone provide their 'Tested-by' on this?

Amicalement,

Signature · 1 line
Albert.
#4 lore raw

PATCH v3 1/2 arm: add support for semihosting for ARMv7M targets

In reply to Vadzim Dambrouski

Hello Vadzim,

Quoted 41 lines · Vadzim Dambrouski

If you enable CONFIG_SEMIHOSTING for STM32F429 target, you will get compile error looking like this:

arch/arm/lib/semihosting.c: In function 'smh_read':
{standard input}: Assembler messages:
{standard input}:34: Error: invalid swi expression
{standard input}:34: Error: value of 1193046 too large for field of 2 bytes at 0 scripts/Makefile.build:277: recipe for target 'arch/arm/lib/semihosting.o' failed

The source of the problem is "svc #0x123456" instruction. This instruction can not be encoded using Thumb2 instruction set used by ARMv7M CPUs. ARM documentation suggests using "bkpt #0xAB" instruction instead [1]. This patch fixes compile errors and adds support for semihosting for STM32F429 or any other ARMv7M target.
This change was sested on STM32F429-DISCOVERY board using OpenOCD and "smhload" u-boot command.

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bgbjhiea.html

---

 arch/arm/lib/semihosting.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/lib/semihosting.c +2 -0
index c3e964e..ed5e8e4 100644
@@ -31,6 +31,8 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
 	register long result asm("r0");
 #if defined(CONFIG_ARM64)
 	asm volatile ("hlt #0xf000" : "=r" (result) : "0"(sysnum), "r"(addr));
+#elif defined(CONFIG_CPU_V7M)
+	asm volatile ("bkpt #0xAB" : "=r" (result) : "0"(sysnum), "r"(addr));
 #else
 	/* Note - untested placeholder */
 	asm volatile ("svc #0x123456" : "=r" (result) : "0"(sysnum), "r"(addr));
Signature · 1 line
2.6.1

Applied to u-boot-arm/master, thanks!

Amicalement,

Signature · 1 line
Albert.