old-www/HOWTO/Unix-and-Internet-Fundament.../devices.html

195 lines
4.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>How do input devices and interrupts work?</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The Unix and Internet Fundamentals HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="What happens when you run programs
after boot time?"
HREF="running-programs.html"><LINK
REL="NEXT"
TITLE="How does my computer do several things at once?"
HREF="multitasking.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Unix and Internet Fundamentals HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="running-programs.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="multitasking.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="devices"
></A
>6. How do input devices and interrupts work?</H1
><P
>Your keyboard is a very simple input device; simple because it
generates small amounts of data very slowly (by a computer's standards).
When you press or release a key, that event is signalled up the keyboard
cable to raise a <I
CLASS="firstterm"
>hardware
interrupt</I
>.</P
><P
>It's the operating system's job to watch for such interrupts. For
each possible kind of interrupt, there will be an <I
CLASS="firstterm"
>interrupt
handler</I
>, a part of the operating system that stashes
away any data associated with them (like your keypress/keyrelease value)
until it can be processed.</P
><P
>What the interrupt handler for your keyboard actually does is post the
key value into a system area near the bottom of memory. There, it will
be available for inspection when the operating system passes control to
whichever program is currently supposed to be reading from the keyboard.</P
><P
>More complex input devices like disk or network cards work in a similar
way. Earlier, I referred to a disk controller using the bus to signal that
a disk request has been fulfilled. What actually happens is that the disk
raises an interrupt. The disk interrupt handler then copies the retrieved
data into memory, for later use by the program that made the request.</P
><P
>Every kind of interrupt has an associated <I
CLASS="firstterm"
>priority
level</I
>.
Lower-priority interrupts (like keyboard events) have to wait on
higher-priority interrupts (like clock ticks or disk events). Unix is
designed to give high priority to the kinds of events that need to be
processed rapidly in order to keep the machine's response smooth.</P
><P
>In your operating system's boot-time messages, you may see references
to <I
CLASS="firstterm"
>IRQ</I
>
numbers. You may be aware that one of the common ways to misconfigure
hardware is to have two different devices try to use the same IRQ, without
understanding exactly why. </P
><P
>Here's the answer. IRQ is short for "Interrupt Request". The operating
system needs to know at startup time which numbered interrupts each
hardware device will use, so it can associate the proper handlers with each
one. If two different devices try use the same IRQ, interrupts will
sometimes get dispatched to the wrong handler. This will usually at least
lock up the device, and can sometimes confuse the OS badly enough that it
will flake out or crash.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="running-programs.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="multitasking.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>What happens when you run programs
after boot time?</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>How does my computer do several things at once?</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>