ÆÊÎöLinuxÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯ÖеĽÇÉ«
ÎÊÌ⣺LinuxÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯ÖеĽÇÉ«ÆÊÎö
ÔÚLinux²Ù×÷ϵͳÖУ¬ÄÚºËÖ÷º¯ÊýÊÇÕû¸öϵͳÆô¶¯Àú³ÌÖеĽ¹µã²¿·Ö£¬ËüÈÏÕæ³õʼ»¯ÏµÍ³µÄ¸÷ÏЧ£¬¼ÓÔØÐëÒªµÄÄ£¿éºÍÇý¶¯³ÌÐò£¬×îÖÕ½«ÏµÍ³Ö¸µ¼µ½Óû§Ì¬¡£±¾ÎĽ«ÏêϸÆÊÎöLinuxÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯Àú³ÌÖеÄÏêϸ½ÇÉ«£¬²¢¸ø³öһЩ´úÂëʾÀýÀ´ËµÃ÷Æ书Ч¡£
1. ÄÚºËÖ÷º¯ÊýµÄ×÷ÓÃ
ÄÚºËÖ÷º¯Êý£¬Ò»Ñùƽ³£Î»ÓÚÎļþ init/main.c ÖÐµÄ start_kernel() º¯Êý£¬ÊÇÕû¸öÄÚºËÆô¶¯µÄÈë¿Úµã¡£ÔÚϵͳÆô¶¯Ê±£¬ÄÚºËÖ÷º¯ÊýµÄÖ÷Òª×÷ÓðüÀ¨£º
³õʼ»¯ÄÚºËÊý¾Ý½á¹¹ºÍϵͳ±äÁ¿
ÉèÖô¦ÀíÆ÷ÇéÐÎ
³õʼ»¯ÄÚºË×Óϵͳ
×°ÔØÐëÒªµÄÄ£¿éºÍÇý¶¯³ÌÐò
Æô¶¯ÏµÍ³µ÷ÀíÆ÷
ÔØÈëÓû§Ì¬³ÌÐò
ͨ¹ýÕâЩ°ì·¨£¬ÄÚºËÖ÷º¯Êý½«ÏµÍ³´ÓÓ²¼þÖ¸µ¼µ½Èí¼þ£¬×îÖÕÈÃÓû§Äܹ»ÔÚϵͳÖÐÔËÐÐÖÖÖÖÓ¦ÓóÌÐò¡£
2. ÄÚºËÖ÷º¯ÊýµÄÏêϸ´úÂëʾÀý
ÏÂÃæ¸ø³öһЩ¼òÆӵĴúÂëʾÀý£¬Õ¹Ê¾ÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯Àú³ÌÖеÄһЩҪº¦²Ù×÷£º
£¨1£©³õʼ»¯ÄÚºËÊý¾Ý½á¹¹ºÍϵͳ±äÁ¿
void start_kernel(void) { setup_arch(); setup_log(); MMU_init(); init_IRQ(); init_timers(); calibrate_delay(); setup_timer(); init_task(); cpus_timer_all(); smp_prepare_cpus(); boot_cpu_init(); time_init(); softirq_init(); build_all_zonelists(); page_alloc_init(); enable_sysrq(); migrate_init(); printk("Linux version %s ", UTS_RELEASE); printk("System is %s on %s ", system_name, machine_name); printk("CPU revision is %d ", cpu_data.revision); printk("machine is %s ", machine_id); }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëʾÀýչʾÁËÄÚºËÖ÷º¯ÊýÖжÔÄÚºËÊý¾Ý½á¹¹ºÍϵͳ±äÁ¿¾ÙÐгõʼ»¯µÄÀú³Ì¡£
£¨2£©ÉèÖô¦ÀíÆ÷ÇéÐÎ
void setup_arch(void) { switch (system_type) { case SYSTEM_32BIT: setup_32bit(); break; case SYSTEM_64BIT: setup_64bit(); break; default: panic("Unsupported system type"); } }
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖô¦ÀíÆ÷ÇéÐÎʱ£¬Æ¾Ö¤ÏµÍ³Î»ÊýŲÓöÔÓ¦µÄ³õʼ»¯º¯Êý¾ÙÐд¦ÀíÆ÷µÄÉèÖá£
£¨3£©³õʼ»¯ÄÚºË×Óϵͳ
void init_task(void) { struct task_struct *p; p = (struct task_struct *) kmalloc(sizeof(struct task_struct)); if (!p) panic("Cannot allocate memory for init task"); memset(p, 0, sizeof(struct task_struct)); p->pid = 1; p->state = TASK_RUNNING; p->mm = &init_mm; current = p; sprintf(p->comm, "%s", "init"); }
µÇ¼ºó¸´ÖÆ
³õʼ»¯ÄÚºË×Óϵͳʱ£¬½¨Éè init Àú³Ì×÷ΪϵͳµÄµÚÒ»¸öÀú³Ì¡£
£¨4£©Æô¶¯ÏµÍ³µ÷ÀíÆ÷
void cpu_idle(void) { while (1) { schedule(); sti(); } }
µÇ¼ºó¸´ÖÆ
ϵͳµ÷ÀíÆ÷ÈÏÕæÀú³Ì¼äµÄÇл»ºÍ×ÊÔ´µÄ·ÖÅÉ£¬cpu_idle º¯ÊýÊÇϵͳ¿ÕÏÐʱµÄ´¦Àíº¯Êý¡£
3. ×ܽá
ÔÚLinux²Ù×÷ϵͳÖУ¬ÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯Àú³ÌÖÐÊÎÑÝןÜÊÇÖ÷ÒªµÄ½ÇÉ«£¬ËüÈÏÕæÕû¸öϵͳµÄ³õʼ»¯ºÍÉèÖÃÊÂÇ飬ΪÓû§Ì¬³ÌÐòµÄÔËÐÐÌṩÁË»ù´¡¡£Í¨¹ýÖð²½ÆÊÎöÄÚºËÖ÷º¯ÊýµÄ¸÷¸ö¹¦Ð§ºÍ´úÂëʾÀý£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÃ÷È·ÄÚºËÆô¶¯µÄÕû¸öÀú³Ì£¬²¢ÉîÈëÑо¿LinuxÄں˵ÄÊÂÇéÔÀí¡£
ÒÔÉϾÍÊÇÆÊÎöLinuxÄÚºËÖ÷º¯ÊýÔÚϵͳÆô¶¯ÖеĽÇÉ«µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡