+ All Categories
Home > Documents > 9232599 IOCTL Device Drivers

9232599 IOCTL Device Drivers

Date post: 30-May-2018
Category:
Upload: nguyenvan-thanh
View: 225 times
Download: 0 times
Share this document with a friend

of 19

Transcript
  • 8/9/2019 9232599 IOCTL Device Drivers

    1/19

    IOCTL and Device drivers:IOCTL and Device drivers:

    Character DevicesCharacter Devices

    AndAndBlock DevicesBlock Devices

    By: Neerav BarotBy: Neerav Barot

    Roll No: 174Roll No: 174M.E I (MSA)M.E I (MSA)

  • 8/9/2019 9232599 IOCTL Device Drivers

    2/19

    80x86 I/0 Ports80x86 I/0 Ports

    Any I/O device is hosted by one, and only one bus.Any I/O device is hosted by one, and only one bus.

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

    The data path that connects a CPU to an I/O device isThe data path that connects a CPU to an I/O device isgenerally called angenerally called an I/O busI/O bus

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

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

    The I/O bus, in turn, is connected to each I/O device by meansThe I/O bus, in turn, is connected to each I/O device by meansof a hierarchy of hardware components..of a hierarchy of hardware components..

  • 8/9/2019 9232599 IOCTL Device Drivers

    3/19

    IOCTL FunctionsIOCTL Functions

    IOCTL functions are used to controlIOCTL functions are used to control

    I/O devices.I/O devices.

    IOCTL do not mean Transfer Of Data.IOCTL do not mean Transfer Of Data.

    Data transfer can take place through DOSData transfer can take place through DOS

    or BIOS or Drivers.or BIOS or Drivers.

  • 8/9/2019 9232599 IOCTL Device Drivers

    4/19

    Types of DevicesTypes of Devices

    Devices are classified in Two TypesDevices are classified in Two Types

    Character Devices:Character Devices: Process single Bit at aProcess single Bit at a

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

    Block Devices :Block Devices : Process block of DataProcess block of Datasimultaneouslysimultaneously

    Examples.. Disk Drive, CDROM.Examples.. Disk Drive, CDROM.

  • 8/9/2019 9232599 IOCTL Device Drivers

    5/19

    Split viewSplit view

  • 8/9/2019 9232599 IOCTL Device Drivers

    6/19

    Character DevicesCharacter Devices

    They are controlled in either Binary orThey are controlled in either Binary orASCII mode by IOCTL functions.ASCII mode by IOCTL functions.

    They are named using DOS conventions.They are named using DOS conventions.

    They are opened with file open functionThey are opened with file open function3DH.3DH.

  • 8/9/2019 9232599 IOCTL Device Drivers

    7/19

    IOCTL character device namesIOCTL character device namesNameName DeviceDevice

    AUXAUX The COM1 Device in most systemsThe COM1 Device in most systems CLOCK$CLOCK$ The real time system clockThe real time system clock COM1COM1 Serial communications port number 1Serial communications port number 1 COM2COM2 Serial communications port number 2Serial communications port number 2 COM3COM3 Serial communications port number 3Serial communications port number 3 COM4COM4 Serial communications port number 4Serial communications port number 4 CONCON Console, the keyboard for Input and the videoConsole, the keyboard for Input and the video

    display for outputdisplay for output EMMXXXX0EMMXXXX0 The expanded memory manager EMM386.EXEThe expanded memory manager EMM386.EXE LPT1LPT1 Parallel Port Number 1Parallel Port Number 1 LPT2LPT2 Parallel Port Number 2Parallel Port Number 2 LPT3LPT3 Parallel Port Number 3Parallel Port Number 3 LPT4LPT4 Parallel Port Number 4Parallel Port Number 4 NULNUL A Nonexistent DeviceA Nonexistent Device PRNPRN LPT1 in Most systemsLPT1 in Most systems XMSXXXX0XMSXXXX0 The Extended Memory Manager HIMEM.SYSThe Extended Memory Manager HIMEM.SYS

  • 8/9/2019 9232599 IOCTL Device Drivers

    8/19

    Contents of DX after status-readContents of DX after status-read

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

    ??????0????????

    File has been written (0)

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

    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)

    File Information

    Device Information

  • 8/9/2019 9232599 IOCTL Device Drivers

    9/19

    Block DevicesBlock Devices

    Block Devices transfer information block at aBlock Devices transfer information block at atimetime

    They are indicated using numbers.They are indicated using numbers.

    BL---BL---00HDefault Block Device00HDefault Block Device

    ------01HBlock Device A01HBlock Device A

    ------02H Block Device B.02H Block Device B.

  • 8/9/2019 9232599 IOCTL Device Drivers

    10/19

    Device DriversDevice Drivers

    Special programs installed by CONFIG.SYSSpecial programs installed by CONFIG.SYS

    to control installable devices.to control installable devices.

    Used for the newly added deviceUsed for the newly added device

    It is a .COM file ( TINY model )It is a .COM file ( TINY model )

  • 8/9/2019 9232599 IOCTL Device Drivers

    11/19

    DEVICE DRIVERDEVICE DRIVER

    Device Driver

    Header Strategy Procedure Interrupt procedure

  • 8/9/2019 9232599 IOCTL Device Drivers

    12/19

    Construction of a device driverConstruction of a device driver

    Interrupt procedure

    Strategy procedure

    Driver Name

    (8 bytes)

    Interrupt offset address

    Strategy offset address

    Attribute

    Driver linkage

    0012H

    000AH

    0008H

    0006H

    0004H

    Header

    0000H

  • 8/9/2019 9232599 IOCTL Device Drivers

    13/19

    HEADERHEADER

    Contains pointers that allow it to chain to otherContains pointers that allow it to chain to otherdrivers loaded in the system.drivers loaded in the system.

    First doubleword (-1) informs that this is lastFirst doubleword (-1) informs that this is lastdriver in chain.driver in chain.

    It is followed by attribute word, whichIt is followed by attribute word, whichindicates type of header included for driverindicates type of header included for driverand type of device the driver installs.and type of device the driver installs.

  • 8/9/2019 9232599 IOCTL Device Drivers

    14/19

    The structure of the header attribute wordThe structure of the header attribute word

    15 8 7 0

    Standard input device (1)

    Standard output device (1)

    NUL device driver (0)

    Clock device (1)

    INT 20H fast character output(1)

    Reserved (0)

    Generic IOCTL supported(1)

    IOCTL quires supported (1)

    Character device (1)

    IOCTL function 2 & 3 supported (1)

    Output until busy supported (1)

    Reserved (0)

    Open and close Supported (1)

  • 8/9/2019 9232599 IOCTL Device Drivers

    15/19

    Strategy ProcedureStrategy Procedure

    It is called whenever device driver is loaded inIt is called whenever device driver is loaded into memory or whenever I/O requests areto memory or whenever I/O requests are

    issued.issued.

    Its main purpose is to save theIts main purpose is to save theRequest headerRequest header

    and its address.and its address.

    Return Status WordReturn Status WordCommunicatesCommunicates

    information back to DOS from Device Driver.information back to DOS from Device Driver.

  • 8/9/2019 9232599 IOCTL Device Drivers

    16/19

    Device Driver Commands in Request Header By DOSDevice Driver Commands in Request Header By DOS

    CommandCommand PurposePurpose

    00H00H Initialize DriverInitialize Driver

    01H01H Media CheckMedia Check 02H02H Build BPB (Block Device Parameter Block)Build BPB (Block Device Parameter Block) 03H03H Control ReadControl Read 04H04H ReadRead 05H05H Non destructive ReadNon destructive Read 06H06H Input StatusInput Status 07H07H Input FlushInput Flush 08H08H WriteWrite 09H09H Write with verifyWrite with verify 0AH0AH Output StatusOutput Status 0BH0BH Output FlushOutput Flush 0CH0CH Control writeControl write 0DH0DH Open DeviceOpen Device

    0EH0EH Close DeviceClose Device 0FH0FH Removable MediaRemovable Media 10H10H Output until BusyOutput until Busy 13H13H Generic IOCTLGeneric IOCTL 17H17H Get logical DeviceGet logical Device 18H18H Set logical DeviceSet logical Device 19H19H IOCTL QueryIOCTL Query

  • 8/9/2019 9232599 IOCTL Device Drivers

    17/19

    INTERRUPT PROCEDREINTERRUPT PROCEDRE

    It uses request header to determine theIt uses request header to determine the

    function requested by DOS.function requested by DOS.

    It performs all functions for Device DriverIt performs all functions for Device Driver

    Interrupt Procedure is different from InterruptInterrupt Procedure is different from InterruptHandler.Handler.

  • 8/9/2019 9232599 IOCTL Device Drivers

    18/19

    ; basic template for developing a device driver; basic template for developing a device driver

    ;;

    .MODEL TINY.MODEL TINY

    00000000 .CODE.CODE 00000000 FFFFFFFFFFFFFFFF CHAINCHAIN DDDD -1-1 ; link to the next driver in chain; link to the next driver in chain

    00040004 00000000 ATTRATTR DWDW 00 ; driver attribute; driver attribute 00060006 0016 R0016 R STRTSTRT DWDW STRATSTRAT ; address of strategy; address of strategy 00080008 001F R001F R INTRINTR DWDW INTTINTT ; address of interrupt; address of interrupt 000A000A 4D 59 44 52 494D 59 44 52 49 DNAMEDNAME DBDB MYDRIVERMYDRIVER ; driver name; driver name 56 45 5256 45 52 00120012 0000000000000000 REQREQ DDDD ?? ; request header address; request header address 00160016 STRATSTRAT PROCPROC FARFAR ; strategy procedure (must be; strategy procedure (must be

    FAR)FAR) 00160016 89 1E 0012 R89 1E 0012 R MOVMOV WORD PTR REQ,BXWORD PTR REQ,BX ; save request header address; save request header address 001A001A 8C 06 0014 R8C 06 0014 R MOVMOV WORD PTR REQ+2,ES;WORD PTR REQ+2,ES; 001E001E CBCB RETRET 001F001F STRATSTRAT ENDPENDP 001F001F INTTINTT PROCPROC FARFAR ; interrupt procedure (must; interrupt procedure (must

    be FAR)be FAR) 001F001F CBCB RETRET ; procedure placed here; procedure placed here 00200020 INTTINTT ENDPENDP ENDEND

  • 8/9/2019 9232599 IOCTL Device Drivers

    19/19


Recommended