Unix kernel calling the kernel

Don Ferencz ferencz at cwsys3..CWRU.Edu
Thu Oct 27 00:51:23 AEST 1988


In article <17200 at shemp.CS.UCLA.EDU> michael at CS.UCLA.EDU () writes:
>I need to know how a part of the unix kernel can call another part of the
>kernel (in particular, open(), read(), write(), close).
> [...]
>The system is a system 5 release 2 (Unix Pc 3.51a)
> [...]
>TRAP inside the kernel. But there is no "open", or "read" routine defined
>in the kernel's name list.
>
>			Michael

I don't want to go into a full desciption of how device driver routines
work, but I have had some experience in their design, so I can give
a brief note on where to look.

You won't find routines named "read()" and "write()" in the kernel tables:
these (and all other) system calls cause a trap that puts the 
processor into "kernel mode" where it looks up the routine name in
the "sysent" table (not very important).  All "read()"s, "write()"s and
other I/O calls look up which device you are referring to, then
based on whether the device is a "block" (like disks) or "character" device,
(like serial ports) check the "bdevsw" or "cdevsw" tables,
respectively.  For the hard disk driver, the "bdevsw" table has
an entry for the "major" number of the hard disk, which should have
a field which then points to the actual routine called.  To make
things easy (???) for us, it is conventional to name the routine
xxxread() and xxxwrite, where "xxx" is the name of the driver (for a 
hard disk driver, it should be "hdread()" and "hdwrite()", so these are
the actual routines you are looking for.

As far as calling one routine from another, that's no problem (unless
you are using STREAMS, which is SYSV 3.0 or greater, so don't sweat
it).  Just make sure you give the correct arguments to "hdread()"
and the like. 

The best source of information on this stuff is "The UNIX Device
Drivers Guide" by AT&T.  I think you'll definitely need a copy to
do any serious device driver work.


===========================================================================
| Don Ferencz                       |  "And in the end/                   |
| ferencz at cwsys3.cwru.EDU           |   The love you take/                |
| Department of Systems Engineering |   Is equal to the love you make."   |
| Case Western Reserve University   |       -- The Beatles                |
===========================================================================



More information about the Comp.unix.wizards mailing list