finding & adding new functions - General Discussion and Assistance - CHDK Forum

finding & adding new functions

  • 5 Replies
  • 5462 Views
*

Offline fudgey

  • *****
  • 1705
  • a570is
finding & adding new functions
« on: 28 / July / 2008, 04:41:26 »
Advertisements
Hi...

I've been poking around the a570is firmware gdb disasembly, ARM assembler manual, chdk sources, the wiki and the forums to learn how to find and add Canon's functions to CHDK. My main target was to check if the firmware strings SSAPI::EnterToCompensationEVF and SSAPI::ExitFromCompensationEVF are functions and if they do what I wished them to do, add them to uBasic and use them in my MD script devel version to get rid of some ugly and unreliable keystrokes.

There seems to be some demand for documentation in this part, so I think I'll write down the steps it takes to the wiki some day soon. So far it's been a success, at least the Enter function did exactly what I want it when I replaced the uBasic shut_down command with it.

But to better understand what I did, I have one question: I added

Code: [Select]
stubs_entry_2.S:
NHSTUB(EnterToCompensationEVF, 0xFFEA4F84)

lolevel.h:
extern void _EnterToCompensationEVF(void);

platform.h:
void EnterToCompensationEVF(void);

platform/generic/wrappers.c:
void EnterToCompensationEVF(void)
{
  _EnterToCompensationEVF();
}

And that makes a function call EnterToCompensationEVF(); magically work from CHDK.

The question: What exactly is the deal with the underscore (_) i.e. what mechanism in the compiler tools takes the stub and links it with that lolevel.h prototype?


And another question: how come there are lsl instructions in some functions when they're running in arm mode? Or can arm mode use thumb mode instructions as well?

*

Offline DataGhost

  • ****
  • 314
  • EOS 40D, S5IS
    • DataGhost.com
Re: finding & adding new functions
« Reply #1 on: 28 / July / 2008, 04:59:29 »
I think it's some sort of defacto standard or maybe even formally documented somewhere, but the underscore preceding a function name usually means that that function is something lowlevel, lower-level than where you're calling it from, external or eh, just not really native to the program it's called from. In CHDK, whenever a function name is preceded by an underscore, it means that it directly calls a function in the Canon firmware, so we can use the real name somewhere else.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: finding & adding new functions
« Reply #2 on: 28 / July / 2008, 06:17:02 »
Quote
NHSTUB(EnterToCompensationEVF, 0xFFEA4F84)

After processing NHSTUB macro (stubs_asm.h):

    .globl _EnterToCompensationEVF
     _EnterToCompensationEVF:
     ldr  pc, =0xFFEA4F84
« Last Edit: 28 / July / 2008, 06:54:15 by ewavr »

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: finding & adding new functions
« Reply #3 on: 28 / July / 2008, 07:07:20 »
After processing NHSTUB macro (stubs_asm.h):

Ah there, thanks :)

*

Offline LjL

  • ****
  • 266
  • A720IS
Re: finding & adding new functions
« Reply #4 on: 28 / July / 2008, 08:40:39 »
The difference between NSTUB and NHSTUB?

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: finding & adding new functions
« Reply #5 on: 28 / July / 2008, 09:17:24 »
>diff NSTUB NHSTUB  :) :)

+++   .weak _##name

So, addresses of functions, defined in stubs_entry_2.S overrides addresses in stubs_entry.S

in C lang this is __attribute__((weak))
« Last Edit: 28 / July / 2008, 09:19:07 by ewavr »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal