免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2406 | 回复: 2

g-bios中的启动函数 [复制链接]

论坛徽章:
0
发表于 2009-03-18 21:36 |显示全部楼层
u-boot中的启动序列指针数组.
init_fnc_t *init_sequence[] = {
        cpu_init,                /* basic cpu dependent setup */
        board_init,                /* basic board dependent setup */
        interrupt_init,                /* set up exceptions */
        env_init,                /* initialize environment */
        init_baudrate,                /* initialze baudrate settings */
        serial_init,                /* serial communications setup */
        console_init_f,                /* stage 1 init of console */
        display_banner,                /* say that we are here */
#if defined(CONFIG_DISPLAY_CPUINFO)
        print_cpuinfo,                /* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
        checkboard,                /* display board info */
#endif
        dram_init,                /* configure available RAM banks */
        display_dram_config,
        NULL,
};
void start_armboot (void)
{
        init_fnc_t **init_fnc_ptr;
        char *s;
#ifndef CFG_NO_FLASH
        ulong size;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
#if !defined (CONFIG_AT91SAM9261EK) && !defined (CONFIG_AT91SAM9263EK)
        unsigned long addr;
#endif
#endif

        /* Pointer is writable since we allocated a register for it */
        gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
        /* compiler optimization barrier needed for GCC >= 3.4 */
        __asm__ __volatile__("": : :"memory");

        memset ((void*)gd, 0, sizeof (gd_t));
        gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
        memset (gd->bd, 0, sizeof (bd_t));

        monitor_flash_len = _bss_start - _armboot_start;

        for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
                if ((*init_fnc_ptr)() != 0) {
                        hang ();
                }
        }

#ifndef CFG_NO_FLASH
        /* configure available FLASH banks */
        size = flash_init ();
        display_flash_config (size);
_________________________________________________________________________
g-bios的启动步骤
extern INIT_FUNC_PTR g_pfInitCallBegin[], g_pfInitCallEnd[];

static __INIT__ int InitSysCrit(void)
{
int sn = 1;
INIT_FUNC_PTR *ppfInitCall = g_pfInitCallBegin;

while (ppfInitCall < g_pfInitCallEnd)
{
  int ret;
  printf("%2d. [0x%08x]: ", sn, *ppfInitCall);
  ret = (*ppfInitCall)();
  if (ret < 0)
   puts("Failed!\n");
  else
   puts("OK!\n");
  ppfInitCall++;
  sn++;
}
return 0;
}
启动函数在哪里定义的?

论坛徽章:
0
发表于 2009-03-19 17:16 |显示全部楼层

回复 #1 laoyoua 的帖子

请楼主看一下下半部的lds脚本,就知道了。

[ 本帖最后由 linke.wang 于 2009-3-20 15:49 编辑 ]

论坛徽章:
0
发表于 2009-03-20 11:17 |显示全部楼层
#define __INIT_ARCH__     __attribute__ ((__section__(".Level0.InitSect"))
#define __INIT_PLAT__     __attribute__ ((__section__(".Level1.InitSect"))
#define __INIT_SUBS__     __attribute__ ((__section__(".Level2.InitSect"))
#define __INIT_DRV__      __attribute__ ((__section__(".Level3.InitSect"))
#define __INIT_APP__      __attribute__ ((__section__(".Level4.InitSect"))


#if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || __GNUC__ >= 4
#define __USED__                        __attribute__((__used__))
#else
#define __USED__                        __attribute__((__unused__))
#endif


typedef int (*INIT_FUNC_PTR)(void);

#define ARCH_INIT(func) \
        static __USED__ __INIT_ARCH__ INIT_FUNC_PTR __initcall_##func = func

#define PLAT_INIT(func) \
        static __USED__ __INIT_PLAT__ INIT_FUNC_PTR __initcall_##func = func

#define SUBSYS_INIT(func) \
        static __USED__ __INIT_SUBS__ INIT_FUNC_PTR __initcall_##func = func

#define DRIVER_INIT(func) \
        static __USED__ __INIT_DRV__  INIT_FUNC_PTR __initcall_##func = func

#define APP_INIT(func) \
        static __USED__ __INIT_APP__  INIT_FUNC_PTR __initcall_##func = func

把函数指针放到对应的段中,下面引用的lds
ENTRY(GBotHalfEntry)
SECTIONS
{
.text ALIGN(4):
{
  GBotHalfEntry = .;
  *(.text)
}
.data ALIGN(4):
{
  *(.data)
}
.bss ALIGN(4):
{
  *(.bss)
}
.GBiosApp ALIGN(4):
{
  g_pGBiosAppBegin = .;
  *(.GBiosApp)
  . = ALIGN(4);
  g_pGBiosAppEnd = .;
}
.InitSect ALIGN(4):
{
  *(.Code.InitSect)
  *(.Data.InitSect)
  g_pfInitCallBegin = .;
  *(.Level0.InitSect)
  *(.Level1.InitSect)
  *(.Level2.InitSect)
  *(.Level3.InitSect)
  *(.Level4.InitSect)
  g_pfInitCallEnd = .;
}

. = ALIGN(4);
g_pGBiosEnd = .;
明白了,谢谢linke

[ 本帖最后由 laoyoua 于 2009-3-20 11:23 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP