这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 嵌入式开发» MCU» VxWorks系统函数loadModule()程序示例[转帖]

共5条 1/1 1 跳转至

VxWorks系统函数loadModule()程序示例[转帖]

菜鸟
2003-07-03 21:51:40 打赏
铁峰:东北大学 计算机专业毕业。精通VxWorks系统编程,Win32系统编程,TCP/IP, SNMP协议。在嵌入式系统上开发了许多非常有价值的程序。 ---------------------------------------------------------------------------------------------------------------------- loadModule()在VxWorks中用来加载.o,.out文件,然后用moduleFindByName()来找到符号表中固定入口函数所在的位置。 可以参考usrLib.h和moduleLib.h来获得详细信息。 #include #include #include #include #include #include #include #include extern SYMTAB_ID sysSymTbl ; int loadTestModuleAndRun() { int fd = ERROR ; int status = ERROR ; MODULE_ID hModule ; FUNCPTR taskEntry = NULL ; SYM_TYPE * pType ; fd = open("/sd0/test.out",O_RDONLY,0) ; if (fd==ERROR) { printf("can not open binary file.\n") ; return ERROR ; } else { printf("binary file opened.\n") ; } if ((hModule=loadModule(fd,LOAD_ALL_SYMBOLS))==NULL) { printf("loadModule error = 0x%x.\n",errno) ; return ERROR; } close(fd) ; status = symFindByName(sysSymTbl,"test", (char **)&taskEntry,pType ) ; if (status==ERROR) { printf("symFindByName error=%d\n", errno) ; return ERROR; } else { /* Type N_ABS=2,N_TEXT=4,N_DATA=6,N_BSS=8;N_EXT=1 */ printf("taskEntryr=0x%x, type=%d\n.", (int)taskEntry,(int)*pType); } status = taskSpawn("test",100,0,30000,taskEntry,      0,0,0,0,0,0,0,0,0,0) ; if (status==ERROR) { printf("taskSpawn error=%d\n",errno) ; return ERROR; } return OK ; }



关键词: VxWorks 系统 函数 loadModule

菜鸟
2003-07-08 02:34:00 打赏
2楼
[quote][b]以下是引用[i]freetalk在2003-7-7 10:06:00[/i]的发言:[/b] 我的文件系统肯定是初始化成功的。 systembel是什么东东? 在哪里加? [/quote][upload=jpg]UploadFile/20037718334365679.jpg[/upload]

菜鸟
2003-11-17 18:58:00 打赏
3楼
Tornado工程配置存在问题 配置INCLUDE_LOADER后,没有调用实际初始化函数,prjConfig.c只有 void usrToolsInit (void) { moduleLibInit (); /* support library for the target-based loader. */ /* target loader */ 。。。 } 命令编译使用的usrConfig.c没有这问题, #ifdef INCLUDE_LOADER moduleLibInit (); /* initialize module manager */ #if defined(INCLUDE_AOUT) loadAoutInit (); /* use a.out format */ #else /* coff or ecoff */ #if defined(INCLUDE_ECOFF) loadEcoffInit (); /* use ecoff format */ #else /* ecoff */ #if defined(INCLUDE_COFF) loadCoffInit (); /* use coff format */ #else /* coff */ #if defined(INCLUDE_ELF) loadElfInit (); /* use elf format */ #else #if defined(INCLUDE_SOM_COFF) loadSomCoffInit (); #else #if defined(INCLUDE_PECOFF) { extern int loadPecoffInit(); loadPecoffInit (); } #endif #endif #endif #endif #endif #endif #endif /* INCLUDE_LOADER */ 如果目标模块为elf格式,prjConfig.c中代码应为 void usrToolsInit (void) { moduleLibInit (); /* support library for the target-based loader. */ loadElfInit(); /* target loader */ 。。。 } 但prjConfig.c是工程自动生成的,所以不能手动修改,改天我写个组件补丁 现在没有办法,只有在loadTestModuleAndRun前手动调用loadXXXInit(); 比如在usrAppInit()中。 ==================================== 至于errno=1835009,我没看到,不过原程序中有错误, 应该定义SYM_TYPE pType ; 若定义指针,需要为指针分配存储空间, 修改ptype相关语句,我使用前面mqchun 的代码,加载cobble.o,运行progStart binary file opened. taskEntryr=0x705b6c, type=5 . -> i tCosmos cosmos 6fdde4 200 READY b3fb0 6fdd94 0 0 tSchlep schlep 6f8e08 220 PEND 5c052 6f8dbc 0 0 tMonitor monitor 6eee50 230 READY 705ebe 6eee1c 0 0 tCrunch crunch 6f3e2c 240 READY 5c89e 6f3e04 0 0 ==================================== 关于wasuke的错误,参考下面贴出的Techtip Relocation value does not fit in 24 bits. loadModule error = 0x3d0001. [align=right][color=#000066][此贴子已经被作者于2003-11-17 11:17:57编辑过][/color][/align]

菜鸟
2003-11-17 19:20:00 打赏
4楼
Dynamic loading of modules fails with 24-bit relocation error. -------------------------------------------------------------------------------- SPR: N/A Patch: N/A -------------------------------------------------------------------------------- Host: N/A Architecture: PowerPC BSP: All Product: VxWorks Version: N/A -------------------------------------------------------------------------------- Problem Description Dynamic loading of object modules fails with the following error: Relocation value does not fit in 24 bits -------------------------------------------------------------------------------- Problem Solution PowerPC Embedded Application Binary Interface, Version 1.0 System V Application Binary Interface, PowerPC Processor Supplement (Sept. 1995) Reproduced failure on mv1604 board 64MB of RAM while loading an object module with external function references. The error message above is known to appear while loading modules with external function references on PowerPC targets having more than 32MB of RAM. The limitation is due to how direct function calls are implemented for the EABI (Embedded Application Binary Interface). The EABI is a standard we follow for the PowerPC architecture and it may be downloaded from the IBM web page. The EABI is based upon the SVR4 ABI, which suggests that all direct function calls be made with the 'bl' instruction. Because the addressing range of the 'bl' instruction is +/- 32MB, all direct function calls referencing functions defined more than 32MB away will fail with the above relocation error. Calling functions indirectly (i.e. through a function pointer) removes the 32MB limitation as 32-bit absolute addressing is used in place of 26-bit PC relative addressing, thus giving you access to all routines in the 4GB address space. Asking people to rewrite their code to make all external function calls through pointers is not very practical and may not be necessary in all cases. The following can be used to work around this problem. 1) Use the -mlongcall flag when compiling your code or use the "#pragma longcall" directive to suggest certain function calls be made through a function pointer. If using versions of Tornado 1.0.x there is a patch to use this workaround. The patch is SPR 22767. Later versions of Tornado do not require any patch. "#pragma longcall" gives a suggestion to the compiler to call a set of functions through a function pointer (using 32-bit absolute addresses). This should be used primarily for external functions, as local functions are less likely to reside far from your module. 2) If your code does not require constant loading and unloading of object modules at runtime, you can also set LOCAL_MEM_SIZE to 32MB and set aside the rest of memory as USER_RESERVED_MEM (i.e. user reserved memory) and use memAddToPool to add the rest after your object modules have been loaded. No further object modules should be loaded after the memAddToPool has been performed. Note: Setting aside user reserved memory is outlined in detail in Wind Tech Note 41 (WTN41). [align=right][color=#000066][此贴子已经被作者于2003-11-17 11:26:20编辑过][/color][/align]

菜鸟
2003-11-18 17:43:00 打赏
5楼
使用lkup “test” 显示 _test 还是 test

共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]