#154042 - simonjhall - Wed Apr 09, 2008 11:08 pm
I was gonna stick this in the RAM library thread, but it's pretty fat.
Here's my mini-howto to finding where 8-bit writes are in your elf. Requires awk and the ARM binutils. If you don't know what this means then this likely isn't a problem that affects you!
Ok, here's the cock-eyed solution I've used on the two games I've done now:
At your command line (I'm a big Cygwin fan btw) type,
This will make a file that contains a lot of lines like,
Note the annoying colon. I now fire up this file in a text editor and do a find/replace all on ':' and just replace it with a space or some kind of whitespace. Save strbs.txt.
(I realise I could replace this step with a bit of fancy awk in the previous command, but I've forgotten 95% of the awk I did in uni...can anyone help me with this?)
My file now looks like
Ok, so this gives us a list of the addresses within the program that contain the strb instruction. Not really that useful... So we use an awesome tool named addr2line to sort this out.
At your command prompt, type:
This may take some time - be patient. Once you're done, strbs2.txt may contain such jollies as:
These are all the locations of the strb instruction within your elf. Go to these locations within your code and assess if it's going to be a problem, and if it is replace it with either a 16-bit read-modify-write or change your data types to be 16-bit or bigger.
As this isn't the only offending instruction, repeat for instructions such as strbeq and strbgt (or whatever the objdump syntax is) etc etc. You'll also find that gcc will often insert calls to memcpy and memset (it's in the gcc spec - I'll find a link at some point) so make sure you grep for these calls too.
Going through the list by hand and fixing the code is the best thing I can then think of doing. I'm sure a more automated solution would be better.
Hope this helps someone.
_________________
Big thanks to everyone who donated for Quake2
Here's my mini-howto to finding where 8-bit writes are in your elf. Requires awk and the ARM binutils. If you don't know what this means then this likely isn't a problem that affects you!
Ok, here's the cock-eyed solution I've used on the two games I've done now:
At your command line (I'm a big Cygwin fan btw) type,
Code: |
arm-eabi-objdump -d my_friend_the.elf | grep strb | awk '{print "0x"$1}' > strbs.txt |
This will make a file that contains a lot of lines like,
Quote: |
...
0x2023de8: 0x2023dec: 0x2023e20: 0x2023e38: 0x2023e3c: 0x2023e64: 0x2023ec0: 0x2023ec4: 0x2023ec8: 0x2023ecc: 0x2023ed0: 0x20247fc: ... |
Note the annoying colon. I now fire up this file in a text editor and do a find/replace all on ':' and just replace it with a space or some kind of whitespace. Save strbs.txt.
(I realise I could replace this step with a bit of fancy awk in the previous command, but I've forgotten 95% of the awk I did in uni...can anyone help me with this?)
My file now looks like
Quote: |
...
0x2023dec 0x2023e20 0x2023e38 0x2023e3c 0x2023e64 0x2023ec0 0x2023ec4 0x2023ec8 0x2023ecc 0x2023ed0 0x20247fc ... |
Ok, so this gives us a list of the addresses within the program that contain the strb instruction. Not really that useful... So we use an awesome tool named addr2line to sort this out.
At your command prompt, type:
Code: |
awk '{system("arm-eabi-addr2line -e im_in_love_with_an.elf " $1)}' strbs.txt | sort > strbs2.txt |
Quote: |
...
c:/devkitPro/dswifi/arm9/source/wifi_arm9.c:645 c:/devkitPro/dswifi/arm9/source/wifi_arm9.c:646 c:/devkitPro/dswifi/arm9/source/wifi_arm9.c:887 c:/devkitPro/dswifi/arm9/source/wifi_arm9.c:892 c:/devkitPro/dswifi/arm9/source/wifi_arm9.c:973 c:\Documents and Settings\Simon\workspace\debugger_remote/network_trans.c:135 c:\Documents and Settings\Simon\workspace\debugger_remote/network_trans.c:195 c:\devkitPro\libnds\include/nds/arm9/videoGL.h:1098 c:\devkitPro\libnds\include/nds/arm9/videoGL.h:1098 c:\devkitPro\libnds\include/nds/arm9/videoGL.h:1098 c:\devkitPro\libnds\include/nds/arm9/videoGL.h:1098 c:\devkitPro\libnds\include/nds/arm9/videoGL.h:1104 ... |
As this isn't the only offending instruction, repeat for instructions such as strbeq and strbgt (or whatever the objdump syntax is) etc etc. You'll also find that gcc will often insert calls to memcpy and memset (it's in the gcc spec - I'll find a link at some point) so make sure you grep for these calls too.
Going through the list by hand and fixing the code is the best thing I can then think of doing. I'm sure a more automated solution would be better.
Hope this helps someone.
_________________
Big thanks to everyone who donated for Quake2