USF CS 630 - Using x86 “protected mode” on our anchor-cluster’s machines

Unformatted text preview:

Using x86 “protected mode” on our anchor-cluster’s machinesSlide 2A programming hurdleThe console’s outputThe console’s inputThe IVT’s roleOur reimplementationSome detailsIdea for UART’s RX-interruptsIdea for UART’s TX-interruptsClearing the screenReposition the cursorFormat of ‘attribute’ bytesANSI color-codesColor-translation tableSetting text attributesCursor visibility commands‘console output’ algorithmProgramming interfaceModem Control RegisterModem Status RegisterLine Status RegisterLine Control RegisterInterrupt Enable RegisterFIFO Control RegisterInterrupt Identification RegisterResponse to UART interruptsHow to transmit a byteHow to receive a byteDemo-programIn-class exerciseUsing x86 “protected mode” on our anchor-cluster’s machinesA look at some terminal emulation features utilized in the “console-redirection” mechanismOur remote-access schemerackmountPC system‘pyramid’ studentworkstationKVM cableethernet cables ‘anchor08’‘anchor07’‘anchor06’‘anchor05’‘anchor04’‘anchor03’‘anchor02’‘anchor01’ sixteenCore 2 Duo systemsCS file-server null-modemserial cables. . . ‘telnet’ applicationA programming hurdle•When you try to test a ‘boot-time’ program on one of our ‘anchor’ machines, you will encounter a problem when your program enters protected-mode: you can no longer see the current screen-output, nor control your program using keyboard-input, since the normal ‘console redirection’ capability (which ‘telnet’ relies on) has been disabledThe console’s output•At boot-time the ‘anchor’ machines use a ‘real-mode’ interrupt-handler in the BIOS to continually transfer information (via the null-modem serial-cable) from the display memory of the local machine to the ‘telnet’ program running on the ‘pyramid’ server•From there it gets sent over the Ethernet network to a student’s computer screenThe console’s input•When a student types a keystroke, it gets sent via the network to the ‘telnet’ program running on ‘pyramid’, whereupon it then is forwarded to the ‘anchor’ machine via the null-modem serial-cable connection•This scheme allows us to do our work on the anchor-machines remotely – from our classroom or CS Labs, or even from homeThe IVT’s role•But this scheme relies on BIOS code that handle’s UART interrupts in ‘real-mode’•When a program enters ‘protected-mode’, it has to switch from its Table of Interrupt Vectors (used in real-mode) to a different table for dispatching of interrupts to ISRs•At that point we lose all the functionality that BIOS’s interrupt-handlers provided!Our reimplementation•Just as we’ve seen how to regain some of the functionality provided by the real-mode BIOS code, by writing our own protected-mode interrupt-handlers for the keyboard and the timer, we can restore the basic ‘console redirection’ capability by writing our own interrupt-handler for the UART when the CPU is in its ‘protected-mode’Some details•We need to write “trivial” interrupt-handlers for a few peripherals besides the UART:–For the timer (so we can see something that’s changing on the display screen)–For the keyboard (so we can control when to quit watching our display)–For any ‘spurious’ interrupts that the 8259 PIC delivers to the CPU (so we won’t “crash” due to unwanted General Protection Exceptions)Idea for UART’s RX-interrupts•When our UART receives a new scancode sent by the ‘telnet’ program on ‘pyramid’ we need it to be treated as if it were from the anchor-machine’s keyboard – but the anchor’s keyboard is out-of-our-reach•So we issue a command to the keyboard-controller to write that scancode into its Output Buffer register (command 0xD2)Idea for UART’s TX-interrupts•When the UART issues its THRE-interrupt (Transmitter Holding Register Empty), we want to output a new byte of information from the anchor-machine’s video memory•The video memory consists of alternating ascii-codes and attribute-codes, requiring distinct treatments for proper display on the remote terminal (or Desktop window)Clearing the screen•Here is an ANSI command-sequence that clears the terminal’s display-screen:char cmd[] = “\033[2J”;int len = strlen( cmd );write( 1, cmd, len );Reposition the cursor•Here is an ANSI command-sequence that moves the cursor to row 12, column 40:char cmd[] = “\033[12;40H”;int len = strlen( cmd );write( 1, cmd, len );Format of ‘attribute’ bytesBLINKBGredBGgreenBGblueFGintenseFGredFGgreenFGblueVGA text-color attributes byte 7 6 5 4 3 2 1 0 foreground color background colorANSI color-codes0 = black1 = red2 = green3 = brown4 = blue5 = magenta6 = cyan7 = grayColor-translation table IBM VGA DEC ANSI--------------------------------------------------------------------------------000 = black 000 = black001 = blue 100 = blue010 = green 010 = green011 = cyan 110 = cyan100 = red 001 = red101 = magenta 101 = magenta110 = brown 011 = brown111 = gray 111 = gray--------------------------------------------------------------------------------Setting text attributes•Here is an ANSI command-sequence that sets foreground and background colors:char cmd[] = “\033[32;44m”;int len = strlen( cmd );write( 1, cmd, len );Cursor visibility commands•Here are ANSI command-sequences that will ‘hide’ or ‘show’ the terminal’s cursor:char hide[] = “\033[?25l”; // lowercase Lchar show[] = “\033[?25h”; // lowercase H‘console output’ algorithmunsigned char color_table[ 8 ] = { 0, 4, 2, 6, 1, 5, 3, 7 };typedef struct { unsigned char ascii, color; } PEL;PEL *vram = (PEL *)0x000B8000;PEL prev = { 0, 0 };for (int row = 0; row < 24; row++){printf( “\033[?25l” ); // make the cursor invisibleprintf( “\033[%d;%dH”, row+1, 1 ); // cursor to row’s beginningfor (int col = 0; col < 80; col++){PEL curr = vram[ row*80 + col ];if ( curr.color != prev.color ){int fg = color_table[ (curr.color >> 0)&7 ];int bg = color_table[ (curr.color >> 4)&7 ];printf( “\033[%d;%dm”, fg + 30, bg + 40 );}printf( “%c”, curr.ascii );prev = curr;}printf( “\033[?25h” ); // make the cursor visiblefflush( stdout ); // insure all data written }Programming interfaceRxD/TxDIERIIR/FCRLCR MCR LSR MSR SCRThe PC uses eight consecutive I/O-ports to access the UART’s registers0x03F8 0x03F9 0x03FA


View Full Document

USF CS 630 - Using x86 “protected mode” on our anchor-cluster’s machines

Documents in this Course
Load more
Download Using x86 “protected mode” on our anchor-cluster’s machines
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 Using x86 “protected mode” on our anchor-cluster’s machines 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 Using x86 “protected mode” on our anchor-cluster’s machines 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?