fixed mutex issue in memheap; fixed compiling issue in kservice.c when COMPILER is not defined; add finsh for win32 porting.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2365 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com
2012-10-22 03:12:21 +00:00
parent b45dfd0a15
commit 1c425607c3
6 changed files with 182 additions and 29 deletions
+18 -2
View File
@@ -27,10 +27,26 @@
* 2010-04-21 yi.qiu add list_module
* 2012-04-29 goprife improve the command line auto-complete feature.
* 2012-06-02 lgnq add list_memheap
* 2012-10-22 Bernard add MS VC++ patch.
*/
#include <rtthread.h>
#include "finsh.h"
#if defined(_MSC_VER)
static struct finsh_syscall* _next_syscall(struct finsh_syscall* call)
{
unsigned int *ptr;
ptr = (unsigned int*) (call + 1);
while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end))
ptr ++;
return (struct finsh_syscall*)ptr;
}
#define _NEXT_SYSCALl(index) index=_next_syscall(index)
#else
#define _NEXT_SYSCALl(index) index++
#endif
rt_inline unsigned int rt_list_len(const rt_list_t *l)
{
@@ -548,7 +564,7 @@ long list(void)
rt_kprintf("--Function List:\n");
{
struct finsh_syscall *index;
for (index = _syscall_table_begin; index < _syscall_table_end; index ++)
for (index = _syscall_table_begin; index < _syscall_table_end; _NEXT_SYSCALl(index))
{
#ifdef FINSH_USING_DESCRIPTION
rt_kprintf("%-16s -- %s\n", index->name, index->desc);
@@ -632,7 +648,7 @@ void list_prefix(char *prefix)
/* checks in system function call */
{
struct finsh_syscall* index;
for (index = _syscall_table_begin; index < _syscall_table_end; index ++)
for (index = _syscall_table_begin; index < _syscall_table_end; _NEXT_SYSCALl(index))
{
if (str_is_prefix(prefix, index->name) == 0)
{
+48 -2
View File
@@ -16,6 +16,11 @@
#include <rtthread.h>
#if defined(_MSC_VER)
#pragma section("FSymTab$f",read)
#pragma section("VSymTab",read)
#endif
/* -- the beginning of option -- */
#define FINSH_NAME_MAX 16 /* max length of identifier */
#define FINSH_NODE_MAX 16 /* max number of node */
@@ -119,6 +124,9 @@ struct finsh_syscall
#endif
syscall_func func; /* the function address of system call */
};
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
/* system call item */
struct finsh_syscall_item
{
@@ -132,6 +140,7 @@ extern struct finsh_syscall_item *global_syscall_list;
struct finsh_syscall* finsh_syscall_lookup(const char* name);
/* system variable table */
struct finsh_sysvar
{
const char* name; /* the name of variable */
@@ -141,6 +150,7 @@ struct finsh_sysvar
u_char type; /* the type of variable */
void* var ; /* the address of variable */
};
/* system variable item */
struct finsh_sysvar_item
{
@@ -163,6 +173,18 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
* @param name the name of function.
* @param desc the description of function, which will show in help.
*/
#ifdef _MSC_VER
#define FINSH_FUNCTION_EXPORT(name, desc) \
const char __fsym_##name##_name[] = #name; \
const char __fsym_##name##_desc[] = #desc; \
__declspec(allocate("FSymTab$f")) const struct finsh_syscall __fsym_##name = \
{ \
__fsym_##name##_name, \
__fsym_##name##_desc, \
(syscall_func)&name \
};
#pragma comment(linker, "/merge:FSymTab=mytext")
#else
#define FINSH_FUNCTION_EXPORT(name, desc) \
const char __fsym_##name##_name[] = #name; \
const char __fsym_##name##_desc[] = #desc; \
@@ -172,6 +194,7 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
__fsym_##name##_desc, \
(syscall_func)&name \
};
#endif
/**
* @ingroup finsh
@@ -182,6 +205,17 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
* @param alias the alias name of function.
* @param desc the description of function, which will show in help.
*/
#ifdef _MSC_VER
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) \
const char __fsym_##name##_name[] = #alias; \
const char __fsym_##name##_desc[] = #desc; \
__declspec(allocate("FSymTab$f")) const struct finsh_syscall __fsym_##name = \
{ \
__fsym_##name##_name, \
__fsym_##name##_desc, \
(syscall_func)&name \
};
#else
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) \
const char __fsym_##name##_name[] = #alias; \
const char __fsym_##name##_desc[] = #desc; \
@@ -191,7 +225,7 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
__fsym_##name##_desc, \
(syscall_func)&name \
};
#endif
/**
* @ingroup finsh
*
@@ -201,6 +235,18 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
* @param type the type of variable.
* @param desc the description of function, which will show in help.
*/
#ifdef _MSC_VER
#define FINSH_VAR_EXPORT(name, type, desc) \
const char __vsym_##name##_name[] = #name; \
const char __vsym_##name##_desc[] = #desc; \
__declspec(allocate("VSymTab")) const struct finsh_sysvar __vsym_##name = \
{ \
__vsym_##name##_name, \
__vsym_##name##_desc, \
type, \
(void*)&name \
};
#else
#define FINSH_VAR_EXPORT(name, type, desc) \
const char __vsym_##name##_name[] = #name; \
const char __vsym_##name##_desc[] = #desc; \
@@ -211,6 +257,7 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name);
type, \
(void*)&name \
};
#endif
#else
#define FINSH_FUNCTION_EXPORT(name, desc) \
const char __fsym_##name##_name[] = #name; \
@@ -369,5 +416,4 @@ void finsh_syscall_append(const char* name, syscall_func func);
*/
void finsh_sysvar_append(const char* name, u_char type, void* addr);
#endif
#endif
+16 -1
View File
@@ -83,12 +83,27 @@ void finsh_syscall_append(const char* name, syscall_func func)
}
#endif
#if defined(_MSC_VER)
static struct finsh_syscall* _next_syscall(struct finsh_syscall* call)
{
unsigned int *ptr;
ptr = (unsigned int*) (call + 1);
while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end))
ptr ++;
return (struct finsh_syscall*)ptr;
}
#define _NEXT_SYSCALL(index) index=_next_syscall(index)
#else
#define _NEXT_SYSCALL(index) index++
#endif
struct finsh_syscall* finsh_syscall_lookup(const char* name)
{
struct finsh_syscall* index;
struct finsh_syscall_item* item;
for (index = _syscall_table_begin; index < _syscall_table_end; index ++)
for (index = _syscall_table_begin; index < _syscall_table_end; _NEXT_SYSCALL(index))
{
if (strcmp(index->name, name) == 0)
return index;
+40
View File
@@ -304,7 +304,17 @@ rt_bool_t finsh_handle_history(struct finsh_shell* shell, char ch)
if (shell->use_history)
{
#if defined(_WIN32)
int i;
rt_kprintf("\r");
for(i=0; i<= 60; i++)
putchar(' ');
rt_kprintf("\r");
#else
rt_kprintf("\033[2K\r");
#endif
rt_kprintf("%s%s", FINSH_PROMPT, shell->line);
return RT_TRUE;;
}
@@ -459,6 +469,26 @@ void finsh_system_var_init(const void* begin, const void* end)
extern "asm" int __vsymtab_start;
extern "asm" int __vsymtab_end;
#endif
#elif defined(_MSC_VER)
#pragma section("FSymTab$a", read)
const char __fsym_begin_name[] = "__start";
const char __fsym_begin_desc[] = "begin of finsh";
__declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin =
{
__fsym_begin_name,
__fsym_begin_desc,
NULL
};
#pragma section("FSymTab$z", read)
const char __fsym_end_name[] = "__end";
const char __fsym_end_desc[] = "end of finsh";
__declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end =
{
__fsym_end_name,
__fsym_end_desc,
NULL
};
#endif
/*
@@ -493,6 +523,16 @@ void finsh_system_init(void)
#elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
finsh_system_var_init(&__vsymtab_start, &__vsymtab_end);
#elif defined(_MSC_VER)
unsigned int *ptr_begin, *ptr_end;
ptr_begin = (unsigned int*)&__fsym_begin; ptr_begin += (sizeof(struct finsh_syscall)/sizeof(unsigned int));
while (*ptr_begin == 0) ptr_begin ++;
ptr_end = (unsigned int*) &__fsym_end; ptr_end --;
while (*ptr_end == 0) ptr_end --;
finsh_system_function_init(ptr_begin, ptr_end);
#endif
#endif