Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Linux Serial Programming for POSIX Operating Systems
Linux device-driver issues
Using our device-drivers How can an application display the data in a device special file?
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
Addressing Modes (Week4)
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
The ATA/IDE Interface Can we write a character-mode device driver for the hard disk?
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
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.
CS2422 Assembly Language & System Programming October 3, 2006.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
Hexadecimal Notation Using sixteen as a number base when representing binary data.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Computer Organization and Assembly Language C/C++ Pointers and Memory Allocation.
Part II: Addressing Modes
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
CIS 234: Character Codes Dr. Ralph D. Westfall April, 2011.
Georgia Institute of Technology Student Computer Simulation Barbara Ericson Georgia Tech Sept 2005.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Industrial Process Control System Simon Hui Engineer Control and Informatics, Industrial Centre.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Pointers OVERVIEW.
The tty Interface An introduction to “systems programming” in the Linux environment.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
Kirk Scott Computer Science The University of Alaska Anchorage 1.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Basic Computer Organization Rashedul Hasan.. Five basic operation No matter what shape, size, cost and speed of computer we are talking about, all computer.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Assembly - Arrays תרגול 7 מערכים.
TANNENBAUM: 5, BIC & SHAW, SILBERSCHATZ: 12 INPUT/OUTPUT DEVICE DRIVERS.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
1 Assembly Language: Function Calls Jennifer Rexford.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Chapter 8 String Operations. 8.1 Using String Instructions.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Clocks, I/O devices, Thin Clients, and Power Management
MICROPROCESSOR BASED SYSTEM DESIGN
Control Unit Lecture 6.
Additional Assembly Programming Concepts
L7 – Assembler Directives
Computer Architecture “Bomb Lab Hints”
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CS 301 Fall 2002 Computer Organization
Advanced UNIX programming
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Some Assembly (Part 2) set.html.
Presentation transcript:

Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects

Basic issues to consider Normal tty operation is ‘canonical’ mode Input gets processed one line at a time Line-editing is allowed (e.g., backspace) User’s keystrokes echoed to the screen In C/C++ demo we could turn off echoing We used two standard interface functions: int tcgetattr( int fileno, struct termios *tty ); Int tcsetattr( int fileno, int flag, struct termios *tty );

Basic Algorithm Save a copy of the initial terminal settings Modify certain bits in the ‘c_lflag’ field: –Turn off the ECHO bit, and –Turn on the ECHONL bit Install the modified terminal settings Perform desired echo-free keyboard input Then reinstall the original terminal settings

How much storage space? We must reserve adequate space for storing the initial terminal settings But we don’t know how big this object is This issue was transparently handled for us in our ‘noecho.cpp” demo by including: #include struct termios save_termios; How can we accomplish this in assembly?

The ‘c_lflag’ field We needed to modify bits in ‘c_lflag’ field Those bits were represented by constants: ECHO and ECHONL Their values were defined in We did not need to know the actual values But header-file isn’t available in assembly So now we do need to know these values Another constant needed is TCSANOW

Memory addressing Where’s ‘c_lflag’ field within termios object We can’t modify its bits until we know that One idea is to study the Linux header-file But where is it? There seem to be several Nested type-declarations add to confusion Another approach: let’s write a program to report the specific information we’ll need Our ‘ttyinfo.cpp’ demo program shows us that sizeof( struct termios ) equals 60 bytes

.section.data # we need storage for two ‘termios’ objects origtty:.space60# original settings worktty:.space60# a ‘working copy’ # Insufficient space would cause big trouble! origttyworktty system would overwite part of the next data-area tcgetattr() does not know the size that we have allocated

Constants in assembly We can use the.equ directive to create our own manifest constants:.equECHO, 0x equECHONL, 0x equTCSANOW, 0x Question: will our program also work on other versions of UNIX besides Linux?

Copying a structure object We can create a program loop to copy the contents of a data-structure Here again we need to know the number of bytes in the structure we want to copy We can use a ‘counted loop’ to do copying Three initialization steps: –put source-address in register %esi –put dest’n address in register %edi –put the byte-count into register %ecx Advance %esi and %edi as each byte is copied

The actual loop code movl$origtty, %esi movl$worktty, %edi movl$60, %ecx again:movb(%esi), %al movb%al, (%edi) incl%esi incl%edi loopagain

Modifying some flag bits Determine offset of the ‘c_lflag’ field (=12) Setup this offset in a CPU register (%edi) movl $12, %edi Use AND-instruction to turn a bit off: andl $~ECHO, worktty(%edi) Use OR-instruction to turn a bit on: orl $ECHONL, worktty(%edi) (Here other approaches also are possible)

Non-canonical terminal modes Certain kinds of applications do not lend themselves to ‘canonical’ terminal input We may want an instant response to each individual keystroke (not to an entire line) Example: computer game using keyboard We can ‘turn off’ canonical line-processing Very similar to ‘turning off’ the input echo i.e., worktty.c_lflag &= ~ICANON;

Two further adjustments Need two changes in the c_cc[] array: worktty.c_cc[ VMIN ] = 1; worktty.c_cc[ VTIME ] = 0; First change causes ‘read()’ function to return as soon as at least one character has been typed Second change causes ‘read() function to return without any time-delay

An application You could use this ‘non-canonical’ terminal mode to implement visual “user feedback” in your ‘password’ program Whenever the user presses a new key, the program immediately responds by printing a neutral character (e.g. ‘*’) to confirm that it has indeed received the user’s input Special handling for ‘backspace’ is needed Suggestion: Try it first in a C/C++ program