Quote from: garloff on 07 / April / 2009, 14:51:43Quote from: reyalp on 23 / November / 2008, 02:07:47The wrappers are supposed to avoid this, by only calling ROM code from arm, never directly from thumb... that's why we have wrappers in the first place! But apparently GCC is assuming that in the 946e-s case, all code will return with BX LR and so optimizing away part of our wrapper.Can we tell gcc to not do this using some volatile annotations or so?If the rom code is not thumb safe, why doesn't we change the wrapperfromCode: [Select]#define NSTUB(name, addr)\ .globl _##name ;\ .weak _##name ;\ _##name: ;\ ldr pc, = ## addrtoCode: [Select]#define NSTUB(name, addr)\ .globl _##name ;\ .weak _##name ;\ _##name: ;\ push {lr} ;\ blx addr ;\ pop {lr} ;\ bx lr
Quote from: reyalp on 23 / November / 2008, 02:07:47The wrappers are supposed to avoid this, by only calling ROM code from arm, never directly from thumb... that's why we have wrappers in the first place! But apparently GCC is assuming that in the 946e-s case, all code will return with BX LR and so optimizing away part of our wrapper.Can we tell gcc to not do this using some volatile annotations or so?
The wrappers are supposed to avoid this, by only calling ROM code from arm, never directly from thumb... that's why we have wrappers in the first place! But apparently GCC is assuming that in the 946e-s case, all code will return with BX LR and so optimizing away part of our wrapper.
#define NSTUB(name, addr)\ .globl _##name ;\ .weak _##name ;\ _##name: ;\ ldr pc, = ## addr
#define NSTUB(name, addr)\ .globl _##name ;\ .weak _##name ;\ _##name: ;\ push {lr} ;\ blx addr ;\ pop {lr} ;\ bx lr
The stubs code is compiled as ARM not Thumb, wouldn't 'blx addr' switch to Thumb before jumping to the firmware address? Since the firmware is ARM wouldn't this crash?
The other problem is you can't guarantee that 'addr' is within the PC relative branch offset range - which is why the current stubs load a 32 bit value into PC.
QuoteThe other problem is you can't guarantee that 'addr' is within the PC relative branch offset range - which is why the current stubs load a 32 bit value into PC.BLX <constant> does not necessarily do what you want even if it is theoretically within a possible range. In some cases it doesn't even compile.
000b9d10 <_AllocateMemory2>: b9d10: e52de004 push {lr} ; (str lr, [sp, #-4]!) b9d14: eb004d27 bl cd1b8 <__*ABS*0xcfc01ab0_veneer> b9d18: e49de004 pop {lr} ; (ldr lr, [sp], #4) b9d1c: e12fff1e bx lr000cd1b8 <__*ABS*0xcfc01ab0_veneer>: cd1b8: e51ff004 ldr pc, [pc, #-4] ; cd1bc <__*ABS*0xcfc01ab0_veneer+0x4> cd1bc: cfc01ab0 .word 0xcfc01ab0
000ba400 <_readdir>: ba400: e52de004 push {lr} ; (str lr, [sp, #-4]!) ba404: faf902b2 blx ffefaed4 <*ABS*0xffefaed4> ba408: e49de004 pop {lr} ; (ldr lr, [sp], #4) ba40c: e12fff1e bx lr
You can LDR <reg>,=addr; BLX REG, but then you might as well just do LDR PC, =addr, since you are pushing and popping LR anyway.
Except that pushing LR isn't going to work: If your function expects more than 4 arguments, you'll have suddenly have LR sitting where one of them is expected. That won't end well.
000b5db4 <readdir>: b5db4: b508 push {r3, lr} b5db6: f003 ffab bl b9d10 <_readdir> b5dba: bd08 pop {r3, pc}
That's strange bl is used instead of blx (I need to investigate why) and r3 is saved.
#define NSTUB(name, addr)\ .globl _##name ;\ .align 2; \ .type _##name , %function; \ .weak _##name ;\ _##name: ;\ ldr pc, = ## addr
I tested with my binutils and if the jump is outside the 32 MB range, it generate an alternative code
That should need an extra mov to LR
QuoteExcept that pushing LR isn't going to work: If your function expects more than 4 arguments, you'll have suddenly have LR sitting where one of them is expected. That won't end well.Yes I forgot that. But after a quick look there no (or not too much) function with more than 4 arguments. So if could be acceptable to do special case for them.
I don't know enough the chdk code source, but if all the rom function are wrapped in wrappers.c, building it as thumb may solve the problem :
#define ROM_CALL(name, addr)\ .globl name ;\ .align 2; \ .type name , %function; \ name: ;\ tst lr, #1;\ pushne {lr}; \ movne lr, pc; \ ldr pc, = addr; \ pop {pc}#define NSTUB(name, addr)\ .weak _##name ;\ ROM_CALL(_##name, addr)#define NHSTUB(name, addr)\ ROM_CALL(_##name, addr)
_CreateTask_vsprintf_iosDrvInstall_ExecuteEventProcedure
grep -e _CreateTask -e _vsprintf -e _iosDrvInstall -e _ExecuteEventProcedure core/main.dump | grep -v ":$" | grep -v bl
PS : dryos rom seems to use bx/blx in its code.
short shooting_get_aperture_from_av96(short av96){ if (av96) return (short)((pow(sqrt2, ((double)av96)/96.0))*100.0); return -1;}
Started by PhyrePhoX « 1 2 » General Chat
Started by RaduP « 1 2 » General Discussion and Assistance
Started by PhyrePhoX General Chat
Started by RaduP General Discussion and Assistance
Started by msl « 1 2 ... 5 6 » General Discussion and Assistance