OBJLOADER Added
Andrew Lunn
andrew@lunn.ch
Fri Jul 8 20:16:00 GMT 2005
> I've been playing with it as well. I've now got an i386 relocator
> working on the synthetic target. I've also modified the test case a
> little so that it uses a romfs. The romfs is built as part of the
> build process and included into the test application.
And here is the patch.
I've not tested the build process on cygwin, so i would not be
supprised if it was broken....
Andrew
-------------- next part --------------
Index: services/objloader/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/ChangeLog,v
retrieving revision 1.1
diff -u -r1.1 ChangeLog
--- services/objloader/current/ChangeLog 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/ChangeLog 8 Jul 2005 20:13:12 -0000
@@ -1,3 +1,15 @@
+2005-07-08 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * include/objelf.h: Include hal_tables.h otherwise we get strange
+ linker errors.
+ * cdl/objloader.cdl: Rearranged the building of the test case.
+ * include/relocate_i386.h (New):
+ * src/relocate_i386.c (New): Added a relocator for i386.
+ * src/objelf.c: Fixed various Elf_Rel vs Elf_Rela issues.
+ * test/load_mods.c:
+ * test/library/hello.c: Modified to make use of the eCos test
+ infrastructure. Uses a romfs to hold the object file to be loaded.
+
2005-05-10 Anthony Tonizzo <atonizzo@lycos.com>
* include/elf.h:
Index: services/objloader/current/cdl/objloader.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/cdl/objloader.cdl,v
retrieving revision 1.1
diff -u -r1.1 objloader.cdl
--- services/objloader/current/cdl/objloader.cdl 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/cdl/objloader.cdl 8 Jul 2005 20:13:13 -0000
@@ -9,6 +9,7 @@
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
## Copyright (C) 2005 eCosCentric Ltd.
+## Copyright (C) 2005 Andrew Lunn
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
@@ -39,7 +40,7 @@
######DESCRIPTIONBEGIN####
#
# Author(s): atonizzo (atonizzo@lycos.com)
-# Contributors:
+# Contributors: Andrew Lunn
# Date: 2005-05-13
#
#####DESCRIPTIONEND####
@@ -51,7 +52,7 @@
description "This package provides support for loading and relocating
object files within eCos."
include_dir cyg/objloader
- include_files elf.h objelf.h loader_fs.h relocate_ppc.h
+ include_files elf.h objelf.h loader_fs.h relocate_ppc.h relocate_i386.h
compile objloader.c objelf.c loader_fs.c
requires CYGPKG_MEMALLOC
requires CYGPKG_IO_FILEIO
@@ -61,18 +62,39 @@
display "Architecture dependent settings"
flavor none
no_define
+ requires CYGINT_SERVICES_OBJLOADER_RELOCATOR == 1
+
description "Each of the options here enables the correct
relocation support for the architectures supported."
+ cdl_interface CYGINT_SERVICES_OBJLOADER_RELOCATOR {
+ display "Suitable function to perform a symbol relocation"
+ description "
+ For each architecture we need a function which relocate
+ a symbol. If we don't have a relocator the loader
+ cannot work."
+ }
+
cdl_option CYGBLD_OBJLOADER_ARCHITECTURE_POWERPC {
display "Support loading on PowerPC processors"
calculated CYGPKG_HAL_POWERPC
+ implements CYGINT_SERVICES_OBJLOADER_RELOCATOR
define_proc {
puts $::cdl_header "#include <cyg/objloader/relocate_ppc.h>"
}
compile relocate_ppc.c
}
+ cdl_option CYGBLD_OBJLOADER_ARCHITECTURE_I386 {
+ display "Support loading on I386 processors"
+ calculated CYGPKG_HAL_I386 || CYGPKG_HAL_SYNTH_I386
+ implements CYGINT_SERVICES_OBJLOADER_RELOCATOR
+ define_proc {
+ puts $::cdl_header "#include <cyg/objloader/relocate_i386.h>"
+ }
+ compile relocate_i386.c
+ }
+
# cdl_option CYGBLD_OBJLOADER_ARCHITECTURE_ARM {
# display "Support loading on ARM processors"
# calculated CYGPKG_HAL_ARM
@@ -129,36 +151,49 @@
}
}
- cdl_option CYGBLD_SERVICES_OBJLOADER_BUILD_TESTS {
- display "Build test library"
+ cdl_component CYGTST_SERVICES_OBJLOADER_BUILD_TESTS {
+ display "Build test library"
default_value 0
+ active_if CYGPKG_FS_ROM
+ active_if CYGINT_SERVICES_OBJLOADER_RELOCATOR
+ requires CYGBLD_FS_ROMFS_MK_ROMFS
no_define
- description "
+ description "
This option enables the building of a library and an
- application for testing the loader. These
- are not built by default since they do not use the dedicated
- testing infrastructure."
-
- make -priority 320 {
- <PREFIX>/bin/test_mods : <PACKAGE>/tests/test_mods.c
- @sh -c "mkdir -p tests $(dir $@)"
- $(CC) -c $(INCLUDE_PATH) -Wp,-MD,deps.tmp -I$(dir $<) $(CFLAGS) -o tests/test_mods.o $<
- @echo $@ ": \\" > $(notdir $@).deps
- @echo $(wildcard $(PREFIX)/lib/*) " \\" >> $(notdir $@).deps
- @tail -n +2 deps.tmp >> $(notdir $@).deps
- @echo >> $(notdir $@).deps
- @rm deps.tmp
- $(CC) $(LDFLAGS) -L$(PREFIX)/lib -Ttarget.ld -o $@ tests/test_mods.o
- }
-
+ application for testing the loader."
+
make -priority 320 {
- <PREFIX>/bin/hello.o : <PACKAGE>/tests/library/hello.c
- @sh -c "mkdir -p tests $(dir $@)"
+ tests/testromfs/hello.o : <PACKAGE>/tests/library/hello.c
+ @sh -c "mkdir -p tests tests/testromfs"
$(CC) -c $(INCLUDE_PATH) -I$(dir $<) $(CFLAGS) -o $@ $<
}
- }
+ make -priority 322 {
+ <PREFIX>/include/cyg/objloader/testromfs_be.h : tests/testromfs/hello.o
+ $(PREFIX)/bin/mk_romfs -b tests/testromfs testromfs_be.bin
+ @mkdir -p "$(dir $@)"
+ @sh $(PREFIX)/bin/file2c.tcl testromfs_be.bin testromfs_be.h
+ @cp testromfs_be.h $@
+ }
+
+ make -priority 322 {
+ <PREFIX>/include/cyg/objloader/testromfs_le.h : tests/testromfs/hello.o
+ $(PREFIX)/bin/mk_romfs tests/testromfs testromfs_le.bin
+ @mkdir -p "$(dir $@)"
+ @sh $(PREFIX)/bin/file2c.tcl testromfs_le.bin testromfs_le.h
+ @cp testromfs_le.h $@
+ }
+ cdl_option CYGPKG_OBJLOADER_TESTS {
+ display "Objloader tests"
+ flavor data
+ no_define
+ calculated { "tests/test_mods" }
+ description "
+ This option specifies the set of tests for the object
+ loader package"
+ }
+ }
}
# ====================================================================
Index: services/objloader/current/include/objelf.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/include/objelf.h,v
retrieving revision 1.1
diff -u -r1.1 objelf.h
--- services/objloader/current/include/objelf.h 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/include/objelf.h 8 Jul 2005 20:13:14 -0000
@@ -58,6 +58,7 @@
#include <pkgconf/system.h>
#include <pkgconf/objloader.h>
+#include <cyg/hal/hal_tables.h>
//==============================================================================
@@ -302,11 +303,11 @@
CYG_LDR_TABLE_ENTRY( cyg_mbox_peek_entry, \
"cyg_mbox_peek", cyg_mbox_peek ); \
CYG_LDR_TABLE_ENTRY( cyg_mbox_waiting_to_get_entry, \
- "cyg_mbox_waiting_to_get_item", \
- cyg_mbox_waiting_to_get_item ); \
+ "cyg_mbox_waiting_to_get", \
+ cyg_mbox_waiting_to_get ); \
CYG_LDR_TABLE_ENTRY( cyg_mbox_waiting_to_put_entry, \
- "cyg_mbox_waiting_to_put_item", \
- cyg_mbox_waiting_to_put_item );
+ "cyg_mbox_waiting_to_put", \
+ cyg_mbox_waiting_to_put );
#define CYG_LDR_TABLE_KAPI_MEMPOOL_FIX() \
CYG_LDR_TABLE_ENTRY( cyg_mempool_fix_create_entry, \
@@ -386,7 +387,7 @@
CYG_LDR_TABLE_ENTRY( cyg_semaphore_timed_wait_entry, \
"cyg_semaphore_timed_wait", cyg_semaphore_timed_wait ); \
CYG_LDR_TABLE_ENTRY( cyg_semaphore_try_wait_entry, \
- "cyg_semaphore_try_wait", cyg_semaphore_try_wait ); \
+ "cyg_semaphore_trywait", cyg_semaphore_trywait ); \
CYG_LDR_TABLE_ENTRY( cyg_semaphore_post_entry, \
"cyg_semaphore_post", cyg_semaphore_post ); \
CYG_LDR_TABLE_ENTRY( cyg_semaphore_peek_entry, \
@@ -426,12 +427,6 @@
"cyg_thread_get_stack_base", cyg_thread_get_stack_base ); \
CYG_LDR_TABLE_ENTRY( cyg_thread_get_stack_size_entry, \
"cyg_thread_get_stack_size", cyg_thread_get_stack_size ); \
-CYG_LDR_TABLE_ENTRY( cyg_thread_get_stack_usage_entry, \
- "cyg_thread_get_stack_usage", \
- cyg_thread_get_stack_usage ); \
-CYG_LDR_TABLE_ENTRY( cyg_thread_measure_stack_usage_entry, \
- "cyg_thread_measure_stack_usage", \
- cyg_thread_measure_stack_usage ); \
CYG_LDR_TABLE_ENTRY( cyg_thread_new_data_index_entry, \
"cyg_thread_new_data_index", cyg_thread_new_data_index ); \
CYG_LDR_TABLE_ENTRY( cyg_thread_free_data_index_entry, \
@@ -442,11 +437,7 @@
CYG_LDR_TABLE_ENTRY( cyg_thread_get_data_ptr_entry, \
"cyg_thread_get_data_ptr", cyg_thread_get_data_ptr ); \
CYG_LDR_TABLE_ENTRY( cyg_thread_set_data_entry, \
- "cyg_thread_set_data", cyg_thread_set_data ); \
-CYG_LDR_TABLE_ENTRY( cyg_thread_add_destructor_entry, \
- "cyg_thread_add_destructor", cyg_thread_add_destructor ); \
-CYG_LDR_TABLE_ENTRY( cyg_thread_rem_destructor_entry, \
- "cyg_thread_rem_destructor", cyg_thread_rem_destructor );
+ "cyg_thread_set_data", cyg_thread_set_data );
#define CYG_LDR_TABLE_STRING() \
CYG_LDR_TABLE_ENTRY( memchr_entry, "memchr", memchr ); \
@@ -484,7 +475,6 @@
CYG_LDR_TABLE_ENTRY( fopen_entry, "fopen", fopen ); \
CYG_LDR_TABLE_ENTRY( fprintf_entry, "fprintf", fprintf ); \
CYG_LDR_TABLE_ENTRY( fputc_entry, "fputc", fputc ); \
-CYG_LDR_TABLE_ENTRY( fputchar_entry, "fputchar", fputchar ); \
CYG_LDR_TABLE_ENTRY( fputs_entry, "fputs", fputs ); \
CYG_LDR_TABLE_ENTRY( fread_entry, "fread", fread ); \
CYG_LDR_TABLE_ENTRY( freopen_entry, "freopen", freopen ); \
@@ -493,16 +483,11 @@
CYG_LDR_TABLE_ENTRY( fsetpos_entry, "fsetpos", fsetpos ); \
CYG_LDR_TABLE_ENTRY( ftell_entry, "ftell", ftell ); \
CYG_LDR_TABLE_ENTRY( fwrite_entry, "fwrite", fwrite ); \
-CYG_LDR_TABLE_ENTRY( fgetc_entry, "fgetc", fgetc ); \
-CYG_LDR_TABLE_ENTRY( fgetchar_entry, "fgetchar", fgetchar ); \
-CYG_LDR_TABLE_ENTRY( fgets_entry, "fgets", fgets ); \
-CYG_LDR_TABLE_ENTRY( fgetw_entry, "fgetw", fgetw ); \
CYG_LDR_TABLE_ENTRY( perror_entry, "perror", perror ); \
CYG_LDR_TABLE_ENTRY( printf_entry, "printf", printf ); \
CYG_LDR_TABLE_ENTRY( putc_entry, "putc", putc ); \
CYG_LDR_TABLE_ENTRY( putchar_entry, "putchar", putchar ); \
CYG_LDR_TABLE_ENTRY( puts_entry, "puts", puts ); \
-CYG_LDR_TABLE_ENTRY( putw_entry, "putw", putw ); \
CYG_LDR_TABLE_ENTRY( remove_entry, "remove", remove ); \
CYG_LDR_TABLE_ENTRY( rename_entry, "rename", rename ); \
CYG_LDR_TABLE_ENTRY( rewind_entry, "rewind", rewind ); \
@@ -531,8 +516,6 @@
"diag_dump_buf_32bit", diag_dump_buf_32bit ); \
CYG_LDR_TABLE_ENTRY( diag_dump_buf_16bit_entry, \
"diag_dump_buf_16bit", diag_dump_buf_16bit ); \
-CYG_LDR_TABLE_ENTRY( __printf_fun_entry, \
- "__printf_fun", __printf_fun ); \
CYG_LDR_TABLE_ENTRY( diag_vdump_buf_with_offset_entry, \
"diag_vdump_buf_with_offset", \
diag_vdump_buf_with_offset ); \
@@ -554,4 +537,3 @@
//==============================================================================
#endif
-
Index: services/objloader/current/include/relocate_i386.h
===================================================================
RCS file: services/objloader/current/include/relocate_i386.h
diff -N services/objloader/current/include/relocate_i386.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ services/objloader/current/include/relocate_i386.h 8 Jul 2005 20:13:14 -0000
@@ -0,0 +1,71 @@
+#ifndef __RELOCATE_I386_H__
+#define __RELOCATE_I386_H__
+
+/* =================================================================
+ *
+ * relocate_i386.h
+ *
+ * Architecture dependent relocation routines for the i386
+ *
+ * =================================================================
+ * ####ECOSGPLCOPYRIGHTBEGIN####
+ * -------------------------------------------
+ * This file is part of eCos, the Embedded Configurable Operating
+ * System.
+ * Copyright (C) 2005 Andrew Lunn <andrew.lunn@ascom.ch>
+ *
+ * eCos is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 or (at your option)
+ * any later version.
+ *
+ * eCos is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with eCos; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * As a special exception, if other files instantiate templates or
+ * use macros or inline functions from this file, or you compile this
+ * file and link it with other works to produce a work based on this
+ * file, this file does not by itself cause the resulting work to be
+ * covered by the GNU General Public License. However the source code
+ * for this file must still be made available in accordance with
+ * section (3) of the GNU General Public License.
+ *
+ * This exception does not invalidate any other reasons why a work
+ * based on this file might be covered by the GNU General Public
+ * License.
+ *
+ * -------------------------------------------
+ * ####ECOSGPLCOPYRIGHTEND####
+ * =================================================================
+ * #####DESCRIPTIONBEGIN####
+ *
+ * Author(s): andrew.lunn@ascom.ch
+ * Date: 2005-07-07
+ * Purpose:
+ * Description:
+ *
+ * ####DESCRIPTIONEND####
+ *
+ * =================================================================
+ */
+
+#define Elf_Rel 0
+#define Elf_Rela 1
+
+#define ELF_ARCH_MACHINE_TYPE 3 // i386
+#define ELF_ARCH_ENDIANNESS ELFDATA2LSB
+#define ELF_ARCH_RELTYPE Elf_Rel
+
+#define R_386_32 1
+#define R_386_PC32 2
+
+void cyg_ldr_flush_cache( void );
+cyg_int32 cyg_ldr_relocate( cyg_int32, cyg_uint32, cyg_int32 );
+
+#endif //__RELOCATE_I386_H__
Index: services/objloader/current/src/objelf.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/src/objelf.c,v
retrieving revision 1.1
diff -u -r1.1 objelf.c
--- services/objloader/current/src/objelf.c 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/src/objelf.c 8 Jul 2005 20:13:15 -0000
@@ -171,12 +171,22 @@
{
sprintf( strname,
"%08X %08X ",
+#if ELF_ARCH_RELTYPE == Elf_Rela
p_rela[j].r_offset,
- p_rela[j].r_info );
+ p_rela[j].r_info
+#else
+ p_rel[j].r_offset,
+ p_rel[j].r_info
+#endif
+ );
diag_printf( strname );
-
+
+#if ELF_ARCH_RELTYPE == Elf_Rela
cyg_uint8 sym_type = ELF32_R_SYM( p_rela[j].r_info );
+#else
+ cyg_uint8 sym_type = ELF32_R_SYM( p_rel[j].r_info );
+#endif
if ( strlen ( p_strtab + p_symtab[sym_type].st_name ) > 0 )
diag_printf( p_strtab + p_symtab[sym_type].st_name );
else
@@ -220,7 +230,7 @@
return (void*)( addr + p_symtab[sym_index].st_value);
}
-static void
+void
*cyg_ldr_external_address( PELF_OBJECT p, cyg_uint32 sym_index )
{
cyg_uint8* tmp2;
Index: services/objloader/current/src/objloader.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/src/objloader.c,v
retrieving revision 1.1
diff -u -r1.1 objloader.c
--- services/objloader/current/src/objloader.c 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/src/objloader.c 8 Jul 2005 20:13:15 -0000
@@ -55,11 +55,11 @@
#include <cyg/infra/diag.h> // For diagnostic printing.
#include <cyg/infra/cyg_ass.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pkgconf/objloader.h>
+
#include <cyg/objloader/elf.h>
#include <cyg/objloader/objelf.h>
#include <cyg/objloader/loader_fs.h>
Index: services/objloader/current/src/relocate_i386.c
===================================================================
RCS file: services/objloader/current/src/relocate_i386.c
diff -N services/objloader/current/src/relocate_i386.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ services/objloader/current/src/relocate_i386.c 8 Jul 2005 20:13:15 -0000
@@ -0,0 +1,100 @@
+/* =================================================================
+ *
+ * relocate_i386.c
+ *
+ * Relocation types for the i386 processor.
+ *
+ * =================================================================
+ * ####ECOSGPLCOPYRIGHTBEGIN####
+ * -------------------------------------------
+ * This file is part of eCos, the Embedded Configurable Operating
+ * System.
+ * Copyright (C) 2005 eCosCentric LTD.
+ * Copyright (C) 2005 Andrew Lunn <andrew.lunn@ascom.ch>.
+ *
+ * eCos is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 or (at your option)
+ * any later version.
+ *
+ * eCos is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with eCos; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * As a special exception, if other files instantiate templates or
+ * use macros or inline functions from this file, or you compile this
+ * file and link it with other works to produce a work based on this
+ * file, this file does not by itself cause the resulting work to be
+ * covered by the GNU General Public License. However the source code
+ * for this file must still be made available in accordance with
+ * section (3) of the GNU General Public License.
+ *
+ * This exception does not invalidate any other reasons why a work
+ * based on this file might be covered by the GNU General Public
+ * License.
+ *
+ * -------------------------------------------
+ * ####ECOSGPLCOPYRIGHTEND####
+ * =================================================================
+ * #####DESCRIPTIONBEGIN####
+ *
+ * Author(s): atonizzo@lycos.com, andrew.lunn@ascom.ch
+ * Date: 2005-07-07
+ * Purpose:
+ * Description:
+ *
+ * ####DESCRIPTIONEND####
+ *
+ * =================================================================
+ */
+
+#include <cyg/infra/diag.h> // For diagnostic printing.
+#include <cyg/hal/hal_cache.h>
+#include <cyg/hal/hal_io.h>
+
+#include <pkgconf/objloader.h>
+#include <cyg/objloader/elf.h>
+#include <cyg/objloader/objelf.h>
+
+#if defined(CYGPKG_HAL_I386) || defined(CYGPKG_HAL_SYNTH_I386)
+void
+cyg_ldr_flush_cache( void )
+{
+ HAL_DCACHE_SYNC();
+ HAL_ICACHE_SYNC();
+}
+
+// in:
+//
+// sym_type Type of relocation to apply,
+// mem Address in memory to modify (relocate).
+// sym_value
+cyg_int32
+cyg_ldr_relocate( cyg_int32 sym_type, cyg_uint32 mem, cyg_int32 sym_value )
+{
+ cyg_int32 i;
+
+ // PPC uses rela, so we have to add the addend.
+ switch( sym_type )
+ {
+ case R_386_32:
+ HAL_READ_UINT32( mem , i );
+ HAL_WRITE_UINT32( mem, i + sym_value );
+ return 0;
+ case R_386_PC32:
+ HAL_READ_UINT32( mem , i );
+ HAL_WRITE_UINT32( mem, i + sym_value - mem );
+ return 0;
+ default:
+ ELFDEBUG( "FIXME: Unknown relocation value!!!\n" );
+ return -1;
+ }
+}
+#endif // CYGPKG_HAL_I386 || CYGPKG_HAL_SYNTH_I386
+
+
Index: services/objloader/current/tests/test_mods.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/tests/test_mods.c,v
retrieving revision 1.1
diff -u -r1.1 test_mods.c
--- services/objloader/current/tests/test_mods.c 7 Jul 2005 10:55:13 -0000 1.1
+++ services/objloader/current/tests/test_mods.c 8 Jul 2005 20:13:16 -0000
@@ -52,9 +52,10 @@
* =================================================================
*/
+#include <pkgconf/system.h>
#include <cyg/kernel/kapi.h> // Kernel API.
#include <cyg/infra/diag.h> // For diagnostic printing.
-#include <pkgconf/io_fileio.h>
+#include <cyg/infra/testcase.h>
#include <unistd.h>
#include <stdlib.h>
@@ -64,10 +65,32 @@
#include <dirent.h>
#include <stdio.h>
-#include <cyg/fileio/fileio.h>
#include <cyg/objloader/elf.h>
#include <cyg/objloader/objelf.h>
+#ifdef CYGPKG_IO_FILEIO
+#include <cyg/fileio/fileio.h>
+#endif
+
+// Test ROMFS data. Two example data files are generated so that
+// the test will work on both big-endian and little-endian targets.
+#if (CYG_BYTEORDER == CYG_LSBFIRST)
+# include <cyg/objloader/testromfs_le.h>
+#else
+# include <cyg/objloader/testromfs_be.h>
+#endif
+
+//==========================================================================
+
+MTAB_ENTRY( romfs_mte1,
+ "/",
+ "romfs",
+ "",
+ (CYG_ADDRWORD) &filedata[0] );
+
+
+//==========================================================================
+
#define THREAD_STACK_SIZE 8192
#define THREAD_PRIORITY 12
@@ -82,10 +105,12 @@
#define SHOW_RESULT( _fn, _res ) \
diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):"");
+int weak_fn_called = 0;
+
void weak_function( void )
{
- // Store the data value passed in for this thread.
- diag_printf( "This is the application function\n" );
+ CYG_TEST_PASS( "Applications weak function called" );
+ weak_fn_called++;
}
void (*thread_a)( cyg_addrword_t );
@@ -98,30 +123,36 @@
void* lib_handle;
void (*fn)( void );
- // It wouldn't be much of a basic example if some
- // kind of hello message wasn't output.
- diag_printf( "Hello eCos World!!!\n\n" );
+ CYG_TEST_INIT();
- err = mount( "/dev/disk0/1", "/", "fatfs" );
- if( err < 0 )
- SHOW_RESULT( mount, err );
+ CYG_TEST_INFO( "Object loader module test started" );
err = chdir( "/" );
+
if( err < 0 )
SHOW_RESULT( chdir, err );
lib_handle = cyg_ldr_open_library( (CYG_ADDRWORD)"/hello.o", 0 );
-// cyg_ldr_print_symbol_names( lib_handle );
-// cyg_ldr_print_rel_names( lib_handle );
+ CYG_TEST_CHECK( lib_handle , "Unable to load object file to load" );
+
fn = cyg_ldr_find_symbol( lib_handle, "print_message" );
+ CYG_TEST_CHECK( fn , "Unable to find print_message function" );
+
fn();
+
fn = cyg_ldr_find_symbol( lib_handle, "weak_function" );
+ CYG_TEST_CHECK( fn , "Unable to find weak_function" );
+
fn();
+ fn = cyg_ldr_find_symbol ( lib_handle, "unresolvable_symbol" );
+ CYG_TEST_CHECK( !fn , "Found none existing symbol!" );
+
thread_a = cyg_ldr_find_symbol( lib_handle, "thread_a" );
thread_b = cyg_ldr_find_symbol( lib_handle, "thread_b" );
-
- // Create our two threads.
+ CYG_TEST_CHECK( thread_a && thread_b , "Unable to find thread functions" );
+
+ // Create our two threads.
cyg_thread_create( THREAD_PRIORITY,
thread_a,
(cyg_addrword_t) 75,
@@ -143,65 +174,37 @@
// Resume the threads so they start when the scheduler begins.
cyg_thread_resume( thread_a_hdl );
cyg_thread_resume( thread_b_hdl );
+
+ cyg_scheduler_start();
}
// -----------------------------------------------------------------------------
// External symbols.
// -----------------------------------------------------------------------------
+CYG_LDR_TABLE_KAPI_ALARM()
+CYG_LDR_TABLE_KAPI_CLOCK()
+CYG_LDR_TABLE_KAPI_COND()
+CYG_LDR_TABLE_KAPI_COUNTER()
+CYG_LDR_TABLE_KAPI_EXCEPTIONS()
+CYG_LDR_TABLE_KAPI_FLAG()
+CYG_LDR_TABLE_KAPI_INTERRUPTS()
+CYG_LDR_TABLE_KAPI_MBOX()
+CYG_LDR_TABLE_KAPI_MEMPOOL_FIX()
+CYG_LDR_TABLE_KAPI_MEMPOOL_VAR()
+CYG_LDR_TABLE_KAPI_MUTEX()
+CYG_LDR_TABLE_KAPI_SCHEDULER()
+CYG_LDR_TABLE_KAPI_SEMAPHORE()
+CYG_LDR_TABLE_KAPI_THREAD()
+CYG_LDR_TABLE_STRING()
+CYG_LDR_TABLE_STDIO()
+CYG_LDR_TABLE_INFRA_DIAG()
+
+// Test case infrastructure function
+CYG_LDR_TABLE_ENTRY( cyg_test_output_entry, "cyg_test_output", cyg_test_output );
+CYG_LDR_TABLE_ENTRY( cyg_test_exit_entry, "cyg_test_exit", cyg_test_exit );
-// eCos semaphores
-CYG_LDR_TABLE_ENTRY( cyg_thread_delay_entry,
- "cyg_thread_delay",
- cyg_thread_delay );
-CYG_LDR_TABLE_ENTRY( cyg_semaphore_wait_entry,
- "cyg_semaphore_wait",
- cyg_semaphore_wait );
-CYG_LDR_TABLE_ENTRY( cyg_semaphore_init_entry,
- "cyg_semaphore_init",
- cyg_semaphore_init );
-CYG_LDR_TABLE_ENTRY( cyg_semaphore_post_entry,
- "cyg_semaphore_post",
- cyg_semaphore_post );
-
-// eCos mailboxes
-CYG_LDR_TABLE_ENTRY( cyg_mbox_put_entry, "cyg_mbox_put", cyg_mbox_put );
-
-// eCos Flags
-CYG_LDR_TABLE_ENTRY( cyg_flag_poll_entry, "cyg_flag_poll", cyg_flag_poll );
-CYG_LDR_TABLE_ENTRY( cyg_flag_setbits_entry,
- "cyg_flag_setbits",
- cyg_flag_setbits );
-
-// eCos misc
-CYG_LDR_TABLE_ENTRY( hal_delay_us_entry, "hal_delay_us", hal_delay_us );
-CYG_LDR_TABLE_ENTRY( cyg_assert_msg_entry, "cyg_assert_msg", cyg_assert_msg );
-CYG_LDR_TABLE_ENTRY( cyg_assert_fail_entry,
- "cyg_assert_fail",
- cyg_assert_fail );
-
-// memory
-CYG_LDR_TABLE_ENTRY( memcpy_entry, "memcpy", memcpy );
-CYG_LDR_TABLE_ENTRY( memset_entry, "memset", memset );
-CYG_LDR_TABLE_ENTRY( memcmp_entry, "memcmp", memcmp );
-CYG_LDR_TABLE_ENTRY( malloc_entry, "malloc", malloc );
-CYG_LDR_TABLE_ENTRY( free_entry, "free", free );
-
-// Strings
-CYG_LDR_TABLE_ENTRY( strcpy_entry, "strcpy", strcpy );
-CYG_LDR_TABLE_ENTRY( strcat_entry, "strcat", strcat );
-CYG_LDR_TABLE_ENTRY( sprintf_entry, "sprintf", sprintf );
-CYG_LDR_TABLE_ENTRY( strlen_entry, "strlen", strlen );
-CYG_LDR_TABLE_ENTRY( strcmp_entry, "strcmp", strcmp );
-CYG_LDR_TABLE_ENTRY( strncmp_entry, "strncmp", strncmp );
-
-// files
-CYG_LDR_TABLE_ENTRY( fopen_entry, "fopen", fopen );
-CYG_LDR_TABLE_ENTRY( fread_entry, "fread", fread );
-CYG_LDR_TABLE_ENTRY( fclose_entry, "fclose", fclose );
-CYG_LDR_TABLE_ENTRY( fseek_entry, "fseek", fseek );
-CYG_LDR_TABLE_ENTRY( stat_entry, "stat", stat );
-
-// Diagnostic printout
-CYG_LDR_TABLE_ENTRY( diag_printf_entry, "diag_printf", diag_printf );
-
+// Test function
CYG_LDR_TABLE_ENTRY( weak_function_entry, "weak_function", weak_function );
+
+// Test Variable
+CYG_LDR_TABLE_ENTRY( weak_fn_called_entry, "weak_fn_called", &weak_fn_called );
Index: services/objloader/current/tests/library/hello.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/objloader/current/tests/library/hello.c,v
retrieving revision 1.1
diff -u -r1.1 hello.c
--- services/objloader/current/tests/library/hello.c 7 Jul 2005 10:55:14 -0000 1.1
+++ services/objloader/current/tests/library/hello.c 8 Jul 2005 20:13:16 -0000
@@ -54,15 +54,19 @@
#include <cyg/kernel/kapi.h> // Kernel API.
#include <cyg/infra/diag.h> // For diagnostic printing.
+#include <cyg/infra/testcase.h>
cyg_sem_t sem_signal_thread;
int thread_a_count;
+extern int weak_fn_called;
+
void weak_function( void ) CYGBLD_ATTRIB_WEAK;
void weak_function( void )
{
// Store the data value passed in for this thread.
- diag_printf( "This is the library function\n" );
+ diag_printf( "INFO:< This is the library weak function>" );
+ CYG_TEST_FAIL ( "Libraries weak function called when apps should be called" );
}
void library_open( void )
@@ -70,20 +74,20 @@
// Initialize the count for thread a.
thread_a_count = 0;
- // Initialize the semaphore with a count of zero,
- // prior to creating the threads.
- cyg_semaphore_init( &sem_signal_thread, 0 );
- diag_printf( "Library initialized...\n" );
+ // Initialize the semaphore with a count of zero,
+ // prior to creating the threads.
+ cyg_semaphore_init( &sem_signal_thread, 0 );
+ CYG_TEST_INFO( "Library initialized" );
}
void library_close( void )
{
- diag_printf( "Ciao...\n" );
+ CYG_TEST_INFO( "Library closed" );
}
void print_message( void )
{
- diag_printf( "Printing a silly message...\n" );
+ diag_printf( "INFO:<Printing a silly message...>\n" );
}
// Thread A - signals thread B via semaphore.
@@ -92,14 +96,16 @@
// Store the data value passed in for this thread.
int msg = (int)data;
- while( 1 )
+ weak_function ();
+
+ while( thread_a_count < 5 )
{
// Increment the thread a count.
thread_a_count++;
// Send out a message to the diagnostic port.
- diag_printf( "Thread A, count: %d message: %d\n", thread_a_count, msg );
+ diag_printf( "INFO:<Thread A, count: %d message: %d>\n", thread_a_count, msg );
// Delay for 1 second.
cyg_thread_delay( 100 );
@@ -107,6 +113,9 @@
// Signal thread B using the semaphore.
cyg_semaphore_post( &sem_signal_thread );
}
+
+ CYG_TEST_CHECK( weak_fn_called == 2 , "Application week function not called" );
+ CYG_TEST_FINISH( "Object loader test finished" );
}
// Thread B - waits for semaphore signal from thread A.
@@ -122,7 +131,6 @@
cyg_semaphore_wait( &sem_signal_thread );
// Send out a message to the diagnostic port.
- diag_printf( "Thread B, message: %d\n", msg );
+ diag_printf( "INFO:< Thread B, message: %d>\n", msg );
}
}
-
Index: fs/rom/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/rom/current/ChangeLog,v
retrieving revision 1.17
diff -u -r1.17 ChangeLog
--- fs/rom/current/ChangeLog 13 Dec 2004 15:34:53 -0000 1.17
+++ fs/rom/current/ChangeLog 8 Jul 2005 20:13:16 -0000
@@ -1,3 +1,9 @@
+2005-07-08 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * cdl/romfs.cdl: All mk_romfs to be build even when the tests are
+ disabled. It is generally useful and other tests programs may want
+ it.
+
2004-12-13 John Dallaway <jld@ecoscentric.com>
* tests/fileio1.c: Rename to romfs1.c. eCos test names should be
Index: fs/rom/current/cdl/romfs.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/rom/current/cdl/romfs.cdl,v
retrieving revision 1.10
diff -u -r1.10 romfs.cdl
--- fs/rom/current/cdl/romfs.cdl 13 Dec 2004 15:34:53 -0000 1.10
+++ fs/rom/current/cdl/romfs.cdl 8 Jul 2005 20:13:16 -0000
@@ -65,6 +65,24 @@
compile -library=libextras.a romfs.c
+ cdl_option CYGBLD_FS_ROMFS_MK_ROMFS {
+ display "Build the tool used to build filesystems"
+ flavor bool
+ default_value 1
+
+ # FIXME: host compiler/flags should be provided by config system
+ make -priority 100 {
+ <PREFIX>/bin/mk_romfs: <PACKAGE>/support/mk_romfs.c <PREFIX>/bin/file2c.tcl
+ @mkdir -p "$(dir $@)"
+ @$(HOST_CC) -g -O2 -o $@ $< || cc -g -O2 -o $@ $< || gcc -g -O2 -o $@ $<
+ @cp $(REPOSITORY)/$(PACKAGE)/support/file2c.tcl $(PREFIX)/bin
+ }
+
+ description "
+ When enabled this option will build a host tool which can be
+ used to create a rom filesystem image."
+ }
+
# ----------------------------------------------------------------
# Tests
@@ -76,16 +94,10 @@
requires CYGINT_LIBC_STARTUP_CONTEXT
requires CYGINT_ISO_STDIO_FORMATTED_IO
requires CYGINT_ISO_STRERROR
+ requires CYGBLD_FS_ROMFS_MK_ROMFS
description "
This option enables the building of the ROM filesystem tests."
- # FIXME: host compiler/flags should be provided by config system
- make -priority 100 {
- <PREFIX>/bin/mk_romfs: <PACKAGE>/support/mk_romfs.c
- @mkdir -p "$(dir $@)"
- @$(HOST_CC) -g -O2 -o $@ $< || cc -g -O2 -o $@ $< || gcc -g -O2 -o $@ $<
- }
-
make -priority 100 {
<PREFIX>/include/cyg/romfs/testromfs_le.h : $(PREFIX)/bin/mk_romfs <PACKAGE>/support/file2c.tcl
$(PREFIX)/bin/mk_romfs $(REPOSITORY)/$(PACKAGE)/tests/testromfs testromfs_le.bin
@@ -101,10 +113,9 @@
<PREFIX>/include/cyg/romfs/testromfs_be.h : $(PREFIX)/bin/mk_romfs <PACKAGE>/support/file2c.tcl
$(PREFIX)/bin/mk_romfs -b $(REPOSITORY)/$(PACKAGE)/tests/testromfs testromfs_be.bin
@mkdir -p "$(dir $@)"
- # work around cygwin path problems by copying to build dir
- @cp $(REPOSITORY)/$(PACKAGE)/support/file2c.tcl .
- sh file2c.tcl testromfs_be.bin testromfs_be.h
- @rm -f $@ file2c.tcl
+ # work around cygwin path problems by copying to bin dir
+ @cp $(REPOSITORY)/$(PACKAGE)/support/file2c.tcl $(PREFIX)/bin/
+ sh $(PREFIX)/bin/file2c.tcl testromfs_be.bin testromfs_be.h
@cp testromfs_be.h $@
}
More information about the Ecos-patches
mailing list