示例#1
0
文件: start.c 项目: MorS25/amcfc
//-------------------------------------------------------------------------*
//函数名: common_startup                                                   *
//功  能: 复制中断向量表到RAM中                                            * 
//参  数: 无								   *	
//说  明: 将ROM中的初始化数据拷贝到RAM中                                   *
//-------------------------------------------------------------------------*
void common_startup(void)
{
    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;
 
 
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */  
    extern uint32 __VECTOR_TABLE[];
    extern uint32 __VECTOR_RAM[];

    /* Copy the vector table to RAM */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x410; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* Point the VTOR to the new copy of the vector table */
    write_vtor((uint32)__VECTOR_RAM);    
    
    /* Get the addresses for the .data section (initialized data section) */
    uint8* data_ram = __section_begin(".data");
    uint8* data_rom = __section_begin(".data_init");
    uint8* data_rom_end = __section_end(".data_init");
    
    /* Copy initialized data from ROM to RAM */
    n = data_rom_end - data_rom;
    while (n--)
      *data_ram++ = *data_rom++;
 
 
    /* Get the addresses for the .bss section (zero-initialized data) */
    uint8* bss_start = __section_begin(".bss");
    uint8* bss_end = __section_end(".bss");
    
    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;    
    
    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead 
     * of ROM. ex: __ramfunc void foo(void);
     */
    uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
    uint8* code_relocate = __section_begin("CodeRelocate");
    uint8* code_relocate_end = __section_end("CodeRelocate");
    
    /* Copy functions from ROM to RAM */
    n = code_relocate_end - code_relocate;
    while (n--)
      *code_relocate_ram++ = *code_relocate++;
}
void
common_startup(void)
{

#if (defined(CW))	
    extern char __START_BSS[];
    extern char __END_BSS[];
    extern uint32 __DATA_ROM[];
    extern uint32 __DATA_RAM[];
    extern char __DATA_END[];
#endif

    /* 声明一个计数器在拷贝循环中使用 */
    uint32 n;

    /* 为不同的数据段定义指针。
     * 这些变量将由链接文件中获取的值初始化
     */
    uint8 * data_ram, * data_rom, * data_rom_end;
    uint8 * bss_start, * bss_end;


    /* 引进链接文件中的VECTOR_TABLE和VECTOR_RAM的地址 */
    extern uint32 __VECTOR_TABLE[];
    extern uint32 __VECTOR_RAM[];

    /* 将中断向量表复制到RAM中 */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x410; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* 将新的中断向量表指针赋给VTOR寄存器 */
    write_vtor((uint32)__VECTOR_RAM);

    /* 获得.data段的地址(已初始化的数据段) */
	#if (defined(CW))
        data_ram = (uint8 *)__DATA_RAM;
	    data_rom = (uint8 *)__DATA_ROM;
	    data_rom_end  = (uint8 *)__DATA_END; /* 该段在CodeWarrior编译器中为RAM地址 */
	    n = data_rom_end - data_ram;
    #elif (defined(IAR))
		data_ram = __section_begin(".data");
		data_rom = __section_begin(".data_init");
		data_rom_end = __section_end(".data_init");
		n = data_rom_end - data_rom;
	#endif		
		
	/* 从ROM复制已初始化的数据到RAM */
	while (n--)
		*data_ram++ = *data_rom++;
	
	
    /* 获得.bss段的地址 (初始化为0的数据) */
	#if (defined(CW))
		bss_start = (uint8 *)__START_BSS;
		bss_end = (uint8 *)__END_BSS;
	#elif (defined(IAR))
		bss_start = __section_begin(".bss");
		bss_end = __section_end(".bss");
	#endif
		
		
	

    /* 清零初始化为0的数据段 */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;

	/* 取得所有应该从ROM复制到RAM的代码段的地址。
         * IAR有一个预定义的关键字可以标记独立的函数为从RAM执行。
         * 在函数的返回类型前添加"__ramfunc"关键字可以将函数标记为从RAM中执行。
         * 例如:__ramfunc void foo(void);
	 */
	#if (defined(IAR))
		uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
		uint8* code_relocate = __section_begin("CodeRelocate");
		uint8* code_relocate_end = __section_end("CodeRelocate");

		/* 将函数从ROM复制到RAM */
		n = code_relocate_end - code_relocate;
		while (n--)
			*code_relocate_ram++ = *code_relocate++;
	#endif
}
示例#3
0
void
common_startup(void)
{

#if (defined(CW))	
    extern char __START_BSS[];
    extern char __END_BSS[];
    extern uint32 __DATA_ROM[];
    extern uint32 __DATA_RAM[];
    extern char __DATA_END[];
#endif

    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;

#ifndef KEIL
    /* Declare pointers for various data sections. These pointers
     * are initialized using values pulled in from the linker file
     */
    uint8 * data_ram, * data_rom, * data_rom_end;
    uint8 * bss_start, * bss_end;
#endif

#if (defined(KEIL))
	extern uint32 Image$$VECTOR_ROM$$Base[];
	extern uint32 Image$$VECTOR_RAM$$Base[];
	#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base  
	#define __VECTOR_RAM Image$$VECTOR_RAM$$Base  
#endif
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
    extern uint32 __VECTOR_TABLE[];
    extern uint32 __VECTOR_RAM[];

    /* Copy the vector table to RAM */
    if (__VECTOR_RAM != __VECTOR_TABLE)
    {
        for (n = 0; n < 0x104; n++)
            __VECTOR_RAM[n] = __VECTOR_TABLE[n];
    }
    /* Point the VTOR to the new copy of the vector table */
    write_vtor((uint32)__VECTOR_RAM);    
    
    /* Get the addresses for the .data section (initialized data section) */
    #if (defined(CW))
        data_ram = (uint8 *)__DATA_RAM;
	data_rom = (uint8 *)__DATA_ROM;
	data_rom_end  = (uint8 *)__DATA_END; /* This is actually a RAM address in CodeWarrior */
	n = data_rom_end - data_ram;
    #elif (defined(IAR))
	data_ram = __section_begin(".data");
	data_rom = __section_begin(".data_init");
	data_rom_end = __section_end(".data_init");
	n = data_rom_end - data_rom;
    #endif		

#ifndef __CC_ARM
		
	/* Copy initialized data from ROM to RAM */
	while (n--)
		*data_ram++ = *data_rom++;
	
	
    /* Get the addresses for the .bss section (zero-initialized data) */
    #if (defined(CW))
	bss_start = (uint8 *)__START_BSS;
	bss_end = (uint8 *)__END_BSS;
    #elif (defined(IAR))
	bss_start = __section_begin(".bss");
	bss_end = __section_end(".bss");
    #endif
	

    /* Clear the zero-initialized data section */
    n = bss_end - bss_start;
    while(n--)
      *bss_start++ = 0;
#endif

    /* Get addresses for any code sections that need to be copied from ROM to RAM.
     * The IAR tools have a predefined keyword that can be used to mark individual
     * functions for execution from RAM. Add "__ramfunc" before the return type in
     * the function prototype for any routines you need to execute from RAM instead
     * of ROM. ex: __ramfunc void foo(void);
     */
    #if (defined(IAR))
  	uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
	uint8* code_relocate = __section_begin("CodeRelocate");
        uint8* code_relocate_end = __section_end("CodeRelocate");

        /* Copy functions from ROM to RAM */
        n = code_relocate_end - code_relocate;
        while (n--)
          *code_relocate_ram++ = *code_relocate++;
    #endif
}
示例#4
0
文件: startup.c 项目: 8bitgeek/fnet
void
common_startup(void)
{
    /* Declare a counter we'll use in all of the copy loops */
    uint32 n;
    
    /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */  
    extern uint32 __vector_table[];

    /* Copy the vector table to RAM */
    if ((uint32 *)FNET_CFG_CPU_VECTOR_TABLE != __vector_table)
    {
        uint32 *vector_ram = (uint32 *)FNET_CFG_CPU_VECTOR_TABLE;
			
        for (n = 0; n < 0x410; n++)
        {
            *vector_ram++= __vector_table[n];					
        }				
    }
	
    /* Point the VTOR to the new copy of the vector table */
    write_vtor((uint32)FNET_CFG_CPU_VECTOR_TABLE);

#if FNET_CFG_COMP_CW
    {
    	RomInfo *ptr_tmp = __S_romp;
    	StaticInitializer s, *p;
    	
    	/* Zero bss section*/
    	fnet_memset(__START_BSS, 0, (__END_BSS - __START_BSS));
        
        /* Copying sections from ROM to RAM.*/
        if((uint32)ptr_tmp)
		{
			int	index;
	
			/*
			 *	Go through the entire table, copying sections from ROM to RAM.
			 */
			for (index = 0;
				 __S_romp[index].Source != 0 ||
				 __S_romp[index].Target != 0 ||
				 __S_romp[index].Size != 0;
				 ++index)
			{
				copy_rom_section( __S_romp[index].Target,
									__S_romp[index].Source,
									__S_romp[index].Size );
			} 	
		}
     	
        /*	See if the static initializer table exists	*/
        if (__sinit__)
        {
        	/*	call all static initializers in the table	*/
        	for (p = __sinit__; p && (s = *p) != 0; p++)
        		s();
        }
    }    
#endif /* FNET_CFG_COMP_CW */
    
#if FNET_CFG_COMP_IAR
    {
		/* Get the addresses for the .data section (initialized data section) */
		uint8* data_ram = __section_begin(".data");
		uint8* data_rom = __section_begin(".data_init");
		uint8* data_rom_end = __section_end(".data_init");
		
		/* Copy initialized data from ROM to RAM */
		n = data_rom_end - data_rom;
		while (n--)
		  *data_ram++ = *data_rom++;
	 
	 
		/* Get the addresses for the .bss section (zero-initialized data) */
		uint8* bss_start = __section_begin(".bss");
		uint8* bss_end = __section_end(".bss");
		
		/* Clear the zero-initialized data section */
		n = bss_end - bss_start;
		while(n--)
		  *bss_start++ = 0;    
		
		/* Get addresses for any code sections that need to be copied from ROM to RAM.
		 * The IAR tools have a predefined keyword that can be used to mark individual
		 * functions for execution from RAM. Add "__ramfunc" before the return type in
		 * the function prototype for any routines you need to execute from RAM instead 
		 * of ROM. ex: __ramfunc void foo(void);
		 */
		uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
		uint8* code_relocate = __section_begin("CodeRelocate");
		uint8* code_relocate_end = __section_end("CodeRelocate");
		
		/* Copy functions from ROM to RAM */
		n = code_relocate_end - code_relocate;
		while (n--)
		  *code_relocate_ram++ = *code_relocate++;
    }
#endif /*FNET_CFG_COMP_IAR*/    
}