mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
add module feature
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@614 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -977,9 +977,4 @@ char *strdup(const char *s) __attribute__((weak, alias("rt_strdup")));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
#include <rtm.h>
|
||||
/* some buildin kernel symbol */
|
||||
RTM_EXPORT(rt_kprintf)
|
||||
#endif
|
||||
/*@}*/
|
||||
|
||||
+21
-11
@@ -19,6 +19,19 @@
|
||||
#include "module.h"
|
||||
#include "kservice.h"
|
||||
|
||||
/* #define RT_MODULE_DEBUG */
|
||||
|
||||
#define elf_module ((Elf32_Ehdr *)module_ptr)
|
||||
#define shdr ((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
|
||||
|
||||
#define IS_PROG(s) (s.sh_type == SHT_PROGBITS)
|
||||
#define IS_NOPROG(s) (s.sh_type == SHT_NOBITS)
|
||||
#define IS_REL(s) (s.sh_type == SHT_REL)
|
||||
#define IS_RELA(s) (s.sh_type == SHT_RELA)
|
||||
#define IS_ALLOC(s) (s.sh_flags == SHF_ALLOC)
|
||||
#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;
|
||||
@@ -55,17 +68,6 @@ rt_uint32_t rt_module_symbol_find(const rt_uint8_t* sym_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define elf_module ((Elf32_Ehdr *)module_ptr)
|
||||
#define shdr ((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
|
||||
|
||||
#define IS_PROG(s) (s.sh_type == SHT_PROGBITS)
|
||||
#define IS_NOPROG(s) (s.sh_type == SHT_NOBITS)
|
||||
#define IS_REL(s) (s.sh_type == SHT_REL)
|
||||
#define IS_RELA(s) (s.sh_type == SHT_RELA)
|
||||
#define IS_ALLOC(s) (s.sh_flags == SHF_ALLOC)
|
||||
#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))
|
||||
|
||||
int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr sym_val, rt_uint32_t module_addr)
|
||||
{
|
||||
Elf32_Addr *where, tmp;
|
||||
@@ -79,7 +81,9 @@ int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr
|
||||
|
||||
case R_ARM_ABS32:
|
||||
*where += (Elf32_Addr)sym_val;
|
||||
#ifdef RT_MODULE_DEBUG
|
||||
rt_kprintf("R_ARM_ABS32: %x -> %x\n", where, *where);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case R_ARM_PC24:
|
||||
@@ -92,7 +96,9 @@ int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr
|
||||
tmp = sym_val - (Elf32_Addr)where + (addend << 2);
|
||||
tmp >>= 2;
|
||||
*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
|
||||
#ifdef RT_MODULE_DEBUG
|
||||
rt_kprintf("R_ARM_PC24: %x -> %x\n", where, *where);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -275,7 +281,9 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
|
||||
for (i = 0; i < nr_reloc; i ++)
|
||||
{
|
||||
Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
|
||||
#ifdef RT_MODULE_DEBUG
|
||||
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)
|
||||
@@ -310,7 +318,9 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RT_MODULE_DEBUG
|
||||
rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name);
|
||||
#endif
|
||||
/* need to resolve symbol in kernel symbol table */
|
||||
Elf32_Addr addr = rt_module_symbol_find(strtab + sym->st_name);
|
||||
if (addr != (Elf32_Addr)RT_NULL)
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
|
||||
#include "kservice.h"
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
extern struct rt_module* rt_current_module;
|
||||
#endif
|
||||
|
||||
#define _OBJ_CONTAINER_LIST_INIT(c) \
|
||||
{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
|
||||
struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
|
||||
@@ -249,8 +253,14 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
|
||||
register rt_base_t temp;
|
||||
struct rt_object_information* information;
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
/* get module object information */
|
||||
information = (rt_current_module != RT_NULL) ?
|
||||
&rt_current_module->module_object[type] : &rt_object_container[type];
|
||||
#else
|
||||
/* get object information */
|
||||
information = &rt_object_container[type];
|
||||
#endif
|
||||
|
||||
object = (struct rt_object*)rt_malloc(information->object_size);
|
||||
if (object == RT_NULL)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* File : module.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 <rtm.h>
|
||||
|
||||
/* some buildin kernel symbol */
|
||||
|
||||
/* thread 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)
|
||||
|
||||
/* kservice symbol */
|
||||
RTM_EXPORT(rt_kprintf)
|
||||
@@ -35,6 +35,9 @@ rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
|
||||
struct rt_thread* rt_current_thread;
|
||||
|
||||
rt_uint8_t rt_current_priority;
|
||||
#ifdef RT_USING_MODULE
|
||||
extern struct rt_module* rt_current_module;
|
||||
#endif
|
||||
|
||||
#if RT_THREAD_PRIORITY_MAX > 32
|
||||
/* maximun priority level, 256 */
|
||||
@@ -260,6 +263,11 @@ void rt_schedule()
|
||||
from_thread = rt_current_thread;
|
||||
rt_current_thread = to_thread;
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
if(rt_current_thread->module_parent != RT_NULL)
|
||||
rt_current_module = rt_current_thread->module_parent;
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_HOOK
|
||||
if (rt_scheduler_hook != RT_NULL) rt_scheduler_hook(from_thread, to_thread);
|
||||
#endif
|
||||
|
||||
+10
-22
@@ -32,6 +32,10 @@ extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
|
||||
extern struct rt_thread* rt_current_thread;
|
||||
extern rt_uint8_t rt_current_priority;
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
extern struct rt_module* rt_current_module;
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
extern rt_list_t rt_thread_defunct;
|
||||
#endif
|
||||
@@ -78,7 +82,8 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
/* init module parent */
|
||||
thread->module_parent = RT_NULL;
|
||||
thread->module_parent =
|
||||
(rt_current_module != RT_NULL) ? rt_current_module : RT_NULL;
|
||||
#endif
|
||||
|
||||
/* init user data */
|
||||
@@ -228,12 +233,12 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
|
||||
static void rt_thread_exit()
|
||||
{
|
||||
struct rt_thread* thread;
|
||||
register rt_base_t temp;
|
||||
register rt_base_t temp;
|
||||
|
||||
/* disable interrupt */
|
||||
temp = rt_hw_interrupt_disable();
|
||||
/* disable interrupt */
|
||||
temp = rt_hw_interrupt_disable();
|
||||
|
||||
/* get current thread */
|
||||
/* get current thread */
|
||||
thread = rt_current_thread;
|
||||
|
||||
/* remove from schedule */
|
||||
@@ -628,21 +633,4 @@ rt_thread_t rt_thread_find(char* name)
|
||||
return thread;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_MODULE
|
||||
#include <rtm.h>
|
||||
/* some buildin kernel 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)
|
||||
#endif
|
||||
/*@}*/
|
||||
|
||||
Reference in New Issue
Block a user