summaryrefslogtreecommitdiff
path: root/components/external/lua
diff options
context:
space:
mode:
author[email protected] <[email protected]>2012-11-22 03:39:22 +0000
committer[email protected] <[email protected]>2012-11-22 03:39:22 +0000
commit74bf69110ea5250a6ba795ab68ee067f19235150 (patch)
treee658bc4819565caeff06ee6e91f9f731b5e50c0c /components/external/lua
parent3968445d4a1ceece9cce84bd18ba56eeeb166a90 (diff)
add support of arm standard c library, support using armcc to compile lua
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2429 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/external/lua')
-rw-r--r--components/external/lua/README.TXT11
-rw-r--r--components/external/lua/lua/compiler.h43
-rw-r--r--components/external/lua/lua/lrotable.c7
-rw-r--r--components/external/lua/lua/lstring.c8
4 files changed, 57 insertions, 12 deletions
diff --git a/components/external/lua/README.TXT b/components/external/lua/README.TXT
index d983056198..beb1cec948 100644
--- a/components/external/lua/README.TXT
+++ b/components/external/lua/README.TXT
@@ -2,7 +2,7 @@
## 简介
RT-Thread中的Lua修改自[eLua](http://www.eluaproject.net/)的Lua-5.1.4版本。
-采用gcc工具链时,Lua依赖于newlib库,其它工具链暂时还不支持。
+采用gcc工具链时,Lua依赖于newlib库,采用keil时,Lua依赖于arm的标准c库。
启动lua的RAM占用情况
- 标准的lua 17.1904296875 KB
- 优化的lua 5.01953125 KB
@@ -24,11 +24,12 @@ RT-Thread中的Lua修改自[eLua](http://www.eluaproject.net/)的Lua-5.1.4版本
3.更多的配置项可以在luaconf.h中找到
## 开发相关
- - 采用gcc工具链时,依赖于newlib,需在rtconfig.h中定义RT_USING_NEWLIB
+ - 采用gcc工具链时,依赖于newlib,需在rtconfig.h中定义RT_USING_NEWLIB
+ 采用keil工具链时,依赖于arm的标准c库,需在rtconfig.h中定义RT_USING_ARM_LIBC
- 开启编译器对C99的支持,如MDK中,在C/C++选项的Misc Controls输入框中添加--c99
- - 需要在链接脚本中定义_stext和_etext,.ordata*放在两者之间。
- 用于判断数据是read-only和writable。MDK中如何实现??
- - 添加新的模块,参见lexample.c
+ - 使用gcc时,需要在链接脚本中定义_stext和_etext,.ordata*放在两者之间。用于判断数据是read-only和writable
+ 使用keil时,需要在分散加载文件中把rodata放在ER_IROM1区
+ - 添加新的模块,参见exlibs/lexamplelib.c
## 目录说明
- lua:从eLua获得Lua-5.1.4版本代码
diff --git a/components/external/lua/lua/compiler.h b/components/external/lua/lua/compiler.h
new file mode 100644
index 0000000000..9a73de99eb
--- /dev/null
+++ b/components/external/lua/lua/compiler.h
@@ -0,0 +1,43 @@
+/**
+ * define start/end address of ro data.
+ * different compiler with different implementation.
+ */
+
+#ifndef __COMPILER_H__
+#define __COMPILER_H__
+
+#if defined(__CC_ARM) // armcc
+
+#warning "Please check scatter file to ensure rodata is in ER_IROM1 region."
+
+/* symbols reference to the scatter file */
+extern char Image$$ER_IROM1$$Base;
+extern char Image$$ER_IROM1$$Limit;
+
+#define RODATA_START_ADDRESS (&Image$$ER_IROM1$$Base)
+#define RODATA_END_ADDRESS (&Image$$ER_IROM1$$Limit)
+
+#elif defined(__GNUC__) // gcc
+
+#warning "Please check linker script to ensure rodata is between _stext and _etext."
+
+/* symbols defined in linker script */
+extern char _stext;
+extern char _etext;
+
+#define RODATA_START_ADDRESS (&_stext)
+#define RODATA_END_ADDRESS (&_etext)
+
+#else // other compilers
+
+/* Firstly, modify rodata's start/end address. Then, comment the line below */
+#error "Please modify RODATA_START_ADDRESS and RODATA_END_ADDRESS below */
+
+/* Perhaps you can use start/end address of flash */
+#define RODATA_START_ADDRESS ((char*)0x08000000)
+#define RODATA_END_ADDRESS ((char*)0x08080000)
+
+#endif
+
+#endif // __COMPILER_H__
+
diff --git a/components/external/lua/lua/lrotable.c b/components/external/lua/lua/lrotable.c
index b8840346f9..c8a8688cca 100644
--- a/components/external/lua/lua/lrotable.c
+++ b/components/external/lua/lua/lrotable.c
@@ -126,9 +126,10 @@ void luaR_getcstr(char *dest, const TString *src, size_t maxsize) {
/* Return 1 if the given pointer is a rotable */
#ifdef LUA_META_ROTABLES
-extern char _stext;
-extern char _etext;
+
+#include "compiler.h"
+
int luaR_isrotable(void *p) {
- return &_stext <= ( char* )p && ( char* )p <= &_etext;
+ return RODATA_START_ADDRESS <= (char*)p && (char*)p <= RODATA_END_ADDRESS;
}
#endif
diff --git a/components/external/lua/lua/lstring.c b/components/external/lua/lua/lstring.c
index 83c0081545..b0c68115e6 100644
--- a/components/external/lua/lua/lstring.c
+++ b/components/external/lua/lua/lstring.c
@@ -100,14 +100,14 @@ static TString *luaS_newlstr_helper (lua_State *L, const char *str, size_t l, in
return newlstr(L, str, l, h, readonly); /* not found */
}
-extern char _stext;
-extern char _etext;
-
static int lua_is_ptr_in_ro_area(const char *p) {
#ifdef LUA_CROSS_COMPILER
return 0;
#else
- return p >= &_stext && p <= &_etext;
+
+#include "compiler.h"
+
+ return p >= RODATA_START_ADDRESS && p <= RODATA_END_ADDRESS;
#endif
}