Hello,everyone!As you can see, I’m a newcomer to this community
Recently I have encountered a problem while assembling source file using the tool devkitARM, which is all of the branch codes are compiled abnormally. The codes such as “bl 0x08XXXXXX” are compiled to “bl itself”,which is 0xFFFE7FFF. Of course,it doesn’t work except I modify all of the errors in a hex editor manually. I’d appreciate it if anyone here can tell me how to solve the problem. I know the question sounds stupid but I am really new to this tool.(In fact, I did the asm hack using a debugger and a hex editor before.) And because I am not a native English speaker so if I haven’t account the question clearly, let me konw.
Here is my assemble.bat:
@echo off
SET startDir=D:\devkitPro\devkitARM\bin\
@rem Assemble into an elf
SET as="%startDir%arm-none-eabi-as"
%as% -g -mcpu=arm7tdmi -mthumb-interwork %1 -o “%~n1.elf”
@rem Print symbol table
SET readelf="%startDir%arm-none-eabi-readelf"
%readelf% -s “%~n1.elf” > “%~n1.symbols.log”
@rem Extract raw assembly binary (text section) from elf
SET objcopy="%startDir%arm-none-eabi-objcopy"
%objcopy% -S “%~n1.elf” -O binary “%~n1.dmp”
for whatever reason gas/gcc no longer accepts bl to an absolute address (actually, i’m surprised that it didn’t give you an error - at least as far as gas is concerned, 0x8whatever is way out of bl range) and instead treats it as a label or something of the sort
you can get around this by making a label that’s .org’d to the relevant place and bl’ing to that, or by using a macro
If you are trying to branch to existing code, BL is probably not what you want - it can only work if you put your code inside the first 4MB of the ROM, and you won’t realistically find space there unless you get rid of existing code. Anyway, you should try to write your code so that it doesn’t matter where you put it. That means that ordinary BL will not work, because it’s relative and you want an absolute address. You need to set up a BX instead. Please see these two threads.
The actual asm code is in the “FEditor Adv\asm\FE7\Spell Anim System” called CSA System.txt. In the reality I need to modify the system because of some reason, so I need to modify the source and re-assemble it. But I encountered that problem while trying to assemble the original unmodified src>_<(But why Xeld hadn’t encountered the problem and compiled it correctly?) I edited the code directly in the hex editor and ran VBA to test it, the branches worked well, but there are too many branches in the system for me to calculate each offset and modify them manually. I have encountered the same problem before while compiling my modified hack based on Nintenlord’s hack and modified the branch mistakes in a debugger one by one and the hack worked pretty well, so I think my way of compilation may have some errors.
I will research your treatise and try to use bx to replace the bl code.Thanx~
Patcher format?Considering my poor English and I don’t know if I understand it correctly.The FEditor Adv uses auto-patch so the changes to rom are directly written in the java source file.Is that connected with the compilation?
What confused me is why Xeld and Nintenlord can compile their src correctly but it(even unmodified one) didn’t work for me.The souce is absolutely the same.
the differences between the two dump files above(compared by the command “fc /b”)
00000052: 88 FF
00000054: E9 FE
0000005A: 84 FF
0000005C: A1 FE
0000005D: FC FF
0000005E: 84 FF
00000060: AB FE
00000061: FC FF
00000066: 38 FF
00000068: ED FE
00000069: FE FF
00000074: 89 FF
00000076: 9E FE
00000077: F8 FF
0000007C: 88 FF
0000007E: DE FE
00000180: 84 FF
00000182: CC FE
00000183: F9 FF
000001AC: 88 FF
000001AE: D4 FE
000001F6: 84 FF
000001F8: 7B FE
000001F9: FC FF
000001FC: 84 FF
000001FE: 4E FE
000001FF: FD FF
0000020C: 9C FF
0000020E: 5A FE
0000020F: FA FF
00000248: 82 FF
0000024B: FD FF
00000258: 9C FF
0000025A: 9C FE
0000025B: FC FF
000003E2: 84 FF
000003E4: E3 FE
000003E5: FA FF
000003E6: 84 FF
000003E8: C5 FE
000003E9: F8 FF
000003EC: 38 FF
000003EE: 30 FE
000003EF: FE FF
hextator is using an old build of devkitARM, the most important part of which is that the version of gas/gcc involved allows you to bl to an absolute address, which i already mentioned
this line, for example:
bl 0x08054678 - CSAPS_CORRECT
this works, but only in devkitARM16 or below. beyond that for whatever reason, gas will not let you bl to a number, only to a label. I can’t remember offhand what the solution to that was (there definitely is one; i’ve used it myself), play around with the math a bit.