diff options
| author | [email protected] <[email protected]> | 2011-09-28 02:10:43 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-09-28 02:10:43 +0000 |
| commit | 96049b7e5c2475f44f49fb1a25a8b06eba9fc231 (patch) | |
| tree | 645f06cc41b20a56d0113434058354153aeafb6a /src | |
| parent | 9bb329daee2f842a724d3cdede9413a839e5069c (diff) | |
add module support for cortex-m3 feature
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1731 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src')
| -rw-r--r-- | src/module.c | 433 | ||||
| -rw-r--r-- | src/module.h | 31 | ||||
| -rw-r--r-- | src/rtm.c | 542 |
3 files changed, 643 insertions, 363 deletions
diff --git a/src/module.c b/src/module.c index 4666419700..d61e1017e2 100644 --- a/src/module.c +++ b/src/module.c @@ -53,8 +53,10 @@ struct rt_page_info rt_uint32_t npage; }; +#ifdef RT_USING_SLAB static void *rt_module_malloc_page(rt_size_t npages); -static void rt_module_free_page(void *page_ptr, rt_size_t npages); +static void rt_module_free_page(rt_module_t module, void *page_ptr, rt_size_t npages); +#endif static rt_module_t rt_current_module = RT_NULL; static struct rt_semaphore mod_sem; @@ -157,21 +159,18 @@ rt_err_t rt_module_set(rt_module_t module) static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf32_Addr sym_val) { Elf32_Addr *where, tmp; - Elf32_Sword addend; + Elf32_Sword addend, offset; + rt_uint32_t upper, lower, sign, j1, j2; where = (Elf32_Addr *)((rt_uint8_t *)module->module_space + rel->r_offset); switch (ELF32_R_TYPE(rel->r_info)) { case R_ARM_NONE: break; - case R_ARM_ABS32: *where += (Elf32_Addr)sym_val; - RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_ABS32: %x -> %x\n", where, *where)); - break; - case R_ARM_PC24: case R_ARM_PLT32: case R_ARM_CALL: @@ -182,11 +181,12 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3 tmp = sym_val - (Elf32_Addr)where + (addend << 2); tmp >>= 2; *where = (*where & 0xff000000) | (tmp & 0x00ffffff); - RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_PC24: %x -> %x\n", where, *where)); - break; - + case R_ARM_REL32: + *where += sym_val - (Elf32_Addr)where; + RT_DEBUG_LOG(RT_DEBUG_MODULE,("R_ARM_REL32: %x -> %x, sym %x, offset %x\n", where, *where, sym_val, rel->r_offset)); + break; case R_ARM_V4BX: *where &= 0xf000000f; *where |= 0x01a0f000; @@ -194,18 +194,56 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3 case R_ARM_GLOB_DAT: case R_ARM_JUMP_SLOT: *where = (Elf32_Addr)sym_val; - RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_JUMP_SLOT: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); - - break; + break; +#if 0 /* To do */ + case R_ARM_GOT_BREL: + temp = (Elf32_Addr)sym_val; + *where = (Elf32_Addr)&temp; + RT_DEBUG_LOG(RT_DEBUG_MODULE, + ("R_ARM_GOT_BREL: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); + break; +#endif case R_ARM_RELATIVE: *where += (Elf32_Addr)sym_val; + //RT_DEBUG_LOG(RT_DEBUG_MODULE, + //("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); + break; + case R_ARM_THM_CALL: + case R_ARM_THM_JUMP24: + upper = *(rt_uint16_t *)where; + lower = *(rt_uint16_t *)((Elf32_Addr)where + 2); - RT_DEBUG_LOG(RT_DEBUG_MODULE, - ("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); - - break; + sign = (upper >> 10) & 1; + j1 = (lower >> 13) & 1; + j2 = (lower >> 11) & 1; + offset = (sign << 24) | ((~(j1 ^ sign) & 1) << 23) | + ((~(j2 ^ sign) & 1) << 22) | + ((upper & 0x03ff) << 12) | + ((lower & 0x07ff) << 1); + if (offset & 0x01000000) + offset -= 0x02000000; + offset += sym_val - (Elf32_Addr)where; + + if (!(offset & 1) || offset <= (rt_int32_t)0xff000000 || + offset >= (rt_int32_t)0x01000000) + { + rt_kprintf("only Thumb addresses allowed\n"); + return -1; + } + + sign = (offset >> 24) & 1; + j1 = sign ^ (~(offset >> 23) & 1); + j2 = sign ^ (~(offset >> 22) & 1); + *(rt_uint16_t *)where = (rt_uint16_t)((upper & 0xf800) | (sign << 10) | + ((offset >> 12) & 0x03ff)); + *(rt_uint16_t *)(where + 2) = (rt_uint16_t)((lower & 0xd000) | + (j1 << 13) | (j2 << 11) | + ((offset >> 1) & 0x07ff)); + upper = *(rt_uint16_t *)where; + lower = *(rt_uint16_t *)((Elf32_Addr)where + 2); + break; default: return -1; } @@ -311,44 +349,20 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module)) /*@}*/ #endif -/** - * This function will load a module from memory and create a thread for it - * - * @param name the name of module, which shall be unique - * @param module_ptr the memory address of module image - * - * @return the module object - * - */ -rt_module_t rt_module_load(const char *name, void *module_ptr) +static struct rt_module* _load_shared_object(const char* name, void* module_ptr) { rt_uint8_t *ptr = RT_NULL; rt_module_t module = RT_NULL; rt_bool_t linked = RT_FALSE; rt_uint32_t index, module_size = 0; - RT_DEBUG_NOT_IN_INTERRUPT; - - rt_kprintf("rt_module_load: %s ,", name); - - /* check ELF header */ - if (rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0) + RT_ASSERT(module_ptr != RT_NULL); + + if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0) { - /* rtmlinke finished */ + /* rtmlinker finished */ linked = RT_TRUE; } - else if (rt_memcmp(elf_module->e_ident, ELFMAG, SELFMAG) != 0) - { - rt_kprintf(" module magic error\n"); - return RT_NULL; - } - - /* check ELF class */ - if(elf_module->e_ident[EI_CLASS] != ELFCLASS32) - { - rt_kprintf(" module class error\n"); - return RT_NULL; - } /* get the ELF image size */ for (index = 0; index < elf_module->e_phnum; index++) @@ -408,9 +422,9 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset); /* locate .rel.plt and .rel.dyn section */ - symtab =(Elf32_Sym *)((rt_uint8_t *)module_ptr + shdr[shdr[index].sh_link].sh_offset); - strtab = (rt_uint8_t*)module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset; - nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel)); + symtab =(Elf32_Sym *) ((rt_uint8_t*)module_ptr + shdr[shdr[index].sh_link].sh_offset); + strtab = (rt_uint8_t*) module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset; + nr_reloc = (rt_uint32_t) (shdr[index].sh_size / sizeof(Elf32_Rel)); /* relocate every items */ for (i = 0; i < nr_reloc; i ++) @@ -420,14 +434,14 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) RT_DEBUG_LOG(RT_DEBUG_MODULE, ("relocate symbol %s shndx %d\n", strtab + sym->st_name, sym->st_shndx)); - if ((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL)) - rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value)); - else if (!linked) + if((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL)) + rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value)); + else if(!linked) { Elf32_Addr addr; RT_DEBUG_LOG(RT_DEBUG_MODULE, - ("unresolved relocate symbol: %s\n", strtab + sym->st_name)); + ("relocate symbol: %s\n", strtab + sym->st_name)); /* need to resolve symbol in kernel symbol table */ addr = rt_module_symbol_find((const char *)(strtab + sym->st_name)); @@ -450,6 +464,19 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) } } +#if 0 + for (index = 0; index < elf_module->e_shnum; index ++) + { + /* find .dynsym section */ + rt_uint8_t* shstrab = (rt_uint8_t*) module_ptr + shdr[elf_module->e_shstrndx].sh_offset; + if (rt_strcmp((const char *)(shstrab + shdr[index].sh_name), ELF_GOT) == 0) + { + rt_hw_set_got_base(module->module_space + shdr[index].sh_offset); + break; + } + } +#endif + /* construct module symbol table */ for (index = 0; index < elf_module->e_shnum; index ++) { @@ -489,8 +516,243 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) count ++; } } - } + } + + return module; +} + +static struct rt_module* _load_relocated_object(const char* name, void* module_ptr) +{ + rt_uint32_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0; + rt_uint32_t module_addr = 0, module_size = 0; + struct rt_module* module = RT_NULL; + rt_uint8_t *ptr, *strtab, *shstrab; + rt_bool_t linked = RT_FALSE; + + if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0) + { + /* rtmlinker finished */ + linked = RT_TRUE; + } + + /* get the ELF image size */ + for (index = 0; index < elf_module->e_shnum; index++) + { + /* text */ + if (IS_PROG(shdr[index]) && IS_AX(shdr[index])) + { + module_size += shdr[index].sh_size; + module_addr = shdr[index].sh_addr; + } + /* rodata */ + if (IS_PROG(shdr[index]) && IS_ALLOC(shdr[index])) + { + module_size += shdr[index].sh_size; + } + /* data */ + if (IS_PROG(shdr[index]) && IS_AW(shdr[index])) + { + module_size += shdr[index].sh_size; + } + /* bss */ + if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index])) + { + module_size += shdr[index].sh_size; + } + } + + /* no text, data and bss on image */ + if (module_size == 0) return RT_NULL; + + /* allocate module */ + module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, (const char*)name); + if (module == RT_NULL) return RT_NULL; + + /* allocate module space */ + module->module_space = rt_malloc(module_size); + if (module->module_space == RT_NULL) + { + rt_object_delete(&(module->parent)); + return RT_NULL; + } + + /* zero all space */ + ptr = module->module_space; + rt_memset(ptr, 0, module_size); + + /* load text and data section */ + for (index = 0; index < elf_module->e_shnum; index++) + { + /* load text section */ + if (IS_PROG(shdr[index]) && IS_AX(shdr[index])) + { + rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size); + RT_DEBUG_LOG(RT_DEBUG_MODULE,("load text 0x%x, size %d\n", ptr, shdr[index].sh_size)); + ptr += shdr[index].sh_size; + } + + /* load rodata section */ + if (IS_PROG(shdr[index]) && IS_ALLOC(shdr[index])) + { + rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size); + rodata_addr = (rt_uint32_t)ptr; + RT_DEBUG_LOG(RT_DEBUG_MODULE,("load rodata 0x%x, size %d, rodata 0x%x\n", ptr, shdr[index].sh_size, *(rt_uint32_t*)data_addr)); + ptr += shdr[index].sh_size; + } + + /* load data section */ + if (IS_PROG(shdr[index]) && IS_AW(shdr[index])) + { + rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size); + data_addr = (rt_uint32_t)ptr; + RT_DEBUG_LOG(RT_DEBUG_MODULE,("load data 0x%x, size %d, data 0x%x\n", ptr, shdr[index].sh_size, *(rt_uint32_t*)data_addr)); + ptr += shdr[index].sh_size; + } + + /* load bss section */ + if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index])) + { + rt_memset(ptr, 0, shdr[index].sh_size); + bss_addr = (rt_uint32_t)ptr; + RT_DEBUG_LOG(RT_DEBUG_MODULE,("load bss 0x%x, size %d,\n", ptr, shdr[index].sh_size)); + } + } + + /* set module entry */ + module->module_entry = (rt_uint8_t*)module->module_space + elf_module->e_entry - module_addr; + + /* handle relocation section */ + for (index = 0; index < elf_module->e_shnum; index ++) + { + if (IS_REL(shdr[index])) + { + rt_uint32_t i, nr_reloc; + Elf32_Sym *symtab; + Elf32_Rel *rel; + + /* get relocate item */ + rel = (Elf32_Rel *) ((rt_uint8_t*)module_ptr + shdr[index].sh_offset); + + /* locate .dynsym and .dynstr */ + symtab =(Elf32_Sym *) ((rt_uint8_t*)module_ptr + shdr[shdr[index].sh_link].sh_offset); + strtab = (rt_uint8_t*) module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset; + shstrab = (rt_uint8_t*) module_ptr + shdr[elf_module->e_shstrndx].sh_offset; + nr_reloc = (rt_uint32_t) (shdr[index].sh_size / sizeof(Elf32_Rel)); + + /* relocate every items */ + for (i = 0; i < nr_reloc; i ++) + { + Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)]; + RT_DEBUG_LOG(RT_DEBUG_MODULE,("relocate symbol: %s\n", strtab + sym->st_name)); + + if (sym->st_shndx != STN_UNDEF) + { + if((ELF_ST_TYPE(sym->st_info) == STT_SECTION) + || (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)) + { + if (rt_strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_RODATA, 8) == 0) + { + /* relocate rodata section */ + RT_DEBUG_LOG(RT_DEBUG_MODULE,("rodata\n")); + rt_module_arm_relocate(module, rel,(Elf32_Addr)(rodata_addr + sym->st_value)); + } + else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_BSS, 5) == 0) + { + /* relocate bss section */ + RT_DEBUG_LOG(RT_DEBUG_MODULE,("bss\n")); + rt_module_arm_relocate(module, rel, (Elf32_Addr)bss_addr + sym->st_value); + } + else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_DATA, 6) == 0) + { + /* relocate data section */ + RT_DEBUG_LOG(RT_DEBUG_MODULE,("data\n")); + rt_module_arm_relocate(module, rel, (Elf32_Addr)data_addr + sym->st_value); + } + } + } + else if(ELF_ST_TYPE(sym->st_info) == STT_FUNC ) + { + /* relocate function */ + rt_module_arm_relocate(module, rel, + (Elf32_Addr)((rt_uint8_t*)module->module_space - module_addr + sym->st_value)); + } + else + { + Elf32_Addr addr; + + if(ELF32_R_TYPE(rel->r_info) != R_ARM_V4BX) + { + RT_DEBUG_LOG(RT_DEBUG_MODULE,("relocate symbol: %s\n", strtab + sym->st_name)); + /* need to resolve symbol in kernel symbol table */ + addr = rt_module_symbol_find(strtab + sym->st_name); + if (addr != (Elf32_Addr)RT_NULL) + { + rt_module_arm_relocate(module, rel, addr); + RT_DEBUG_LOG(RT_DEBUG_MODULE,("symbol addr 0x%x\n", addr)); + } + else rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name); + } + else + { + rt_module_arm_relocate(module, rel, addr); + } + } + rel ++; + } + } + } + + return module; +} + +/** + * This function will load a module from memory and create a thread for it + * + * @param name the name of module, which shall be unique + * @param module_ptr the memory address of module image + * + * @return the module object + * + */ +rt_module_t rt_module_load(const char* name, void* module_ptr) +{ + rt_module_t module; + + RT_DEBUG_NOT_IN_INTERRUPT; + + rt_kprintf("rt_module_load: %s ,", name); + /* check ELF header */ + if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) != 0 + && rt_memcmp(elf_module->e_ident, ELFMAG, SELFMAG) != 0) + { + rt_kprintf(" module magic error\n"); + return RT_NULL; + } + + /* check ELF class */ + if(elf_module->e_ident[EI_CLASS] != ELFCLASS32) + { + rt_kprintf(" module class error\n"); + return RT_NULL; + } + + if(elf_module->e_type == ET_REL) + { + module = _load_relocated_object(name, module_ptr); + } + else if(elf_module->e_type == ET_DYN) + { + module = _load_shared_object(name, module_ptr); + } + else + { + rt_kprintf("unsupported elf type\n"); + return RT_NULL; + } + + if(module == RT_NULL) return RT_NULL; + /* init module object container */ rt_module_init_object_container(module); @@ -502,10 +764,12 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) /* init module memory allocator */ module->mem_list = RT_NULL; +#ifdef RT_USING_SLAB /* create page array */ module->page_array = (void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info)); module->page_cnt = 0; - +#endif + /* create module thread */ module->stack_size = 2048; module->thread_priority = 25; @@ -598,10 +862,11 @@ rt_module_t rt_module_open(const char *path) return RT_NULL; } - name = _strip_name(path); + //name = _strip_name(path); + name = path; module = rt_module_load(name, (void *)buffer); rt_free(buffer); - rt_free(name); + //rt_free(name); return module; } @@ -802,20 +1067,19 @@ rt_err_t rt_module_unload(rt_module_t module) } } - if (module->page_cnt > 0) +#ifdef RT_USING_SLAB + if(module->page_cnt > 0) { - int i; struct rt_page_info *page = (struct rt_page_info *)module->page_array; - rt_kprintf("warning: some module memory still hasn't be freed\n"); - - //list_memlist("tetris"); + rt_kprintf("warning: module memory still hasn't been free finished\n"); - for(i=0; i<module->page_cnt; i++) + while(module->page_cnt != 0) { - rt_module_free_page(page[i].page_ptr, page[i].npage); - } + rt_module_free_page(module, page[0].page_ptr, page[0].npage); + } } +#endif /* release module space memory */ rt_free(module->module_space); @@ -902,6 +1166,7 @@ static void *rt_module_malloc_page(rt_size_t npages) rt_current_module->page_cnt ++; RT_ASSERT(rt_current_module->page_cnt <= PAGE_COUNT_MAX); + rt_kprintf("rt_module_malloc_page 0x%x %d\n", chunk, npages); return chunk; } @@ -915,37 +1180,39 @@ static void *rt_module_malloc_page(rt_size_t npages) * * @note this function is used for RT-Thread Application Module */ -static void rt_module_free_page(void *page_ptr, rt_size_t npages) +static void rt_module_free_page(rt_module_t module, void *page_ptr, rt_size_t npages) { int i, index; struct rt_page_info *page; - //rt_kprintf("rt_module_free_page 0x%x %d\n", page_ptr, npages); + rt_kprintf("rt_module_free_page 0x%x %d\n", page_ptr, npages); rt_page_free(page_ptr, npages); - page = (struct rt_page_info *)rt_current_module->page_array; + page = (struct rt_page_info*)module->page_array; - for (i=0; i<rt_current_module->page_cnt; i++) + for(i=0; i<module->page_cnt; i++) { if (page[i].page_ptr == page_ptr) { if (page[i].npage == npages + 1) { page[i].page_ptr += npages * RT_MM_PAGE_SIZE / sizeof(rt_uint32_t); + page[i].npage -= npages; } - else if (page[i].npage == npages) - { - for (index=i; index<rt_current_module->page_cnt-1; index++) + else if(page[i].npage == npages) + { + for(index=i; index<module->page_cnt-1; index++) { page[index].page_ptr = page[index + 1].page_ptr; page[index].npage = page[index + 1].npage; } - page[rt_current_module->page_cnt - 1].page_ptr = RT_NULL; - page[rt_current_module->page_cnt - 1].npage = 0; + page[module->page_cnt - 1].page_ptr = RT_NULL; + page[module->page_cnt - 1].npage = 0; + + module->page_cnt--; } else RT_ASSERT(RT_FALSE); - - rt_current_module->page_cnt --; + rt_current_module->page_cnt--; return; } @@ -985,9 +1252,8 @@ void *rt_module_malloc(rt_size_t size) b->size = nunits; *prev = n; - //rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size); + rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size); rt_sem_release(&mod_sem); - //list_memlist("tetris"); return (void *)(b + 1); } @@ -997,7 +1263,7 @@ void *rt_module_malloc(rt_size_t size) *prev = b->next; rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size); - //list_memlist("tetris"); + rt_sem_release(&mod_sem); return (void *)(b + 1); } @@ -1035,7 +1301,7 @@ void rt_module_free(rt_module_t module, void *addr) RT_ASSERT(addr); RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0); - //rt_kprintf("rt_module_free 0x%x\n", addr); + rt_kprintf("rt_module_free 0x%x\n", addr); rt_sem_take(&mod_sem, RT_WAITING_FOREVER); @@ -1075,13 +1341,12 @@ void rt_module_free(rt_module_t module, void *addr) *prev = b->next; } - rt_module_free_page(b, npage); + rt_module_free_page(module, b, npage); } } /* unlock */ rt_sem_release(&mod_sem); - ////list_memlist("tetris"); return; } @@ -1107,7 +1372,7 @@ void rt_module_free(rt_module_t module, void *addr) } else *prev = n->next; - rt_module_free_page(n, npage); + rt_module_free_page(module, n, npage); } } else @@ -1117,7 +1382,6 @@ void rt_module_free(rt_module_t module, void *addr) /* unlock */ rt_sem_release(&mod_sem); - //list_memlist("tetris"); return; } @@ -1131,7 +1395,7 @@ void rt_module_free(rt_module_t module, void *addr) int npage = n->size * sizeof(struct rt_page_info) / RT_MM_PAGE_SIZE; if (npage > 0) { - rt_module_free_page(n, npage); + rt_module_free_page(module, n, npage); if (n->size % RT_MM_PAGE_SIZE != 0) { rt_size_t nunits = npage * RT_MM_PAGE_SIZE / sizeof(struct rt_mem_head); @@ -1155,7 +1419,6 @@ void rt_module_free(rt_module_t module, void *addr) /* unlock */ rt_sem_release(&mod_sem); - //list_memlist("tetris"); } /* diff --git a/src/module.h b/src/module.h index d50d3d364f..c35a7723fe 100644 --- a/src/module.h +++ b/src/module.h @@ -56,6 +56,12 @@ typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ (ehdr).e_ident[EI_MAG3] == ELFMAG3) +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Relocatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ + /* ELF Header */ typedef struct elfhdr { @@ -148,6 +154,7 @@ typedef struct elf32_sym #define STT_LOPROC 13 /* processor specific range */ #define STT_HIPROC 15 +#define STN_UNDEF 0 /* undefined */ #define ELF_ST_BIND(info) ((info) >> 4) #define ELF_ST_TYPE(info) ((info) & 0xf) @@ -176,16 +183,20 @@ typedef struct /* * Relocation type for arm */ -#define R_ARM_NONE 0 -#define R_ARM_PC24 1 -#define R_ARM_ABS32 2 -#define R_ARM_GLOB_DAT 21 -#define R_ARM_JUMP_SLOT 22 -#define R_ARM_RELATIVE 23 -#define R_ARM_PLT32 27 -#define R_ARM_CALL 28 -#define R_ARM_JUMP24 29 -#define R_ARM_V4BX 40 +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_THM_CALL 10 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_RELATIVE 23 +#define R_ARM_GOT_BREL 26 +#define R_ARM_PLT32 27 +#define R_ARM_CALL 28 +#define R_ARM_JUMP24 29 +#define R_ARM_THM_JUMP24 30 +#define R_ARM_V4BX 40 /* Program Header */ typedef struct @@ -1,268 +1,274 @@ -/* - * File : rtm.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2010-04-12 yi.qiu first version - */ - -#include <rtthread.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -/* some buildin kernel symbol */ - -#ifdef RT_USING_MODULE -#include <rtm.h> - -RTM_EXPORT(rt_object_get_information); - -/* - * thread interface symbol - */ - -RTM_EXPORT(rt_thread_init); -RTM_EXPORT(rt_thread_detach); -RTM_EXPORT(rt_thread_create); -RTM_EXPORT(rt_thread_self); -RTM_EXPORT(rt_thread_find); -RTM_EXPORT(rt_thread_startup); -RTM_EXPORT(rt_thread_delete); -RTM_EXPORT(rt_thread_yield); -RTM_EXPORT(rt_thread_delay); -RTM_EXPORT(rt_thread_control); -RTM_EXPORT(rt_thread_suspend); -RTM_EXPORT(rt_thread_resume); -RTM_EXPORT(rt_thread_timeout); - -#ifdef RT_USING_SEMAPHORE -/* - * semaphore interface symbol - */ -RTM_EXPORT(rt_sem_init); -RTM_EXPORT(rt_sem_detach); -RTM_EXPORT(rt_sem_create); -RTM_EXPORT(rt_sem_delete); -RTM_EXPORT(rt_sem_take); -RTM_EXPORT(rt_sem_trytake); -RTM_EXPORT(rt_sem_release); -RTM_EXPORT(rt_sem_control); -#endif - -#ifdef RT_USING_MUTEX -/* - * mutex interface symbol - */ -RTM_EXPORT(rt_mutex_init); -RTM_EXPORT(rt_mutex_detach); -RTM_EXPORT(rt_mutex_create); -RTM_EXPORT(rt_mutex_delete); -RTM_EXPORT(rt_mutex_take); -RTM_EXPORT(rt_mutex_release); -RTM_EXPORT(rt_mutex_control); -#endif - -#ifdef RT_USING_EVENT -/* - * event interface symbol - */ -RTM_EXPORT(rt_event_init); -RTM_EXPORT(rt_event_detach); -RTM_EXPORT(rt_event_create); -RTM_EXPORT(rt_event_delete); -RTM_EXPORT(rt_event_send); -RTM_EXPORT(rt_event_recv); -RTM_EXPORT(rt_event_control); -#endif - -#ifdef RT_USING_MAILBOX -/* - * mailbox interface symbol - */ -RTM_EXPORT(rt_mb_init); -RTM_EXPORT(rt_mb_detach); -RTM_EXPORT(rt_mb_create); -RTM_EXPORT(rt_mb_delete); -RTM_EXPORT(rt_mb_send); -RTM_EXPORT(rt_mb_recv); -RTM_EXPORT(rt_mb_control); -#endif - -#ifdef RT_USING_MESSAGEQUEUE -/* - * message queue interface symbol - */ -RTM_EXPORT(rt_mq_init); -RTM_EXPORT(rt_mq_detach); -RTM_EXPORT(rt_mq_create); -RTM_EXPORT(rt_mq_delete); -RTM_EXPORT(rt_mq_send); -RTM_EXPORT(rt_mq_urgent); -RTM_EXPORT(rt_mq_recv); -RTM_EXPORT(rt_mq_control); -#endif - -#ifdef RT_USING_MEMPOOL -/* - * memory pool interface symbol - */ -RTM_EXPORT(rt_mp_init); -RTM_EXPORT(rt_mp_detach); -RTM_EXPORT(rt_mp_create); -RTM_EXPORT(rt_mp_delete); -RTM_EXPORT(rt_mp_alloc); -RTM_EXPORT(rt_mp_free); -#endif - -#ifdef RT_USING_HEAP -/* - * heap memory interface symbol - */ -RTM_EXPORT(rt_malloc); -RTM_EXPORT(rt_free); -RTM_EXPORT(rt_realloc); -RTM_EXPORT(rt_calloc); -#endif -/* - * clock & timer interface symbol - */ -RTM_EXPORT(rt_tick_get); -RTM_EXPORT(rt_tick_from_millisecond); -RTM_EXPORT(rt_system_timer_init); -RTM_EXPORT(rt_system_timer_thread_init); -RTM_EXPORT(rt_timer_init); -RTM_EXPORT(rt_timer_detach); -RTM_EXPORT(rt_timer_create); -RTM_EXPORT(rt_timer_delete); -RTM_EXPORT(rt_timer_start); -RTM_EXPORT(rt_timer_stop); -RTM_EXPORT(rt_timer_control); - -/* - * kservice interface symbol - */ -RTM_EXPORT(rt_memcpy); -RTM_EXPORT(rt_memcmp); -RTM_EXPORT(rt_memset); -RTM_EXPORT(rt_kprintf); -RTM_EXPORT(rt_sprintf); -RTM_EXPORT(rt_strstr); -RTM_EXPORT(rt_snprintf); - -/* - * misc interface symbol - */ -extern int __aeabi_idiv; -extern int __aeabi_ddiv; -extern int __aeabi_dmul; -extern int __aeabi_i2d; -extern int __aeabi_uidiv; -extern int __aeabi_uidivmod; -extern int __aeabi_idivmod; -extern int __aeabi_d2iz; - -RTM_EXPORT(__aeabi_ddiv); -RTM_EXPORT(__aeabi_dmul); -RTM_EXPORT(__aeabi_i2d); -RTM_EXPORT(__aeabi_uidiv); -RTM_EXPORT(__aeabi_idiv); -RTM_EXPORT(__aeabi_idivmod); -RTM_EXPORT(__aeabi_uidivmod); -RTM_EXPORT(__aeabi_d2iz); -RTM_EXPORT(strcmp); -RTM_EXPORT(strcpy); -RTM_EXPORT(strlen); -RTM_EXPORT(rand); -RTM_EXPORT(memset); -RTM_EXPORT(memcpy); - -#ifdef RT_USING_NEWLIB - -#include <unistd.h> -#include <assert.h> - -RTM_EXPORT(snprintf); -RTM_EXPORT(access); -RTM_EXPORT(__assert_func); - -#include <time.h> -RTM_EXPORT(localtime); -RTM_EXPORT(time); - -#endif - -#ifdef RT_USING_DFS -#include <dfs_posix.h> - -RTM_EXPORT(open); -RTM_EXPORT(close); -RTM_EXPORT(read); -RTM_EXPORT(write); -RTM_EXPORT(stat); -#endif - -#ifdef RT_USING_RTGUI -/* FIX ME , should be removed from here */ -#include <rtgui/dc.h> -#include <rtgui/rtgui_server.h> -#include <rtgui/rtgui_system.h> -#include <rtgui/widgets/view.h> -#include <rtgui/widgets/workbench.h> -#include <rtgui/widgets/widget.h> -#include <rtgui/widgets/button.h> -#include <rtgui/widgets/label.h> -#include <rtgui/widgets/list_view.h> -#include <rtgui/widgets/listctrl.h> -#include <rtgui/widgets/filelist_view.h> - -RTM_EXPORT(rtgui_label_create); -RTM_EXPORT(rtgui_view_show); -RTM_EXPORT(rtgui_view_create); -RTM_EXPORT(rtgui_view_destroy); -RTM_EXPORT(rtgui_view_event_handler); -RTM_EXPORT(rtgui_dc_draw_text); -RTM_EXPORT(rtgui_dc_begin_drawing); -RTM_EXPORT(rtgui_dc_end_drawing); -RTM_EXPORT(rtgui_workbench_event_loop); -RTM_EXPORT(rtgui_workbench_event_handler); -RTM_EXPORT(rtgui_workbench_add_view); -RTM_EXPORT(rtgui_workbench_create); -RTM_EXPORT(rtgui_workbench_destroy); -RTM_EXPORT(rtgui_workbench_close); -RTM_EXPORT(rtgui_timer_start); -RTM_EXPORT(rtgui_timer_create); -RTM_EXPORT(rtgui_timer_destory); -RTM_EXPORT(rtgui_timer_stop); -RTM_EXPORT(rtgui_thread_register); -RTM_EXPORT(rtgui_thread_deregister); -RTM_EXPORT(rtgui_widget_focus); -RTM_EXPORT(rtgui_widget_set_event_handler); -RTM_EXPORT(rtgui_widget_rect_to_device); -RTM_EXPORT(rtgui_widget_update); -RTM_EXPORT(rtgui_widget_get_rect); -RTM_EXPORT(rtgui_widget_set_rect); -RTM_EXPORT(rtgui_widget_get_toplevel); -RTM_EXPORT(rtgui_panel_register); -RTM_EXPORT(rtgui_panel_set_default_focused); -RTM_EXPORT(rtgui_button_create); -RTM_EXPORT(rtgui_button_destroy); -RTM_EXPORT(rtgui_button_set_onbutton); -RTM_EXPORT(rtgui_container_add_child); -RTM_EXPORT(rtgui_filelist_view_create); -RTM_EXPORT(rtgui_filelist_view_get_fullpath); -RTM_EXPORT(rtgui_list_view_create); -RTM_EXPORT(rtgui_list_view_destroy); -RTM_EXPORT(rtgui_listctrl_set_onitem); -RTM_EXPORT(rtgui_image_create_from_mem); -RTM_EXPORT(rtgui_listctrl_create); - -#endif -#endif - +/*
+ * File : rtm.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-04-12 yi.qiu first version
+ */
+
+#include <rtthread.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+/* some buildin kernel symbol */
+
+#ifdef RT_USING_MODULE
+#include <rtm.h>
+
+RTM_EXPORT(rt_object_get_information);
+
+/*
+ * thread interface symbol
+ */
+
+RTM_EXPORT(rt_thread_init);
+RTM_EXPORT(rt_thread_detach);
+RTM_EXPORT(rt_thread_create);
+RTM_EXPORT(rt_thread_self);
+RTM_EXPORT(rt_thread_find);
+RTM_EXPORT(rt_thread_startup);
+RTM_EXPORT(rt_thread_delete);
+RTM_EXPORT(rt_thread_yield);
+RTM_EXPORT(rt_thread_delay);
+RTM_EXPORT(rt_thread_control);
+RTM_EXPORT(rt_thread_suspend);
+RTM_EXPORT(rt_thread_resume);
+RTM_EXPORT(rt_thread_timeout);
+
+#ifdef RT_USING_SEMAPHORE
+/*
+ * semaphore interface symbol
+ */
+RTM_EXPORT(rt_sem_init);
+RTM_EXPORT(rt_sem_detach);
+RTM_EXPORT(rt_sem_create);
+RTM_EXPORT(rt_sem_delete);
+RTM_EXPORT(rt_sem_take);
+RTM_EXPORT(rt_sem_trytake);
+RTM_EXPORT(rt_sem_release);
+RTM_EXPORT(rt_sem_control);
+#endif
+
+#ifdef RT_USING_MUTEX
+/*
+ * mutex interface symbol
+ */
+RTM_EXPORT(rt_mutex_init);
+RTM_EXPORT(rt_mutex_detach);
+RTM_EXPORT(rt_mutex_create);
+RTM_EXPORT(rt_mutex_delete);
+RTM_EXPORT(rt_mutex_take);
+RTM_EXPORT(rt_mutex_release);
+RTM_EXPORT(rt_mutex_control);
+#endif
+
+#ifdef RT_USING_EVENT
+/*
+ * event interface symbol
+ */
+RTM_EXPORT(rt_event_init);
+RTM_EXPORT(rt_event_detach);
+RTM_EXPORT(rt_event_create);
+RTM_EXPORT(rt_event_delete);
+RTM_EXPORT(rt_event_send);
+RTM_EXPORT(rt_event_recv);
+RTM_EXPORT(rt_event_control);
+#endif
+
+#ifdef RT_USING_MAILBOX
+/*
+ * mailbox interface symbol
+ */
+RTM_EXPORT(rt_mb_init);
+RTM_EXPORT(rt_mb_detach);
+RTM_EXPORT(rt_mb_create);
+RTM_EXPORT(rt_mb_delete);
+RTM_EXPORT(rt_mb_send);
+RTM_EXPORT(rt_mb_recv);
+RTM_EXPORT(rt_mb_control);
+#endif
+
+#ifdef RT_USING_MESSAGEQUEUE
+/*
+ * message queue interface symbol
+ */
+RTM_EXPORT(rt_mq_init);
+RTM_EXPORT(rt_mq_detach);
+RTM_EXPORT(rt_mq_create);
+RTM_EXPORT(rt_mq_delete);
+RTM_EXPORT(rt_mq_send);
+RTM_EXPORT(rt_mq_urgent);
+RTM_EXPORT(rt_mq_recv);
+RTM_EXPORT(rt_mq_control);
+#endif
+
+#ifdef RT_USING_MEMPOOL
+/*
+ * memory pool interface symbol
+ */
+RTM_EXPORT(rt_mp_init);
+RTM_EXPORT(rt_mp_detach);
+RTM_EXPORT(rt_mp_create);
+RTM_EXPORT(rt_mp_delete);
+RTM_EXPORT(rt_mp_alloc);
+RTM_EXPORT(rt_mp_free);
+#endif
+
+#ifdef RT_USING_HEAP
+/*
+ * heap memory interface symbol
+ */
+RTM_EXPORT(rt_malloc);
+RTM_EXPORT(rt_free);
+RTM_EXPORT(rt_realloc);
+RTM_EXPORT(rt_calloc);
+#endif
+/*
+ * clock & timer interface symbol
+ */
+RTM_EXPORT(rt_tick_get);
+RTM_EXPORT(rt_tick_from_millisecond);
+RTM_EXPORT(rt_system_timer_init);
+RTM_EXPORT(rt_system_timer_thread_init);
+RTM_EXPORT(rt_timer_init);
+RTM_EXPORT(rt_timer_detach);
+RTM_EXPORT(rt_timer_create);
+RTM_EXPORT(rt_timer_delete);
+RTM_EXPORT(rt_timer_start);
+RTM_EXPORT(rt_timer_stop);
+RTM_EXPORT(rt_timer_control);
+
+/*
+ * kservice interface symbol
+ */
+RTM_EXPORT(rt_memcpy);
+RTM_EXPORT(rt_memcmp);
+RTM_EXPORT(rt_memset);
+RTM_EXPORT(rt_kprintf);
+RTM_EXPORT(rt_sprintf);
+RTM_EXPORT(rt_strstr);
+RTM_EXPORT(rt_snprintf);
+
+/*
+ * misc interface symbol
+ */
+extern int __aeabi_idiv;
+extern int __aeabi_ddiv;
+extern int __aeabi_dmul;
+extern int __aeabi_i2d;
+extern int __aeabi_uidiv;
+extern int __aeabi_uidivmod;
+extern int __aeabi_idivmod;
+extern int __aeabi_d2iz;
+
+RTM_EXPORT(__aeabi_ddiv);
+RTM_EXPORT(__aeabi_dmul);
+RTM_EXPORT(__aeabi_i2d);
+RTM_EXPORT(__aeabi_uidiv);
+RTM_EXPORT(__aeabi_idiv);
+RTM_EXPORT(__aeabi_idivmod);
+RTM_EXPORT(__aeabi_uidivmod);
+RTM_EXPORT(__aeabi_d2iz);
+RTM_EXPORT(strcmp);
+RTM_EXPORT(strcpy);
+RTM_EXPORT(strlen);
+RTM_EXPORT(rand);
+RTM_EXPORT(memset);
+RTM_EXPORT(memcpy);
+
+#if defined(RT_USING_NEWLIB) && defined(RT_USING_PTHREADS)
+
+#include <unistd.h>
+
+RTM_EXPORT(printf);
+RTM_EXPORT(snprintf);
+RTM_EXPORT(access);
+RTM_EXPORT(__assert_func);
+
+#include <time.h>
+RTM_EXPORT(localtime);
+RTM_EXPORT(time);
+
+#include <math.h>
+RTM_EXPORT(sin);
+RTM_EXPORT(cos);
+
+#endif
+
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+
+RTM_EXPORT(open);
+RTM_EXPORT(close);
+RTM_EXPORT(read);
+RTM_EXPORT(write);
+RTM_EXPORT(stat);
+#endif
+
+#ifdef RT_USING_RTGUI
+/* FIX ME , should be removed from here */
+#include <rtgui/dc.h>
+#include <rtgui/rtgui_server.h>
+#include <rtgui/rtgui_system.h>
+#include <rtgui/widgets/view.h>
+#include <rtgui/widgets/workbench.h>
+#include <rtgui/widgets/widget.h>
+#include <rtgui/widgets/button.h>
+#include <rtgui/widgets/label.h>
+#include <rtgui/widgets/list_view.h>
+#include <rtgui/widgets/listctrl.h>
+#include <rtgui/widgets/filelist_view.h>
+
+RTM_EXPORT(rtgui_label_create);
+RTM_EXPORT(rtgui_view_show);
+RTM_EXPORT(rtgui_view_create);
+RTM_EXPORT(rtgui_view_destroy);
+RTM_EXPORT(rtgui_view_event_handler);
+RTM_EXPORT(rtgui_dc_draw_text);
+RTM_EXPORT(rtgui_dc_begin_drawing);
+RTM_EXPORT(rtgui_dc_end_drawing);
+RTM_EXPORT(rtgui_workbench_event_loop);
+RTM_EXPORT(rtgui_workbench_event_handler);
+RTM_EXPORT(rtgui_workbench_add_view);
+RTM_EXPORT(rtgui_workbench_create);
+RTM_EXPORT(rtgui_workbench_destroy);
+RTM_EXPORT(rtgui_workbench_close);
+RTM_EXPORT(rtgui_timer_start);
+RTM_EXPORT(rtgui_timer_create);
+RTM_EXPORT(rtgui_timer_destory);
+RTM_EXPORT(rtgui_timer_stop);
+RTM_EXPORT(rtgui_thread_register);
+RTM_EXPORT(rtgui_thread_deregister);
+RTM_EXPORT(rtgui_widget_focus);
+RTM_EXPORT(rtgui_widget_set_event_handler);
+RTM_EXPORT(rtgui_widget_rect_to_device);
+RTM_EXPORT(rtgui_widget_update);
+RTM_EXPORT(rtgui_widget_get_rect);
+RTM_EXPORT(rtgui_widget_set_rect);
+RTM_EXPORT(rtgui_widget_get_toplevel);
+RTM_EXPORT(rtgui_panel_register);
+RTM_EXPORT(rtgui_panel_set_default_focused);
+RTM_EXPORT(rtgui_button_create);
+RTM_EXPORT(rtgui_button_destroy);
+RTM_EXPORT(rtgui_button_set_onbutton);
+RTM_EXPORT(rtgui_container_add_child);
+RTM_EXPORT(rtgui_filelist_view_create);
+RTM_EXPORT(rtgui_filelist_view_get_fullpath);
+RTM_EXPORT(rtgui_list_view_create);
+RTM_EXPORT(rtgui_list_view_destroy);
+RTM_EXPORT(rtgui_listctrl_set_onitem);
+RTM_EXPORT(rtgui_image_create_from_mem);
+RTM_EXPORT(rtgui_listctrl_create);
+RTM_EXPORT(rtgui_listctrl_set_items);
+
+#endif
+#endif
+
|
