看了2天main.c,对里面的东西了解不是很透。等后面牵涉到在回过头来看看。敬请指教。
asmlinkage void __init start_kernel(void)
{
char * command_line;
extern struct kernel_param __start___param[], __stop___param[];
/*
* Interrupts are still disabled. Do necessary setups, then
* enable them
*/
lock_kernel();/*锁定内核*/
boot_cpu_init();
page_address_init(); /* 设置内存边界,在配置highmem才作工作 */
printk(KERN_NOTICE);
printk(linux_banner);//input linux versiom
setup_arch(&command_line); /* 初始化与CPU体系相关的设备,并将启动时存在内
存那某区域的命令分析出来放在command_line中 */
setup_per_cpu_areas();/*给每个CPU分配启动内存*/
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
/*建立调度器优先于任何中断(如定时器)整个系统的结构在smp_init()时间,但同时还要激活调度器功能*/
/*
* Set up the scheduler prior starting any interrupts (such as the
* timer interrupt). Full topology setup happens at smp_init()
* time - but meanwhile we still have a functioning scheduler.
*/
sched_init();
/*
* Disable preemption - early bootup scheduling is extremely
* fragile until we cpu_idle() for the first time.
*/
preempt_disable();/*关闭抢占式*/
build_all_zonelists();/*建立内存区域链表节点*/
page_alloc_init(); /* 发通知给每个CPU,处理每个CPU的内存状态*/
printk(KERN_NOTICE "Kernel command line: %s/n", saved_command_line);
parse_early_param();/*分析检查早期内核的命令参数*/
/*分析命令行参数*/
parse_args("Booting kernel", command_line, __start___param,
__stop___param - __start___param,
&unknown_bootoption);
sort_main_extable();/*排序内核及模块运行出错表*/
trap_init(); /*设置陷阱门和中断门*/
rcu_init();/*初始化RCU机制*/
init_IRQ(); /*初始化中断*/
pidhash_init();/*按物理内存的量初始化pid_hash表的大小*/
init_timers();/*发通知初始化每个CPU的定时器*/
hrtimers_init();
softirq_init();/*初始化软中断*/
time_init();/*初始化系统时间*/
/*
* HACK ALERT! This is early. We're enabling the console before
* we've done PCI setups etc, and console_init() must be aware of
* this. But we do want output early, in case something goes wrong.
*/
console_init(); /*初始化控制台*/
if (panic_later)
panic(panic_later, panic_param);
profile_init();
local_irq_enable();/*开中断*/
#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start && !initrd_below_start_ok &&
initrd_start < min_low_pfn << PAGE_SHIFT) {
printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
"disabling it./n",initrd_start,min_low_pfn << PAGE_SHIFT);
initrd_start = 0;
}
#endif
vfs_caches_init_early();
cpuset_init_early();
mem_init();/*初始化物理内存页面*/
kmem_cache_init();/*初始化cache相关的链表*/
setup_per_cpu_pageset();
numa_policy_init(); /*初始化NUMA内存管理策略*/
if (late_time_init)
late_time_init();
calibrate_delay();/*设置tick和jiffers*/
pidmap_init();/*初始化pidmap_array,分配pid=0给当前进程*/
pgtable_cache_init(); /*初始化pgd_cache*/
prio_tree_init();/*初始化优先级树index_bits_to_maxindex数组*/
anon_vma_init(); /*创建anon_vma结构对象slab缓存*/
#ifdef CONFIG_X86
if (efi_enabled)
efi_enter_virtual_mode();
#endif
fork_init(num_physpages); /*创建init进程*/
proc_caches_init();
buffer_init();
unnamed_dev_init();
key_init();
security_init();
vfs_caches_init(num_physpages);
radix_tree_init();
signals_init();
/* rootfs populating might need page-writeback */
page_writeback_init();
#ifdef CONFIG_PROC_FS
proc_root_init();
#endif
cpuset_init();
check_bugs();
acpi_early_init(); /* before LAPIC and SMP init */
/* Do the rest non-__init'ed, we're now alive */
rest_init();
}
执行完init初始化程序后,多任务的环境已经建立,init进程要通过fork()派生出的系统进程和登录进程来挂你多用户的访问了。(本来已经把linux内核完全剖析相关的东西摘录下来,作为参考,但在word里忘了保存。就不贴出来了。可以参考参考)。