3

I have a compiled Tricore binary that I am patching. By creating a .asm file from IDA Pro of a function and reformatting it, I can get it to reassemble faithfully apart from call (relative) and jump (relative) instructions. One of the reasons for going through this was so that the assembler would automatically recalculate the offsets from the program counter for the relative jumps and calls in the relocated code.

The failure is because the .org 0x80280000 is not working as I hoped and the a.out file has a base of 0x0 so the call and j are not reachable from that address. I do not want to alter the code to absolute calli.

This fails:

.org 0x80280000
call 0x8027024C
j    0x80292420

orgtest1.s: Assembler messages:

orgtest1.s:2: Error: Opcode/operand mismatch: call 0x8027024C

orgtest1.s:3: Error: Opcode/operand mismatch: j 0x80292420

This fails:

call 0x8027024C
j    0x80292420

orgtest1.s:1: Error: Opcode/operand mismatch: call 0x8027024C

orgtest1.s:2: Error: Opcode/operand mismatch: j 0x80292420

This succeeds:

call 0x7024C
j    0x92420

The problem is not that the instructions are illegal (and jumping to a lower address is legal), but that I cannot find a way to tell the assembler where the origin is.

I do not know if this is expected behaviour from GNU AS? I am reading that it cannot calculate addresses lower than .org, and indeed if I set an .org of 0x8000 and call 0x2404 it ends up at 0xA404 so the call instruction is simply adding the displacement to the program counter and not calling an absolute address.

2
  • 2
    as assembles source code into relocatable object files. Relocation is performed by ld which links relocatable files into executable files like a.out. The base address of .text will be 0x0 until the assembled relocatable object file is linked, which is when relocation is performed and ld sets the program entry point to a memory address like 0x80280000.
    – julian
    Feb 5, 2017 at 2:01
  • Thanks SYS_V. I think this will be a limitation for my use case. I think I will end up moving binary blobs and fixing the call and jump targets at the hex level, rather than putting the assembly into my project to be reassembled. I just thought the reassembly route could be more elegant. I have a demo of Tasking I can try, but although it says it is Aurix only, the command line tools seem to have switches to get it to stick to Tricore 1.3 instruction set. I would prefer to use one toolchain, but will report back any success with this method.
    – John Banks
    Feb 6, 2017 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.