1 / 19

System Programming

NFC-IET-2011. System Programming. Lecture-02 Interrupt Mechanism Dated: March 08, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU. Comparison b/w Interrupt and Procedure. Procedures call Call MyProc A = Addition(4,5 );

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-02 Interrupt Mechanism Dated: March 08, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU

  2. Comparison b/w Interrupt and Procedure • Procedures call • Call MyProc • A= Addition(4,5); • Printf(“hello world”); • Procedures are part of the program • On invocation of the procedure the parameter list and the return address are saved • the value of IP register in case of near procedure • the value of CS and IP registers in case of far procedure • Whenever a procedure is called its address need to be specified by some notation i.e. • in C language the name of the procedure is specified to call a procedure which effectively can be used as its address

  3. Comparison b/w Interrupt and Procedure(Contd…) • Interrupt call • Int 21h • Int 10h • Int3 • Interrupts invoked in the program are no where declared in the program unlike procedures • Interrupts reside in memory • what would be the address of the interrupt? • Interrupts supported by the operating system resides in kernel (core part of the operating system) • in case of DOS, the kernel is io.sys which loads in memory at boot time • in case of windows the kernel is kernel32.dll or kernel.dll. These files contain most of the I/O routines and are loaded as required • interrupts supported by ROM BIOS , are loaded in ROM part of the main memory which usually starts at the address F000:0000H • some device drivers may provide some I/O routines , so when the system boots these I/O routines get memory resident at interrupt service routines

  4. Comparison b/w Interrupt and Procedure(Contd…) • A program at compile time does not know the exact address where the interrupt service routine will be residing in memory, so the loader cannot assign addresses for interrupt invocations. When a device driver loads in memory it places the address of the services provided by itself in the interrupt vector table • When an interrupt is invoked three registers are pushed as the return address i.e. the values of IP, CS and Flags in the described order which are restored on return • Also no parameters are pushed onto the stack, on invocation parameters can only be passed through registers

  5. Comparison b/w Interrupt and Procedure(Contd…) Main Call proc1() Call proc2() Int 21h Proc1() Int 10h Proc2()

  6. Interrupt Vector Table • Interrupt vector table is a global table situated at the address 0000:0000H • The interrupt number specified in the interrupt call is used as an index into the interrupt vector table (to get the address of the interrupt service routine) • The size of interrupt vector table is 1024 bytes or 1 KB • Each entry in the IVT is sized 4 bytes hence 256 interrupt vectors are possible numbered (0-FFH) • Each entry in the table contains a far address of an interrupt handlers hence there is a maximum of 256 handlers • Each handlers can have a number of services within itself • The number of operations that can be performed by calling an interrupt service routine (ISR) is indefinite depending upon the nature of the operating system

  7. Interrupt Vector Table(Contd…) 0000:0000 INT0 INT1 0000:0004 INTFF 0000:03FFH

  8. Calculation Of a Vector Address in IVT • Each vector contains a far address of an interrupt handler • The address of the vector can be easily calculated, if the interrupt number is known • The segment address of the whole IVT is 0000H,the offset address for a particular interrupt handler can be determined by multiplying its number with 4 e.g. • the offset address of the vector of INT 21H will be 21H * 4 = 84H and segment address for all vectors is 0. Hence its far address is 0000:0084H(this is the far address of the interrupt vector and not the interrupt service routine or interrupt handler) • The vector in turn contains the address of the interrupt service routine which is an arbitrary value depending upon the location of the ISR residing in memory.

  9. The meaning of the four bytes within the interrupt vector • each entry within the IVT contain a far address • first two bytes (lower word) shows the offset address • the next two bytes (higher word) is the segment address 0000:0000 INT 0 0000:0003 0000:0004 INT 1 0000:0007

  10. Location of ISRs (Interrupt service routines) • Generally there are three kind of ISR within a system depending upon the entity which implements it • BIOS (Basic I/O services) ISRs • DOS ISRs • ISRs provided by third party device drivers • ISRs provided by the ROM-BIOS would be typically resident at any location after the address F000:0000H because this is the address within memory from where the ROM-BIOS starts • ISRs provided by DOS would be resident in the DOS kernel (mainly IO.SYS and MSDOS.SYS loaded in memory) and • ISRs provided by third party device drivers will be resident in the memory occupied by the device drivers

  11. IO.SYS Device Driver Command. COM USER PROGRAM ROM BIOS ISR’s are Routines Resident in Memory F000:0000

  12. Address Name Size Type ------- -------- ------ ------ 000000 000400 Interrupt Vector 000400 000100 ROM Communication Area 000500 000200 DOS Communication Area 000700 IO 000370 System Data CON System Device Driver AUX System Device Driver PRN System Device Driver CLOCK$ System Device Driver COM1 System Device Driver LPT1 System Device Driver LPT2 System Device Driver LPT3 System Device Driver COM2 System Device Driver COM3 System Device Driver COM4 System Device Driver 000A70 MSDOS 001670 System Data 0020E0 IO 002110 System Data KBD 000CE0 System Program HIMEM 0004E0 DEVICE= XMSXXXX0 Installed Device Driver 000490 FILES= 000090 FCBS= 000200 LASTDRIVE= 0007D0 STACKS= 004200 COMMAND 000A20 Program 004C30 MSDOS 000070 -- Free -- 004CB0 COMMAND 000410 Environment 0050D0 MEM 000350 Environment 005430 MEM 0174E0 Program 01C920 MSDOS 0836C0 -- Free -- 09FFF0 SYSTEM 029000 System Program 0C9000 IO 003100 System Data MOUSE 0030F0 System Program 0CC110 MSDOS 000330 -- Free -- 0CC450 MSCDEXNT 0001D0 Program 0CC630 REDIR 000A70 Program 0CD0B0 DOSX 0087A0 Program 0D5860 DOSX 000080 Data 0D58F0 MSDOS 00A700 -- Free -- 655360 bytes total conventional memory 655360 bytes available to MS-DOS 633776 largest executable program size 1048576 bytes total contiguous extended memory 0 bytes available contiguous extended memory 941056 bytes available XMS memory MS-DOS resident in High Memory Area

  13. Interrupt Invocation • Push Flags, CS, IP Registers, Clear Interrupt Flag • Use (INT#)*4 as Offset and Zero as Segment • This is the address of interrupt Vector and not the ISR • Use lower two bytes of interrupt Vector as offset and move into IP • Use the higher two bytes of Vector as Segment Address and move it into CS=0:[offset+2] • Branch to ISR and Perform I/O Operation • Return to Point of Interruption by Popping the 6 bytes i.e. Flags CS, IP.

  14. Parameter Passing to S/W Interrupts

  15. S/W Interrupts Invocation Psuedo Variables AX, BX, CX, DX _AX = 0x1234H a = _BX

  16. geninterrupt ( 0 x int# )

  17. Interrupt 21/09 Description Int # 21 Service # 9 Inputs AH = 0x09 DS = Segment Address of string DX = Offset Address of string Output Display a String

  18. Example: #include<stdio.h> #include<BIOS.H> #include<DOS.H> char st[80] ={"Hello World$"}; void main() { _DX = (unsigned int) st; _AH = 0x09; geninterrupt(0x21); }

  19. Questions?!!!Thanks

More Related