SylixOS ARM BSP 第三篇【bspInit.c】

此篇博客为 SylixOS ARM BSP 编写连载的第三篇,主要介绍 bspInit.c 文件具体实现。
bspInit.c 为 BSP 操作系统初始化部分代码,通常由startup.S 初始完基本处理器参数后调用,下面以 S3C2440A 处理器为例,逐块介绍 bspInit.c 代码。


SylixOS ARM BSP 第二篇中提到 startup.S 初始化完成会将会调用 bspInit() 函数,此函数用于初始化操作系统,并开始多任务调度。

int bspInit (void) { static __section(.noinit) CHARcKernelHeap[6 * LW_CFG_MB_SIZE]; static __section(.noinit) CHARcSystemHeap[6 * LW_CFG_MB_SIZE]; halModeInit(); debugChannelInit(0); API_KernelStartParam("ncpus=1 kdlog=no kderror=yes kfpu=no heapchk=yes"); API_KernelStart(usrStartup, cKernelHeap,sizeof(cKernelHeap), cSystemHeap,sizeof(cSystemHeap)); return(-1); }

代码中定义的 cKernelHeap 与 cSystemHeap 为 SylixOS 内核堆与系统堆内存位置( cKernelHeap 与 cSystemHeap 数组不需要被清零),这里通过 static char 数字的方式开辟,__section(.noinit) 其中 __section() 是一个宏,原型在 sys/compiler.h 中定义:
#ifdef BSD /* bsd system use __attribute__ ((__section__(S))) not #S, so compiler bsd source MUST defined BSD */ #define __section(S)__attribute__ ((__section__(S))) #else #define __section(S)__attribute__ ((__section__(#S))) #endif

表示将被定义的对象放在某一个指定的段中,这里的 __section(.noinit) 表示 cKernelHeap 与 cSystemHeap 数组放在 .noinit 段中(如果没有指定,则默认在 .bss 段中),类似汇编中的 SECTION() 操作。
.noinit 段不需要在 startup.S 中没有像 .bss 段一样被清零,所以这样的方法可以加快系统启动时间。

halModeInit() 是目标机模式初始化函数,目前为空函数,如有需要用户可以加入自己的代码,此代码将会在操作系统初始化之前被调用。
debugChannelInit() 操作系统内部使用 bspDebugMsg() 作为内部调试信息打印接口,debugChannelInit() 就是初始化这个打印接口,bspDebugMsg() 函数将在以后的 bspLib.c 博文中详细说明。
API_KernelStartParam() 是系统内核函数,负责设置操作系统启动参数,启动参数为一个字符串,格式为【参数名=参数值】多个参数之间用空格隔开,SylixOS 目前支持的启动参数有:
参数名 默认值 说明
ncpus 1 CPU 个数,例如单核处理器 ncpus=1 多核处理器 ncpus=CPU 数量,注意:ncpus 不得大于 LW_CFG_MAX_PROCESSORS
dlog no
是否允许操作系统通过 bspDebugMsg() 函数打印调试信息,dlog=yes 代表允许,dlog=no 代表不允许
derror yes 是否允许操作系统通过 bspDebugMsg() 函数打印错误信息,参数与 dlog 相同
kfpu no 是否允许操作系统内核使用硬浮点运算器,强烈建议此参数为 no
heapchk yes 是否允许操作系统对所有内存堆操作进行内存访问越界检查,建议参数为 yes
varea 0xC0000000 表示系统虚拟内存空间起始点,虚拟空间配置将在以后的 bspMap.h 博文中详细说明。
vsize 0x40000000
hz 100
hhz 100
irate 5
hpsec 1



(未完,待续)
【SylixOS ARM BSP 第三篇【bspInit.c】】转载自:http://hanhui03.blog.51cto.com

    推荐阅读