因为使用的镜像是VxWorks_rom,所以usrInit函数在文件config/all/usrConfig.c中定义,由romStart函数调用,此时中断为全关状态,多任务内核还未开启,主要完成清除BSS段,设置中断向量表,初始化硬件最后使用usrRoot启动内核。
下面是以S3C2410为例,将源码中不必要的部分去除后的代码:
#define TRAP_VALUE_1 0x12348765
#define TRAP_VALUE_2 0x5a5ac3c3
LOCAL volatile UINT32 trapValue1 = TRAP_VALUE_1;
LOCAL volatile UINT32 trapValue2 = TRAP_VALUE_2;
void usrInit
(
int startType
)
{
while (trapValue1 != TRAP_VALUE_1 || trapValue2 != TRAP_VALUE_2)//用以检查代码段复制是否成功完成,成功完成的含义如是否对齐到合适的内存位置,以及在复制过程中数据是否完好等
{
/* infinite loop */;
}
#ifdef INCLUDE_SYS_HW_INIT_0
SYS_HW_INIT_0 ();//sysHwInit0(),在文件sysLib.c中定义
#endif /* INCLUDE_SYS_HW_INIT_0 */
/* configure data and instruction cache if available and leave disabled */
#ifdef INCLUDE_CACHE_SUPPORT
cacheLibInit (USER_I_CACHE_MODE, USER_D_CACHE_MODE);//设置指令和数据Cache的模式
#endif /* INCLUDE_CACHE_SUPPORT */
bzero (edata, end - edata); /* zero out bss variables */
sysStartType = startType; /* save type of system start */
intVecBaseSet ((FUNCPTR *) VEC_BASE_ADRS); /* set vector base table */
excVecInit (); /* install exception vectors 安装中断处理程序*/
sysHwInit (); /* initialize system hardware */
usrKernelInit (); /* configure the Wind kernel */
#ifdef INCLUDE_USB
# ifdef INCLUDE_OHCI_PCI_INIT
sysUsbPciOhciInit ();
# endif
#endif
cacheEnable (INSTRUCTION_CACHE); /* enable instruction cache */
cacheEnable (DATA_CACHE); /* enable data cache */
/* start the kernel specifying usrRoot as the root task */
kernelInit ((FUNCPTR) usrRoot, ROOT_STACK_SIZE,
(char *) MEM_POOL_START_ADRS,
sysMemTop (), ISR_STACK_SIZE, INT_LOCK_LEVEL);
}
在usrInit函数中调用了一些其他的函数,例如sysHwInit0()(在sysLib.c中定义),同样去除无关的代码后,如下:
void sysHwInit0 (void)
{
#ifdef INCLUDE_CACHE_SUPPORT
/*
* Install the appropriate cache library, no address translation
* routines are required for this BSP, as the default memory map has
* virtual and physical addresses the same.
*/
cacheArm920tLibInstall (NULL, NULL);//cache Lib
#endif /* INCLUDE_CACHE_SUPPORT */
#if defined(INCLUDE_MMU)
/* Install the appropriate MMU library and translation routines */
mmuArm920tLibInstall (NULL, NULL);//MMU Lib
#endif
return;
}
可以看出该函数主要负责CACHE和MMU单元的支持
接着调用函数intVecBaseSet和excVecInit完成中断初始化,紧接着调用sysHwInit完成板级硬件的初始化,具体如下:
void sysHwInit (void)
{
/* install the IRQ/SVC interrupt stack splitting routine */
FAST PART_ID partId;
_func_armIntStackSplit = sysIntStackSplit;
#ifdef INCLUDE_SERIAL
/* initialise the serial devices */
sysSerialHwInit (); /* initialise serial data structure */
#endif /* INCLUDE_SERIAL */
}
该函数主要调用sysSerialHwInit函数完成串口的初始化.
sysHwInit函数执行完后,接着执行usrKernelInit完成内核数据结构的配置,同样去除无关代码后,如下:
/*******************************************************************************
*
* usrKernelInit - configure kernel data structures
*
* NOMANUAL
*/
void usrKernelInit (void)
{
classLibInit (); /* initialize class (must be first) */
taskLibInit (); /* initialize task object */
#ifdef INCLUDE_TASK_HOOKS //在Makefile中已定义
taskHookInit (); /* initialize task hook package */
#ifdef INCLUDE_SHOW_ROUTINES//在Config.h中定义
taskHookShowInit (); /* task hook show routine */
#endif /* INCLUDE_SHOW_ROUTINES */
#endif /* INCLUDE_TASK_HOOKS */
#ifdef INCLUDE_SEM_BINARY//在Makefile中定义
semBLibInit (); /* initialize binary semaphore */
#endif /* INCLUDE_SEM_BINARY */
#ifdef INCLUDE_SEM_MUTEX//在Makefile中定义
semMLibInit (); /* initialize mutex semaphore */
#endif /* INCLUDE_SEM_MUTEX */
#ifdef INCLUDE_SEM_COUNTING//在Makefile中定义
semCLibInit (); /* initialize counting semaphore */
#endif /* INCLUDE_SEM_COUNTING */
#ifdef INCLUDE_VXEVENTS//在Makefile中定义
eventLibInit ();
#endif /* INCLUDE_VXEVENTS */
#ifdef INCLUDE_WATCHDOGS//在Makefile中定义
wdLibInit (); /* initialize watchdog */
#ifdef INCLUDE_SHOW_ROUTINES//在Makefile中定义
wdShowInit (); /* watchdog object show routine */
#endif /* INCLUDE_SHOW_ROUTINES */
#endif /* INCLUDE_WATCHDOGS */
#ifdef INCLUDE_MSG_Q//在Makefile中定义
msgQLibInit (); /* initialize message queues */
#ifdef INCLUDE_SHOW_ROUTINES
msgQShowInit (); /* message queue object show routine */
#endif /* INCLUDE_SHOW_ROUTINES */
#endif /* INCLUDE_MSG_Q */
#ifdef INCLUDE_SHOW_ROUTINES//在Makefile中定义
classShowInit (); /* class object show routine */
taskShowInit (); /* task object show routine */
semShowInit (); /* semaphore object show routine */
#endif /* INCLUDE_SHOW_ROUTINES */
/* configure the kernel queues */
#ifdef INCLUDE_CONSTANT_RDY_Q//定义了
qInit (&readyQHead, Q_PRI_BMAP, (int)&readyQBMap, 256); /* fixed ready q */
#else
qInit (&readyQHead, Q_PRI_LIST); /* simple priority ready q */
#endif /* !INCLUDE_CONSTANT_RDY_Q */
qInit (&activeQHead, Q_FIFO); /* FIFO queue for active q */
qInit (&tickQHead, Q_PRI_LIST); /* simple priority semaphore q*/
workQInit (); /* queue for deferred work */
}
#endif /* __INCusrKernelc */
紧接着,启用指令和数据Cache功能,并讲usrRoot作为根任务启动内核.