Issue byte codes for ARMv7's movw and movt?

Jeffrey Walton noloader@gmail.com
Tue May 21 02:05:00 GMT 2019


On Mon, May 20, 2019 at 7:51 PM Richard Earnshaw
<Richard.Earnshaw@foss.arm.com> wrote:
>
> On 21/05/2019 00:39, Jeffrey Walton wrote:
> > Hi Everyone,
> >
> > I'm having trouble crafting the byte codes for the following from C/C++:
> >
> >     asm volatile("movw %0,%1 \n"
> >         "movt %0,%1 \n"
> >         : "=r"(a) : "i"(0x1234));
> >
> > When I tested and disassembled it produced:
> >
> >     00000000 <_Z4testv>:
> >        0:   f241 2334       movw    r3, #4660       ; 0x1234
> >        4:   f2c1 2334       movt    r3, #4660       ; 0x1234
> >        8:   4770            bx      lr
> > ...
> > I seem to recall there's a special way of doing this with ARM such
> > that two code paths are not needed, but I don't recall them. I thought
> > it used .word or .instruction, but I can't find a reference at the
> > moment.
> >
> > How do I issue the byte codes for movw and movt?
>
> Use the .inst directive.  If you don't, the assembler will mark the area
> as data and bad things might happen during linking, especially on
> big-endian devices.

Thanks, that's what I was looking for. I was searching for '.insn'
instead of '.inst'.

We can't use .inst.n and .inst.w because of Clang and its old tricks.
it pretends to be GCC but cannot consume the program.

This works well for both GCC and Clang:

    int a;
    asm volatile (
        ".arm              \n\t"
        ".inst 0xe3010234  \n\t"   // movw r0, 0x1234
        ".inst 0xe3410234  \n\t"   // movt r0, 0x1234
        "mov %0, r0        \n\t"   // mov [a], r0
        : "=r" (a) : : "r0");

If the SIGILL does not occur and a=0x12341234, then ARMv7 is available.

Jeff



More information about the Gcc-help mailing list