Unformatted text preview:

The UART alternative Substituting input from our PC s serial port for local keystrokes when we do single stepping Problem background Last time we saw how the x86 s trap flag and debug breakpoint registers could be used to support single stepping through program code to help us diagnose bugs But a conflict arises when we attempt to debug code that handles keyboard input as in the isrKBD routine for Project 2 Our debugger also uses keyboard input Use another control device To circumvent the contention for keyboard control we ask can some other peripheral device substitute for our PC s keyboard as a convenient debugger input source Our classroom and CS Lab machines offer us a way to utilize their serial ports as an alternative device interface for doing this type of debugger single stepping task Kudlick Classroom 08 09 10 15 04 05 06 07 01 02 03 16 17 18 19 11 12 13 14 20 28 29 30 24 25 26 27 21 22 23 lectern Indicates a null modem PC to PC serial cable connection PC to PC communications student workstation KVM cable rackmount PC system student workstation KVM cable null modem serial cable rackmount PC system ethernet cables Using echo and cat Our device driver module named uart c is intended to allow unprivileged programs that are running on a pair of adjacent PCs to communicate via a null modem cable Transmitting echo Hello dev uart Receiving cat dev uart Hello Instructions in isrDBG Our usedebug s used these instructions to support user control of single stepping isrDBG code32 Our trap handler for Debug Exceptions interrupt 0x01 now await the release of a user s keypress kbwait in test jz 0x64 al 0x01 al kbwait poll keyboard controller status a new scancode has arrived no continue polling controller in test jz 0x60 al 0x80 al kbwait else input the new scancode was it a key being released no wait for a keypress break UART s line status The PC s 16550 serial UART interface has a status port and a data port that behave in a manner that s similar to those ports in the keyboard controller so we can replace instructions in our isrDBG procedure that accessed keyboard controller ports with instructions that access the UART s ports This avoids contention for the keyboard How to program the UART Universal Asynchronous Receiver Transmitter See our CS630 course website at http cs usfca edu cruse cs630f08 for links to the UART manufacturer s documentation and to an in depth online programming tutorial Software controls the UART s operations by accessing several registers using the x86 processor s in and out instructions The 16550 UART registers Base 0 Divisor Latch Register Base 0 Transmit Data Register 8 bits Write only Base 0 Received Data Register 8 bits Read only Base 1 Interrupt Enable Register 8 bits Read Write Base 2 Interrupt Identification Register 8 bits Read only Base 2 FIFO Control Register 8 bits Write only Base 3 Line Control Register 8 bits Read Write Base 4 Modem Control Register 8 bits Read Write Base 5 Line Status Register 8 bits Read only Base 6 Modem Status Register 8 bits Read only Base 7 Scratch Pad Register 8 bits Read Write 16 bits R W UART s I O port interface The PC uses eight consecutive I O ports to access the UART s registers 0x03F8 RxD TxD 0x03F9 0x03FA 0x03FB 0x03FC 0x03FD 0x03FE 0x03FF IER IIR FCR LCR MCR LSR MSR SCR interrupt enable register receive buffer register and transmitter holding register also Divisor Latch register line status register line control register modem control register interrupt identification register and FIFO control register modem status register scratchpad register Comparing STATUS ports Keyboard controller s status register i o port 0x64 7 6 Parity error Timeout error 5 Data is from Mouse 4 3 Keyboard locked Last byte went to 0x64 2 System initialized 1 0 Input Buffer Full Output Buffer Full Serial UART s line status register i o port 0x03FD 7 6 Error in Transmitter idle Rx FIFO 5 THR empty 4 3 Break interrupt Framing error 2 Parity error 1 0 Overrun error Received Data Ready Changes to isrDBG keyboard controls single stepping serial UART controls single stepping isrDBG isrDBG kbwait poll for OUTB 1 in 0x64 al test 0x01 al jz kbwait input new scancode in 0x60 al inwait poll for RDR 1 mov 0x03FD dx in dx al test 0x01 al jz inwait input new data byte mov 0x03F8 dx in dx al ignore make codes test 0x80 al jz kbwait send back a reply mov al out al dx Using a Linux application To control our debugger from another PC we ve written an application program that runs under Linux and it uses our uart c device driver to circumvent privilege level restrictions that Linux imposes on access to i o ports by code which runs in ring3 Our application is named kb2cable cpp It also illustrates use of i o multiplexing Linux Kernel Modules Linux allows us to write our own installable kernel modules and add them to a running system Runs in ring3 Runs in ring0 application device driver module call ret call syscall standard runtime libraries user space ret Operating System kernel sysret kernel space Linux char driver components Device driver LKM layout module s payload is a collection of callback functions having prescribed prototypes function function function the usual pair of module administration functions fops AND a package of function pointers init registers the fops exit unregisters the fops write and read Obviously your driver module s payload will have to include methods functions which perform the write and read operations that applications will invoke You may decide your driver needs also to implement certain additional methods For example to support i o multiplexing our driver needed to implement poll UART initialization For two PC s to communicate via the serial null modem cable their UART s must be configured to use identical baudrates and data formats i e 115200 bps 8 N 1 Our uart c driver performs this essential configuration in its module init function Our remotedb s application does it in an extra real mode subroutine we ve added The sequence of steps steps are described below in pseudo code initializing the UART communication parameters for 115200 bps 8 N 1 outb outb outb outw outb outb 0x00 UART BASE 1 0xC7 UART BASE 2 0x83 UART BASE 3 0x0001 UART BASE 0 0x03 UART BASE 3 0x03 UART BASE 4 Interrupt Enable register FIFO Control register Line Control DLAB 1 Divisor Latch register Line Control DLAB 0 Modem Control inb inb inb inb UART BASE 6 UART BASE 5 UART BASE 0 UART BASE 2 Modem Status Line Status Received Data Interrupt Identification l


View Full Document

USF CS 630 - The UART alternative

Documents in this Course
Load more
Download The UART alternative
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The UART alternative and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The UART alternative 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?