Wednesday, June 16, 2010

S3C2440 - Kernel - Start Kernel -1

上一篇介紹了在 Start Kernel 的幾個步驟, 這邊會詳細介紹每個步驟的目的.

(1) lock_kernel();
第一件要做的事情就是先 lock kernel.
static inline void lock_kernel(void)
{
if (!++current->lock_depth) // task_struct /include/linux/sched.h, initialized by fork.c
spin_lock(&kernel_flag);
}
current = get_current( ) , 也就是取得目前 process 的 task_struct*

kernel_flag 是一個 kernel local spin lock. 所有的 process 獲得這個 kernel local spin lock 才可以存取 kernel resource.

process 的 lock_depth 初始值是 -1. 在 fork.c 中設置. 當 lock_depth >= 0 時候, process 才可以得到 kernel local spin lock.

在 kernel 有很多種方法可以作為 kernel control path 的 synchronous. Kernel control path 可以當成是一連串的執行命令. Spin lock 是最常使用到的, 而且也適用於 all cpu.

(2) Print linux version
printk(linux_banner); // Linux version 2.4.18-rmk7-pxa1 (harlan@harlan) (gcc version 2.95.3 20010315 (release)) #13 日 6月 3 08:02:23 CST 2007

這其實是列印 linux version. 至於 printk 內容就請自己去看了.


No comments: