74.html
来自「linux 0.11中文版 有注释」· HTML 代码 · 共 632 行 · 第 1/4 页
HTML
632 行
<a name='L436'><a href='../S/77.html#L252' title='Refered from 252 in kernel/system_call.s.'>do_timer</a> (<b>long</b> cpl)
<a name='L437'><font color='red'>{</font>
<a name='L438'> <b>extern</b> <b>int</b> beepcount; <i><font color='green'>// 扬声器发声时间滴答数(kernel/chr_drv/console.c,697)</font></i>
<a name='L439'> <b>extern</b> <b>void</b> <a href='../S/60.html#L965' title='Defined at 965 in kernel/chr_drv/console.c.'>sysbeepstop</a> (<b>void</b>); <i><font color='green'>// 关闭扬声器(kernel/chr_drv/console.c,691)</font></i>
<a name='L440'>
<a name='L441'> <i><font color='green'>// 如果发声计数次数到,则关闭发声。(向0x61 口发送命令,复位位0 和1。位0 控制8253</font></i>
<a name='L442'> <i><font color='green'>// 计数器2 的工作,位1 控制扬声器)。</font></i>
<a name='L443'> <b>if</b> (beepcount)
<a name='L444'> <b>if</b> (!--beepcount)
<a name='L445'> <a href='../S/60.html#L965' title='Defined at 965 in kernel/chr_drv/console.c.'>sysbeepstop</a> ();
<a name='L446'>
<a name='L447'> <i><font color='green'>// 如果当前特权级(cpl)为0(最高,表示是内核程序在工作),则将超级用户运行时间stime 递增;</font></i>
<a name='L448'> <i><font color='green'>// 如果cpl > 0,则表示是一般用户程序在工作,增加utime。</font></i>
<a name='L449'> <b>if</b> (cpl)
<a name='L450'> current->utime++;
<a name='L451'> <b>else</b>
<a name='L452'> current->stime++;
<a name='L453'>
<a name='L454'> <i><font color='green'>// 如果有用户的定时器存在,则将链表第1 个定时器的值减1。如果已等于0,则调用相应的处理</font></i>
<a name='L455'> <i><font color='green'>// 程序,并将该处理程序指针置为空。然后去掉该项定时器。</font></i>
<a name='L456'> <b>if</b> (next_timer)
<a name='L457'> <font color='red'>{</font> <i><font color='green'>// next_timer 是定时器链表的头指针(见270 行)。</font></i>
<a name='L458'> next_timer->jiffies--;
<a name='L459'> <b>while</b> (next_timer && next_timer->jiffies <= 0)
<a name='L460'> <font color='red'>{</font>
<a name='L461'> <b>void</b> (*fn) (<b>void</b>); <i><font color='green'>// 这里插入了一个函数指针定义!!!??</font></i>
<a name='L462'>
<a name='L463'> fn = next_timer->fn;
<a name='L464'> next_timer->fn = <a href='../D/261.html' title='Multiple defined in 12 places.'>NULL</a>;
<a name='L465'> next_timer = next_timer->next;
<a name='L466'> (fn) (); <i><font color='green'>// 调用处理函数。</font></i>
<a name='L467'> <font color='red'>}</font>
<a name='L468'> <font color='red'>}</font>
<a name='L469'> <i><font color='green'>// 如果当前软盘控制器FDC 的数字输出寄存器中马达启动位有置位的,则执行软盘定时程序(245 行)。</font></i>
<a name='L470'> <b>if</b> (current_DOR & 0xf0)
<a name='L471'> <a href='../S/74.html#L351' title='Defined at 351 in kernel/sched.c.'>do_floppy_timer</a> ();
<a name='L472'> <b>if</b> ((--current->counter) > 0)
<a name='L473'> <b>return</b>; <i><font color='green'>// 如果进程运行时间还没完,则退出。</font></i>
<a name='L474'> current->counter = 0;
<a name='L475'> <b>if</b> (!cpl)
<a name='L476'> <b>return</b>; <i><font color='green'>// 对于超级用户程序,不依赖counter 值进行调度。</font></i>
<a name='L477'> <a href='../S/74.html#L146' title='Defined at 146 in kernel/sched.c.'>schedule</a> ();
<a name='L478'><font color='red'>}</font>
<a name='L479'>
<a name='L480'><i><font color='green'>// 系统调用功能 - 设置报警定时时间值(秒)。</font></i>
<a name='L481'><i><font color='green'>// 如果已经设置过alarm 值,则返回旧值,否则返回0。</font></i>
<a name='L482'><b>int</b>
<a name='L483'><a href='../R/630.html' title='Multiple refered from 2 places.'>sys_alarm</a> (<b>long</b> seconds)
<a name='L484'><font color='red'>{</font>
<a name='L485'> <b>int</b> old = current->alarm;
<a name='L486'>
<a name='L487'> <b>if</b> (old)
<a name='L488'> old = (old - jiffies) / <a href='../S/36.html#L5' title='Defined at 5 in include/linux/sched.h.'>HZ</a>;
<a name='L489'> current->alarm = (seconds > 0) ? (jiffies + <a href='../S/36.html#L5' title='Defined at 5 in include/linux/sched.h.'>HZ</a> * seconds) : 0;
<a name='L490'> <b>return</b> (old);
<a name='L491'><font color='red'>}</font>
<a name='L492'>
<a name='L493'><i><font color='green'>// 取当前进程号pid。</font></i>
<a name='L494'><b>int</b>
<a name='L495'><a href='../R/649.html' title='Multiple refered from 2 places.'>sys_getpid</a> (<b>void</b>)
<a name='L496'><font color='red'>{</font>
<a name='L497'> <b>return</b> current->pid;
<a name='L498'><font color='red'>}</font>
<a name='L499'>
<a name='L500'><i><font color='green'>// 取父进程号ppid。</font></i>
<a name='L501'><b>int</b>
<a name='L502'><a href='../R/650.html' title='Multiple refered from 2 places.'>sys_getppid</a> (<b>void</b>)
<a name='L503'><font color='red'>{</font>
<a name='L504'> <b>return</b> current->father;
<a name='L505'><font color='red'>}</font>
<a name='L506'>
<a name='L507'><i><font color='green'>// 取用户号uid。</font></i>
<a name='L508'><b>int</b>
<a name='L509'><a href='../R/651.html' title='Multiple refered from 2 places.'>sys_getuid</a> (<b>void</b>)
<a name='L510'><font color='red'>{</font>
<a name='L511'> <b>return</b> current->uid;
<a name='L512'><font color='red'>}</font>
<a name='L513'>
<a name='L514'><i><font color='green'>// 取euid。</font></i>
<a name='L515'><b>int</b>
<a name='L516'><a href='../R/646.html' title='Multiple refered from 2 places.'>sys_geteuid</a> (<b>void</b>)
<a name='L517'><font color='red'>{</font>
<a name='L518'> <b>return</b> current->euid;
<a name='L519'><font color='red'>}</font>
<a name='L520'>
<a name='L521'><i><font color='green'>// 取组号gid。</font></i>
<a name='L522'><b>int</b>
<a name='L523'><a href='../R/647.html' title='Multiple refered from 2 places.'>sys_getgid</a> (<b>void</b>)
<a name='L524'><font color='red'>{</font>
<a name='L525'> <b>return</b> current->gid;
<a name='L526'><font color='red'>}</font>
<a name='L527'>
<a name='L528'><i><font color='green'>// 取egid。</font></i>
<a name='L529'><b>int</b>
<a name='L530'><a href='../R/645.html' title='Multiple refered from 2 places.'>sys_getegid</a> (<b>void</b>)
<a name='L531'><font color='red'>{</font>
<a name='L532'> <b>return</b> current->egid;
<a name='L533'><font color='red'>}</font>
<a name='L534'>
<a name='L535'><i><font color='green'>// 系统调用功能 -- 降低对CPU 的使用优先权(有人会用吗??)。</font></i>
<a name='L536'><i><font color='green'>// 应该限制increment 大于0,否则的话,可使优先权增大!!</font></i>
<a name='L537'><b>int</b>
<a name='L538'><a href='../R/662.html' title='Multiple refered from 2 places.'>sys_nice</a> (<b>long</b> increment)
<a name='L539'><font color='red'>{</font>
<a name='L540'> <b>if</b> (current->priority - increment > 0)
<a name='L541'> current->priority -= increment;
<a name='L542'> <b>return</b> 0;
<a name='L543'><font color='red'>}</font>
<a name='L544'>
<a name='L545'><i><font color='green'>// 调度程序的初始化子程序。</font></i>
<a name='L546'><b>void</b>
<a name='L547'><a href='../R/585.html' title='Multiple refered from 2 places.'>sched_init</a> (<b>void</b>)
<a name='L548'><font color='red'>{</font>
<a name='L549'> <b>int</b> <a href='../D/839.html' title='Multiple defined in 4 places.'>i</a>;
<a name='L550'> <b>struct</b> desc_struct *p; <i><font color='green'>// 描述符表结构指针。</font></i>
<a name='L551'>
<a name='L552'> <b>if</b> (<b>sizeof</b> (<b>struct</b> sigaction) != 16) <i><font color='green'>// sigaction 是存放有关信号状态的结构。</font></i>
<a name='L553'> <a href='../S/72.html#L24' title='Defined at 24 in kernel/panic.c.'>panic</a> ("Struct sigaction MUST be 16 bytes");
<a name='L554'> <i><font color='green'>// 设置初始任务(任务0)的任务状态段描述符和局部数据表描述符(include/asm/system.h,65)。</font></i>
<a name='L555'> <a href='../S/25.html#L75' title='Defined at 75 in include/asm/system.h.'>set_tss_desc</a> (gdt + <a href='../S/36.html#L254' title='Defined at 254 in include/linux/sched.h.'>FIRST_TSS_ENTRY</a>, &(init_task.task.tss));
<a name='L556'> <a href='../S/25.html#L78' title='Defined at 78 in include/asm/system.h.'>set_ldt_desc</a> (gdt + <a href='../S/36.html#L256' title='Defined at 256 in include/linux/sched.h.'>FIRST_LDT_ENTRY</a>, &(init_task.task.ldt));
<a name='L557'> <i><font color='green'>// 清任务数组和描述符表项(注意i=1 开始,所以初始任务的描述符还在)。</font></i>
<a name='L558'> p = gdt + 2 + <a href='../S/36.html#L254' title='Defined at 254 in include/linux/sched.h.'>FIRST_TSS_ENTRY</a>;
<a name='L559'> <b>for</b> (<a href='../D/839.html' title='Multiple defined in 4 places.'>i</a> = 1; <a href='../D/839.html' title='Multiple defined in 4 places.'>i</a> < <a href='../S/36.html#L4' title='Defined at 4 in include/linux/sched.h.'>NR_TASKS</a>; <a href='../D/839.html' title='Multiple defined in 4 places.'>i</a>++)
<a name='L560'> <font color='red'>{</font>
<a name='L561'> task[<a href='../D/839.html' title='Multiple defined in 4 places.'>i</a>] = <a href='../D/261.html' title='Multiple defined in 12 places.'>NULL</a>;
<a name='L562'> p->a = p->b = 0;
<a name='L563'> p++;
<a name='L564'> p->a = p->b = 0;
<a name='L565'> p++;
<a name='L566'> <font color='red'>}</font>
<a name='L567'> <i><font color='green'>/* Clear NT, so that we won't have troubles with that later on */</font></i>
<a name='L568'> <i><font color='green'>/* 清除标志寄存器中的位NT,这样以后就不会有麻烦 */</font></i>
<a name='L569'> <i><font color='green'>// NT 标志用于控制程序的递归调用(Nested Task)。当NT 置位时,那么当前中断任务执行</font></i>
<a name='L570'> <i><font color='green'>// iret 指令时就会引起任务切换。NT 指出TSS 中的back_link 字段是否有效。</font></i>
<a name='L571'> <b>__asm__</b> ("pushfl ; andl $0xffffbfff,(%esp) ; popfl"); <i><font color='green'>// 复位NT 标志。</font></i>
<a name='L572'> <a href='../S/36.html#L262' title='Defined at 262 in include/linux/sched.h.'>ltr</a> (0); <i><font color='green'>// 将任务0 的TSS 加载到任务寄存器tr。</font></i>
<a name='L573'> <a href='../S/36.html#L264' title='Defined at 264 in include/linux/sched.h.'>lldt</a> (0); <i><font color='green'>// 将局部描述符表加载到局部描述符表寄存器。</font></i>
<a name='L574'> <i><font color='green'>// 注意!!是将GDT 中相应LDT 描述符的选择符加载到ldtr。只明确加载这一次,以后新任务</font></i>
<a name='L575'> <i><font color='green'>// LDT 的加载,是CPU 根据TSS 中的LDT 项自动加载。</font></i>
<a name='L576'> <i><font color='green'>// 下面代码用于初始化8253 定时器。</font></i>
<a name='L577'> <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x36, 0x43); <i><font color='green'>/* binary, mode 3, LSB/MSB, ch 0 */</font></i>
<a name='L578'> <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (<a href='../S/74.html#L59' title='Defined at 59 in kernel/sched.c.'>LATCH</a> & 0xff, 0x40); <i><font color='green'>/* LSB */</font></i><i><font color='green'>// 定时值低字节。</font></i>
<a name='L579'> <a href='../S/22.html#L3' title='Defined at 3 in include/asm/io.h.'>outb</a> (<a href='../S/74.html#L59' title='Defined at 59 in kernel/sched.c.'>LATCH</a> >> 8, 0x40); <i><font color='green'>/* MSB */</font></i><i><font color='green'>// 定时值高字节。</font></i>
<a name='L580'> <i><font color='green'>// 设置时钟中断处理程序句柄(设置时钟中断门)。</font></i>
<a name='L581'> <a href='../S/25.html#L33' title='Defined at 33 in include/asm/system.h.'>set_intr_gate</a> (0x20, &timer_interrupt);
<a name='L582'> <i><font color='green'>// 修改中断控制器屏蔽码,允许时钟中断。</font></i>
<a name='L583'> <a href='../S/22.html#L3' title='Defined at 3 in include/asm/io.h.'>outb</a> (<a href='../S/22.html#L25' title='Defined at 25 in include/asm/io.h.'>inb_p</a> (0x21) & ~0x01, 0x21);
<a name='L584'> <i><font color='green'>// 设置系统调用中断门。</font></i>
<a name='L585'> <a href='../S/25.html#L43' title='Defined at 43 in include/asm/system.h.'>set_system_gate</a> (0x80, &system_call);
<a name='L586'><font color='red'>}</font>
</pre>
<hr>
<a name='BOTTOM'>
<i><font color='green'>/* [<][>]<a href='#L36'>[^]</a><a href='#L547'>[v]</a><a href='#TOP'>[top]</a>[bottom]<a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?