Programming the I/O Hardware

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

Chapter 2 (cont.) An Introduction to the 80x86 Microprocessor Family Objectives: The different addressing modes and instruction types available The usefulness.
1 Homework Reading (linked from my web page) –S and S Extracts –National Semiconductor UART Data Sheet Machine Projects –mp2 due at start of class 12 Labs.
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
COMP 2003: Assembly Language and Digital Logic
1 Homework Reading –Tokheim, Section 13-6 Continue mp1 –Questions? Labs –Continue labs with your assigned section.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language Advantages 1. It reveals the secret of your computer’s hardware and software. 2. Speed. 3. Some special applications and occasions. Disadvantages.
1 Homework Reading –Professional Assembly Language, pp 17-32, Continue work on mp1 –Questions? Lab with your assigned section this week.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
The 8086 Microprocessor The 8086, announced in 1978, was the first 16-bit microprocessor introduced by Intel Corporation 8086 is 16-bit MPU. Externally.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
Programming the I/O Hardware Reference: –textbook: Tanenbaum ch.5.1 – s.htmlwww.cs.umb.edu/ulab/UsingCforHardwareReg.
(-133)*33+44* *33+44*14 Input device memory calculator Output device controller Control bus data bus memory.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 2 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Input/Output (I/O) Important OS function – control I/O
Chapter Overview General Concepts IA-32 Processor Architecture
Homework Reading Labs Tokheim, Section 13-6 S and S Extracts
Homework Reading Lab with your assigned section starts next week
Homework Reading Continue mp1 Labs Tokheim, Section 13-6 Questions?
CS-401 Computer Architecture & Assembly Language Programming
Pentium I/O: I/O, I/O and off to work we go
Programming the I/O Hardware
Introduction to 8086 Microprocessor
Homework Reading (linked from my web page) Machine Projects Labs
Input/Output.
8086 MICROPROCESSOR ARCHITECTURE & SEGMENTATION
8086 Microprocessor.
Computer Organization & Assembly Language Chapter 3
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Chapter 4 Data Movement Instructions
CS 286 Computer Organization and Architecture
Basic Microprocessor Architecture
Assembly IA-32.
CS703 - Advanced Operating Systems
Homework Reading Continue work on mp1
Computer Architecture
Symbolic Instruction and Addressing
Introduction to Assembly Language
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
BIC 10503: COMPUTER ARCHITECTURE
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
Operating Systems Chapter 5: Input/Output Management
The Microprocessor & Its Architecture
Transmitter Interrupts
Symbolic Instruction and Addressing
Chapter 5: I/O Systems.
Computer Architecture and Assembly Language
Assembly Language (CSW 353)
Computer Architecture CST 250
Unit-I 80386DX Architecture
Chapter 6 –Symbolic Instruction and Addressing
Process.
8086 microprocessior PIN OUT DIAGRAM OF  Power supply and frequency signals  It uses 5V DC supply at V CC pin 40, and uses ground at V SS pin.
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Programming the I/O Hardware Reference: textbook: Tanenbaum ch.5.1 http://www.cs.umb.edu/ulab/UsingCforHardwareRegs.html “Linux Assembly Language Programming” by Bob Neveln

Types of I/O Devices Block devices(e.g. disk) store information in fixed-size blocks each one has its own address Character devices (e.g. serial I/O) accept or deliver a stream of characters not addressable Others (e.g. clocks) generate interrupts at fixed intervals

Programming the I/O CPU reads/writes into control registers and data buffers of the hardware to transfer data CPU communicates with registers via: 1) I/O Port number use special I/O instructions (e.g. in REG, PORT) 2) Memory-mapped I/O map control registers to memory locations use the same instruction to access memory to access registers 3) Hybrid memory-mapped I/O data buffers and I/O ports for control registers.

Memory-mapped I/O Separate memory and I/O space Memory-mapped I/O Hybrid

80386Processor - Registers Processor %ax % eax %ah %al Memory Memory % bx Address % ebx % bh % bl 0x00000000 % cx M/IO# % ecx % ch % cl % dx W/R# % edx %dh %dl A-Bus % esp %sp (32 bits) % ebp % bp D-Bus % esi % si (32 bits) % edi % di 0xFFFFFFFF Neveln , Figure 3-14 (Adapted)

Additional x86 Processor Registers Additional status and control registers not shown in Neveln Fig. 3-14 – Instruction Pointer/Extended Instruction Pointer % eip Extended Flags – % eflags Bit definitions of the eflags register is shown in http://en.wikipedia.org/wiki/FLAGS_register_(computing)

x86 Processor Architecture Uses the hybrid approach I/O port: 0 - 64K e.g. COM1: base address 0x3f8 COM2: base address 0x2f8 Device data buffers: 640K - 1M To read data, CPU puts out the address on the bus’ address lines and assert the READ signal. A separate port/memory line is used to select I/O ports or memory.

x86 I/O Instructions 8-bit I/O instructions in assembly language outb %a1, %dx /* output 8-bit data from %a1 /* I/O port number in %dx inb %dx, %a1 /* input 8-bit data to %a1 /* I/O port number in %dx

Use Tutor to do input/output port From CS341 lecture: http://www.cs.umb.edu/ulab/UsingCforHardwareRegs.html Tutor > ps 2f8 41 -- ps for port set ATutor> Tutor > pd 2f8 -- pd for port display 02f8 0d 00 c1 03…..

Serial Port I/O Programming Using C Don’t use hard coded numbers! Look at $pcinc/serial.h for symbolic constants #define COM1_BASE 0x3f8 #define COM2_BASE 0x2f8 #define COM3_BASE 0x3e8 #define COM4_BASE 0x2e8 #define UART_TX 0 /* send data */ #define UART_RX 0 /* recv data */ . . . #define UART_IER 1 /* interrupt enable*/ #define UART_LCR 3 /* line control */ #define UART_MCR 4 /* modem control */ #define UART_LSR 5 /* line status */ #define UART_MSR 6 /* modem status */

Serial Port I/O Programming Using C (cont’d) /* These are the bit definitions for the Line Status Register */ #define UART_LSR_TEMT 0x40 /* Transmitter empty */ #define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */ #define UART_LSR_BI 0x10 /* Break interrupt indicator */ #define UART_LSR_FE 0x08 /* Frame error indicator */ #define UART_LSR_PE 0x04 /* Parity error indicator */ #define UART_LSR_OE 0x02 /* Overrun error indicator */ #define UART_LSR_DR 0x01 /* Receiver data ready */ /* These are the bit definitions for the Interrupt Enable Register */ #define UART_IER_MSI 0x08 /* Enable Modem status interrupt */ #define UART_IER_RLSI 0x04 /* Enable receiver line status interrupt */ #define UART_IER_THRI 0x02 /* Enable Transmitter holding register int. */ #define UART_IER_RDI 0x01 /* Enable receiver data interrupt */

Serial Port I/O Programming Using C (cont’d) unsigned char status; outpt(COM1_BASE + UART_TX, ‘A’); status = inpt(COM1_BASE + UART_LSR); Use literal values Use offset values

Serial Port I/O Program: $pcex/echo.c /* echo.c: use low-level i/o to echo console input */ /* build with makefile in $pcex: make C=echo */ #include <stdio.h> #include <serial.h> void main(){ int console = sys_get_console_dev(); /* find out current sys console */ int conport; int c = 0; switch (console) { case COM1: conport = COM1_BASE; break; case COM2: conport = COM2_BASE; break; default: printf("Expected serial port for console, exiting\n"); return; } while (c != 'q') { /* "poll" the DR (data-ready) bit until it goes on */ while ((inpt(conport+UART_LSR)&UART_LSR_DR)==0) ; /* busy-wait for char */ c = inpt(conport+UART_RX); outpt(conport+UART_TX, c); /* should be ready */

Different Ways to Perform I/O Programmed I/O CPU does all the work CPU does polling or busy waiting until I/O is free Interrupt-Driven I/O allows the CPU to do something else while waiting for the I/O to be free I/O using DMA DMA controller feeds the data to the I/O without bothering the CPU

Example of Programmed I/O Steps in printing a string When printer is available, copy string to kernel space. Wait for printer before writing “A” to printer’s data register Assembles the string in a buffer in user space. Wait for printer to be available. Wait for printer to be ready again before writing “B”

C code for the printing example Copy_from_user(buffer, p, count); for(i=0; i <count; i++) { while (*printer_status_reg !=READY); *printer_data_register = p[i]; } return_to_user();