diff options
| author | [email protected] <[email protected]> | 2012-10-22 03:12:21 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-10-22 03:12:21 +0000 |
| commit | 1c425607c3940e77e4d4893348bbc8d375004d37 (patch) | |
| tree | be4c944a906381f375c58d6317b0e51c2c0da9a5 /components | |
| parent | b45dfd0a157dc9c3f8e38d30608042e470118525 (diff) | |
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
Diffstat (limited to 'components')
| -rw-r--r-- | components/finsh/cmd.c | 20 | ||||
| -rw-r--r-- | components/finsh/finsh.h | 50 | ||||
| -rw-r--r-- | components/finsh/finsh_vm.c | 17 | ||||
| -rw-r--r-- | components/finsh/shell.c | 40 |
4 files changed, 122 insertions, 5 deletions
diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index d33cdebda8..8cd82c2d5f 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -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) { diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index 03a2e4778a..10ef09da0a 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -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 diff --git a/components/finsh/finsh_vm.c b/components/finsh/finsh_vm.c index 3214bed15e..c5b6dcf632 100644 --- a/components/finsh/finsh_vm.c +++ b/components/finsh/finsh_vm.c @@ -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; diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 601bf647f6..c10c193c9c 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -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 |
