Up vote 1 down vote favorite 1 share g+ share fb share tw.
I'm trying to write a firmware mod (to existing firmware, for which I don't have source code) All Thumb code. Does anybody have any idea how to do this, in gcc as (GAS) assembler: Use BL without having to manually calculate offsets, when BL'ing to some existing function (not in my code.. but I know its address) Currently, if I want to use BL ...i have to : -go back in my code -figure out and add all the bytes that would result from assembling all the previous instructions in the function i'm writing -add the begining address of my function to that (i specify the starting address of what i'm writing, in the linker script) -and then substract the address of the firmfunc function I want to call All this... just to calculate the offset... to be able to write abl offset... to call an existing firmware function? And if I change any code before that BL, I have to do it all over again manually!
See.. this is why I want to learn to use BX right... instead of BL Also, I don't quite understand the BX. If I use BX to jump to an absolute address, do I have to increase the actual address by 1, when caling Thumb code from Thumb code (to keep the lsb byte 1)... and the CPU will know it's thumb code? Gcc arm gas link|improve this question edited Feb 20 at 21:05 asked Feb 19 at 11:19tintino465 100% accept rate.
BIG EDIT: Changing the answer based on what I have learned recently and a better understanding of the question First off I don't know how to tell the linker to generate a bl to an address that is a hardcoded address and not actually in this code. You might try to rig up an elf file that has labels and such but dummy or no code, don't know if that will fool the linker or not. You would have to modify the linker script as well.
Not worth it. Your other question that was spawned from this one: Arm/Thumb: using BX in Thumb code, to call a Thumb function, or to jump to a Thumb instruction in another function For branching this works just fine: LDR R6, =0x24000 ADD R6, #1 @ (set lsb to 1) BX R6 or save an instruction and just do this LDR R6, =0x24001 BX R6 if you want to branch link and you know the address and you are in thumb mode and want to get to thumb code then ldr r6,=0x24001 bl thumb_trampoline ;@returns here ... . Thumb_func thumb_trampoline: bx r6 And almost the exact same if you are starting in arm mode, and want to get to thumb code at an address you already know.
Ldr r6,=0x24001 bl arm_trampoline ;@returns here ... arm_trampoline: bx r6 You have to know that you can trash r6 in this way (make sure r6 isnt saving some value being used by some code that called this code). Very sorry misleading you with the other answer, I could swear that mov lr,pc pulled in the lsbit as a mode, but it doesnt.
Now if you look at the encoding for the instruction bl is relative not absolute, you can only branch to addresses relative to the program counter. This is a fixed word length instruction set, you will want to either use bx which allows mode switching but is limited to registers, use it as I have shown above or if possible based on the mode (maybe only works in arm mode) ldr pc,=function_name, which is a long branch and uses another word (like a variable word length instruction) but like bx is a branch not a branch link. – dwelch Feb 19 at 15:03 Thanks, for nice explanation.
But I would like to be able to BL to existing thumb functions in the firmware, for which I know the address. This way I don't have to mess with LR, but I don't know how to put this in assembler... or linker script... like if I do BL LABEL, I have to tell the assembler what address that LABEL is at... because it's not in my code... and don't know how to tell it that – tintino Feb 19 at 16:27 i'll accept the answer, it's good info ... still if anyone knows.. pls reply. There has to be a way.
How does the linker link to functions you import (external functions your code calls) - what directive to use for that in asm or linker script? – tintino Feb 19 at 16:35 ahh, I see what you are saying. Yeah some how you would need to have the linker know about a label with a specific address.
Don't know how to do that, you can uncheck my answer and let someone else try, no sweat... – dwelch Feb 19 at 21:20 1 MY THUMB TO ARM CODE IS BROKEN! It does no work this way, see this question instead stackoverflow.com/questions/9368360/… – dwelch Feb 197 at 0:24.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.