diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/idle.c | 2 | ||||
| -rw-r--r-- | src/module.c | 121 | ||||
| -rw-r--r-- | src/module.h | 9 | ||||
| -rw-r--r-- | src/rtm.c | 129 |
4 files changed, 94 insertions, 167 deletions
diff --git a/src/idle.c b/src/idle.c index b5cccf1260..453f6bc409 100644 --- a/src/idle.c +++ b/src/idle.c @@ -97,7 +97,7 @@ static void rt_thread_idle_entry(void* parameter) /* if sub thread list and main thread are null */ if((module->module_thread == RT_NULL) && rt_list_isempty(&module->module_object[RT_Object_Class_Thread].object_list) && - (module->parent.flag & RT_MODULE_FLAG_AUTO_CLEAN)) + (module->module_info->module_type == RT_Module_Class_APP)) { /* unload module */ rt_module_unload(module); diff --git a/src/module.c b/src/module.c index 19fbd04fb2..decd8e6222 100644 --- a/src/module.c +++ b/src/module.c @@ -19,7 +19,8 @@ #include "module.h" #include "kservice.h" -/* #define RT_MODULE_DEBUG */ +#define RT_MODULE_DEBUG +#ifdef RT_USING_MODULE #define elf_module ((Elf32_Ehdr *)module_ptr) #define shdr ((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff)) @@ -32,10 +33,11 @@ #define IS_AX(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR)) #define IS_AW(s) ((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE)) -#ifdef RT_USING_MODULE rt_list_t rt_module_symbol_list; struct rt_module* rt_current_module; struct rt_module_symtab *_rt_module_symtab_begin = RT_NULL, *_rt_module_symtab_end = RT_NULL; +extern const struct rt_shell ishell; + void rt_system_module_init() { #ifdef __CC_ARM @@ -101,6 +103,11 @@ int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr #endif break; + case R_ARM_V4BX: + *where &= 0xf000000f; + *where |= 0x01a0f000; + break; + default: return -1; } @@ -174,7 +181,7 @@ static void rt_module_init_object_container(struct rt_module* module) struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) { - rt_uint32_t index, rodata_addr = 0, bss_addr = 0; + rt_uint32_t index, rodata_addr = 0, data_addr = 0, bss_addr = 0; rt_uint32_t module_addr = 0, module_size = 0; struct rt_module* module = RT_NULL; rt_uint8_t *ptr, *strtab, *shstrab; @@ -219,7 +226,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) /* allocate module */ module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, (const char*)name); - if (module == RT_NULL) return module; + if (module == RT_NULL) return RT_NULL; /* allocate module space */ module->module_space = rt_malloc(module_size); @@ -254,7 +261,8 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) /* load data section */ if (IS_PROG(shdr[index]) && IS_AW(shdr[index])) { - module->module_data = (rt_uint32_t)ptr; + data_addr = (rt_uint32_t)ptr; + rt_kprintf("data section address 0x%x\n", data_addr); rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size); ptr += shdr[index].sh_size; } @@ -263,6 +271,7 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index])) { bss_addr = (rt_uint32_t)ptr; + rt_kprintf("bss section address 0x%x\n", bss_addr); rt_memset(ptr, 0, shdr[index].sh_size); } } @@ -293,24 +302,35 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) { Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)]; #ifdef RT_MODULE_DEBUG - rt_kprintf("relocate symbol: %s\n", strtab + sym->st_name); + rt_kprintf("relocate symbol %s\n", strtab + sym->st_name); #endif if (sym->st_shndx != STN_UNDEF) { - if(ELF_ST_TYPE(sym->st_info) == STT_SECTION) + if((ELF_ST_TYPE(sym->st_info) == STT_SECTION) + || (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)) { + rt_kprintf("section name %s\n", shstrab + shdr[sym->st_shndx].sh_name); if (rt_strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_RODATA, 8) == 0) { /* relocate rodata section */ rt_module_arm_relocate(module, rel, - (Elf32_Addr)(rodata_addr), + (Elf32_Addr)(rodata_addr + sym->st_value), module_addr); } else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_BSS, 5) == 0) { /* relocate bss section */ - rt_module_arm_relocate(module, rel, (Elf32_Addr)bss_addr, module_addr); - } + rt_module_arm_relocate(module, rel, + (Elf32_Addr)bss_addr + sym->st_value, + module_addr); + } + else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_DATA, 6) == 0) + { + /* relocate bss section */ + rt_module_arm_relocate(module, rel, + (Elf32_Addr)data_addr + sym->st_value, + module_addr); + } } else if(ELF_ST_TYPE(sym->st_info) == STT_FUNC ) { @@ -319,25 +339,26 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) (Elf32_Addr)((rt_uint8_t*)module->module_space - module_addr + sym->st_value), module_addr); } - else if(ELF_ST_TYPE(sym->st_info) == STT_OBJECT) - { - /* relocate object in data section */ - rt_module_arm_relocate(module, rel, - (Elf32_Addr)(module->module_data + sym->st_value), - module_addr); - } } else { Elf32_Addr addr; + + if(ELF32_R_TYPE(rel->r_info) != R_ARM_V4BX) + { #ifdef RT_MODULE_DEBUG - rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name); + rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name); #endif - /* need to resolve symbol in kernel symbol table */ - addr = rt_module_symbol_find(strtab + sym->st_name); - if (addr != (Elf32_Addr)RT_NULL) + /* 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, module_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, module_addr); - else rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name); + } } rel ++; @@ -347,27 +368,50 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name) /* init module object container */ rt_module_init_object_container(module); - - /* set module defalut clean type */ - module->parent.flag |= RT_MODULE_FLAG_AUTO_CLEAN; - - /* create module main thread */ - module->module_thread = rt_thread_create((const char*)name, - module->module_entry, RT_NULL, - 512, 90, 10); - module->module_thread->module_parent = module; - rt_thread_startup(module->module_thread); + /* enter elf entry */ + ((elf_entry)module->module_entry)(&ishell, &module->module_info); return module; } +void rt_module_run(struct rt_module* module) +{ + struct rt_module_info *info; + + /* check parameter */ + RT_ASSERT(module != RT_NULL); + RT_ASSERT(module->module_info != RT_NULL); + + info = module->module_info; + if(info->module_type == RT_Module_Class_APP) + { + /* application */ + module->module_thread = rt_thread_create(module->parent.name, + module->module_entry, RT_NULL, + 512, 90, 10); + module->module_thread->module_parent = module; + rt_thread_startup(module->module_thread); + } + else if(info->module_type == RT_Module_Class_EXTENSION) + { + /* extension */ + } + else if(info->module_type == RT_Module_Class_SERVICE) + { + /* service */ + } +} + void rt_module_unload(struct rt_module* module) { int i; struct rt_object* object; struct rt_timer *timer; struct rt_list_node *list, *node; - + + /* check parameter */ + RT_ASSERT(module != RT_NULL); + /* suspend module main thread */ if (module->module_thread->stat == RT_THREAD_READY) rt_thread_suspend(module->module_thread); @@ -379,7 +423,16 @@ void rt_module_unload(struct rt_module* module) for (node = list->next; node != list; node = node->next) { object = rt_list_entry(node, struct rt_object, list); - rt_object_delete(object); + if (rt_object_is_systemobject(object) == RT_EOK) + { + /* detach static objcet */ + rt_object_detach(object); + } + else + { + /* delete dynamic object */ + rt_object_delete(object); + } } } diff --git a/src/module.h b/src/module.h index ae2e8b83a8..486e956b4f 100644 --- a/src/module.h +++ b/src/module.h @@ -155,11 +155,12 @@ typedef struct { * Relocation type for arm
*/
#define R_ARM_NONE 0
-#define R_ARM_PC24 1
+#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_ARM_PLT32 27
-#define R_ARM_CALL 28
-#define R_ARM_JUMP24 29
+#define R_ARM_CALL 28
+#define R_ARM_JUMP24 29
+#define R_ARM_V4BX 40
/* Program Header */
typedef struct {
@@ -202,4 +203,6 @@ typedef struct { /* Symbol table index */
#define STN_UNDEF 0 /* undefined */
+typedef rt_err_t (*elf_entry)( const void * env, struct rt_module_info **module_info;);
+
#endif
@@ -14,132 +14,3 @@ #include <rtthread.h>
#include <rtm.h>
-
-/* some buildin kernel symbol */
-#ifdef RT_USING_MODULE
-/*
- * 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_kprintf)
-
-#endif
|
