[U-Boot] [PATCH v3 2/6] common/cmd_boot: keep ARM v7M in thumb mode during do_go_exec()

Matt Porter mporter at konsulko.com
Tue May 5 21:00:23 CEST 2015


On ARM v7M, the processor will return to ARM mode when executing
a blx instruction with bit 0 of the address == 0. Always set it
to 1 to stay in thumb mode.

Signed-off-by: Matt Porter <mporter at konsulko.com>
---
v3:
	- Implement using an override of the weak do_go_exec() when
	  building for ARMv7-M.

 arch/arm/lib/Makefile   |  1 +
 arch/arm/lib/cmd_boot.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 arch/arm/lib/cmd_boot.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 8288d2f..4c95a77 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -26,6 +26,7 @@ ifndef CONFIG_SYS_GENERIC_BOARD
 obj-y	+= board.o
 endif
 
+obj-$(CONFIG_CPU_V7M) += cmd_boot.o
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_SYS_L2_PL310) += cache-pl310.o
diff --git a/arch/arm/lib/cmd_boot.c b/arch/arm/lib/cmd_boot.c
new file mode 100644
index 0000000..37bb6a5
--- /dev/null
+++ b/arch/arm/lib/cmd_boot.c
@@ -0,0 +1,44 @@
+/*
+ * (C) Copyright 2008-2011
+ * Graeme Russ, <graeme.russ at gmail.com>
+ *
+ * (C) Copyright 2002
+ * Daniel Engström, Omicron Ceti AB, <daniel at omicron.se>
+ *
+ * (C) Copyright 2002
+ * Wolfgang Denk, DENX Software Engineering, <wd at denx.de>
+ *
+ * (C) Copyright 2002
+ * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
+ * Marius Groeger <mgroeger at sysgo.de>
+ *
+ * Copyright 2015 ATS Advanced Telematics Systems GmbH
+ * Copyright 2015 Konsulko Group, Matt Porter <mporter at konsulko.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * ARMv7M does not support ARM instruction mode. However, the
+ * interworking BLX and BX instructions do encode the ARM/Thumb
+ * field in bit 0. This means that when executing any Branch
+ * and eXchange instruction we must set bit 0 to one to guarantee
+ * that we keep the processor in Thumb instruction mode. From The
+ * ARMv7-M Instruction Set A4.1.1:
+ *   "ARMv7-M only supports the Thumb instruction execution state,
+ *    therefore the value of address bit [0] must be 1 in interworking
+ *    instructions, otherwise a fault occurs."
+ */
+unsigned long do_go_exec(ulong (*entry)(int, char * const []),
+			 int argc, char * const argv[])
+{
+	ulong addr = (ulong)entry | 1;
+	entry = (void *)addr;
+
+	return entry(argc, argv);
+}
-- 
2.1.0



More information about the U-Boot mailing list