1 / 17

System Programming

NFC-IET-2011. System Programming. Lecture-06 Interrupt Mechanism Dated: March 30, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU.

mick
Download Presentation

System Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NFC-IET-2011 System Programming Lecture-06 Interrupt Mechanism Dated: March 30, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU

  2. On exit the values within the registers are unchanged as compared to the values which were stored in registers on entry into the procedures. Reentrant Procedures & Interrupt

  3. Registers: AX, BX, CX, DX, ES, DS, SI, DI, BP

  4. #include <stdio.h>void interrupt *old();void interrupt newint()void main (){old = getvect(0x65);setvect(0x65,newint);_AX=0xf00f;geninterrupt(0x65);a = _AX printf(“%x”,a);}void interrupt newint(){_AX=0x1234;}

  5. Push AX,BX,CX,DX,ES,DS,SI,DI,BP Flow Diagram: Push flags, CS, IP POP BP,DI,SI,DS,ES,DX,CX,BX,AX Pop IP,CS,flags

  6. Push AX, Push BX, Push CX, Push DX, Push ES, Push DS, Push SI, Push DI, Push BP ---------- ---------- ---------- ---------- Pop BP, Pop DI, Pop SI , Pop DS, Pop ES, Pop DX, Pop CX, Pop BX, Pop AX, IRET -------------------- Int -------------------- Typical Reentrant Routine:

  7. BP DI SI DS ES DX CX BX AX IP CS Flags

  8. Example: void main (){ x = sum(4, 5); printf (“%d”, x); a = 10; b = 20; x = sum(a, b); printf (“%d”, x);}int sum (int i, int j){ return i+j;} SP 4 5 RP SP a b RP

  9. Example: AX =1234H AX =FF55H Proc1 ( ) AX = ?

  10. Accessing Stack Example: void interrupt newint ( unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){ a = AX; b = BX; d = ES;}

  11. Example: void main ( ) {setvect(0x65,newint); _AX = 0x1234; Geninterrupt (0x65); a = _AX; Printf (“%x”, a); } void interrupt newint( unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){ AX = 0xF00F; }

  12. Keyboard Interrupt Hook (int# 15H Service# 4FH) Move Scan Code from 60H port to AL Int 15H Service 4FH Key Pressed Convert to ASCII & place it in keyboard buffer

  13. Example: #include <dos.h> #include <bios.h> #include <stdio.h> void interrupt (*oldint15) ( ); void interrupt newint15(unsigned int BP, …, flags); void main ( ) { oldint15 = getvect (0x15); setvect (0x15, newint15); keep (0, 1000); }

  14. void interrupt newint15(unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){ if (*(((char*)&AX) + 1) = = 0x4F ) { if (*((char*)&AX) = = 0x2C) *(((char*)&AX)) = 0x1E; else if (*((char*)&AX) = = 0x1E) *((char*)&AX) = = 0x2C; else (*oldint15)(); } }

  15. Disk Interrupt ( int# 13H Service# 3) On Entry AH = Service # = 03AL = No of Blocks to write BX = Offset Address of Data CH = Track No. , CL = Sector DH = Head # DL = Drive #(Starts from 0x80 for fixed disk & 0 for removable disks) ES = Segment Address of data buffer. On Exit AH = return Code Carry flag = 0 ( No Error AH = 0) Carry flag = 1 ( Error AH = Error Code)

  16. Addressing of Block Specified: Head, Sec, Track #pragma inline #include <dos.h> #include <bios.h> void interrupt (*oldtsr) ( ); void interrupt newtsr (unsigned int BP, …, flags); void main ( ) { oldtsr = getvect (0x13); setvect = (0x13, newtsr); keep (0, 1000); }

  17. void interrupt newtsr(unsigned int BP, unsigned int DI, unsigned int SI, unsigned int DS, unsigned int ES, unsigned int DX, unsigned int CX, unsigned int BX, unsigned int AX, unsigned int CS, unsigned int IP, unsigned int flags){ _ES = ES; _DX = DX;if ( _AH = = 0x03) _CX = CX; _BX = BX; if(( _DH= =1 && _CH= =0 _AX = AX; && _CL= =1)&& _DL>=0x80) *oldtsr; { asm pushf; asm clc; asm pop flags; asm pushf; AX = _AX; BX = _BX; asm pop flags; CX = _CX; DX = _DX; return; ES = _ES; } }

More Related