250 likes | 384 Views
NFC-IET-2011. System Programming. Lecture-08 Interrupt Mechanism-Microprocessor Signals Dated: April 11, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU. Keyboard Buffer. Keyboard Buffer is located in BIOS Data Area. Starts at 40: IEH
E N D
NFC-IET-2011 System Programming Lecture-08 Interrupt Mechanism-Microprocessor Signals Dated: April 11, 2011 By Somia Razzaq Note: Some slides and images of following lecture are taken from VU
Keyboard Buffer Keyboard Buffer is located in BIOS Data Area. Starts at 40: IEH Ends at 40 : 3DH Has 32 byes of memory 2 bytes for each character. Head points is located at address 40 : 1A to 40 : IBH Tail points located at address 40 : IC to 40 : IDH
40:1AH 40:1CH Head Tail 40:1EH 40:3DH
0x20 0x21 0x22 0x23 Head = 0x24
0xIE Tail 0x20 Head = 0x24
So KBD buffer acts as a circular buffer. The tail value should be examination to get to the start of the buffer.
#include <dos.h>void interrupt (*old)();void interrupt new1();char for *scr = (char far*) 0x0040001C; void main(){ old = getvect(0x09); setvect(0x09,new1); keep(0,1000);}
void interrupt new1 (){if(inportb(0x60)==83){*((char far*)0x0040000+*scr)=25; if((*scr)==60) *scr=30; else *scr+=2;outportb(0x20,0x20);return;}}
For Master outportb(0x20,0x20);For Slave outportb(0x20,0x20); outportb(0xA0,0x20);
OCW2*OCW3 00 If EOI is to be Initialized 001 FOR Non Specific EOI 01 If other Registers are to be accessed
01 To read IRR or ISR 10 = IRR 11= In-Service Register
No EOI relevant Don’t Care Other Register to be Accessed
IRR Accessed 01 PIC Notified about reading operation
ISR Accessed 01 PIC Notified about reading operation
#include <stdio.h>#include <dos.h>#include <bios.h>void main ( ){ char a;outport(0x20,8);outport(0x20,0x0A); a=inport(0x20);printf (“value of IRR is %x”, a);outport(0x20,0x08);outport(0x20,0x0B); a=inport(0x20);printf (“value of ISR is %x”, a); }
More about TSR Programs • A TSR need to be loaded once in memory • Multiple loading will leave redundant copies in memory • So we need to have some check which will load the program only once
int flag;flag =1;Keep(0,1000);if (flag==1) Make TSRelse exit Program But this wont Work
Answers is to use a memory area as flag that is global to all programs.i.e. IVT
int 65 is empty, we can use its vector as a flag. Address of vector seg = 0 offset = 65H * 4
#include<stdio.h> #include<BIOS.H> #include<DOS.H> unsigned int far * int65vec = (unsigned far *) MK_FP(0,0x65*4) void interrupt (*oldint) ( ); void interrupt newfunc ( ); void main() { if((*int65vec) = = 0xF00F) { oldint =getvect (0x08); setvect(0x08, newint); (*int65vec) = 0xF00F; keep (0,1000); }else { puts (“Program Already Resident”); }} void interrupt newfunc () { ::::::: ::::::: (*oldint) ( ); }
But what if another program is resident or using this vector. Another Method Service # 0xFF usually does not exist for ISR’s. Key is to create another service # 0xFF for the ISR interrupt besides other processing.
#include<stdio.h> #include<BIOS.H> #include<DOS.H> void interrupt (*oldint) ( ); void interrupt newfunc ( unsigned int BP,..…,flags); void main() { _DI = 0; _AH = 0xFF; geninterrupt (0x13); if (_DI = = 0xF00F) { puts (“Program Already Resident”); exit (0); }
else { oldint = getvect (0x13); setvect (0x13, newint); Keep (0, 1000); }} void interrupt newint ( ) { if (_AH == 0xFF){ DI = 0xF00F; return; }else { ::::::: ::::::: } (*oldint) ( ); }