Sunteți pe pagina 1din 29

System Programming

BSCS-7th Semester Dr. Wajeeha Khalil

Running a TSR Program

TSR programs must be compiled with .com in extension .com doesnt exceed 64kB size. TSR programs should be run by making its com file and exit the compiler, then run it. Save the program using with .c extension.

Another Example
#include<BIOS.H> #include<DOS.H> char 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

Continued
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); } } 4 }

2nd Program
#include<BIOS.H> #include<DOS.H> void main() {
_AH = 1;

geninterrupt (0x65); _AH = 0; geninterrupt (0x65); }


5

Different ISR provides different services. Each interrupt invoked points to a number of services for example Interrupt 21h has many services, numbered 0, 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 and exectues the corresponding service
6

Interrupt Interception, Hooks/Stealing

Normal execution reviewed


Execution Interrupted ISR Perform I/O

Normal Execution of Interrupt

Interrupt Interception Reviewed


New Routine

Original Routine

Interrupt Interception

Interrupt Interception Reviewed: continued


Original Routine

New Routine

Other form of Interrupt Interception

10

Program (ISR Interception)

void Interrupt newint(); void Interrupt (*old)(); \\ declare an interrupt pointer void main() { old=getvect(0x08); \\ saving the original ISR address Setvect(0x08,newint);\\ setting the vector Keep(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

12

TIMER interrupt

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

BIOS Data Area (0040:0000)


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.

14

Keyboard Status Variable


40:17H 7 6 5 4 3 2 1 0

Insert key Caps Lock Key Num Lock key Scroll lock key
15

Right Shift key Left Shift Key


Ctrl Key Alt Key

Keyboard Status Word

Program
#include <dos.h> void Interrupt (*old)(); void Interrupt new(); Char far *scr=(char far* ) 0x00400017; \\ Far Pointer initialized with a double word Void main() { old=getvect(0x08); Setvect(0x08,new); Keep(0,1000); }
16

Void interrupt new (){ *scr=64; (*old)(); } Call original interrupt (*old)() at the end. Can call it in the beginning only in software interrupts.

New Routine

Original Routine

Interrupt Interception

17

18

Memory isolated and mapped I/O


A device may be interfaced with the processor to perform memory mapped or isolated I/O. Main memory and I/O ports both are physically a kind of memory device. In case of Isolated I/O, I/O ports are used to hold data temporary 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 is memory mapped. 19

Isolated I/O
IN
M P I/O ports

OUT
The device or controller uses certain ports to

communicate with processor Control bus signals Signal M means to read/write from memory..(Isolated I/O) Signal I/O means to read/write from I/O .
20

Memory Mapped I/O


MOV

M P

I/O Ports

MOV
21

Memory map
Some portion of memory is reserved, so place decreased
In isolated we used ports instead

Isolated i/o has complicated architecture, different

number of signals. Complicated hardware design. Simple hardware memory map design instead As number of control increases
Monitor uses memory mapped I/O MonitorVGAMemory
22

23

Memory Mapped I/O on Monitor


The output on the monitor is controller by a controller 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 is needed to be conveyed to the video controller in order to describe the text or that graphics that is to be displayed. Such large amount of data being output through isolated I/O does not form into a feasible idea as the number of port in PCs is limited to 65536.
24

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.

25

Memory Maped I/O on Monitor


B8OO:0000 B8OO:0001 B8OO:0002 B8OO:0003

Low Byte = ASCII CODE High Byte =Attribute Byte

26

Overview of Attribute Byte


fore color Blink

X X X X X X X X
Back Color Bold Color

Low Byte = Ascii Code High Byte = Attribute Byte

000 100 010 001 111


27

Black Red Green Blue White

Program
unsigned int far *scr=0xb8000000; void main() { (*scr)=0x0756; (*(scr+1))=0x7055; } This example will generate the output VU
28

//56 = B //55 = U

Explaination
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 fore color. ).

0x56 and 0x55 are the ASCII value of V and U respectively.


29

S-ar putea să vă placă și