1) __attribute__((section("section_name"))) fuctions: put the functions and datas into in the section pointed by "section_name" #define STR(x) (#x) #define ERIC_ATTRIB_SECTION(setction) __attribute__((section(setction))) #define ERIC_TAB_ENTRY( _name ) \ ERIC_ATTRIB_SECTION(".eric.table." STR(_name) ".data") 2)"#" and "##"
(1)"#" symbol convert a symbol to string. #define STR(x) (#x) (2)"##" symbol is used to connect the two symbols #define STR_LINK(x, y) (x##y)
3) how to use __asm__
__asm__ __volatile__( assembly language part: output part: input part: broken part: ) (1) we use ";" "\n" or "\n\t" to distinguish expression of the assembly language part we could use the following example to use __asm__
#define str(x) #x #define LAB(x) x
#define ERIC_TAB_BEGIN(label, name) \ __asm__(".section \".eric.table." str(name) ".begin\",\"aw\"\n" \ ".globl " str(LAB(label)) "\n" \ ".type " str(LAB(label)) ",object\n" \ ".p2align " str(LAB) "\n" \ str(LAB(_label)) ":\n" \ ".previous\n" \ ) 4) how to use above data struct (1)we use the ERIC_TAB_BEGIN to start a new read_write section and also we can use ERIC_TAB_END(.begin->.finish) to end a section (2)how to use the ERIC_TAB_ENTRY to install test a) we can define the following data struct struct lib_init_sturct{ unsigned int id; unsigned int p_id; int (*call_func)(void*); }; typedef struct lib_init_sturct lib_init_s; b) we can install the following func to install the function to the section #define LIB_INIT_ENTRY(__name, _id, _p_id, _call_func) \ static int _call_func(void* ptr); \ lib_init_s __name \ ERIC_TAB_ENTRY(eric_lib_init_table) = \ { .id = _id, \ .p_id = _p_id, \ .call_func = _call_func } such as: LIB_INIT_ENTRY(eric_table, 0x600, 0x20, eric_initiate_hw) (3) how to use the call the function in the section 1)we can define the following datastruct to define the section. ERIC_TABLE_BEGIN(_lib_init_table, eric_lib_init_table); ERIC_TABLE_END(_lib_init_table_end, eric_lib_init_table); extern lib_init_s _lib_init_table[]; extern lib_init_s _lib_init_table_end[]; 2)we can use the following codes to call the entry that installed in the section int init_eric_lib(unsigned int lib_id, unsigned int product_id, void* ptr) { lib_init_s* init = NULL; int result = -1; for (init = &_lib_init_table[0]; init != (lib_init_s*)&_lib_init_table_end; init++) { if (product_id == init->prod_id && lib_id == init->lib_id) { result = init->call_func(ptr); break; } } return result; }