Skip to contentSkip to conversation

ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

PATCH New Uwe Kleine-König 5 participants 14 messages Jan 11, 2013 – Feb 19, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

---
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/kernel/head.S       |    8 +++++++-
 arch/arm/mm/Kconfig          |    6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
arch/arm/kernel/head-nommu.S +7 -1
index 3782320..ae7ed46 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_THUMBONLY_CPU
+	.thumb
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif
 
 	setmode	PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
 						@ and irqs disabled
arch/arm/kernel/head.S +7 -1
index 4eee351..0af2749 100644
@@ -73,15 +73,21 @@
  * crap here - that's what the boot loader (or in extreme, well justified
  * circumstances, zImage) is for.
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_THUMBONLY_CPU
+	.thumb
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif
 
 #ifdef CONFIG_ARM_VIRT_EXT
 	bl	__hyp_stub_install
arch/arm/mm/Kconfig +6 -0
index 3fd629d..bc3150c 100644
@@ -1,5 +1,11 @@
 comment "Processor Type"
 
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB
+
 # Select CPU types depending on the architecture selected.  This selects
 # which CPUs we support in the kernel image, and the compiler instruction
 # optimiser behaviour.
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Hi Uwe,

Quoted 3 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

Clearly something like this is necessary, but it isn't something I'd like for people to start using *unless* they have a THUMB only CPU (for example, to work around dodgy boot-loaders, etc)

Seeing as there are no THUMB-only CPUs with an MMU, I think we could safely constrain this change to:
a) depend on !MMU
b) only touch head-nommu.S

Does that cause any issue for what you're doing.

[...]

Quoted 6 lines
arch/arm/mm/Kconfig +0 -0
index 3fd629d..bc3150c 100644
@@ -1,5 +1,11 @@
  comment "Processor Type"

arch/arm/mm/Kconfig line 11

Quoted 10 lines
arch/arm/mm/Kconfig +6 -0
 
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB
+
  # Select CPU types depending on the architecture selected.  This selects
  # which CPUs we support in the kernel image, and the compiler instruction
  # optimiser behaviour.

Also, a couple of minor questions about this:
- What's the rationale for the placement within the file - it looks a bit curious up the top there.
- Given the fact that we don't want people using this except in very specific circumstances, should we write a little bit of help for the option?

Jonny

#2 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Hi Jonny,

Quoted 10 lines · Jonathan Austin

Hi Uwe,

Quoted 3 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

Clearly something like this is necessary, but it isn't something I'd like for people to start using *unless* they have a THUMB only CPU (for example, to work around dodgy boot-loaders, etc)

Quoted 6 lines

Seeing as there are no THUMB-only CPUs with an MMU, I think we could safely constrain this change to:
a) depend on !MMU
b) only touch head-nommu.S

Does that cause any issue for what you're doing.

Would be ok for me, too. I don't care much.

Quoted 7 lines
Quoted 7 lines
arch/arm/mm/Kconfig +0 -0
index 3fd629d..bc3150c 100644
@@ -1,5 +1,11 @@
 comment "Processor Type"
 
Quoted 13 lines

arch/arm/mm/Kconfig line 11

Quoted 9 lines
arch/arm/mm/Kconfig +6 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB
+
 # Select CPU types depending on the architecture selected.  This selects
 # which CPUs we support in the kernel image, and the compiler instruction
 # optimiser behaviour.

Also, a couple of minor questions about this:
- What's the rationale for the placement within the file - it looks a bit curious up the top there.

Conceptually it's a symbol that is selected by the different processor symbols. So IMHO it's fine to have it in front of the processor symbols. Maybe it should even go before the line reading:

comment "Processor Type"

. OTOH similar symbols (like CPU_32v4, CPU_CP15) are at the end, too. So yes, probably it's better to move it further down. And maybe rename it to CPU_THUMBONLY?

Quoted 3 lines

- Given the fact that we don't want people using this except in very specific circumstances, should we write a little bit of help for the option?

I can move what I wrote in the comment above the symbol into a help text instead.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#3 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Quoted 13 lines · Uwe Kleine-K?nig

Hi Jonny,

Quoted 10 lines · Jonathan Austin

Hi Uwe,

Quoted 3 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

Clearly something like this is necessary, but it isn't something I'd like for people to start using *unless* they have a THUMB only CPU (for example, to work around dodgy boot-loaders, etc)

Quoted 7 lines
Quoted 6 lines

Seeing as there are no THUMB-only CPUs with an MMU, I think we could safely constrain this change to:
a) depend on !MMU
b) only touch head-nommu.S

Does that cause any issue for what you're doing.

Would be ok for me, too. I don't care much.

Please do so then. I had the same concern.

Nicolas

#4 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

In reply to Uwe Kleine-König

arch/arm/mm/Kconfig line 7

Quoted 5 lines · Uwe Kleine-K?nig
arch/arm/mm/Kconfig +5 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB

Hmm, not convinced this is the best solution. Yes, fine for there to be a THUMBONLY_CPU option, _but_ not the select statements onto user visible symbols. We can get this instead by:

config THUMB2_KERNEL
bool "Compile the kernel in Thumb-2 mode" if !THUMBONLY_CPU depends on (CPU_V7 && !CPU_V6 && !CPU_V6K) || THUMBONLY_CPU default y if THUMBONLY_CPU
select AEABI
select ARM_ASM_UNIFIED
select ARM_UNWIND

and:

config ARM_THUMB

        bool "Support Thumb user binaries" if !THUMBONLY_CPU
        depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || \
		   CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || \
		   CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || \
		   CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || \
		   CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || \
		   CPU_V6K || CPU_V7 || CPU_FEROCEON || THUMBONLY_CPU
        default y

And... I'm left wondering - should we have this instead:

config CPU_ARM
bool

config CPU_THUMB
bool

which indicates whether the CPU supports the ARM instruction set or the Thumb instruction set (or both) - that should then allow us to select those from the individual CPU_xxx options and eliminate that big long list of dependencies against ARM_THUMB.

#5 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Hi Russell,

Quoted 36 lines · Russell King - ARM Linux

arch/arm/mm/Kconfig line 7

Quoted 5 lines · Uwe Kleine-K?nig
arch/arm/mm/Kconfig +5 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB

Hmm, not convinced this is the best solution. Yes, fine for there to be a THUMBONLY_CPU option, _but_ not the select statements onto user visible symbols. We can get this instead by:

config THUMB2_KERNEL
bool "Compile the kernel in Thumb-2 mode" if !THUMBONLY_CPU depends on (CPU_V7 && !CPU_V6 && !CPU_V6K) || THUMBONLY_CPU default y if THUMBONLY_CPU
select AEABI
select ARM_ASM_UNIFIED
select ARM_UNWIND

and:

config ARM_THUMB

        bool "Support Thumb user binaries" if !THUMBONLY_CPU
        depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || \
		   CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || \
		   CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || \
		   CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || \
		   CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || \
		   CPU_V6K || CPU_V7 || CPU_FEROCEON || THUMBONLY_CPU
        default y

And... I'm left wondering - should we have this instead:

config CPU_ARM
bool

Quoted 7 lines

config CPU_THUMB
bool

which indicates whether the CPU supports the ARM instruction set or the Thumb instruction set (or both) - that should then allow us to select those from the individual CPU_xxx options and eliminate that big long list of dependencies against ARM_THUMB.

I like your idea and I will come up with a patch.

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#6 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Hello Russell,

Quoted 37 lines · Uwe Kleine-K?nig
Quoted 36 lines · Russell King - ARM Linux

arch/arm/mm/Kconfig line 7

Quoted 5 lines · Uwe Kleine-K?nig
arch/arm/mm/Kconfig +5 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB

Hmm, not convinced this is the best solution. Yes, fine for there to be a THUMBONLY_CPU option, _but_ not the select statements onto user visible symbols. We can get this instead by:

config THUMB2_KERNEL
bool "Compile the kernel in Thumb-2 mode" if !THUMBONLY_CPU depends on (CPU_V7 && !CPU_V6 && !CPU_V6K) || THUMBONLY_CPU default y if THUMBONLY_CPU
select AEABI
select ARM_ASM_UNIFIED
select ARM_UNWIND

and:

config ARM_THUMB

        bool "Support Thumb user binaries" if !THUMBONLY_CPU
        depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || \
		   CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || \
		   CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || \
		   CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || \
		   CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || \
		   CPU_V6K || CPU_V7 || CPU_FEROCEON || THUMBONLY_CPU
        default y

And... I'm left wondering - should we have this instead:

config CPU_ARM
bool

Quoted 8 lines
Quoted 7 lines

config CPU_THUMB
bool

which indicates whether the CPU supports the ARM instruction set or the Thumb instruction set (or both) - that should then allow us to select those from the individual CPU_xxx options and eliminate that big long list of dependencies against ARM_THUMB.

I like your idea and I will come up with a patch.

This looks nice and clean, but after having thought about it for a while it turns out not to be that easy.

For THUMB2_KERNEL only CPUs must be supported that can do Thumb2. That means the logic must be something like:

config THUMB2_KERNEL
bool "Compile the kernel in Thumb-2 mode" if ALL_CONFIGURED_CPUS_SUPPORT_ARM depends on ALL_CONFIGURED_CPUS_SUPPORT_THUMB2
default y if !ALL_CONFIGURED_CPUS_SUPPORT_ARM

for the ALL_CONFIGURED_CPUS_SUPPORT_ARM and .._THUMB2 symbols to do the right thing, we'd need something like:

	config CPU_32v4
		bool
		...
		select ISA_ARM
		select ISA_THUMB_NONE

	config CPU_32v4T
		bool
		...
		select ISA_ARM
		select ISA_THUMB1
	...
	config CPU_32v7
		bool
		select ISA_ARM
		select ISA_THUMB2

	config CPU_32v7M
		bool
		select ISA_ARM_NONE
		select ISA_THUMB2

	config ALL_CONFIGURED_CPUS_SUPPORT_ARM
		bool
		default ISA_ARM && !ISA_ARM_NONE

	config ALL_CONFIGURED_CPUS_SUPPORT_THUMB2
		bool
		default ISA_THUMB2 && !ISA_THUMB1 && !ISA_THUMB_NONE

which looks less nice than what I thought first.

What do you think? Is it still worthwhile to implement this?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#7 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

In reply to Russell King - ARM Linux

Hi Russell, Uwe

Quoted 10 lines · Russell King - ARM Linux

arch/arm/mm/Kconfig line 7

Quoted 5 lines · Uwe Kleine-K?nig
arch/arm/mm/Kconfig +5 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB

Hmm, not convinced this is the best solution. Yes, fine for there to be a THUMBONLY_CPU option, _but_ not the select statements onto user visible symbols. We can get this instead by:

I'm curious what it is about having the select statements onto user visible symbols that isn't good. Is it just that it will manipulate things underneath the users' feet?

(I'm not disagreeing! I like your proposal, but when I saw the original patch this didn't raise flags with me, so I'd like to understand the reasons)

Quoted 5 lines

config CPU_ARM
bool

config CPU_THUMB
bool

The only thing I might add is that we don't want people confusing the selection of THUMB2_KERNEL with exclusively selecting CPU_THUMB (which should be very rare). The latter would imply the former, but in almost all cases where THUMB2_KERNEL is selected we should also have CPU_ARM selected...

However things fall out, I'd still like to be *unable* to use THUMBONLY_CPU *with* an MMU, as it is a clear sign (at least for the foreseeable future) that something has been misunderstood.

Jonny

#8 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Quoted 14 lines · Jonathan Austin

Hi Russell, Uwe

Quoted 10 lines · Russell King - ARM Linux

arch/arm/mm/Kconfig line 7

Quoted 5 lines · Uwe Kleine-K?nig
arch/arm/mm/Kconfig +5 -0
+# Select this if your CPU doesn't support the 32 bit ARM instructions.
+config THUMBONLY_CPU
+	bool
+	select THUMB2_KERNEL
+	select ARM_THUMB

Hmm, not convinced this is the best solution. Yes, fine for there to be a THUMBONLY_CPU option, _but_ not the select statements onto user visible symbols. We can get this instead by:

Quoted 3 lines

I'm curious what it is about having the select statements onto user visible symbols that isn't good. Is it just that it will manipulate things underneath the users' feet?

Consider this: you run make xconfig (or whatever config tool you prefer). You're presented with an option, which you want to disable. It says the possible values for it are 'Y' (n and m are not possible).

So, you start to wonder why this is - why you're even being presented with an option where it only has one allowable state. That's not an option, that's an ultimatum!

Now, you ask the config tool for the reason why the symbol is selected. It gives you a big long list of dependencies - I've seen some of these which are over 50 lines long. A complex nest of options which are && and ||'d together. You've no clue which one(s) result in the symbol being selected.

So, the presentation of that symbol is nothing more than pure noise and in some cases just leads to frustration at not being able to achieve the configuration that's desired.

Quoted 7 lines

(I'm not disagreeing! I like your proposal, but when I saw the original patch this didn't raise flags with me, so I'd like to understand the reasons)

Quoted 3 lines

config CPU_ARM
bool

Quoted 6 lines
Quoted 2 lines

config CPU_THUMB
bool

The only thing I might add is that we don't want people confusing the selection of THUMB2_KERNEL with exclusively selecting CPU_THUMB (which should be very rare).

Note: these aren't user visible symbols (note the lack of option text after 'bool' - that makes them hidden). Instead, these symbols are to be selected from the CONFIG_CPU_ARM926T etc symbols - so it's a choice that the developers are making.

We can also add a "help" stanza to both these to describe what they're representing, or if people prefer a comment before the option.

#9 lore raw

PATCH v2 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

In reply to Uwe Kleine-König

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

---
Changes since (implicit) v1,
id: 1357904397-8476-1-git-send-email-u.kleine-koenig at pengutronix.de:

- drop modification to entry for MMU machines
- don't select user-visible symbols
- rename THUMBONLY_CPU to CPU_THUMBONLY
- move CPU_THUMBONLY definition further down in arch/arm/mm/Kconfig

 arch/arm/Kconfig             |    3 ++-
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/mm/Kconfig          |    9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
arch/arm/Kconfig +2 -1
index 67874b8..e04c779 100644
@@ -1656,8 +1656,9 @@ config HZ
 	default 100
 
 config THUMB2_KERNEL
-	bool "Compile the kernel in Thumb-2 mode"
+	bool "Compile the kernel in Thumb-2 mode" if !CPU_THUMBONLY
 	depends on CPU_V7 && !CPU_V6 && !CPU_V6K
+	default y if CPU_THUMBONLY
 	select AEABI
 	select ARM_ASM_UNIFIED
 	select ARM_UNWIND
arch/arm/kernel/head-nommu.S +7 -1
index 3782320..e8ecae2 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_CPU_THUMBONLY
+	.thumb
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif
 
 	setmode	PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
 						@ and irqs disabled
arch/arm/mm/Kconfig +8 -1
index 3fd629d..8defd63 100644
@@ -397,6 +397,13 @@ config CPU_V7
 	select CPU_PABRT_V7
 	select CPU_TLB_V7 if MMU
 
+config CPU_THUMBONLY
+	bool
+	# There are no CPUs available with MMU that don't implement an ARM ISA:
+	depends on !MMU
+	help
+	  Select this if your CPU doesn't support the 32 bit ARM instructions.
+
 # Figure out what processor architecture version we should be using.
 # This defines the compiler instruction set which depends on the machine type.
 config CPU_32v3
@@ -608,7 +615,7 @@ config ARCH_DMA_ADDR_T_64BIT
 	bool
 
 config ARM_THUMB
-	bool "Support Thumb user binaries"
+	bool "Support Thumb user binaries" if !CPU_THUMBONLY
 	depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || CPU_V6K || CPU_V7 || CPU_FEROCEON
 	default y
 	help
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v2 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Quoted 5 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

Quoted 86 lines

---
Changes since (implicit) v1,
id: 1357904397-8476-1-git-send-email-u.kleine-koenig at pengutronix.de:

- drop modification to entry for MMU machines
- don't select user-visible symbols
- rename THUMBONLY_CPU to CPU_THUMBONLY
- move CPU_THUMBONLY definition further down in arch/arm/mm/Kconfig

 arch/arm/Kconfig             |    3 ++-
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/mm/Kconfig          |    9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
arch/arm/Kconfig +2 -1
index 67874b8..e04c779 100644
@@ -1656,8 +1656,9 @@ config HZ
 	default 100
 
 config THUMB2_KERNEL
-	bool "Compile the kernel in Thumb-2 mode"
+	bool "Compile the kernel in Thumb-2 mode" if !CPU_THUMBONLY
 	depends on CPU_V7 && !CPU_V6 && !CPU_V6K
+	default y if CPU_THUMBONLY
 	select AEABI
 	select ARM_ASM_UNIFIED
 	select ARM_UNWIND
arch/arm/kernel/head-nommu.S +7 -1
index 3782320..e8ecae2 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_CPU_THUMBONLY
+	.thumb
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif
 
 	setmode	PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
 						@ and irqs disabled
arch/arm/mm/Kconfig +8 -1
index 3fd629d..8defd63 100644
@@ -397,6 +397,13 @@ config CPU_V7
 	select CPU_PABRT_V7
 	select CPU_TLB_V7 if MMU
 
+config CPU_THUMBONLY
+	bool
+	# There are no CPUs available with MMU that don't implement an ARM ISA:
+	depends on !MMU
+	help
+	  Select this if your CPU doesn't support the 32 bit ARM instructions.
+
 # Figure out what processor architecture version we should be using.
 # This defines the compiler instruction set which depends on the machine type.
 config CPU_32v3
@@ -608,7 +615,7 @@ config ARCH_DMA_ADDR_T_64BIT
 	bool
 
 config ARM_THUMB
-	bool "Support Thumb user binaries"
+	bool "Support Thumb user binaries" if !CPU_THUMBONLY
 	depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || CPU_V6K || CPU_V7 || CPU_FEROCEON
 	default y
 	help
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

In reply to Uwe Kleine-König
Quoted 25 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

---
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/kernel/head.S       |    8 +++++++-
 arch/arm/mm/Kconfig          |    6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
arch/arm/kernel/head-nommu.S +3 -1
index 3782320..ae7ed46 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_THUMBONLY_CPU
+	.thumb

arch/arm/kernel/head-nommu.S line 49

Quoted 10 lines
arch/arm/kernel/head-nommu.S +4 -0
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif

The behaviour is that we start the file is kernel entry state, then we switch to kernel run state.

The switch is only needed for kernels which run on CPUs supporting both states, where the run state is not ARM.

So, it would be neater for these entry sequences to look something like:

HAS_ARM(.arm) @ because -mthumb is default for Thumb kernels anyway

ENTRY(stext)
HAS_ARM(THUMB( @ code to switch to Thumb ))

@ real code starts here, in run state.

Where

#ifdef CONFIG_THUMBONLY_CPU
#define HAS_ARM(x...)
#else
#define HAS_ARM(x...) x
#endif

(I haven't read the whole thread yet, so decisions about what config variables and macro names should be used may be overridden by other people...)

Thoughts?

Cheers
---Dave

#12 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Hello Dave,

Quoted 63 lines · Dave Martin
Quoted 25 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

---
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/kernel/head.S       |    8 +++++++-
 arch/arm/mm/Kconfig          |    6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
arch/arm/kernel/head-nommu.S +3 -1
index 3782320..ae7ed46 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_THUMBONLY_CPU
+	.thumb

arch/arm/kernel/head-nommu.S line 49

Quoted 10 lines
arch/arm/kernel/head-nommu.S +4 -0
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif

The behaviour is that we start the file is kernel entry state, then we switch to kernel run state.

The switch is only needed for kernels which run on CPUs supporting both states, where the run state is not ARM.

So, it would be neater for these entry sequences to look something like:

HAS_ARM(.arm) @ because -mthumb is default for Thumb kernels anyway

ENTRY(stext)
HAS_ARM(THUMB( @ code to switch to Thumb ))

@ real code starts here, in run state.

Where

#ifdef CONFIG_THUMBONLY_CPU
#define HAS_ARM(x...)
#else
#define HAS_ARM(x...) x
#endif

Quoted 3 lines

(I haven't read the whole thread yet, so decisions about what config variables and macro names should be used may be overridden by other people...)

I don't agree on better readability, the result would look like:

		__HEAD

	HAS_ARM(.arm)

		ENTRY(stext)

	HAS_ARM(THUMB(adr	r9, BSYM(1f)	)
	HAS_ARM(THUMB(bx	r9		)
	HAS_ARM(THUMB(.thumb			)
	HAS_ARM(THUMB(1:			)

in contrast to:

		__HEAD

	#ifdef CONFIG_CPU_THUMBONLY
		.thumb
	ENTRY(stext)
	#else
		.arm
	ENTRY(stext)

	 THUMB( adr     r9, BSYM(1f)    )       @ Kernel is always entered in ARM.
	 THUMB( bx      r9              )       @ If this is a Thumb-2 kernel,
	 THUMB( .thumb                  )       @ switch to Thumb now.
	 THUMB(1:                       )
	#endif

(modulo comments and indention maybe). Even though it uses an #ifdef I consider the latter variant more readable. Maybe it's only me? Other than that I'd probably choose a longer name instead of HAS_ARM to make it more self-documenting what it is about (something with _ISA_ in its name). This obviously makes readability worse.

So I'm still happy with the version I sent.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#13 lore raw

PATCH 1/1 ARM: let CPUs not being able to run in ARM mode enter in THUMB mode

Quoted 100 lines · Uwe Kleine-K?nig

Hello Dave,

Quoted 63 lines · Dave Martin
Quoted 25 lines · Uwe Kleine-K?nig

Some ARM cores are not capable to run in ARM mode (e.g. Cortex-M3). So obviously these cannot enter the kernel in ARM mode. Make an exception for them and let them enter in THUMB mode.

---
 arch/arm/kernel/head-nommu.S |    8 +++++++-
 arch/arm/kernel/head.S       |    8 +++++++-
 arch/arm/mm/Kconfig          |    6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
arch/arm/kernel/head-nommu.S +3 -1
index 3782320..ae7ed46 100644
@@ -32,15 +32,21 @@
  * numbers for r1.
  *
  */
-	.arm
 
 	__HEAD
+
+#ifdef CONFIG_THUMBONLY_CPU
+	.thumb

arch/arm/kernel/head-nommu.S line 49

Quoted 10 lines
arch/arm/kernel/head-nommu.S +4 -0
+ENTRY(stext)
+#else
+	.arm
 ENTRY(stext)
 
  THUMB(	adr	r9, BSYM(1f)	)	@ Kernel is always entered in ARM.
  THUMB(	bx	r9		)	@ If this is a Thumb-2 kernel,
  THUMB(	.thumb			)	@ switch to Thumb now.
  THUMB(1:			)
+#endif

The behaviour is that we start the file is kernel entry state, then we switch to kernel run state.

The switch is only needed for kernels which run on CPUs supporting both states, where the run state is not ARM.

So, it would be neater for these entry sequences to look something like:

HAS_ARM(.arm) @ because -mthumb is default for Thumb kernels anyway

ENTRY(stext)
HAS_ARM(THUMB( @ code to switch to Thumb ))

@ real code starts here, in run state.

Where

#ifdef CONFIG_THUMBONLY_CPU
#define HAS_ARM(x...)
#else
#define HAS_ARM(x...) x
#endif

Quoted 3 lines

(I haven't read the whole thread yet, so decisions about what config variables and macro names should be used may be overridden by other people...)

I don't agree on better readability, the result would look like:

		__HEAD

	HAS_ARM(.arm)

		ENTRY(stext)

	HAS_ARM(THUMB(adr	r9, BSYM(1f)	)
	HAS_ARM(THUMB(bx	r9		)
	HAS_ARM(THUMB(.thumb			)
	HAS_ARM(THUMB(1:			)

in contrast to:

		__HEAD

	#ifdef CONFIG_CPU_THUMBONLY
		.thumb
	ENTRY(stext)
	#else
		.arm
	ENTRY(stext)

	 THUMB( adr     r9, BSYM(1f)    )       @ Kernel is always entered in ARM.
	 THUMB( bx      r9              )       @ If this is a Thumb-2 kernel,
	 THUMB( .thumb                  )       @ switch to Thumb now.
	 THUMB(1:                       )
	#endif
Quoted 5 lines

(modulo comments and indention maybe). Even though it uses an #ifdef I consider the latter variant more readable. Maybe it's only me? Other than that I'd probably choose a longer name instead of HAS_ARM to make it more self-documenting what it is about (something with _ISA_ in its name). This obviously makes readability worse.

Well, maybe so.

Note that Thumb is also the default instruction set for any Thumb-2 kernel; that's why we needed .arm in the first place.

We could turn the switch to Thumb into a macro in assembler.h -- that's actually needed elsewhere:

#if defined(CONFIG_THUMB2_KERNEL) && !defined(CONFIG_CPU_THUMBONLY)

.macro entry_isa
.arm
.endm

.macro switch_to_kernel_isa rtemp
THUMB( adr \rtemp, BSYM(9999f) )
THUMB( bx \rtemp )
THUMB( .thumb )
THUMB( 9999: )
.endm

#else

.macro entry_isa
.endm
.macro switch_to_kernel_isa rtemp
.endm

#endif

Then head.S becomes

	__HEAD

	entry_isa

ENTRY(stext)
switch_to_kernel_isa r9

The macros can be reused in the zImage decompressor, the mcpm low-level entry point and possibly elsewhere.

What do you think?

Cheers
---Dave