Vous êtes sur la page 1sur 19

IOCTL and Device drivers:

Character Devices
And
Block Devices

By: Neerav Barot


Roll No: 174
M.E I (MSA)
80x86 I/0 Ports
 Any I/O device is hosted by one, and only one bus.

 The bus type affects the internal design of the I/O device, as
well as how the device has to be handled by the kernel

 The data path that connects a CPU to an I/O device is


generally called an I/O bus

 The 80 x 86 microprocessors use 16 of their address pins to


address I/O devices and 8, 16, or 32 of their data pins to
transfer data.

 The I/O bus, in turn, is connected to each I/O device by means


of a hierarchy of hardware components..
IOCTL Functions
 IOCTL functions are used to control
I/O devices.

 IOCTL do not mean Transfer Of Data.

 Data transfer can take place through DOS


or BIOS or Drivers.
Types of Devices
 Devices are classified in Two Types

 Character Devices: Process single Bit at a


time….
Examples are..Keyboard, Mouse, Printer.

 Block Devices : Process block of Data


simultaneously
Examples.. Disk Drive, CDROM.
Split view
Character Devices
 They are controlled in either Binary or
ASCII mode by IOCTL functions.

 They are named using DOS conventions.

 They are opened with file open function


3DH.
IOCTL character device names
Name Device
 AUX The COM1 Device in most systems
 CLOCK$ The real time system clock
 COM1 Serial communications port number 1
 COM2 Serial communications port number 2
 COM3 Serial communications port number 3
 COM4 Serial communications port number 4
 CON Console, the keyboard for Input and the video
display for output
 EMMXXXX0 The expanded memory manager EMM386.EXE
 LPT1 Parallel Port Number 1
 LPT2 Parallel Port Number 2
 LPT3 Parallel Port Number 3
 LPT4 Parallel Port Number 4
 NUL A Nonexistent Device
 PRN LPT1 in Most systems
 XMSXXXX0 The Extended Memory Manager HIMEM.SYS
Contents of DX after status-read
File Information
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
? ? ? ? ? ? ? ? 0 ? ? ? ? ? ?

File has been written (0)

Device Information
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

? ? ? ? ? ? ? 1
Standard Input Device (1)
Standard Output Device (1)
NUL device (1)
Clock device (1)
Supports INT 28H(1)
Binary data (1) OR ASCII data (0)
Signals EOF (0)
Supports IOCTL functions O2H and 03H (0)
Block Devices
 Block Devices transfer information block at a
time

 They are indicated using numbers.

 BL---00H……Default Block Device


---01H……Block Device A
---02H…… Block Device B….
Device Drivers
 Special programs installed by CONFIG.SYS
to control installable devices.

 Used for the newly added device

 It is a .COM file ( TINY model )


DEVICE DRIVER

Device Driver

Header Strategy Procedure Interrupt procedure


Construction of a device driver

Interrupt procedure

Strategy procedure
0012H

Driver Name
(8 bytes)
000AH
Interrupt offset address
0008H Header
Strategy offset address
0006H
Attribute
0004H
Driver linkage
0000H
HEADER
 Contains pointers that allow it to chain to other
drivers loaded in the system.

 First doubleword (-1) informs that this is last


driver in chain.

 It is followed by attribute word, which


indicates type of header included for driver
and type of device the driver installs.
The structure of the header attribute word

15 8 7 0
XXX

Standard input device (1)


Character device (1)
Standard output device (1)
IOCTL function 2 & 3 supported (1)
NUL device driver (0)
Output until busy supported (1)
Clock device (1)
Reserved (0)
INT 20H fast character output(1)
Open and close Supported (1)
Reserved (0)
Generic IOCTL supported(1)
IOCTL quires supported (1)
Strategy Procedure
 It is called whenever device driver is loaded in
to memory or whenever I/O requests are
issued.

 It’s main purpose is to save the Request header


and its address.

 Return Status Word Communicates


information back to DOS from Device Driver.
Device Driver Commands in Request Header By DOS
Command Purpose
 00H Initialize Driver
 01H Media Check
 02H Build BPB (Block Device Parameter Block)
 03H Control Read
 04H Read
 05H Non destructive Read
 06H Input Status
 07H Input Flush
 08H Write
 09H Write with verify
 0AH Output Status
 0BH Output Flush
 0CH Control write
 0DH Open Device
 0EH Close Device
 0FH Removable Media
 10H Output until Busy
 13H Generic IOCTL
 17H Get logical Device
 18H Set logical Device
 19H IOCTL Query
INTERRUPT PROCEDRE
 It uses request header to determine the
function requested by DOS.

 It performs all functions for Device Driver

 Interrupt Procedure is different from Interrupt


Handler.
; basic template for developing a device driver
;
.MODEL TINY
0000 .CODE
 0000 FFFFFFFF CHAIN DD -1 ; link to the next driver in chain
 0004 0000 ATTR DW 0 ; driver attribute
 0006 0016 R STRT DW STRAT ; address of strategy
 0008 001F R INTR DW INTT ; address of interrupt
 000A 4D 59 44 52 49 DNAME DB ‘MYDRIVER’ ; driver name
 56 45 52
 0012 00000000 REQ DD ? ; request header address
 0016 STRAT PROC FAR ; strategy procedure (must be
FAR)
 0016 89 1E 0012 R MOV WORD PTR REQ,BX ; save request header address
 001A 8C 06 0014 R MOV WORD PTR REQ+2,ES;
 001E CB RET
 001F STRAT ENDP
 001F INTT PROC FAR ; interrupt procedure (must
be FAR)
 001F CB RET ; procedure placed here
 0020 INTT ENDP
 END

Vous aimerez peut-être aussi