Skip to content

PowerPC missing 'bctar' family of instructions #2666

Open
@hainest

Description

@hainest

While testing #2663, I found that Capstone is missing the bctar/bctarl instructions. It turns out that it's because LLVM doesn't have them. They were introduced in Power8 back in 2013, so that's surprising. It would be good to manually add them into Capstone until they become available. I'm assuming the best place for that is in capstone-engine/llvm-capstone, but I don't speak TableGen so it would take me a while to do that.

echo 'void test(){ __asm__ volatile("bctar 0x14, 0x0, 0x0"); }' |  clang -x c -mtune=power9 -c -o test.o -
<stdin>:1:31: error: invalid instruction, did you mean: bca, bcctr, bctr, bctrl, bfctr, bta, btctr?
    1 | void test(){ __asm__ volatile("bctar 0x14, 0x0, 0x0"); }
      |                               ^
<inline asm>:1:2: note: instantiated into assembly here
    1 |         bctar 0x14, 0x0, 0x0
      |         ^~~~~
1 error generated.
echo 'void test(){ __asm__ volatile("bctar 0x14, 0x0, 0x0"); }' |  gcc -x c -mtune=power9 -c -o test.o - && objdump -d test.o

test.o:     file format elf64-powerpcle

Disassembly of section .text:

0000000000000000 <test>:
   0:   f8 ff e1 fb     std     r31,-8(r1)
   4:   d1 ff 21 f8     stdu    r1,-48(r1)
   8:   78 0b 3f 7c     mr      r31,r1
   c:   60 04 80 4e     btar
  10:   00 00 00 60     nop
  14:   30 00 3f 38     addi    r1,r31,48
  18:   f8 ff e1 eb     ld      r31,-8(r1)
  1c:   20 00 80 4e     blr
        ...
  28:   80 01 00 01     .long 0x1000180
./cstool -dar ppc64 "60 04 80 4e"
ERROR: invalid assembly code

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    LLVMAnything LLVM relatedPowerPCArch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions