ARM: traps: fix opcode endianness when read from user memory

Currently code has inverted logic: opcode from user memory is
swapped to a proper endianness only in case of read error.
While normally opcode should be swapped only if it was read
correctly from user memory.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
ARM: probes: fix instruction fetch order with <asm/opcodes.h>

If we are running BE8, the data and instruction endian-ness do not
match, so use <asm/opcodes.h> to correctly translate memory accesses
into ARM instructions.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
[taras.kondratiuk@linaro.org: fixed Thumb instruction fetch order]
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
ARM: kprobes-test: use <asm/opcodes.h> for instruction accesses

Ensure we read instructions in the correct endian-ness by using
the <asm/opcodes.h> helper to transform them as necessary.

CC: Jon Medhurst <tixy@yxit.co.uk>
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
ARM: kprobes-test: Use <asm/opcodes.h> for ARM instruction building

The kprobes test will build certain instructions incorrectly if building
big endian as .word output gets endian-swapped by the linker. Change to
using <asm/opcodes.h> and __inst_arm() to produce instructions.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
[taras.kondratiuk@linaro.org: fixed a few missed instructions]
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
ARM: kprobes-test: Use <asm/opcodes.h> for thumb instruction building

The kprobes test will build certain instructions incorrectly if building
big endian as .word output gets endian-swapped by the linker. Change to
using <asm/opcodes.h> and __inst_thumbXX() to produce instructions.

CC: Jon Medhurst <tixy@yxit.co.uk>
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
[taras.kondratiuk@linaro.org: removed "untested" warning from description]
Tested-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
ARM: kprobes-test: Workaround GAS .align bug

By default if no fill symbol is given to .align directive in a code
section it fills gap with NOPs. If previous fragment is not
instruction-aligned, additional pre-alignment is done by zero bytes
before NOPs. These zero bytes are marked as data by special symbol $d in
symbol table. Unfortunately GAS assumes that there is only code in the
code section so it "puts back" code symbol $a at the end of this
pre-alignment. So if there is some data after alignment it will be
interpreted as code and will be swapped back to LE for BE8 system during
a final linking.

If explicit fill value is given to .align, the NOP-padding code is
skipped and symbol table does not get messed-up.

So the workaround for this issue:
Use explicit fill value if data should be aligned in the code section.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
ARM: kprobes-test: fix next_instruction()

Fix next_instruction() function to correctly swap the instruction
loaded from memory.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
[ben.dooks@codethink.co.uk: edited commit message as item already fixed]
Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
ARM: add test for as supporting '.inst'

Add a test for the assembler supporting .inst and then defining
ARM_HAVE_INST for any position where this is needed.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
ARM: opcodes: Use .inst to emit instructions if available

Use of assembler data directives such as .long and .short to emit
instruction opcodes can confuse tools that try to interpret the
linker output, such as disassemblers or debuggers.

Newer versions of the GNU assembler support an .inst directive,
which can be used instead to mark the emitted bytes correctly as
instructions.

This patch makes use of the .inst directive instead of data
directives, if available.

Signed-off-by: Dave Martin <dave.martin@linaro.org>