Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.

Slides:



Advertisements
Similar presentations
Linux Serial Programming for POSIX Operating Systems
Advertisements

Using our device-drivers How can an application display the data in a device special file?
 An operating system (OS) is a set of computer programs that allow the user to perform basic tasks like copying, moving, saving and printing files. 
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
Chap 2 System Structures.
Operating-System Structures
PacNOG 6: Nadi, Fiji Using Commands in Linux Hervey Allen Network Startup Resource Center.
Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
Using x86 “protected mode” on our anchor-cluster’s machines A look at some terminal emulation features utilized in the “console- redirection” mechanism.
Crafting a ‘demo’ program A ‘walk-through’ of the program development cycle for an example in assembly language.
Terminal Control operating systems. Terminal Control may seem like an arcane subject, but … It illustrates the relationship between devices and files.
1 UNIX 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX.
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
A code-walkthrough Commentary on our ‘model3d.cpp’ demo-program – an initial ‘prototype’ for 3D wire-frame animations.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Guide To UNIX Using Linux Third Edition
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
UNIX chapter 03 Getting Started Mr. Mohammad Smirat.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
ANSI command-sequences A look at some terminal emulation features utilized in the “console- redirection” mechanism.
Getting Started with Linux: Novell’s Guide to CompTIA’s Linux+ (Course 3060) Section 2 Use the Linux Desktop.
Systems Software Operating Systems.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Using the “CLI” Unix / Linux Preparation Course May 25 Djibouti.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved OPERATING SYSTEMS DESIGN.
System Calls 1.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Chapter 5. Connection Controls. Device == File ? Filenames Properties permission bits system call – open, read, write, lseek, close, stat.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
CENT 305 Information Systems Security Linux Introduction.
ICOM Noack Operating Systems - Administrivia Prontuario - Please time-share and ask questions Info is in my homepage amadeus/~noack/ Make bookmark.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Linux Terminal System ● Conceptual Linux terminal ● Terminal API ● Terminal emulators ● Graphical user interfaces.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
The Fundamentals of Using Windows 95. Windows 95 ã operating system that performs every function necessary for the user to communicate and control computer.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
ES305 Virtual Tools in Engineering Design Importing Objects Prof. Searleman
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
Using Commands Unix/IP Preparation Course July 19, 2009 Eugene, Oregon, USA
Agenda Getting Started: Using Unix Unix Structure / Features Elements of the Unix Philosophy Unix Command Structure Command Line Editing Online Unix Command.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
The tty Interface An introduction to “systems programming” in the Linux environment.
Using Commands Unix / Linux Preparation Course May 6, 2012 Serrekunda, The Gambia.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Software refer to all the programs that can be run on the computer.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Using the “CLI” Unix / Linux Preparation Course June 9, 2013 Lusaka, Zambia.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
SCSC 455 Computer Security Chapter 3 User Security.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Chapter 2. System Structures
BIF713 Introduction to Linux. Agenda Getting Started: Using Linux Unix and Linux - Structure / Features Elements of the Linux Philosophy Linux Command.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
CHARACTER INPUT / OUTPUT AND INPUT VALIDATION. Introduction Input and output devices: keyboards, disk drives, mouse, monitors, printers. I/O functions.
Computer Electronic device Accepts data - input
Advanced UNIX programming
Computer Electronic device Accepts data - input
On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface.
Presentation transcript:

Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects

Our course’s theme Using the computer to study the computer

Two ‘dynamic visualizations’ Showing the Linux kernel’s algorithm for setting up ‘permanent kernel mappings’ Showing the dual-CPUs’ responses to device-interrupts and CPU-exceptions

Some application tools We need to modify the terminal-console’s normal way of processing keyboard-input and of displaying its line-at-a-time output ANSI terminal escape-sequences allow page-oriented output (i.e., left-and-right, up-and-down), control of cursor-visibility and of character-attributes (e.g., colors)

The ‘tty’ interface ‘tty’ is an acronyn for ‘TeleTYpe’ terminal Such devices have a keyboard and screen Behavior emulates technology from 1950s Usually a tty operates in ‘canonical’ mode: –Each user-keystroke is ‘echoed’ to screen –Some editing is allowed (e.g., backspace) –The keyboard-input is internally buffered –The -key signals an ‘end-of-line’ –Programs receive input one-line-at-a-time

‘tty’ customization Sometimes canonical mode isn’t suitable (an example: animated computer games) The terminal’s behavior can be modified! UNIX provides a convenient interface: –#include –struct termios tty; –int tcgetattr( int fd, struct termios *tty ); –int tcsetattr( int fd, int flag, struct termios *tty );

How does the ‘tty’ work? TeleTYpe display device HARDWARE SOFTWARE application tty_driver c_lflag input handling c_iflag c_cc output handling c_oflag terminal_driver c_cflag User space Kernel space struct tty { c_iflag; c_oflag; c_cflag; c_lflag; c_line; c_cc[ ]; };

The ‘c_lflag’ field This field is just an array of flag bits Individual bits have symbolic names Names conform to a POSIX standard Linux names match other UNIX’s names Though actual symbol values may differ Your C/C++ program should use: #include for portability to other UNIX environments

ICANON and ECHO Normally the ‘c_lflag’ field has these set They can be cleared using bitwise logic: tty.c_lflag &= ~ECHO;// inhibit echo tty.c_lflag &= ~ICANON;// no buffering tty.c_lflag &= ~ISIG;// no CTRL-C

The ‘c_cc[ ]’ array ‘struct termios’ objects include an array The array-indices have symbolic names Symbol-names are standardized in UNIX Array entries are ‘tty’ operating parameters Two useful ones for our purposes are: tty.c_cc[ VMIN ] and tty.c_cc[ VTIME ]

How to setup ‘raw’ terminal-mode Step 1: Use ‘tcgetattr()’ to get a copy of the current tty’s ‘struct termios’ settings Step 2: Make a working copy of that object Step 3: Modify its flags and control-codes Step 4: Use ‘tcsetattr()’ to install changes Step 5: Perform desired ‘raw’ mode input Step 6: Use ‘tcsetattr()’ to restore the terminal to its original default settings

Input-mode needs five settings tty.c_cc[ VMIN ] = 0; –so the ‘read()’ function will return -- even if there is not at least one new input-character available tty.c_cc[ VTIME ] = 0; –so there will be no time-delay, after each new key pressed, until the ‘read()’ function returns tty.c_lflag &= ~ECHO;// no input-echoing tty.c_lflag &= ~ICANON;// no buffering tty.c_lflag &= ~ISIG;// no -C

Demo program: ‘noncanon.cpp’ This program may soon prove useful It shows the keyboard scancode values It demonstrates ‘noncanonical’ tty mode It clears the ISIG bit (in ‘c_lflags’ field) This prevents -C from being used to abort the program: the user must ‘quit’ by hitting the -key; so default terminal-settings will get reinstalled

‘Noncanonical’ terminal i/o We’ve now learned how to reprogram the terminal to allow “raw” keyboard input #include struct termiostty; tcgetattr( 0, &tty );// get tty settings tty.c_lflag &= ~( ICANON | ECHO | ISIG ); tty.c_cc[ VMIN ] = 1; tty.c_cc[ VTIME ] = 0; tcsetattr( 0, TCSAFLUSH, &tty );// install

ANSI command-sequences A look at some terminal emulation features utilized in the “console- redirection” mechanism

Clearing the screen Here is an ANSI command-sequence that clears the terminal’s display-screen: charcmd[] = “\033[2J”; intlen = strlen( cmd ); write( 1, cmd, len );

Reposition the cursor Here is an ANSI command-sequence that moves the cursor to row 12, column 40: charcmd[] = “\033[12;40H”; intlen = strlen( cmd ); write( 1, cmd, len );

ANSI color-codes 0 = black 1 = red 2 = green 3 = brown 4 = blue 5 = magenta 6 = cyan 7 = gray

Setting text attributes Here is an ANSI command-sequence that sets foreground and background colors: charcmd[] = “\033[32;44m”; intlen = strlen( cmd ); write( 1, cmd, len );

Cursor visibility commands Here are ANSI command-sequences that will ‘hide’ or ‘show’ the terminal’s cursor: charhide[] = “\033[?25l”;// lowercase L charshow[] = “\033[?25h”;// lowercase H

In-class exercise #1 Modify this simple C++ program so that it will print its “Hello” message in colors and be located in the center of the screen: #include int main( void ) { printf( “Hello, world! \n” ); }

In-class exercise #2 Compile and install our ‘pkmaps.c’ module Then download, compile and execute our ‘mapwatch.cpp’ visualization-application While ‘mapwatch’ continues to run in one window of your graphical desktop, open a second window nearby and execute some common commands, for example: $ ls $ mmake pkmaps

In-class exercise #3 Compile and install our ‘smpwatch.c’ LKM Then download, compile and execute our ‘smpwatch.cpp’ visualization-application In a nearby window, try hitting some keys and moving the mouse Try executing the ‘ping’ command to see if another machine responds, for example: $ ping stargate