Computer Systems and Multimedia - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Computer Systems and Multimedia

Description:

A problem that plagues windows NT/2000 and windows XP, is its strict control ... PC can have up to three LPT devices. Each device has a unique port I/O address ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 23
Provided by: pku64
Category:

less

Transcript and Presenter's Notes

Title: Computer Systems and Multimedia


1
Computer Systems and Multimedia
  • WinIO

2
WinIo
  • Introduction
  • A problem that plagues windows NT/2000 and
    windows XP, is its strict control over I/o ports.
  • Windows NT/2000/XP will cause an exception
    (privilege instruction) if an attempt is made to
    access a port that it is not privileged to talk
    to
  • Accessing I/O ports is governed by two events.
    The I/O privilege level (IOPL) in the EFLAGS
    register and the I/O permission bit map of a task
    state segment (TSS)
  • Under windows NT, there are two I/O privilege
    levels used, level 0 and level 3. User mode
    programs will run in level 3 (lesser privilege),
    while device drivers and the kernel will run in
    level 0

3
WinIo - contd
  • This allows trusted operating system and drivers
    running in kernel mode to access the ports, while
    preventing less trusted user mode processes from
    touching the I/O ports and causing conflicts.
  • All user mode program should talk to a device
    driver which arbitrates access
  • The I/O permission bit map can be used to allow
    programs not privilege enough (i.e user mode
    programs) the ability to access the I/O ports
  • When an I/O instruction is executed, the
    processor will first check if the task is
    privilege enough to access the port. Should be
    the case, the I/O instruction will be executed.
    However if the task is not allowed to so I/O, the
    processor will then check the I/O permission bit
    map
  • The I/O permission bit map uses a single bit to
    represent each I/O address
  • If the bit corresponding to a port is set, then
    the instruction will generate an exception.
    However, if the bit is clear then the I/O
    operation will proceed
  • This gives a mean to allow certain processes to
    access certain ports

4
WinIO
  • The WinIo library allows 32 bit windows
    applications to directly access I/O ports and
    physical memory
  • It bypasses windows protection mechanisms by
    using a combination of kernel mode device driver
    and several low level programming techniques
  • The functions available in WinIO are as follows
  • InitializeWinIo PROTO
  • Parameter none
  • Returns true if succeeds, otherwise false
  • This function must be called before using any
    other functions in the library
  • ShutdownWinIo PROTO
  • Parameter none
  • Return none
  • This function must be called before terminating
    the application in case the WinIo library is no
    longer required. This shuts down the WinIo
    library and frees the resources which were
    allocated by a call to the function

5
WinIO - contd
  • GetPortValue PROTO portaddrDWORD,lpPortValueDWO
    RD, \ bSizeDWORD
  • Parameter
  • portaddr I/O port address
  • lpPortValue pointer to a variable that
    receives the value from the port
  • bSize Number of bytes to read can either be 1,
    2 or 4
  • Returns true if succeeds, otherwise false
  • This function reads a byte, a word or a double
    word from the specified port
  • SetPortValue PROTO portaddrDWORD,PortValueDWORD
    , \ bSizeDWORD
  • Parameter
  • portaddr I/O port address
  • PortValue Value to be written to the port
  • bSize Number of bytes to read can either be 1,
    2 or 4
  • Returns true if succeeds, otherwise false
  • This function writes a byte, a word or a double
    word to the specified port

6
WinIO - contd
  • GetPhysLong PROTO lpPhysaddrDWORD,lpPhysValDWOR
    D
  • Parameter
  • lpPhysaddr pointer to physical address
  • lpPhysVal pointer to DWORD variable that
    receives value from physical memory
  • Returns true if succeeds, otherwise false
  • This function reads a double word from the
    specified memory location
  • SetPhysLong PROTO lpPhysaddrDWORD,PhysValDWORD
  • Parameter
  • lpPhysaddr pointer to physical address
  • PhysVal DWORD value to be written to physical
    memory location
  • Returns true if succeeds, otherwise false
  • This function writes a double word to the
    specified memory location

7
WinIO - contd
  • MapPhysToLin PROTO lpPhysaddrDWORD,PhysSizelDWO
    RD,\ lpPhysMemHandleDWORD
  • Parameter
  • lpPhysaddr pointer to physical address
  • PhysSize number of bytes to map
  • lpPhysMemHandle points to a variable that will
    receive the physical memory section handle if the
    call is successful
  • Returns linear address corresponding to physical
    address if succeeds, otherwise NULL
  • This function maps a region of physical memory to
    linear address space
  • UnmapPhysicalMemory PROTO lpPhysMemHandle
    DWORD, linAddrDWORD
  • Parameter
  • lpPhysMemHandle handle to physical memory
    section from above
  • linAddr linear address return from above
  • Returns true if succeeds, otherwise false
  • This function unmaps a region of physical memory
    (previously mapped)

8
WinIO - contd
  • Using WinIo
  • Place winio.dll, winio.vxd and winio.sys in the
    directory where the applications executable file
    reside
  • Include winio.lib in the application using
    includelib directive or include winio.lib in the
    link command line
  • Add header file winio.inc in the application
    using include directive
  • Call InitializeWinIo
  • Call the librarys functions to access port or
    physical memory
  • Call ShutdownWinIo

9
WinIO - contd
  • Include \include\Irvine32.inc
  • includelib \lib\kernel32.lib
  • includelib \lib\user32.lib
  • includelib WinIo.lib ltltltltltltltltltltltltltltltltltltltltltlt
    Library
  • include WinIo.inc ltltltltltltltltltltltltltltltltltltltltltlt Include
    file
  • .data
  • value DWORD ?
  • str BYTE Value returned
  • .code
  • start
  • invoke InitializeWinIo
  • invoke SetPortVal, 378h, 0ffh, 1
  • invoke GetPortVal,378h,addr value,1
  • mov edx,offset str
  • call writestring
  • mov eax,value
  • call writehex
  • invoke ShutdownWinIo
  • invoke ExitProcess, NULL

10
WinIO - contd
  • Parallel Interface (Port)
  • Originally designed for printers
  • Attach via 25 pin or Centronics connector
  • Provides 8 bit I/O
  • Provides TTL level (5 V) external I/O
  • Major signals

11
WinIO - contd
  • Provides easy interface to PC
  • Just redefine meaning of signals and attach
    hardware to PC
  • PC can have up to three LPT devices
  • Each device has a unique port I/O address
  • Most Computers have LPT1 as the printer port

12
WinIO - contd
  • Control Port (37Ah)

13
WinIO - contd
  • Status Port (379h)

14
WinIO - contd
  • Writing to Parallel Port

15
WinIO - contd
  • includelib \lib\kernel32.lib
  • includelib \lib\user32.lib
  • includelib WinIo.lib ltltltltltltltltltltltltltltltltltltltltltlt
    Library
  • include WinIo.inc ltltltltltltltltltltltltltltltltltltltltltlt Include
    file
  • .data
  • portdata DWORD ?
  • value DWORD ?
  • .code
  • start
  • invoke InitializeWinIo
  • invoke SetPortVal, 378h, portdata, 1 send data
    to port output
  • invoke GetPortVal,379h,addr value,1 get status
  • mov al,byte ptr value
  • again
  • test al,80h test busy
  • jz again
  • invoke SetPortVal,37Ah,0dh,1 send strobe (low)
  • invoke SetPortVal,37Ah,0ch,1 pull strobe high
  • invoke ShutdownWinIo

16
WinIO - contd
  • Serial Interface (Port)
  • Implemented as COM1 and COM2
  • Address of COM1 port

17
WinIO - contd
  • Transmitter Holding Register 3F8 (DLAB0)
  • Contains character to be sent serially (write)
  • Receiver Buffer Register 3F8 (DLAB0)
  • Contains character received (read)
  • Divisor Latch LSB 3F8 (DLAB1)
  • Contains lower divisor
  • Divisor Latch LSB 3F9 (DLAB1)
  • Contains upper divisor
  • Divisor Input frequency /(baud rate16)

18
WinIO - contd
  • Interrupt Enable Register 3F9 (DLAB0)
  • Interrupt Identification Register 3FA
  • Bit 1 bit 0
  • 0 0 Receiver Line Status
  • 0 1 Received Data Available
  • 1 0 Transmitter Holding Register empty
  • 1 1 Modem Status

19
WinIO - contd
  • Line Control Register 3FB
  • bit 1 bit 0 bit 2
  • 0 0 5 bits 0 1 stop bit
  • 0 1 6 bits 1 2 stop bits
  • 1 0 7 bits
  • 1 1 8 bits
  • bit 4 bit 3
  • 0 0 no parity
  • 0 1 odd parity
  • 1 0 no parity
  • 1 1 even parity

20
WinIO - contd
  • Modem Control Register 3FC
  • Line Status Register 3FD
  • Divisor Latch LSB 3FE

21
WinIO - contd
  • Forcing DTR and RTS (without using modem)
  • Invoke SetPortVal,3FCh,03h,1 modem control
    register at 3FC
  • writing 1 to bit and bit0 forces
  • DTR and CTS to 0
  • Initialization
  • Invoke SetPortVal,3FBh,83h,1 no parity,stop
    bit 1, data 8 bit,dlab1
  • Invoke SetPortVal,3F8h,0Ch,1 lower divisor
    number
  • Invoke SetPortVal,3F9h,00h,1 upper divisor
    number, baud rate 9600
  • Invoke SetPortVal,3FCh,7Fh,1 reset dlab
  • Receiving and Sending Character (Polling)
  • sin
  • invoke GatePortVal,3FDh,addr status,1
  • mov al,byte ptr status
  • test al,1 check DR 1, Data received?
  • jz sout
  • invoke GetPortVal,3F8h,addr dataIn,1 read data
  • jmp sin

22
WinIO - contd
  • sout
  • test al,20h check THRE 1, to send
  • jz sin
  • invoke SetPortVal,3F8h,portdata,1 send data
  • jmp sin
Write a Comment
User Comments (0)
About PowerShow.com