This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to embed an arbitrary opcode


On Fri, 2009-06-19 at 15:17 +0100, Nick Clifton wrote:
> Hi Richard,
> 
> > Yay!  Something I've wanted for a long time...
> 
> :-)
> 
> > One question.  What happens if .iword is used in Thumb mode, or .ishort
> > in ARM mode?
> 
> Well the new pseudos explicitly set the mapping state based on their 
> size, so for example if .iword were used in Thumb mode it would cause a 
> $a symbol to be emitted at point.  Ie:
> 
>    % cat fred.s
>          .text
>          .global foo
>    foo:
>          nop
>          .iword  0xe320f003
>          nop
>          .ishort 0x1234
>          nop
> 
>          .thumb
>          .global bar
>    bar:
>          nop
>          .ishort 0x1234
>          nop
>          .iword 0xe320f003
>          nop
> 
>    % as fred.s -o fred.o
>    % objdump -d fred.o
>    00000000 <foo>:
>     0:   e1a00000        nop                     (mov r0,r0)
>     4:   e320f003        wfi
>     8:   e1a00000        nop                     (mov r0,r0)
>     c:   1234            asrs    r4, r6, #8
>     e:   e1a00000        nop                     (mov r0,r0)
> 
>    00000012 <bar>:
>    12:   46c0            nop                     (mov r8, r8)
>    14:   1234            asrs    r4, r6, #8
>    16:   46c0            nop                     (mov r8, r8)
>    18:   e320f003        wfi
>    1c:   46c0            nop                     (mov r8, r8)
> 

Yuk!

> 
> > I think it would be better to just have .insn (or .inst),
> > which takes 32-bit numbers in ARM state and 16-bit numbers in thumb.
> > The assembler has to know what state it's in anyway in order to generate
> > the correct mapping symbol information.
> 
> I suspect that users are going to want to be able to use this mechanism 
> to insert arbitrary ARM or THUMB opcodes at arbitrary places without 
> regard to whether the assembler is currently in arm mode or thumb mode.
> 

I doubt that.  Anyway, it's no real hardship to put .arm or .thumb in
the sources as well if you want a specific state.

> It would be quite easy to extend the patch however to add a third pseudo 
> op (.inst is fine by me) which chooses it size based on the current 
> mode.  So attached is an improved version of the patch which does just 
> that.  Let me know what you think and if everyone likes it I will check 
> it in.  (Along with a testcase based on the fred.s file above).
> 

My main concern is that .iword generates a 32-bit number, so could be
thought of meaning a 32-bit thumb(2) instruction.  It would be very
confusing to then find it quietly produced an ARM instruction
(especially on cortex-m* processors)!

IMO if you want explicit 16- and 32-bit operations, then I'd go
for .iword in thumb meaning a 32-bit thumb instruction where the most
significant 16 bits of the number represent sub-word 1 and the least
significant 16 bits represent sub-word 2.  Using .ishort when not in
thumb state should be an error.

R.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]