Upload
salmansami01
View
217
Download
0
Embed Size (px)
Citation preview
7/31/2019 SPLect-5_2
1/29
System ProgrammingBSCS-7th Semester
Dr. Wajeeha Khalil
7/31/2019 SPLect-5_2
2/29
TSR programs must be compiled with .com in
extension .com doesnt exceed 64kB size.
TSR programs should be run by making its com fileand exit the compiler, then run it.
Save the program using with .c extension.
2
Running a TSR Program
7/31/2019 SPLect-5_2
3/29
#include#includechar st[80] ={"Hello World$"};char st1[80] ={"Hello Students!$"};void interrupt (*oldint65)( );void interrupt newint65( );void main()
{ oldint65 = getvect(0x65);setvect(0x65, newint65);keep(0, 1000);\\made program resident
}3
Another Example
7/31/2019 SPLect-5_2
4/29
void interrupt newint65( ){if (( _AH ) = = 0){
_AH = 0x09;_DX = (unsigned int) st;geninterrupt (0x21);
}else{
if (( _AH ) = = 1)
{_AH = 0x09;_DX = (unsigned int) st1;geninterrupt (0x21);
}
}}
Continued
4
7/31/2019 SPLect-5_2
5/29
#include#include
void main(){
_AH = 1;
geninterrupt (0x65);_AH = 0;geninterrupt (0x65);
}5
2nd Program
7/31/2019 SPLect-5_2
6/29
Different ISR provides different services. Each
interrupt invoked points to a number of services forexample Interrupt 21h has many services, numbered0, 1, 2, 3
Sw interrupts have number of services.
Service number is stored in AH register For example, Int 21h,
A case statement, checks the service number andexectues the corresponding service
6
7/31/2019 SPLect-5_2
7/29
Interrupt Interception,
Hooks/Stealing
7/31/2019 SPLect-5_2
8/29
Execution Interrupted
ISR Perform I/O
Normal Execution of Interrupt
8
Normal execution reviewed
7/31/2019 SPLect-5_2
9/29
Interrupt Interception
New Routine
Original Routine
9
Interrupt Interception Reviewed
7/31/2019 SPLect-5_2
10/29
Other form of Interrupt Interception
New Routine
Original Routine
10
Interrupt Interception Reviewed:continued
7/31/2019 SPLect-5_2
11/29
void Interrupt newint();void Interrupt (*old)(); \\ declare an interrupt pointer
void main(){
old=getvect(0x08); \\ saving the original ISR addressSetvect(0x08,newint);\\ setting the vectorKeep(0,100);\\ make program resident in memory
}void interrupt newint ()
{. . . . . . . . . . . . . . \\ perform your operations(*old)();\\ call the original ISR
}*You can also call the (*old)() in the start of newint().
11
Program (ISR Interception)
7/31/2019 SPLect-5_2
12/29
12
7/31/2019 SPLect-5_2
13/29
Hardware Interrupt
Invoked by means of hardware
Occurs 18.2 times per second(one 18th of a second)
Generated by Programmable Interrupt Timer (PIT)
13
TIMER interrupt
7/31/2019 SPLect-5_2
14/29
BIOS Data Area (0040:0000)
14
A description of bios data area is as follows
Cant write values in this area, just reading.
A certain area in RAM, used by BIOS for storage of data
etc, while BIOS routines are processed. Segment 40 and offset 0. there are various variables
placed here.
On this starting address, a variable is placed that shows
us the status of the keyboard. Lets c.
7/31/2019 SPLect-5_2
15/29
Keyboard Status Variable
15
7 6 5 4 3 2 1 0
Right ShiftkeyLeft Shift Key
Ctrl Key
Alt Key
InsertkeyCaps Lock Key
Num Lock key
Scroll lock key
40:17H
Keyboard Status Word
7/31/2019 SPLect-5_2
16/29
7/31/2019 SPLect-5_2
17/29
17
Interrupt Interception
New Routine
Original Routine
7/31/2019 SPLect-5_2
18/29
18
7/31/2019 SPLect-5_2
19/29
A device may be interfaced with the processor toperform memory mapped or isolated I/O.
Main memory and I/O ports both are physically a kindof memory device.
In case of Isolated I/O, I/O ports are used to hold datatemporary while sending/receiving the data to/from
the I/O device. If the similar function is performed using a dedicated
part of main memory then the I/O operation ismemory mapped.
Memory isolated and mapped I/O
19
7/31/2019 SPLect-5_2
20/29
20
Isolated I/O
MP
I/O ports
IN
OUT
The device or controller uses certain ports to
communicate with processor Control bus signals
Signal M means to read/write frommemory..(Isolated I/O)
Si nal I/O means to read write from I O .
7/31/2019 SPLect-5_2
21/29
21
Memory Mapped I/O
MP
I/O Ports
MOV
MOV
7/31/2019 SPLect-5_2
22/29
22
Memory map Some portion of memory is reserved, so place decreased
In isolated we used ports instead
Isolated i/o has complicated architecture, differentnumber of signals. Complicated hardware design.
Simple hardware memory map design instead
As number of control increases
Monitor uses memory mapped I/O
MonitorVGAMemory
7/31/2019 SPLect-5_2
23/29
23
7/31/2019 SPLect-5_2
24/29
The output on the monitor is controller by acontroller called video controller within the PC.
One of the reason for adopting memory mapped I/O
for the monitor is that a large amount of data isneeded to be conveyed to the video controller inorder to describe the text or that graphics that is tobe displayed.
Such large amount of data being output throughisolated I/O does not form into a feasible idea as thenumber of port in PCs is limited to 65536.
Memory Mapped I/O on Monitor
24
7/31/2019 SPLect-5_2
25/29
25
In text mode 80 columns, 25 rows (characters)80*25 characters
Which characters to show on monitor? Two bytes of storage required for each character
Low byte = ASCII Code
High byte = attribute byte
Character to be displayed are stored in VGA cards memory.
7/31/2019 SPLect-5_2
26/29
Memory Maped I/O on Monitor
26
B8OO:0000
B8OO:0001
B8OO:0002B8OO:0003
Low Byte = ASCII CODE
High Byte =Attribute Byte
7/31/2019 SPLect-5_2
27/29
Overview of Attribute Byte
27
X X X X X X X X
Back Color ColorBold
Blink
Low Byte = Ascii CodeHigh Byte = Attribute Byte
000 Black
100 Red
010 Green
001 Blue
111 White
fore color
7/31/2019 SPLect-5_2
28/29
Program
28
unsigned int far *scr=0xb8000000;
void main(){
(*scr)=0x0756; //56 = B(*(scr+1))=0x7055; //55 = U
}
This example will generate the output UV
7/31/2019 SPLect-5_2
29/29
The far pointer scr is assigned 0xb800H in the high word (segment address)
0x0000H in the low word (offset address).
The word at this address is loaded with the value
0x0756H
next word is loaded by the value 0x7055H,
0x07 is the attribute byte meaning black back color
and white fore color and
the byte 0x70h means white back color and black forecolor. ).
0x56 and 0x55 are the ASCII value of V and Urespectively.
Explaination
29