55.html

来自「linux 0.11中文版 有注释」· HTML 代码 · 共 661 行 · 第 1/5 页

HTML
661
字号
<html>
<head>
<title>kernel/blk_drv/floppy.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/104.html'>kernel</a>/<a href='../files/105.html'>blk_drv</a>/floppy.c</h2>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L202'>[^]</a><a href='#L689'>[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='#L202' title='Defined at 202.'>floppy_deselect</a>
<li><a href='#L223' title='Defined at 223.'>floppy_change</a>
<li><a href='#L253' title='Defined at 253.'>setup_DMA</a>
<li><a href='#L301' title='Defined at 301.'>output_byte</a>
<li><a href='#L328' title='Defined at 328.'>result</a>
<li><a href='#L353' title='Defined at 353.'>bad_flp_intr</a>
<li><a href='#L380' title='Defined at 380.'>rw_interrupt</a>
<li><a href='#L413' title='Defined at 413.'>setup_rw_floppy</a>
<li><a href='#L446' title='Defined at 446.'>seek_interrupt</a>
<li><a href='#L474' title='Defined at 474.'>transfer</a>
<li><a href='#L530' title='Defined at 530.'>recal_interrupt</a>
<li><a href='#L544' title='Defined at 544.'>unexpected_floppy_interrupt</a>
<li><a href='#L556' title='Defined at 556.'>recalibrate_floppy</a>
<li><a href='#L571' title='Defined at 571.'>reset_interrupt</a>
<li><a href='#L587' title='Defined at 587.'>reset_floppy</a>
<li><a href='#L609' title='Defined at 609.'>floppy_on_interrupt</a>
<li><a href='#L630' title='Defined at 630.'>do_fd_request</a>
<li><a href='#L689' title='Defined at 689.'>floppy_init</a>
</ol>
<hr>
<pre>
<a name='L1'><i><font color='green'>/*</font></i>
<a name='L2'><i><font color='green'>* linux/kernel/floppy.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'><i><font color='green'>/*</font></i>
<a name='L8'><i><font color='green'>* 02.12.91 - Changed to static variables to indicate need for reset</font></i>
<a name='L9'><i><font color='green'>* and recalibrate. This makes some things easier (output_byte reset</font></i>
<a name='L10'><i><font color='green'>* checking etc), and means less interrupt jumping in case of errors,</font></i>
<a name='L11'><i><font color='green'>* so the code is hopefully easier to understand.</font></i>
<a name='L12'><i><font color='green'>*/</font></i>
<a name='L13'><i><font color='green'>/*</font></i>
<a name='L14'><i><font color='green'>* 02.12.91 - 修改成静态变量,以适应复位和重新校正操作。这使得某些事情</font></i>
<a name='L15'><i><font color='green'>* 做起来较为方便(output_byte 复位检查等),并且意味着在出错时中断跳转</font></i>
<a name='L16'><i><font color='green'>* 要少一些,所以希望代码能更容易被理解。</font></i>
<a name='L17'><i><font color='green'>*/</font></i>
<a name='L18'>
<a name='L19'><i><font color='green'>/*</font></i>
<a name='L20'><i><font color='green'>* This file is certainly a mess. I've tried my best to get it working,</font></i>
<a name='L21'><i><font color='green'>* but I don't like programming floppies, and I have only one anyway.</font></i>
<a name='L22'><i><font color='green'>* Urgel. I should check for more errors, and do more graceful error</font></i>
<a name='L23'><i><font color='green'>* recovery. Seems there are problems with several drives. I've tried to</font></i>
<a name='L24'><i><font color='green'>* correct them. No promises.</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'>* 这个文件当然比较混乱。我已经尽我所能使其能够工作,但我不喜欢软驱编程,</font></i>
<a name='L28'><i><font color='green'>* 而且我也只有一个软驱。另外,我应该做更多的查错工作,以及改正更多的错误。</font></i>
<a name='L29'><i><font color='green'>* 对于某些软盘驱动器好象还存在一些问题。我已经尝试着进行纠正了,但不能保证</font></i>
<a name='L30'><i><font color='green'>* 问题已消失。</font></i>
<a name='L31'><i><font color='green'>*/</font></i>
<a name='L32'>
<a name='L33'><i><font color='green'>/*</font></i>
<a name='L34'><i><font color='green'>* As with hd.c, all routines within this file can (and will) be called</font></i>
<a name='L35'><i><font color='green'>* by interrupts, so extreme caution is needed. A hardware interrupt</font></i>
<a name='L36'><i><font color='green'>* handler may not sleep, or a kernel panic will happen. Thus I cannot</font></i>
<a name='L37'><i><font color='green'>* call "floppy-on" directly, but have to set a special timer interrupt</font></i>
<a name='L38'><i><font color='green'>* etc.</font></i>
<a name='L39'><i><font color='green'>*</font></i>
<a name='L40'><i><font color='green'>* Also, I'm not certain this works on more than 1 floppy. Bugs may</font></i>
<a name='L41'><i><font color='green'>* abund.</font></i>
<a name='L42'><i><font color='green'>*/</font></i>
<a name='L43'><i><font color='green'>/*</font></i>
<a name='L44'><i><font color='green'>* 如同hd.c 文件一样,该文件中的所有子程序都能够被中断调用,所以需要特别</font></i>
<a name='L45'><i><font color='green'>* 地小心。硬件中断处理程序是不能睡眠的,否则内核就会傻掉(死机)?。因此不能</font></i>
<a name='L46'><i><font color='green'>* 直接调用"floppy-on",而只能设置一个特殊的时间中断等。</font></i>
<a name='L47'><i><font color='green'>*</font></i>
<a name='L48'><i><font color='green'>* 另外,我不能保证该程序能在多于1 个软驱的系统上工作,有可能存在错误。</font></i>
<a name='L49'><i><font color='green'>*/</font></i>
<a name='L50'>
<a name='L51'><font color='darkred'>#include</font> &lt;<a href='36.html'>linux/sched.h</a>&gt;        <i><font color='green'>// 调度程序头文件,定义了任务结构task_struct、初始任务0 的数据,</font></i>
<a name='L52'><i><font color='green'>// 还有一些有关描述符参数设置和获取的嵌入式汇编函数宏语句。</font></i>
<a name='L53'><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='L54'><font color='darkred'>#include</font> &lt;<a href='34.html'>linux/kernel.h</a>&gt;       <i><font color='green'>// 内核头文件。含有一些内核常用函数的原形定义。</font></i>
<a name='L55'><font color='darkred'>#include</font> &lt;linux/fdreg.h&gt;        <i><font color='green'>// 软驱头文件。含有软盘控制器参数的一些定义。</font></i>
<a name='L56'><font color='darkred'>#include</font> &lt;<a href='25.html'>asm/system.h</a>&gt;         <i><font color='green'>// 系统头文件。定义了设置或修改描述符/中断门等的嵌入式汇编宏。</font></i>
<a name='L57'><font color='darkred'>#include</font> &lt;<a href='22.html'>asm/io.h</a>&gt;             <i><font color='green'>// io 头文件。定义硬件端口输入/输出宏汇编语句。</font></i>
<a name='L58'><font color='darkred'>#include</font> &lt;<a href='24.html'>asm/segment.h</a>&gt;        <i><font color='green'>// 段操作头文件。定义了有关段寄存器操作的嵌入式汇编函数。</font></i>
<a name='L59'>
<a name='L60'><font color='darkred'>#define</font> <a href='../R/121.html' title='Multiple refered from 9 places.'>MAJOR_NR</a> 2              <i><font color='green'>// 软驱的主设备号是2。</font></i>
<a name='L61'><font color='darkred'>#include</font> "<a href='54.html'>blk.h</a>"                <i><font color='green'>// 块设备头文件。定义请求数据结构、块设备数据结构和宏函数等信息。</font></i>
<a name='L62'>
<a name='L63'><b>static</b> <b>int</b> recalibrate = 0;     <i><font color='green'>// 标志:需要重新校正。</font></i>
<a name='L64'><b>static</b> <b>int</b> reset = 0;           <i><font color='green'>// 标志:需要进行复位操作。</font></i>
<a name='L65'><b>static</b> <b>int</b> seek = 0;            <i><font color='green'>// 寻道。</font></i>
<a name='L66'>
<a name='L67'><b>extern</b> <b>unsigned</b> <b>char</b> current_DOR;       <i><font color='green'>// 当前数字输出寄存器(Digital Output Register)。</font></i>
<a name='L68'>
<a name='L69'><font color='darkred'>#define</font> <a href='../R/498.html' title='Multiple refered from 7 places.'>immoutb_p</a>(val,port) \   <i><font color='green'>// 字节直接输出(嵌入汇编语言宏)。</font></i>
<a name='L70'><b>__asm__</b> ("outb %0,%1\n\tjmp 1f\n1:\tjmp 1f\n1:"::"a" ((<b>char</b>) (val)),
<a name='L71'>         "i" (port))
<a name='L72'><i><font color='green'>// 这两个定义用于计算软驱的设备号。次设备号 = TYPE*4 + DRIVE。计算方法参见列表后。</font></i>
<a name='L73'><font color='darkred'>#define</font> <a href='../R/289.html' title='Multiple refered from 4 places.'>TYPE</a>(x) ((x)&gt;&gt;2)        <i><font color='green'>// 软驱类型(2--1.2Mb,7--1.44Mb)。</font></i>
<a name='L74'><font color='darkred'>#define</font> DRIVE(x) ((x)&amp;0x03)     <i><font color='green'>// 软驱序号(0--3 对应A--D)。</font></i>
<a name='L75'><i><font color='green'>/*</font></i>
<a name='L76'><i><font color='green'>* Note that MAX_ERRORS=8 doesn't imply that we retry every bad read</font></i>
<a name='L77'><i><font color='green'>* max 8 times - some types of errors increase the errorcount by 2,</font></i>
<a name='L78'><i><font color='green'>* so we might actually retry only 5-6 times before giving up.</font></i>
<a name='L79'><i><font color='green'>*/</font></i>
<a name='L80'><i><font color='green'>/*</font></i>
<a name='L81'><i><font color='green'>* 注意,下面定义MAX_ERRORS=8 并不表示对每次读错误尝试最多8 次 - 有些类型</font></i>
<a name='L82'><i><font color='green'>* 的错误将把出错计数值乘2,所以我们实际上在放弃操作之前只需尝试5-6 遍即可。</font></i>
<a name='L83'><i><font color='green'>*/</font></i>
<a name='L84'><font color='darkred'>#define</font> <a href='../R/124.html' title='Multiple refered from 4 places.'>MAX_ERRORS</a> 8
<a name='L85'><i><font color='green'>/*</font></i>
<a name='L86'><i><font color='green'>* globals used by 'result()'</font></i>
<a name='L87'><i><font color='green'>*/</font></i>
<a name='L88'><i><font color='green'>/* 下面是函数'result()'使用的全局变量 */</font></i>
<a name='L89'><i><font color='green'>// 这些状态字节中各比特位的含义请参见include/linux/fdreg.h 头文件。</font></i>
<a name='L90'><font color='darkred'>#define</font> <a href='../R/126.html' title='Multiple refered from 2 places.'>MAX_REPLIES</a> 7           <i><font color='green'>// FDC 最多返回7 字节的结果信息。</font></i>
<a name='L91'>     <b>static</b> <b>unsigned</b> <b>char</b> reply_buffer[<a href='../S/55.html#L90' title='Defined at 90 in kernel/blk_drv/floppy.c.'>MAX_REPLIES</a>];    <i><font color='green'>// 存放FDC 返回的结果信息。</font></i>
<a name='L92'><font color='darkred'>#define</font> <a href='../R/232.html' title='Multiple refered from 4 places.'>ST0</a> (reply_buffer[0])   <i><font color='green'>// 返回结果状态字节0。</font></i>
<a name='L93'><font color='darkred'>#define</font> <a href='../R/233.html' title='Multiple refered from 4 places.'>ST1</a> (reply_buffer[1])   <i><font color='green'>// 返回结果状态字节1。</font></i>
<a name='L94'><font color='darkred'>#define</font> <a href='../S/55.html#L388' title='Refered from 388 in kernel/blk_drv/floppy.c.'>ST2</a> (reply_buffer[2])   <i><font color='green'>// 返回结果状态字节2。</font></i>
<a name='L95'><font color='darkred'>#define</font> ST3 (reply_buffer[3])   <i><font color='green'>// 返回结果状态字节3。</font></i>
<a name='L96'>
<a name='L97'><i><font color='green'>/*</font></i>
<a name='L98'><i><font color='green'>* This struct defines the different floppy types. Unlike minix</font></i>
<a name='L99'><i><font color='green'>* linux doesn't have a "search for right type"-type, as the code</font></i>

⌨️ 快捷键说明

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