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

📄 52.html

📁 linux 0.11中文版 有注释
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<html>
<head>
<title>init/main.c</title>
<meta name='robots' content='noindex,nofollow'>
<meta name='generator' content='GLOBAL-5.4.1'>
</head>
<body text='#191970' bgcolor='#f5f5dc' vlink='gray'>
<a name='TOP'><h2><a href='../mains.html'>root</a>/<a href='../files/103.html'>init</a>/main.c</h2>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L35'>[^]</a><a href='#L232'>[v]</a>[top]<a href='#BOTTOM'>[bottom]</a><a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
<hr>
<h2>DEFINITIONS</h2>
This source file includes following definitions.
<ol>
<li><a href='#L35' title='Defined at 35.'>_syscall0</a>
<li><a href='#L103' title='Defined at 103.'>time_init</a>
<li><a href='#L138' title='Defined at 138.'>main</a>
<li><a href='#L203' title='Defined at 203.'>printf</a>
<li><a href='#L232' title='Defined at 232.'>init</a>
</ol>
<hr>
<pre>
<a name='L1'><i><font color='green'>/*</font></i>
<a name='L2'><i><font color='green'> * linux/init/main.c</font></i>
<a name='L3'><i><font color='green'> *</font></i>
<a name='L4'><i><font color='green'> * (C) 1991 Linus Torvalds</font></i>
<a name='L5'><i><font color='green'> */</font></i>
<a name='L6'>
<a name='L7'><font color='darkred'>#define</font> <a href='../S/50.html#L71' title='Refered from 71 in include/unistd.h.'>__LIBRARY__</a>             <i><font color='green'>// 定义该变量是为了包括定义在unistd.h 中的内嵌汇编代码等信息。</font></i>
<a name='L8'><font color='darkred'>#include</font> &lt;<a href='50.html'>unistd.h</a>&gt;             <i><font color='green'>// *.h 头文件所在的默认目录是include/,则在代码中就不用明确指明位置。</font></i>
<a name='L9'><i><font color='green'>// 如果不是UNIX 的标准头文件,则需要指明所在的目录,并用双引号括住。</font></i>
<a name='L10'><i><font color='green'>// 标准符号常数与类型文件。定义了各种符号常数和类型,并申明了各种函数。</font></i>
<a name='L11'><i><font color='green'>// 如果定义了__LIBRARY__,则还包括系统调用号和内嵌汇编代码_syscall0()等。</font></i>
<a name='L12'><font color='darkred'>#include</font> &lt;<a href='49.html'>time.h</a>&gt;               <i><font color='green'>// 时间类型头文件。其中最主要定义了tm 结构和一些有关时间的函数原形。</font></i>
<a name='L13'>
<a name='L14'><i><font color='green'>/*</font></i>
<a name='L15'><i><font color='green'> * we need this inline - forking from kernel space will result</font></i>
<a name='L16'><i><font color='green'> * in NO COPY ON WRITE (!!!), until an execve is executed. This</font></i>
<a name='L17'><i><font color='green'> * is no problem, but for the stack. This is handled by not letting</font></i>
<a name='L18'><i><font color='green'> * main() use the stack at all after fork(). Thus, no function</font></i>
<a name='L19'><i><font color='green'> * calls - which means inline code for fork too, as otherwise we</font></i>
<a name='L20'><i><font color='green'> * would use the stack upon exit from 'fork()'.</font></i>
<a name='L21'><i><font color='green'> *</font></i>
<a name='L22'><i><font color='green'> * Actually only pause and fork are needed inline, so that there</font></i>
<a name='L23'><i><font color='green'> * won't be any messing with the stack from main(), but we define</font></i>
<a name='L24'><i><font color='green'> * some others too.</font></i>
<a name='L25'><i><font color='green'> */</font></i>
<a name='L26'><i><font color='green'>/*</font></i>
<a name='L27'><i><font color='green'> * 我们需要下面这些内嵌语句 - 从内核空间创建进程(forking)将导致没有写时复制(COPY ON WRITE)!!!</font></i>
<a name='L28'><i><font color='green'> * 直到一个执行execve 调用。这对堆栈可能带来问题。处理的方法是在fork()调用之后不让main()使用</font></i>
<a name='L29'><i><font color='green'> * 任何堆栈。因此就不能有函数调用 - 这意味着fork 也要使用内嵌的代码,否则我们在从fork()退出</font></i>
<a name='L30'><i><font color='green'> * 时就要使用堆栈了。</font></i>
<a name='L31'><i><font color='green'> * 实际上只有pause 和fork 需要使用内嵌方式,以保证从main()中不会弄乱堆栈,但是我们同时还</font></i>
<a name='L32'><i><font color='green'> * 定义了其它一些函数。</font></i>
<a name='L33'><i><font color='green'> */</font></i>
<a name='L34'><b>static</b> <b>inline</b>
<a name='L35'><a href='../S/88.html#L14' title='Refered from 14 in lib/setsid.c.'>_syscall0</a> (<b>int</b>, fork)           <i><font color='green'>// 是unistd.h 中的内嵌宏代码。以嵌入汇编的形式调用</font></i>
<a name='L36'>        <i><font color='green'>// Linux 的系统调用中断0x80。该中断是所有系统调用的</font></i>
<a name='L37'>        <i><font color='green'>// 入口。该条语句实际上是int fork()创建进程系统调用。</font></i>
<a name='L38'>        <i><font color='green'>// syscall0 名称中最后的0 表示无参数,1 表示1 个参数。</font></i>
<a name='L39'>     <b>static</b> <b>inline</b> _syscall0 (<b>int</b>, pause)       <i><font color='green'>// int pause()系统调用:暂停进程的执行,直到</font></i>
<a name='L40'>        <i><font color='green'>// 收到一个信号。</font></i>
<a name='L41'>     <b>static</b> <b>inline</b> _syscall1 (<b>int</b>, setup, <b>void</b> *, BIOS) <i><font color='green'>// int setup(void * BIOS)系统调用,仅用于</font></i>
<a name='L42'>        <i><font color='green'>// linux 初始化(仅在这个程序中被调用)。</font></i>
<a name='L43'>     <b>static</b> <b>inline</b> _syscall0 (<b>int</b>, sync)        <i><font color='green'>// int sync()系统调用:更新文件系统。</font></i>
<a name='L44'><font color='darkred'>#include</font> &lt;<a href='38.html'>linux/tty.h</a>&gt;          <i><font color='green'>// tty 头文件,定义了有关tty_io,串行通信方面的参数、常数。</font></i>
<a name='L45'><font color='darkred'>#include</font> &lt;<a href='36.html'>linux/sched.h</a>&gt;        <i><font color='green'>// 调度程序头文件,定义了任务结构task_struct、第1 个初始任务</font></i>
<a name='L46'>        <i><font color='green'>// 的数据。还有一些以宏的形式定义的有关描述符参数设置和获取的</font></i>
<a name='L47'>        <i><font color='green'>// 嵌入式汇编函数程序。</font></i>
<a name='L48'><font color='darkred'>#include</font> &lt;<a href='33.html'>linux/head.h</a>&gt;         <i><font color='green'>// head 头文件,定义了段描述符的简单结构,和几个选择符常量。</font></i>
<a name='L49'><font color='darkred'>#include</font> &lt;<a href='25.html'>asm/system.h</a>&gt;         <i><font color='green'>// 系统头文件。以宏的形式定义了许多有关设置或修改</font></i>
<a name='L50'>        <i><font color='green'>// 描述符/中断门等的嵌入式汇编子程序。</font></i>
<a name='L51'><font color='darkred'>#include</font> &lt;<a href='22.html'>asm/io.h</a>&gt;             <i><font color='green'>// io 头文件。以宏的嵌入汇编程序形式定义对io 端口操作的函数。</font></i>
<a name='L52'><font color='darkred'>#include</font> &lt;<a href='41.html'>stddef.h</a>&gt;             <i><font color='green'>// 标准定义头文件。定义了NULL, offsetof(TYPE, MEMBER)。</font></i>
<a name='L53'><font color='darkred'>#include</font> &lt;<a href='40.html'>stdarg.h</a>&gt;             <i><font color='green'>// 标准参数头文件。以宏的形式定义变量参数列表。主要说明了-个</font></i>
<a name='L54'>        <i><font color='green'>// 类型(va_list)和三个宏(va_start, va_arg 和va_end),vsprintf、</font></i>
<a name='L55'>        <i><font color='green'>// vprintf、vfprintf。</font></i>
<a name='L56'><font color='darkred'>#include</font> &lt;<a href='50.html'>unistd.h</a>&gt;
<a name='L57'><font color='darkred'>#include</font> &lt;<a href='29.html'>fcntl.h</a>&gt;              <i><font color='green'>// 文件控制头文件。用于文件及其描述符的操作控制常数符号的定义。</font></i>
<a name='L58'><font color='darkred'>#include</font> &lt;<a href='45.html'>sys/types.h</a>&gt;          <i><font color='green'>// 类型头文件。定义了基本的系统数据类型。</font></i>
<a name='L59'><font color='darkred'>#include</font> &lt;<a href='31.html'>linux/fs.h</a>&gt;           <i><font color='green'>// 文件系统头文件。定义文件表结构(file,buffer_head,m_inode 等)。</font></i>
<a name='L60'>     <b>static</b> <b>char</b> printbuf[1024];        <i><font color='green'>// 静态字符串数组。</font></i>
<a name='L61'>
<a name='L62'>     <b>extern</b> <b>int</b> vsprintf ();    <i><font color='green'>// 送格式化输出到一字符串中(在kernel/vsprintf.c,92 行)。</font></i>
<a name='L63'>     <b>extern</b> <b>void</b> init (<b>void</b>);   <i><font color='green'>// 函数原形,初始化(在168 行)。</font></i>
<a name='L64'>     <b>extern</b> <b>void</b> blk_dev_init (<b>void</b>);   <i><font color='green'>// 块设备初始化子程序(kernel/blk_drv/ll_rw_blk.c,157 行)</font></i>
<a name='L65'>     <b>extern</b> <b>void</b> chr_dev_init (<b>void</b>);   <i><font color='green'>// 字符设备初始化(kernel/chr_drv/tty_io.c, 347 行)</font></i>
<a name='L66'>     <b>extern</b> <b>void</b> hd_init (<b>void</b>);        <i><font color='green'>// 硬盘初始化程序(kernel/blk_drv/hd.c, 343 行)</font></i>
<a name='L67'>     <b>extern</b> <b>void</b> floppy_init (<b>void</b>);    <i><font color='green'>// 软驱初始化程序(kernel/blk_drv/floppy.c, 457 行)</font></i>
<a name='L68'>     <b>extern</b> <b>void</b> mem_init (<b>long</b> start, <b>long</b> end);       <i><font color='green'>// 内存管理初始化(mm/memory.c, 399 行)</font></i>
<a name='L69'>     <b>extern</b> <b>long</b> rd_init (<b>long</b> mem_start, <b>int</b> length);  <i><font color='green'>//虚拟盘初始化(kernel/blk_drv/ramdisk.c,52)</font></i>
<a name='L70'>     <b>extern</b> <b>long</b> kernel_mktime (<b>struct</b> tm *tm); <i><font color='green'>// 建立内核时间(秒)。</font></i>
<a name='L71'>     <b>extern</b> <b>long</b> startup_time;  <i><font color='green'>// 内核启动时间(开机时间)(秒)。</font></i>
<a name='L72'>
<a name='L73'>        <i><font color='green'>/*</font></i>
<a name='L74'><i><font color='green'>         * This is set up by the setup-routine at boot-time</font></i>
<a name='L75'><i><font color='green'>         */</font></i>
<a name='L76'>        <i><font color='green'>/*</font></i>
<a name='L77'><i><font color='green'>         * 以下这些数据是由setup.s 程序在引导时间设置的(参见第2 章2.3.1 节中的表2.1)。</font></i>
<a name='L78'><i><font color='green'>         */</font></i>
<a name='L79'><font color='darkred'>#define</font> EXT_MEM_K (*(<b>unsigned</b> <b>short</b> *)0x90002)  <i><font color='green'>// 1M 以后的扩展内存大小(KB)。</font></i>
<a name='L80'><font color='darkred'>#define</font> DRIVE_INFO (*(<b>struct</b> drive_info *)0x90080)      <i><font color='green'>// 硬盘参数表基址。</font></i>
<a name='L81'><font color='darkred'>#define</font> ORIG_ROOT_DEV (*(<b>unsigned</b> <b>short</b> *)0x901FC)      <i><font color='green'>// 根文件系统所在设备号。</font></i>
<a name='L82'>
<a name='L83'>        <i><font color='green'>/*</font></i>
<a name='L84'><i><font color='green'>         * Yeah, yeah, it's ugly, but I cannot find how to do this correctly</font></i>
<a name='L85'><i><font color='green'>         * and this seems to work. I anybody has more info on the real-time</font></i>
<a name='L86'><i><font color='green'>         * clock I'd be interested. Most of this was trial and error, and some</font></i>
<a name='L87'><i><font color='green'>         * bios-listing reading. Urghh.</font></i>

⌨️ 快捷键说明

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