From 9ccdf4172ee0fc3e7fe8ac0db122a81572e9c0f8 Mon Sep 17 00:00:00 2001 From: prife Date: Tue, 26 Feb 2013 16:03:08 +0800 Subject: [PATCH] basic mingw support for simulator: kernel and finsh --- bsp/simulator/SConstruct | 23 +++- bsp/simulator/drivers/board.c | 2 +- bsp/simulator/mingw.ld | 222 ++++++++++++++++++++++++++++++++++ bsp/simulator/rtconfig.h | 13 +- bsp/simulator/rtconfig.py | 42 ++++++- libcpu/SConscript | 3 + libcpu/sim/win32/cpu_port.c | 2 + 7 files changed, 297 insertions(+), 10 deletions(-) create mode 100644 bsp/simulator/mingw.ld diff --git a/bsp/simulator/SConstruct b/bsp/simulator/SConstruct index 12dbd7a02..bc6db0ef8 100755 --- a/bsp/simulator/SConstruct +++ b/bsp/simulator/SConstruct @@ -51,13 +51,34 @@ if rtconfig.PLATFORM == 'cl': env.Append(LINKFLAGS=rtconfig.LFLAGS) env['LIBS']=libs env['CPPDEFINES']=definitions +elif rtconfig.PLATFORM == 'mingw': + libs = Split(''' + winmm + gdi32 + winspool + comdlg32 + advapi32 + shell32 + ole32 + oleaut32 + uuid + odbc32 + odbccp32 + ''') + TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT + env = Environment(tools = ['mingw'], + AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, + CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, + AR = rtconfig.AR, ARFLAGS = '-rc', + LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) + env['LIBS']=libs + env.PrependENVPath('PATH', rtconfig.EXEC_PATH) else: TARGET = 'rtthread' env.Append(CCFLAGS=rtconfig.CFLAGS) env.Append(LINKFLAGS=rtconfig.LFLAGS) env.Append(LIBS=['m']) - # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui']) diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c index 669628df7..dcb8d9a04 100755 --- a/bsp/simulator/drivers/board.c +++ b/bsp/simulator/drivers/board.c @@ -53,7 +53,7 @@ void rt_hw_win32_low_cpu(void) #endif } -#ifdef _WIN32 +#ifdef _MSC_VER #ifndef _CRT_TERMINATE_DEFINED #define _CRT_TERMINATE_DEFINED _CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code); diff --git a/bsp/simulator/mingw.ld b/bsp/simulator/mingw.ld new file mode 100644 index 000000000..d5ff228fa --- /dev/null +++ b/bsp/simulator/mingw.ld @@ -0,0 +1,222 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT(pei-i386) +SEARCH_DIR("/usr/local/mingw32/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib"); +SECTIONS +{ + /* Make the virtual address and file offset synced if the alignment is + lower than the target page size. */ + . = SIZEOF_HEADERS; + . = ALIGN(__section_alignment__); + .text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) : + { + *(.init) + *(.text) + *(SORT(.text$*)) + *(.glue_7t) + *(.glue_7) + ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; + LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); + ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; + LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); + *(.fini) + /* ??? Why is .gcc_exc here? */ + *(.gcc_exc) + PROVIDE (etext = .); + *(.gcc_except_table) + } + + /* setction information for finsh shell begin */ + . = ALIGN(__section_alignment__); + FSymTab () : + { + ___fsymtab_start = .; __fsymtab_start = .; + KEEP(*(FSymTab)) + ___fsymtab_end = .; __fsymtab_end = .; + } + . = ALIGN(__section_alignment__); + VSymTab () : + { + ___vsymtab_start = .; __vsymtab_start = .; + KEEP(*(VSymTab)) + ___vsymtab_end = .; __vsymtab_end = .; + } + /* setction information for finsh shell end */ + + /* The Cygwin32 library uses a section to avoid copying certain data + on fork. This used to be named ".data". The linker used + to include this between __data_start__ and __data_end__, but that + breaks building the cygwin32 dll. Instead, we name the section + ".data_cygwin_nocopy" and explictly include it after __data_end__. */ + .data BLOCK(__section_alignment__) : + { + __data_start__ = . ; + *(.data) + *(.data2) + *(SORT(.data$*)) + *(.jcr) + __data_end__ = . ; + *(.data_cygwin_nocopy) + } + + .rdata BLOCK(__section_alignment__) : + { + *(.rdata) + *(SORT(.rdata$*)) + *(.eh_frame) + ___RUNTIME_PSEUDO_RELOC_LIST__ = .; + __RUNTIME_PSEUDO_RELOC_LIST__ = .; + *(.rdata_runtime_pseudo_reloc) + ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + __RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + } + .pdata BLOCK(__section_alignment__) : + { + *(.pdata) + } + .bss BLOCK(__section_alignment__) : + { + __bss_start__ = . ; + *(.bss) + *(COMMON) + __bss_end__ = . ; + } + .edata BLOCK(__section_alignment__) : + { + *(.edata) + } + /DISCARD/ : + { + *(.debug$S) + *(.debug$T) + *(.debug$F) + *(.drectve) + } + .idata BLOCK(__section_alignment__) : + { + /* This cannot currently be handled with grouped sections. + See pe.em:sort_sections. */ + SORT(*)(.idata$2) + SORT(*)(.idata$3) + /* These zeroes mark the end of the import list. */ + LONG (0); LONG (0); LONG (0); LONG (0); LONG (0); + SORT(*)(.idata$4) + SORT(*)(.idata$5) + SORT(*)(.idata$6) + SORT(*)(.idata$7) + } + .CRT BLOCK(__section_alignment__) : + { + ___crt_xc_start__ = . ; + *(SORT(.CRT$XC*)) /* C initialization */ + ___crt_xc_end__ = . ; + ___crt_xi_start__ = . ; + *(SORT(.CRT$XI*)) /* C++ initialization */ + ___crt_xi_end__ = . ; + ___crt_xl_start__ = . ; + *(SORT(.CRT$XL*)) /* TLS callbacks */ + /* ___crt_xl_end__ is defined in the TLS Directory support code */ + ___crt_xp_start__ = . ; + *(SORT(.CRT$XP*)) /* Pre-termination */ + ___crt_xp_end__ = . ; + ___crt_xt_start__ = . ; + *(SORT(.CRT$XT*)) /* Termination */ + ___crt_xt_end__ = . ; + } + .tls BLOCK(__section_alignment__) : + { + ___tls_start__ = . ; + *(.tls) + *(.tls$) + *(SORT(.tls$*)) + ___tls_end__ = . ; + } + .endjunk BLOCK(__section_alignment__) : + { + /* end is deprecated, don't use it */ + PROVIDE (end = .); + PROVIDE ( _end = .); + __end__ = .; + } + .rsrc BLOCK(__section_alignment__) : + { + *(.rsrc) + *(SORT(.rsrc$*)) + } + .reloc BLOCK(__section_alignment__) : + { + *(.reloc) + } + .stab BLOCK(__section_alignment__) (NOLOAD) : + { + *(.stab) + } + .stabstr BLOCK(__section_alignment__) (NOLOAD) : + { + *(.stabstr) + } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section. Unlike other targets that fake this by putting the + section VMA at 0, the PE format will not allow it. */ + /* DWARF 1.1 and DWARF 2. */ + .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_aranges) + } + .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_pubnames) + } + /* DWARF 2. */ + .debug_info BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_info) *(.gnu.linkonce.wi.*) + } + .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_abbrev) + } + .debug_line BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_line) + } + .debug_frame BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_frame) + } + .debug_str BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_str) + } + .debug_loc BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_loc) + } + .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_macinfo) + } + /* SGI/MIPS DWARF 2 extensions. */ + .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_weaknames) + } + .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_funcnames) + } + .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_typenames) + } + .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_varnames) + } + /* DWARF 3. */ + .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_ranges) + } +} + diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index 3e9fb2e74..470d0af06 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -83,6 +83,7 @@ /* SECTION: Device System */ /* Using Device System */ #define RT_USING_DEVICE +#define RT_USING_DEVICE_IPC /* #define RT_USING_UART1 */ /* SECTION: Console options */ @@ -96,9 +97,9 @@ /* SECTION: MTD interface options */ /* using mtd nand flash */ -#define RT_USING_MTD_NAND +/* #define RT_USING_MTD_NAND */ /* using mtd nor flash */ -#define RT_USING_MTD_NOR +/* #define RT_USING_MTD_NOR */ /* SECTION: finsh, a C-Express shell */ #define RT_USING_FINSH @@ -107,7 +108,7 @@ #define FINSH_USING_DESCRIPTION /* SECTION: device file system */ -#define RT_USING_DFS +/* #define RT_USING_DFS */ #define DFS_FILESYSTEM_TYPES_MAX 8 /* DFS: ELM FATFS options */ @@ -126,7 +127,7 @@ /* #define RT_USING_DFS_NFS */ /* DFS: UFFS nand file system options */ -#define RT_USING_DFS_UFFS +/* #define RT_USING_DFS_UFFS */ /* configuration for uffs, more to see dfs_uffs.h and uffs_config.h */ #define RT_CONFIG_UFFS_ECC_MODE UFFS_ECC_HW_AUTO /* enable this ,you need provide a mark_badblock/check_block function */ @@ -138,7 +139,7 @@ /* DFS: windows share directory mounted to rt-thread/dfs */ /* only used in bsp/simulator */ #ifdef _WIN32 -#define RT_USING_DFS_WINSHAREDIR +//#define RT_USING_DFS_WINSHAREDIR #endif /* the max number of mounted file system */ @@ -199,7 +200,7 @@ #define RT_LWIP_TCP_WND 8192 /* SECTION: RT-Thread/GUI */ -#define RT_USING_RTGUI +/* #define RT_USING_RTGUI */ /* name length of RTGUI object */ #define RTGUI_NAME_MAX 12 diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index 4007e0b1d..3d0c641ef 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -1,7 +1,7 @@ # toolchains options ARCH='sim' #CROSS_TOOL='msvc' or 'gcc' or 'mingw' (mingw is not supported yet!) -CROSS_TOOL='msvc' +CROSS_TOOL='mingw' # cross_tool provides the cross compiler # EXEC_PATH is the compiler execute path @@ -10,11 +10,20 @@ if CROSS_TOOL == 'gcc': PLATFORM = 'gcc' EXEC_PATH = '/usr/bin/gcc' -if CROSS_TOOL == 'msvc': +elif CROSS_TOOL == 'mingw': + CPU = 'win32' + PLATFORM = 'mingw' + EXEC_PATH = r'D:\Program Files\CodeBlocks\MinGW\bin' + +elif CROSS_TOOL == 'msvc': CPU = 'win32' PLATFORM = 'cl' EXEC_PATH = '' +else : + print "bad CROSS TOOL!" + exit(1) + BUILD = 'debug' #BUILD = '' @@ -48,6 +57,35 @@ if PLATFORM == 'gcc': POST_ACTION = '' +elif PLATFORM == 'mingw': + # toolchains + PREFIX = '' + CC = PREFIX + 'gcc' + AS = PREFIX + 'gcc' + AR = PREFIX + 'ar' + LINK = PREFIX + 'gcc' + TARGET_EXT = 'exe' + SIZE = PREFIX + 'size' + OBJDUMP = PREFIX + 'objdump' + OBJCPY = PREFIX + 'objcopy' + + DEVICE = ' -ffunction-sections -fdata-sections' + DEVICE = ' ' + CFLAGS = ' -Wl,--output-def ' + AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' + #LFLAGS = DEVICE + ' -Wl,-Map=rtthread-win32.map -T mingw.ld' + LFLAGS = DEVICE + ' -Wl,-Map=rtthread-win32.map --gc-sections,--whole-archive -T mingw.ld ' + CPATH = '' + LPATH = '' + + if BUILD == 'debug': + CFLAGS += ' -g -O0 -gdwarf-2' + AFLAGS += ' -gdwarf-2' + else: + CFLAGS += ' -O2' + + POST_ACTION = '' + elif PLATFORM == 'cl': # toolchains PREFIX = '' diff --git a/libcpu/SConscript b/libcpu/SConscript index a1609d5fd..0d0097609 100644 --- a/libcpu/SConscript +++ b/libcpu/SConscript @@ -18,6 +18,9 @@ if rtconfig.PLATFORM == 'iar': if rtconfig.PLATFORM == 'cl': src = Glob(path + '/*.c') +if rtconfig.PLATFORM == 'mingw': + src = Glob(path + '/*.c') + CPPPATH = [RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/' + rtconfig.CPU, RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/common'] group = DefineGroup(rtconfig.CPU.upper(), src, depend = [''], CPPPATH = CPPPATH) diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 38c387b19..6bf3c79cf 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -111,6 +111,7 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam); static void SetThreadName(DWORD dwThreadID, char* threadName) { +#if defined(_MSC_VER) THREADNAME_INFO info; info.dwType = 0x1000; info.szName = threadName; @@ -124,6 +125,7 @@ static void SetThreadName(DWORD dwThreadID, char* threadName) __except(EXCEPTION_EXECUTE_HANDLER) { } +#endif } /*