0

I've used arm-none-eabi-objdump to look at the internals of a crt0.o file. To be specific, this is is one of the crt0.o files that came packaged with the arm-none-eabi toolchain.

I'm confused by the use of the beq opcode near the start of the .text section:

Disassembly of section .text:

00000000 <_stack_init>:
   0:   e10f4000    mrs r4, CPSR
   4:   e314000f    tst r4, #15
   8:   0a00001c    beq 80 <_stack_init+0x80>

From the "Using as" manual (for as, the GNU assembler) that came with the same toolchain:

beq *label*:

A polymorph instruction which is jeq label in case if jump distance within allowed range for cpu's jump instruction. If not, this unrolls into a sequence of

jne $+6 br label

jeq is defined thus:

jeq %d,(%s|imm32),disp16

Jump if equal.

So the above use of beq appears to result in jeq being called with two opcodes instead of three, and one of those opcodes does not have a comma between it and its predecessor!

Can someone explain to me how this line of code is actually working, and what the jump is actually conditional on here?

AJM
  • 1,317
  • 2
  • 15
  • 30
  • 3
    You are looking at the manual for the wrong architecture. – fuz Jul 11 '22 at 17:58
  • 3
    Refer to the ARMv7 (or whatever variant of the ARM architecture it is you are using) Architecture Reference Manual for the correct description. But TL;DR: In ARM mode, `beq` is `b` with an `eq` condition code. – fuz Jul 11 '22 at 17:59
  • 2
    Yeah, the manual section you are reading looks like MSP430 (see the section heading at the top of the page), not ARM. Generally the GNU `as` manual does not document the machine's actual instruction set; only the "meta" stuff that is specific to the GNU assembler, as opposed to other assemblers for the same architecture. As fuz says, the As fuz says, the Architecture Reference Manual (written by Arm, not GNU) is what you need here. – Nate Eldredge Jul 11 '22 at 18:27
  • 3
    The actual ARM `b` instruction does in fact take just one immediate operand. – Nate Eldredge Jul 11 '22 at 18:28
  • @NateEldredge @fuz The manual I'm citing is "Using as The GNU Assembler (GNU Arm Embedded Toolchain 10.3-2021.10) Version 2.36.1" This came packaged with the `arm-none-eabi-gcc` toolchain, and was installed to `C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\share\doc\gcc-arm-none-eabi\pdf\as.pdf`. If it's for a non-ARM architecture like MSP430, something is VERY odd here. – AJM Jul 11 '22 at 18:59
  • 2
    They probably just provided a copy of the [upstream GNU assembler manual](https://sourceware.org/binutils/docs/as/), which documents all the architectures that the assembler can be configured to support, and didn't bother to cut out the sections that are irrelevant to ARM. – Nate Eldredge Jul 11 '22 at 19:02
  • @NateEldredge On examination... you're right about *"didn't bother to cut out the sections that are irrelevant to ARM."* After scrolling up a few pages, the heading "MSP 430 Dependent Features" confirmed it. I knew this document was based on the "upstream" manual, but I had expected it to be modified for ARM 32-bit with non-ARM content removed. – AJM Jul 11 '22 at 19:03
  • BTW, there don't seem to be any PDF manuals included with the later `11.2 2022.02` version of the toolchain. – AJM Jul 21 '22 at 13:59

0 Answers0