On Fri, Jul 01, 2011 at 03:38:48PM +0100, Tixy wrote:
I'm trying to work out what compile time checks I can do determine which ARM architecture the kernel binary may be run on.
Is __LINUX_ARM_ARCH__ the architecture that the kernel is being built to support, or is it the instruction set being used by the compiler? (If these aren't always the same.)
Also, when a kernel is built for ARMv6 and ARMv7, I assume that __LINUX_ARM_ARCH__ == 6 ?
I think yes -- it's the baseline architecture, even if some specific files get built for a newer architecture in a kernel supporting multiple CPUs. This define is set globally in arch/arm/Makefile.
Finally, is it safe to assume that a single kernel binary will never support both v5 and v6 hardware? What about v4 and v5?
I think it's "too hard" to support v6 and pre-v6 in the same kernel, so such configurations are not really supported.
Other than that, I'm not too sure. Nico or someone may know.
A Thumb-2 kernel cannot, by definition, run on anything prior to ARMv6T2.
My ultimate goal is to correctly simulate ARM instructions which behave differently on different architectures, for this, there will also need to be some runtime checking. I can do this by running some test code at boot time, but does the kernel already have some CPU architecture or feature detection that I can make use of?
Most opcodes are either UNPREDICTABLE or UNDEFINED before they get defined to mean something in some version of the architecture.
There are a few exceptions to this, but perhaps it's not worth the effort of emulating them all(?)
I was also looking at the Instruction Set Attribute Register in CP15, these give me the exact information I want, but I suspect that determining their availability will be as difficult as writing code to probe the features I'm interested in (ARM/Thumb interworking).
v7 processors and a few earlier processors have these registers.
If it's the ARM/Thumb interworking behaviour you're interested in, note that the kernel is a non-interworking environment, and cannot be built for (or contain any) Thumb code on ARMv4T. So those instructions really shouldn't make a difference unless the kernel is buggy.
The interworking behaviour is uniform for ARMv5(T) and above, but since kernels built in Thumb cannot run on pre-v7, and kernels built in ARM cannot (or certainly should not) contain any Thumb code, these niceties may not matter.
Cheers ---Dave