Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
To: "noloader@gmail.com" <noloader@gmail.com>
Cc: GDB Users <gdb@sourceware.org>
Subject: Re: Question on ARM/Thumb-16 Disassembly
Date: Mon, 20 Jun 2011 16:14:00 -0000	[thread overview]
Message-ID: <4DFF71E2.5040402@arm.com> (raw)
In-Reply-To: <BANLkTikATazyeKYowM451mZCRFTRf4o_3g@mail.gmail.com>

Jeffrey,

On 20/06/11 16:35, Jeffrey Walton wrote:
> Hi All,
>
> A couple of questions for ARM/Thumb-2. I'm working on a live iPhone,
> so I'm using Apple's GAS.

It would be useful if you could give the command line you are using - as 
I can't give precise answers without that info.  Most of the comments I 
make below are based upon the behaviour of the vanilla FSF tools, Apple 
may have changed their behaviours in ways I am unaware of.

> I've got a function generated for Thumb-16 which performs a branch
> (immediately after an ADD) based on Carry. For some reason, I'm
> getting unexpected results after the ADD - the carry flag is always
> high (ie, CY = 1 in CPSR), even when adding 0 + 0, 1 + 1, etc.
>
> Under GDB, I perform a disassembly looking for something I might have
> munged (or unexpected code generation and interactions). The first
> thing I noticed is some instructions are 4 bytes despite being in
> Thumb-16 mode (shown below). For example, the MOV at 0x00002334 is 4
> bytes.
>
> (1) Has anyone encountered a situation where a status flag gets
> pinned? The ARM Instruction Reference states the status flags are
> updated in Thumb mode (except when one or more high registers are
> specified as operands).

There are two types of assembly language syntax in GAS for ARM:

  1. 'divided' syntax - where add instruction has different semantics 
depending on whether you are in Thumb or ARM state.
  2. 'unified' syntax - where the add instruction has the same semantics 
in ARM and Thumb state.

(Look for a .syntax directive in your assembly source).

My guess is that you have written something like the following in your 
assembly code:
    add r0, r1, r2

Which would set the flags in Thumb-1 code when using divided syntax but 
does not when using unified syntax.

So the fix is to do the following instead:
    adds r0, r1, r2

[The additional 's' means set the flags].

> (2) Are 4 byte instructions expected when GCC generates Thumb-16 code?
> The ARM Instruction Reference seems to state otherwise.

GCC will generate code using all the features available in the 
instruction set for the CPU/architecture it is compiling for.  Therefore 
if you are compiling for Cortex-A8 (say) and specify -mthumb on the 
command line it will use both 16-bit and 32-bit Thumb instructions (as 
they will be available).  There is no way to tell GCC to compile for a 
CPU supporting Thumb-2 but restrict itself to just Thumb-1 instructions.

I hope this helps.

Thanks,

Matt


  reply	other threads:[~2011-06-20 16:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-20 15:35 Jeffrey Walton
2011-06-20 16:14 ` Matthew Gretton-Dann [this message]
2011-06-21  3:05   ` Jeffrey Walton
2011-06-21  4:53     ` Jeffrey Walton
2011-06-21  5:01       ` Jeffrey Walton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DFF71E2.5040402@arm.com \
    --to=matthew.gretton-dann@arm.com \
    --cc=gdb@sourceware.org \
    --cc=noloader@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox