⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1127.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><TITLE>
linux知识宝库/内核技术/linux内核分析----初始化</TITLE>
<META http-equiv=content-type content="text/html; charset=gb2312">
<META content=linuxtips,linux,php,mysql,apache name=keywords>
<STYLE type=text/css>A:link {
	COLOR: #666666; TEXT-DECORATION: underline
}
A:active {
	COLOR: #666666; TEXT-DECORATION: underline
}
A:visited {
	COLOR: #666666; TEXT-DECORATION: underline
}
A:hover {
	COLOR: #708090; TEXT-DECORATION: none
}
.articletitle {
	FONT-WEIGHT: bold; FONT-SIZE: 18px; COLOR: #335588; LINE-HEIGHT: 26px; FONT-FAMILY: trebuchet ms, arial, verdana, helvetica, sans-serif; TEXT-DECORATION: none
}
INPUT {
	FONT-WEIGHT: normal; FONT-SIZE: 11px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
TEXTAREA {
	FONT-WEIGHT: normal; FONT-SIZE: 11px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.bginput {
	BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: #999999 1px solid; BORDER-BOTTOM: #999999 1px solid; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #f9f9f9
}
.text {
	BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #cccccc 1px solid
}
SELECT {
	FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: 宋体; BACKGROUND-COLOR: #ffffff
}
.firstalt {
	BACKGROUND-COLOR: #eeeeee
}
.secondalt {
	BACKGROUND-COLOR: #ffffff
}
.bigfont {
	FONT-SIZE: 45px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.normalfont {
	FONT-SIZE: 12px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.middlefont {
	FONT-SIZE: 11px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.smallfont {
	FONT-SIZE: 9px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.smallbold {
	FONT-WEIGHT: bold; COLOR: #000000
}
.articletitle {
	FONT-WEIGHT: bold; FONT-SIZE: 18px; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.subhead {
	FONT-WEIGHT: bold; FONT-SIZE: 13px; COLOR: #006699; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
#content A:link {
	COLOR: #3366cc; TEXT-DECORATION: underline
}
#content A:active {
	COLOR: #3366cc; TEXT-DECORATION: underline
}
#content A:visited {
	COLOR: #3366cc; TEXT-DECORATION: underline
}
#content A:hover {
	COLOR: #9966cc; TEXT-DECORATION: none
}
.content {
	FONT-SIZE: 14px; LINE-HEIGHT: 130%; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.titlefont {
	FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: verdana, arial, helvetica, sans-serif,宋体
}
.bodyline {
	BORDER-RIGHT: #aebdc4 1px solid; BORDER-TOP: #aebdc4 1px solid; BORDER-LEFT: #aebdc4 1px solid; BORDER-BOTTOM: #aebdc4 1px solid; BACKGROUND-COLOR: #ffffff
}
.cattitle {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #000000; LETTER-SPACING: 1px
}
.tableoutline {
	BORDER-RIGHT: #c4c4c4 1px solid; BORDER-TOP: #c4c4c4 1px solid; BORDER-LEFT: #c4c4c4 1px solid; BORDER-BOTTOM: #c4c4c4 1px solid
}
.root_td {
	PADDING-LEFT: 5px; FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY: Verdana; HEIGHT: 22px; BACKGROUND-COLOR: #ffffff; font-color: #000000
}
.child_td {
	PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 12px; PADDING-BOTTOM: 3px; COLOR: #000000; FONT-FAMILY: Verdana; HEIGHT: 22px; BACKGROUND-COLOR: #f5f5f5; TEXT-DECORATION: underline
}
#cattitle A:link {
	COLOR: #000000; TEXT-DECORATION: none
}
#cattitle A:visited {
	COLOR: #000000; TEXT-DECORATION: none
}
#cattitle A:active {
	COLOR: #000000; TEXT-DECORATION: none
}
#cattitle A:hover {
	COLOR: #000000; TEXT-DECORATION: none
}
</STYLE>

<SCRIPT language=JavaScript type=text/javascript>
<!--
if (parent.frames.length > 0) {
    parent.location.href = self.document.location
}
function ToggleNode(nodeObject, imgObject){
             if(nodeObject.style.display == '' || nodeObject.style.display == 'inline'){
               nodeObject.style.display = 'none';
               imgObject.src = 'images/plus.gif'/*tpa=http://www.linuxhero.com/docs/images/plus.gif*/;
             }else{
               nodeObject.style.display = 'inline';
               imgObject.src = 'images/minus.gif'/*tpa=http://www.linuxhero.com/docs/images/minus.gif*/;
            }
}
-->
</SCRIPT>

<BODY text=#000000 bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0" 
marginheight="0">
<CENTER>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  
  <TR>
    <TD vAlign=top>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=296 
          border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=76 
border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=100 
          border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=98 
border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=79 
border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=103 
          border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=26 
border=0></TD>
          <TD><IMG height=1 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 
        border=0></TD></TR>
        <TR>
          <TD colSpan=3><A title=linux知识宝库 
            href="index.html" tppabs="http://www.linuxhero.com/docs/index.html"><IMG height=83 
            src="images/header_r1_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c1.gif" width=472 border=0 
            name=header_r1_c1></A></TD>
            <TD colSpan=3>
              <form action="http://www.linuxhero.com/docs/search.html" method=get>
                <table 
                        style="BORDER-RIGHT: #c4c4c4 1px solid; BORDER-TOP: #c4c4c4 1px solid; BORDER-LEFT: #c4c4c4 1px solid; BORDER-BOTTOM: #c4c4c4 1px solid" 
                        cellspacing=0 cellpadding=3 width="95%" border=0 align="center">
                  <tbody> 
                  <tr> 
                    <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"> 
                      <div align=center><font class=normalfont>搜索文章: 
                        <input type=hidden value=result name=action2>
                          <input type=radio checked value=title name=type>标题 
                          <input type=radio value=content name=type>内容 
                          <input type=image src="images/button_go.gif" tppabs="http://www.linuxhero.com/docs/images/button_go.gif" border=0 name=image2>
                        </font></div>
                    </td>
                  </tr>
                  <tr> 
                    <td noWrap> 
                      <div align="center"> 
                        <input maxlength=100 size=30 name=keyword2>
                      </div>
                    </td>
                  </tr></tbody> 
                </table>
              </form>
            </TD>
            <TD rowSpan=2><IMG src="images/header_r1_c7.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c7.gif" width=26 border=0 name=header_r1_c7></TD>
          <TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
        <TR>
          <TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22 
            src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0 
            name=header_r2_c1></TD>
          <TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
              <DIV align=right><FONT class=normalfont>当前位置: 
              <A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
              <font color="#FF6699">&gt;&gt;</font>
<A href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</A>                 | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
            </TD>
          <TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 
        border=0></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff 
        border=0>
         <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
              
              <TR>
                <TD vAlign=top align=middle width="60%">
                  <TABLE cellSpacing=0 cellPadding=0 width="100%" 
                  background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
                    <TBODY>
                    <TR>
                        <TD vAlign=top width="80%"> 
                          <DIV align=center>
                        <FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
                            </FORM>
                        <TABLE cellSpacing=0 cellPadding=0 width="95%" 
                          border=0><TBODY>
                          <TR>
                            <TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif" 
                          height=30></TD></TR></TBODY></TABLE>
                        <TABLE cellSpacing=0 cellPadding=3 width="95%" 
                        align=center border=0>
                          <TBODY>
                          <TR>
                            <TD>
                              <TABLE cellSpacing=0 cellPadding=3 width="100%" 
                              border=0>
                                <TBODY>
                                <TR>
                                      <TD vAlign=top> 
<p><FONT class=normalfont><B><font color=blue>linux内核分析----初始化</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:e4gle <e4gle@whitecell.org><br>来自:Linux知识宝库<br>联系方式:无名<br><br>参考我提供的三个文件:bootsect.txt,head.txt,setup.txt<br>
至于x86的引导无非如下步骤:<br>
1,cpu初始化自身,在固定位置执行一条指令。<br>
2,这条指令条转到bios中。<br>
3,bios找到启动设备并获取mbr,该mbr指向我们的lilo<br>
4,bios装载并把控制权交给lilo<br>
5,压缩内核自解压,并把控制权转交给解压内核。<br>
简单点讲,就是cpu成为内核引导程序的引导程序的引导程序的引导程序,西西。<br>
这时内核将跳转到start_kernel是/init/main.c的重点函数,main.c函数很多定义都是为此函数服务的,这里我简要介绍一下这个函数的初始化流程。<br>
<br>
初始化内核:<br>
从start_kernel函数(/init/main.c)开始系统初始化工作,好,我们首先分析这个函数:<br>
函数开始首先:<br>
#ifdef __SMP__<br>
static int boot_cpu = 1;<br>
/* "current" has been set up, we need to load it now *//*定义双处理器用*/<br>
if (!boot_cpu)<br>
initialize_secondary();<br>
boot_cpu = 0;<br>
#endif<br>
<br>
定义双处理器。<br>
<br>
printk(linux_banner);       /*打印linux banner*/<br>
打印内核标题信息。<br>
<br>
开始初始化自身的部分组件(包括内存,硬件终端,调度等),我来逐个分析其中的函数:<br>
setup_arch(&command_line, &memory_start, &memory_end);/*初始化内存*/<br>
返回内核参数和内核可用的物理地址范围<br>
函数原型如下:<br>
setup_arch(char **, unsigned long *, unsigned long *);<br>
返回内存起始地址:<br>
memory_start = paging_init(memory_start,memory_end);<br>
看看paging_init的定义,是初始化请求页:<br>
paging_init(unsigned long start_mem, unsigned long end_mem)(会在以后的内存管理子系统分析时详细介绍)<br>
{<br>
int i;<br>
struct memclust_struct * cluster;<br>
struct memdesc_struct * memdesc;<br>
<br>
/* initialize mem_map[] */<br>
start_mem = free_area_init(start_mem, end_mem);/*遍历查找内存的空闲页*/<br>
<br>
/* find free clusters, update mem_map[] accordingly */<br>
memdesc = (struct memdesc_struct *)<br>
(hwrpb-&gt;mddt_offset + (unsigned long) hwrpb);<br>
cluster = memdesc-&gt;cluster;<br>
for (i = memdesc-&gt;numclusters ; i &gt; 0; i--, cluster++) {<br>
unsigned long pfn, nr;<br>
<br>
/* Bit 0 is console/PALcode reserved.  Bit 1 is<br>
  non-volatile memory -- we might want to mark<br>
  this for later */<br>
if (cluster-&gt;usage & 3)<br>
continue;<br>
pfn = cluster-&gt;start_pfn;<br>
if (pfn &gt;= MAP_NR(end_mem)) /* if we overrode mem size */<br>
continue;<br>
nr = cluster-&gt;numpages;<br>
if ((pfn + nr) &gt; MAP_NR(end_mem)) /* if override in cluster */<br>
nr = MAP_NR(end_mem) - pfn;<br>
<br>
while (nr--)<br>
clear_bit(PG_reserved, &mem_map[pfn++].flags);<br>
}<br>
<br>
memset((void *) ZERO_PAGE(0), 0, PAGE_SIZE);<br>
<br>
return start_mem;<br>
}<br>
<br>
trap_init();     初始化硬件中断<br>
/arch/i386/kernel/traps.c文件里定义此函数<br>
<br>
sched_init()     初始化调度<br>
/kernel/sched.c文件里有详细的调度算法(这些会在以后进程管理和调度的结构分析中详细介绍)<br>
<br>
parse_options(command_line) 分析传给内核的各种选项(随后再详细介绍)<br>
<br>
memory_start = console_init(memory_start,memory_end) 初始化控制台<br>
<br>
memory_start = kmem_cache_init(memory_start, memory_end) 初始化内核内存cache(同样,在以后的内存管理分析中介绍此函数)<br>
<br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -