Chaining Interrupts. Short contents What does chaining interrupts mean? TSR programs Chaining an interrupt example program Reentrancy problems with DOS.

Slides:



Advertisements
Similar presentations
Programming 8086 – Part IV Stacks, Macros
Advertisements

CS 450 Module R3. Next Week R2 is due next Friday ▫Make sure to correct all errors with R1 ▫Correct errors in the documentation as well, it will be checked.
10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Subroutine and Interrupt.
University of Tehran 1 Microprocessor System Design Interrupt Omid Fatemi
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Microprocessors system architectures – IA32 real and virtual-8086 mode Jakub Yaghob.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Flow Diagram: Push flags, CS, IP Pop IP,CS,flags Push AX,BX,CX,DX,ES,DS,SI,DI,BP POP BP,DI,SI,DS,ES,DX,CX,BX,AX.
Chapter 14 80x86, Large Model Port Porting to real mode and for the large model –Real mode: 1Mb memory space (pointers in this model require 32 bits) –In.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
CS2422 Assembly Language & System Programming November 2, 2006.
8.7 Memory management Program E Program D System memory DOS INT 21, function 48H: Allocate Memory Specification: allocates a number of memory paragraphs.
Interrupt Processing Haibo Wang ECE Department
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Kip Irvine: Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, All rights reserved. You may modify.
Introduction to Interrupts
8.6 Multitasking User 1 PP User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4 User 1 User 2 User 3 User 4... time the time.
Structure of DOS application programs. Contents: 1. PSP 2..COM and.EXE 3. TSR: Terminate and Stay Resident Programs.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
Lecture 10 Interrupts, Part 2, putting it all together Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
80386DX.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
ECE291 Computer Engineering II Lecture 13 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Stack Operations LIFO structure (last-in,first-out) –The last value put into the stack is the first value taken out Runtime stack –A memory array that.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Implementing function/ procedure calls (in Pascal and C)
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Strings, Procedures and Macros
Writing and using procedures
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Functions/Methods in Assembly
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
ECE291 Computer Engineering II Lecture 14 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
University of Tehran 1 Microprocessor System Design Programmable Interrupt Controller Omid Fatemi
Assembly 08 Interrupts. Introduction Interrupts are similar to procedures –They are used to alter a program’s control flow –The interrupt service is also.
Bootable Programs Building an O/S. Basic Requirements of any O/S Respond to interrupts (all kinds) Preserve user environment Protect users and self from.
ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt.
Microprocessor System Design Programmable Interrupt Controller.
ICS312 Set 12 Subroutines: Passing Arguments Using the Stack.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
ECE291 Computer Engineering II Lecture 14 Josh Potts University of Illinois at Urbana- Champaign.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Microprocessor and Assembly Language
8254 – SOFTWARE PROGRAMMABLE TIMER
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Microprocessor and Assembly Language
3.6 Data transfer Instructions
Stack and Subroutines Module M17.1 Section 11.2.
Programming 8086 – Part IV Stacks, Macros
Symbolic Instruction and Addressing
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Presentation transcript:

Chaining Interrupts

Short contents What does chaining interrupts mean? TSR programs Chaining an interrupt example program Reentrancy problems with DOS Reentrancy problems with BIOS The multiplex interrupt (INT 2Fh) Installing and removing a TSR Debugging TSRs Difficulties in chaining interrupts in Windows

What does chaining interrupts mean? MS-DOS places at memory address 0000:0000 the interrupt vector table (holds FAR address of each handler/ISR – Interrupt Service Routine) Purpose of chaining interrupts: implementing missing functionalities from the OS, optimizing BIOS or DOS routines, altering OS behavior Steps in chaining interrupts: 1)Writing the new ISR (the new handler); 2)Saving old handler’s (the original one) address; 3)Modifying handler’s address in the interrupt vector table; 4)Calling the new ISR; 5)Eventually, calling the old ISR; 6)Restoring the original handler;

Saving old handler’s address Accessing the interrupt vector table directly: oldint77 dd ? ; space for storing old handler’s addr. … mov es, 0 cli ; deactivate interrupts mov ax, word ptr es:[4*77h] mov word ptr cs:oldint77, ax mov ax, word ptr es:[4*77h+2] mov word ptr cs:[oldint77+2], ax sti ; reactivate interrupts Using DOS function no. 35h: oldint77 dd ? ; for storing old handler’s address … mov ax, 3577h ; ES:BX –address of current handler int 21h mov word ptr cs:oldint77, bx mov word ptr cs:[oldint77+2], es

Modifying handler’s address in the interrupt vector table Accessing the interrupt vector table directly : mov es, 0 cli mov word ptr es:[4*77h],offset Newhandler mov word ptr es:[4*77h+2],seg Newhandler sti Using DOS function no. 25h: push ds mov ax, 2577h mov dx, seg Newhandler mov ds, dx mov dx, offset Newhandler int 21h pop ds

Calling the original handler and returning from the ISR Calling the old handler, then return in the new handler: pushf; pushing flags on to the stack call dword ptr cs:oldint77 … iret ; popf + retf Calling the old handler, then return in the application: jmp dword ptr cs:oldint77

Writing the new ISR We can not count on (know) the value of any register except CS and IP If we modify registers inside the ISR their values must be saved previously and then restored prior of returning from the ISR

TSR Programs (Terminate and Stay Resident) MS-DOS programs are: transient : free memory when they terminate execution resident : does not return all memory back to DOS TSRs are used for introducing multitasking functionality into a monotasking OS Staying resident is done using DOS function no. 31h TSRs have a transient section (executed once in the beginning) and a resident one (stays in memory after completion) Active TSRs (activated by system generated hardware interrupts) TSR-uri pasive (activated by an explicit call)

DOS memory map and TSRs (1) DOS memory map, no active application DOS memory map, one active application

DOS memory map and TSRs (2) DOS memory map, one resident application DOS memory map with one resident application and one transient application

Chaining an interrupt example program(1) assume cs:cod cod segment org 100h start: jmp install ;resident part message db “Parameters initialized for COM1 ! $" minstalled db “Handler already installed $" Oldip dw ? Oldcs dw ? signature db “exemplu rutina" handler: ;****New handler**** cmp ah,00h jnz CallOldHandler push ax push ds push dx mov ah,9h push cs pop ds lea dx,message int 21h ;uninstall new handler ;mov ax,2514h ;mov dx,word ptr Oldip ;mov ds,word ptr Oldcs pop dx pop ds pop ax iret CallOldHandler : jmp dword ptr Oldip

Chaining an interrupt example program(2) install: ;check whether new ISR has already been installed mov ah,35h mov al,14h int 21h ;in es:bx we have the address of 14h ISR mov word ptr Oldip,bx mov word ptr Oldcs,es ;compare the addresses of old and new handler cmp bx,offset handler jne notinstalled ;compare signatures push cs pop ds lea si,signature ; ds:si contains address of signature ; es:si contains address of signature from the old handler mov di,si cld mov cx,handler-signature repe cmpsb jne notinstalled mov ah,9h lea dx,minstalled int 21h ;ending program mov ax,4c01h int 21h

Chaining an interrupt example program(3) notinstalled: mov ah,25h mov al,14h push cs pop ds lea dx,handler int 21h mov ah,31h mov al,00h lea dx,install add dx,15 mov cl,4 shr dx,cl int 21h cod ends end start

Reentrancy problems with DOS Happens when the current application calls a DOS function and during the execution of this DOS function an asynchronous event (e.g. timer interrupt, pressing a key) occurs which activates a TSR that at his turn calls DOS. DOS is not reentrant: it does not allow several DOS calls to be active in the same time May lead to system hang In general, the problem does not occur for passive TSRs InDOS flag on 1 byte(=0 if no DOS call is active, !=0 if a DOS call is in progress) + DOS function34h (GetInDosFlagAddress) CritError flag– set when a DOS calls issues a critical error; error’s details are saved at a fix memory address which gets overwritten each time

Reentrancy problems with BIOS Some BIOS interrupts are not reentrant, others are reentrant BIOS doesn’t provide an InBIOS flag For not reentrant BIOS interrupts one can implement a wrapper ISR to simulate the InBIOS flag: int17 proc far inc CS:InBIOS pushf call dword ptr CS:OldInt17 dec CS:InBIOS iret int17 endp

The multiplex interrupt(INT 2Fh) When we install a passive TSR we have to choose an interrupt vector (number) to patch into: We can randomly choose an interrupt vector from the interrupt vector table We can choose an interrupt which implements specific functionality We can choose the multiplex interrupt, 2Fh The multiplex interrupt, 2Fh: reserved for providing a general mechanism for installing, testing the presence and communicating with a TSR

Installing and removing a TSR To check at install time: The handler is not already installed (using a signature) The interrupt vector is free (reserved) To do at uninstall time: Stop all pending actions of this TSR Restore all interrupt vectors to their former values Return all reserved memory back to DOS [Last two tasks difficult to accomplish] Exemplifying the aforementioned issues: “TSR Monitor Tastatura” example, section 6.8, pag. 229, the blue book

Debugging a TSR (1) Compile and linkedit the TSR (possible with debug information included). Load the TSR into TD and execute the transient part naturally. When this part is executed, the resident part would be installed into the RAM memory. Set a breakpoint in the resident part (preferably in the beginning) with the F2 key (or from the Breakpoints menu). Select option File | Resident from the menu in order to make TD resident. This is done in order to get the DOS prompter again. Once we are back to DOS the resident part gets active. When the program execution gets to the breakpoint, TD comes back showing the TSR in the respective point. Thus, debugging this code is then possible. (Coming back to TD from DOS is done by pressing CTRL-Break twice)

Debugging a TSR (2)

Debugging a TSR (3)

Debugging a TSR (4)

Debugging a TSR (5)

Debugging a TSR (6)

Debugging a TSR (7)

Difficulties in chaining interrupts in Windows There are no systems running native MS-DOS any more Windows OS emulates a virtual hardware architecture in which DOS is run We can not chain interrupts that work with hardware equipment because this is virtual (e.g. int 13h for working with the disk, int 10h for working in graphical mode etc)