Init functions a la Linux...
Posted: Sun Jan 14, 2007 4:43 pm
I'm trying to create a macro that would add the specified function to a special section in the object file, so that a "standard" function can execute all the initialization functions... Somewhat like module_init does in Linux kernel modules...
I tried many versions but none if them worked...
This first one doesn't work because inline assembly can only have input and output registers if it's inside a function...
One of the first I tried...
With the last one, INITIALIZER("This Function", funct_t_i_w_t_d) preprocesses as:
Which is more or less what I expected, and seems right... But them, if I try to produce assembly from that, gcc says:
I've also consulted linux include files but they are very confusing...
Do you know any simple solution that doesn't involve writing a separate (and smarter!) preprocessor?
Basically, what I want is a macro that adds to the section .init a string to be printed at execute time (before calling the function) and the address of the function (that will then be threated as a function pointer)...
And I would like to get read of that ".long" asm pseudo-op to something more portable (I'm not sure, but I suppose that the .long directive generates a doubleword in any architecture... what I really need is the address size)...
JJ
I tried many versions but none if them worked...
This first one doesn't work because inline assembly can only have input and output registers if it's inside a function...
Code: Select all
#define INITIALIZER(name, symbol); __asm__ ( \
".section .init\n" \
".asciiz \"" name "\"\n" \
".long %0\n" \
".section .text\n" \
: \
: "n" (&symbol) \
: )
Code: Select all
#define CHARACTER_THAT_QUOTES "
#define INITIALIZER(name, symbol); __asm__ ( \
".section .init\n" \
".asciiz \"" name "\"\n" \
".long $" CHARACTER_THAT_QUOTES symbol CHARACTER_THAT_QUOTES "\n" \
".section .text\n")
Code: Select all
__asm__ ( ".section .init\n" ".asciiz \"" "This Function" "\"\n" ".long $" " funct_t_i_w_t_d " "\n" ".section .text\n");
Code: Select all
In file included from exp.c:1:
Aldr_mod.h:21:56: warning: backslash-newline at end of file
exp.c:10: error: missing terminating " character
exp.c:10: error: expected ‘)’ before ‘funct_t_i_w_t_d’
exp.c:10: error: missing terminating " character
Do you know any simple solution that doesn't involve writing a separate (and smarter!) preprocessor?
Basically, what I want is a macro that adds to the section .init a string to be printed at execute time (before calling the function) and the address of the function (that will then be threated as a function pointer)...
And I would like to get read of that ".long" asm pseudo-op to something more portable (I'm not sure, but I suppose that the .long directive generates a doubleword in any architecture... what I really need is the address size)...
JJ