Linux内核分析之三——使用gdb跟踪调试内核从start_kernel到init进程启动

本文详细解析了Linux内核启动过程,从start_kernel函数开始,探讨了一系列的初始化工作,直到rest_init函数调用时产生了0号进程。0号进程并非通过常规fork生成,而是内核自身创建,而1号进程则是内核态下通过kernel_thread和do_fork产生的,负责执行用户空间的/sbin/init等程序。
摘要由CSDN通过智能技术生成

作者:姚开健

原创作品转载请注明出处

《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000

Linux内核(本文以Linux-3.18.6为例)的启动在源代码init文件夹里的main.c文件,在经过执行一些汇编代码(把内核代码文件放到内存中解压缩,初始化C执行环境等等工作)后,会进入一个C编写的函数start_kernel,这是汇编代码与C代码的分界点,函数如下:

asmlinkage __visible void __init start_kernel(void)
501{
502	char *command_line;
503	char *after_dashes;
504
505	/*
506	 * Need to run as early as possible, to initialize the
507	 * lockdep hash:
508	 */
509	lockdep_init();
510	set_task_stack_end_magic(&init_task);
511	smp_setup_processor_id();
512	debug_objects_early_init();
513
514	/*
515	 * Set up the the initial canary ASAP:
516	 */
517	boot_init_stack_canary();
518
519	cgroup_init_early();
520
521	local_irq_disable();
522	early_boot_irqs_disabled = true;
523
524/*
525 * Interrupts are still disabled. Do necessary setups, then
526 * enable them
527 */
528	boot_cpu_init();
529	page_address_init();
530	pr_notice("%s", linux_banner);
531	setup_arch(&command_line);
532	mm_init_cpumask(&init_mm);
533	setup_command_line(command_line);
534	setup_nr_cpu_ids();
535	setup_per_cpu_areas();
536	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */
537
538	build_all_zonelists(NULL, NULL);
539	page_alloc_init();
540
541	pr_notice("Kernel command line: %s\n", boot_command_line);
542	parse_early_param();
543	after_dashes = parse_args("Booting kernel",
544				  static_command_line, __start___param,
545				  __stop___param - __start___param,
546				  -1, -1, &unknown_bootoption);
547	if (!IS_ERR_OR_NULL(after_dashes))
548		parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
549			   set_init_arg);
550
551	jump_label_init();
552
553	/*
554	 * These use large bootmem allocations and must precede
555	 * kmem_cache_init()
556	 */
557	setup_log_buf(0);
558	pidhash_init();
559	vfs_caches_init_early();
560	sort_mai
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值