Date post: | 01-Jun-2018 |
Category: |
Documents |
Upload: | king-faisal-khan |
View: | 221 times |
Download: | 0 times |
of 338
8/9/2019 System Programming - CS609 Handouts.doc
1/337
8/9/2019 System Programming - CS609 Handouts.doc
2/337
8/9/2019 System Programming - CS609 Handouts.doc
3/337
8/9/2019 System Programming - CS609 Handouts.doc
4/337
8/9/2019 System Programming - CS609 Handouts.doc
5/337
8/9/2019 System Programming - CS609 Handouts.doc
6/337
8/9/2019 System Programming - CS609 Handouts.doc
7/337
8/9/2019 System Programming - CS609 Handouts.doc
8/337
8/9/2019 System Programming - CS609 Handouts.doc
9/337
8/9/2019 System Programming - CS609 Handouts.doc
10/337
8/9/2019 System Programming - CS609 Handouts.doc
11/337
8/9/2019 System Programming - CS609 Handouts.doc
12/337
8/9/2019 System Programming - CS609 Handouts.doc
13/337
8/9/2019 System Programming - CS609 Handouts.doc
14/337
8/9/2019 System Programming - CS609 Handouts.doc
15/337
8/9/2019 System Programming - CS609 Handouts.doc
16/337
8/9/2019 System Programming - CS609 Handouts.doc
17/337
8/9/2019 System Programming - CS609 Handouts.doc
18/337
8/9/2019 System Programming - CS609 Handouts.doc
19/337
8/9/2019 System Programming - CS609 Handouts.doc
20/337
8/9/2019 System Programming - CS609 Handouts.doc
21/337
8/9/2019 System Programming - CS609 Handouts.doc
22/337
8/9/2019 System Programming - CS609 Handouts.doc
23/337
8/9/2019 System Programming - CS609 Handouts.doc
24/337
8/9/2019 System Programming - CS609 Handouts.doc
25/337
8/9/2019 System Programming - CS609 Handouts.doc
26/337
8/9/2019 System Programming - CS609 Handouts.doc
27/337
8/9/2019 System Programming - CS609 Handouts.doc
28/337
8/9/2019 System Programming - CS609 Handouts.doc
29/337
8/9/2019 System Programming - CS609 Handouts.doc
30/337
8/9/2019 System Programming - CS609 Handouts.doc
31/337
8/9/2019 System Programming - CS609 Handouts.doc
32/337
8/9/2019 System Programming - CS609 Handouts.doc
33/337
8/9/2019 System Programming - CS609 Handouts.doc
34/337
8/9/2019 System Programming - CS609 Handouts.doc
35/337
8/9/2019 System Programming - CS609 Handouts.doc
36/337
8/9/2019 System Programming - CS609 Handouts.doc
37/337
8/9/2019 System Programming - CS609 Handouts.doc
38/337
8/9/2019 System Programming - CS609 Handouts.doc
39/337
8/9/2019 System Programming - CS609 Handouts.doc
40/337
8/9/2019 System Programming - CS609 Handouts.doc
41/337
8/9/2019 System Programming - CS609 Handouts.doc
42/337
8/9/2019 System Programming - CS609 Handouts.doc
43/337
8/9/2019 System Programming - CS609 Handouts.doc
44/337
8/9/2019 System Programming - CS609 Handouts.doc
45/337
8/9/2019 System Programming - CS609 Handouts.doc
46/337
8/9/2019 System Programming - CS609 Handouts.doc
47/337
8/9/2019 System Programming - CS609 Handouts.doc
48/337
8/9/2019 System Programming - CS609 Handouts.doc
49/337
8/9/2019 System Programming - CS609 Handouts.doc
50/337
8/9/2019 System Programming - CS609 Handouts.doc
51/337
8/9/2019 System Programming - CS609 Handouts.doc
52/337
8/9/2019 System Programming - CS609 Handouts.doc
53/337
8/9/2019 System Programming - CS609 Handouts.doc
54/337
8/9/2019 System Programming - CS609 Handouts.doc
55/337
8/9/2019 System Programming - CS609 Handouts.doc
56/337
8/9/2019 System Programming - CS609 Handouts.doc
57/337
8/9/2019 System Programming - CS609 Handouts.doc
58/337
8/9/2019 System Programming - CS609 Handouts.doc
59/337
8/9/2019 System Programming - CS609 Handouts.doc
60/337
8/9/2019 System Programming - CS609 Handouts.doc
61/337
8/9/2019 System Programming - CS609 Handouts.doc
62/337
8/9/2019 System Programming - CS609 Handouts.doc
63/337
8/9/2019 System Programming - CS609 Handouts.doc
64/337
8/9/2019 System Programming - CS609 Handouts.doc
65/337
8/9/2019 System Programming - CS609 Handouts.doc
66/337
8/9/2019 System Programming - CS609 Handouts.doc
67/337
8/9/2019 System Programming - CS609 Handouts.doc
68/337
8/9/2019 System Programming - CS609 Handouts.doc
69/337
8/9/2019 System Programming - CS609 Handouts.doc
70/337
8/9/2019 System Programming - CS609 Handouts.doc
71/337
8/9/2019 System Programming - CS609 Handouts.doc
72/337
8/9/2019 System Programming - CS609 Handouts.doc
73/337
8/9/2019 System Programming - CS609 Handouts.doc
74/337
8/9/2019 System Programming - CS609 Handouts.doc
75/337
8/9/2019 System Programming - CS609 Handouts.doc
76/337
8/9/2019 System Programming - CS609 Handouts.doc
77/337
8/9/2019 System Programming - CS609 Handouts.doc
78/337
8/9/2019 System Programming - CS609 Handouts.doc
79/337
8/9/2019 System Programming - CS609 Handouts.doc
80/337
8/9/2019 System Programming - CS609 Handouts.doc
81/337
8/9/2019 System Programming - CS609 Handouts.doc
82/337
8/9/2019 System Programming - CS609 Handouts.doc
83/337
8/9/2019 System Programming - CS609 Handouts.doc
84/337
8/9/2019 System Programming - CS609 Handouts.doc
85/337
8/9/2019 System Programming - CS609 Handouts.doc
86/337
8/9/2019 System Programming - CS609 Handouts.doc
87/337
8/9/2019 System Programming - CS609 Handouts.doc
88/337
8/9/2019 System Programming - CS609 Handouts.doc
89/337
8/9/2019 System Programming - CS609 Handouts.doc
90/337
8/9/2019 System Programming - CS609 Handouts.doc
91/337
8/9/2019 System Programming - CS609 Handouts.doc
92/337
8/9/2019 System Programming - CS609 Handouts.doc
93/337
8/9/2019 System Programming - CS609 Handouts.doc
94/337
8/9/2019 System Programming - CS609 Handouts.doc
95/337
8/9/2019 System Programming - CS609 Handouts.doc
96/337
8/9/2019 System Programming - CS609 Handouts.doc
97/337
8/9/2019 System Programming - CS609 Handouts.doc
98/337
8/9/2019 System Programming - CS609 Handouts.doc
99/337
8/9/2019 System Programming - CS609 Handouts.doc
100/337
8/9/2019 System Programming - CS609 Handouts.doc
101/337
8/9/2019 System Programming - CS609 Handouts.doc
102/337
8/9/2019 System Programming - CS609 Handouts.doc
103/337
8/9/2019 System Programming - CS609 Handouts.doc
104/337
8/9/2019 System Programming - CS609 Handouts.doc
105/337
8/9/2019 System Programming - CS609 Handouts.doc
106/337
8/9/2019 System Programming - CS609 Handouts.doc
107/337
8/9/2019 System Programming - CS609 Handouts.doc
108/337
8/9/2019 System Programming - CS609 Handouts.doc
109/337
8/9/2019 System Programming - CS609 Handouts.doc
110/337
8/9/2019 System Programming - CS609 Handouts.doc
111/337
8/9/2019 System Programming - CS609 Handouts.doc
112/337
8/9/2019 System Programming - CS609 Handouts.doc
113/337
8/9/2019 System Programming - CS609 Handouts.doc
114/337
8/9/2019 System Programming - CS609 Handouts.doc
115/337
8/9/2019 System Programming - CS609 Handouts.doc
116/337
8/9/2019 System Programming - CS609 Handouts.doc
117/337
8/9/2019 System Programming - CS609 Handouts.doc
118/337
8/9/2019 System Programming - CS609 Handouts.doc
119/337
8/9/2019 System Programming - CS609 Handouts.doc
120/337
8/9/2019 System Programming - CS609 Handouts.doc
121/337
8/9/2019 System Programming - CS609 Handouts.doc
122/337
8/9/2019 System Programming - CS609 Handouts.doc
123/337
8/9/2019 System Programming - CS609 Handouts.doc
124/337
1+ - C M Ports
&(( Modem Configuration
T%e abo5e slide s%o3s t%e configuration used to interconnect t3o & 'Ts In t%is 3ay a
full du$le8 communication can be $erformed and moreo5er flo3 control can also be
$erformed using S', TS, 'TS and CTS signals!
Sam$le Program
8/9/2019 System Programming - CS609 Handouts.doc
125/337
1+ - C M Ports
8/9/2019 System Programming - CS609 Handouts.doc
126/337
1+ - C M Ports
12 - +OM Ports IISam$le Program using :I S routines
T%e initiali;e . function initiali;es t%e C M $ort 3%ose number is $assed as $arameter
using :I S ser5ices! T%e recie5ec%ar . function uses t%e C M $ort number to recei5e a
byte from t%e C M $ort using :I S ser5ices!
8/9/2019 System Programming - CS609 Handouts.doc
127/337
1+ - C M Ports
T%e sendc%ar . function sends a c%aracter to t%e C M $ort using :I S ser5ice 3%ose
number is $assed as $arameter! nd t%e getcomstatus . function retrie5es t%e status of t%e
C M $ort 3%ose number %as been s$ecified and returns t%e modem and line status in an
unsigned int!
(et s su$$ose t3o & 'Ts are interconnected using a &(( modem
In t%e main . function t%ere is a 3%ile loo$ 3%ic% retrie5es t%e status of t%e C M $ort!
nce t%e status %as been retrie5ed it c%ec s if a byte can be transmitted, if a ey %as been
$ressed and its is clear to send a byte t%e code 3it%in t%e if statement sends t%e in$ut byte
to t%e C M $ort using sendc%ar . function!
8/9/2019 System Programming - CS609 Handouts.doc
128/337
8/9/2019 System Programming - CS609 Handouts.doc
129/337
1+ - C M Ports
T%e SelfTest ff . function turns t%is facility off! T%e 3ritec%ar . function 3rites t%e a
byte $assed to t%is function on t%e data $ort! T%e readc%ar . function reads a byte from t%e
data $ort!
T%e main function after initiali;ing and turning t%e self test mode on enters a loo$ 3%ic%
3ill terminate on in$ut of t%e esca$e c%aracter! T%is loo$ also controls t%e $osition of t%e
cursor suc% t%e cursor goes to t%e ne8t line rig%t after a full line %as been ty$ed!
8/9/2019 System Programming - CS609 Handouts.doc
130/337
1+ - C M Ports
ll t%e in$ut from t%e eyboard is directed to t%e out$ut of t%e & 'T and all t%e in$ut
from t%e & 'T is also directed to t%e lo3er $art of t%e screen! s t%e & 'T is in self test
mode t%e out$ut becomes t%e in$ut! nd %ence t%e user can see out$ut send to t%e & 'T
in t%e lo3er $art of t%e screen as s%o3n in t%e slide belo3
8/9/2019 System Programming - CS609 Handouts.doc
131/337
1+ - C M Ports
Sam$le Program using interru$t dri5en I/
8/9/2019 System Programming - CS609 Handouts.doc
132/337
1+ - C M Ports
T%is si $rogram is also uite similar to t%e $re5ious one! T%e only difference is t%at in t%is
t%e I/ is $erformed in an interru$t dri5en $atter using t%e Int 080C as t%e C M1 uses
I' *! lso to use it in t%is 3ay I' * must be unmas ed from t%e IM' register in PIC!
lso before returning from t%e IS' t%e PIC must be signaled an 7 I code!
8/9/2019 System Programming - CS609 Handouts.doc
133/337
1+ - C M Ports
8/9/2019 System Programming - CS609 Handouts.doc
134/337
1+ - C M Ports
14 - *ea" Time +"oc3 *T+Sam$le Program
T%is $rogram is same functionally as one of t%e $re5ious $rograms 3%ic% used :I S
ser5ices to get t%e in$ut data and send t%e out$ut data! T%e only difference is t%at in t%is
case it does t%e same directly accessing t%e $orts!
8/9/2019 System Programming - CS609 Handouts.doc
135/337
8/9/2019 System Programming - CS609 Handouts.doc
136/337
1+ - C M Ports
N 3%ene5er recei5ed indicates t%e start of communication and N )) 3%ene5er
recei5ed indicates a tem$orary $ause in t%e communication!
)ollo3ing is a $seudo code 3%ic% can be used to im$lement t%e soft3are oriented flo3
control!
t%e recei5ed c%aracter is firstly analysed for N or N )) c%aracter! If N is recei5ed
t%e status is set to T'&7 and if N )) is recei5ed t%e status is set to ) (S7! T%e
c%aracters 3ill only be recei5ed if t%e status is T'&7 ot%er3ise t%ey 3ill be discarded!
8/9/2019 System Programming - CS609 Handouts.doc
137/337
'eal Time Cloc
'eal time cloc is a de5ice incor$orated into t%e PC to u$date time e5en if t%e com$uter
is off! It %as t%e c%aracteristics s%o3n in t%e slide abo5e 3%ic% enables it to u$date time
e5en if t%e com$uter is off!
T%e :I S interru$t 081 % can be used to configure t%is cloc as s%o3n in t%e slide
belo3 it %as 5arious ser5ice for getting/setting time/date and alarm!
8/9/2019 System Programming - CS609 Handouts.doc
138/337
1 - 'eal Time Cloc 'TC.
8/9/2019 System Programming - CS609 Handouts.doc
139/337
1 - 'eal Time Cloc 'TC.
8/9/2019 System Programming - CS609 Handouts.doc
140/337
1 - 'eal Time Cloc 'TC.
8/9/2019 System Programming - CS609 Handouts.doc
141/337
1 - 'eal Time Cloc 'TC.
8/9/2019 System Programming - CS609 Handouts.doc
142/337
1 - 'eal Time Cloc 'TC.
'TC internals
T%e 'TC internally %as an array of registers 3%ic% can be used to access t%e 6* byte
battery $o3ered CM S ' M!
8/9/2019 System Programming - CS609 Handouts.doc
143/337
1 - 'eal Time Cloc 'TC.
T%e follo3ing slide s%o3s t%e function of some of t%e bytes in t%e battery $o3ered ' M
used to store t%e units of time and date!
8/9/2019 System Programming - CS609 Handouts.doc
144/337
1 - 'eal Time Cloc 'TC.
ay of t%e 3ee
T%e 5alue in t%e days of t%e 3ee byte indicates t%e day according to slide s%o3n abo5e!
Eenerally :C 5alues are used to re$resent t%e units of time and date!
8/9/2019 System Programming - CS609 Handouts.doc
145/337
1 - 'eal Time Cloc 'TC.
ccessing t%e :attery Po3ered ' M
)ollo3ing slide s%o3n a fragment of code t%at can be used to read or 3rite onto any byte
3it%in t%e 6* byte battery $o3ered ' M!
8/9/2019 System Programming - CS609 Handouts.doc
146/337
1 - 'eal Time Cloc 'TC.
Cloc Status 'egisters
T%e lo3er * bits of t%is register stores a code indicating t%e fre uency 3it% 3%ic% t%e
'TC %ard3are interru$t can interru$t t%e $rocessor! T%e ne8t field is used to s$ecify t%e
time fre uency i!e! t%e fre uency 3it% t%e time is sam$led and %ence u$dated! T%e most
significant bit indicates t%at after time sam$ling if t%e time %as been u$dated in to t%e 6*
byte ' M or not!
8/9/2019 System Programming - CS609 Handouts.doc
147/337
1 - 'eal Time Cloc 'TC.
17 - *ea" Time +"oc3 *T+ II
Cloc Status 'egisters
T%e status register : is t%e main control register! It is used to s$ecify t%e date time
formats and is also used to enable interru$t on 5arious e5ents li e alarm time and time u$-
dation! not%er feature of 'TC is $eriodic interru$t 3%ic% occur 3it% a fre uency
s$ecified in t%e register!
Status register is used to identify t%e reason of interru$t generation as described in t%e
slide abo5e!
8/9/2019 System Programming - CS609 Handouts.doc
148/337
1 - 'eal Time Cloc 'TC.
nly t%e most significant byte in status register is im$ortant 3%ic% on being 0 indicates
t%at t%e battery is dead!
Sam$le Program!
8/9/2019 System Programming - CS609 Handouts.doc
149/337
8/9/2019 System Programming - CS609 Handouts.doc
150/337
8/9/2019 System Programming - CS609 Handouts.doc
151/337
14 - 'eal Time Cloc 'TC. II
T%e time units are similarly read and con5erted to SCII and dis$layed!
Frite t%e Time on 'TC
8/9/2019 System Programming - CS609 Handouts.doc
152/337
14 - 'eal Time Cloc 'TC. II
T%e abo5e listing of t%e $rogram in$uts t%e time from t%e user 3%ic% is in SCII format!
It con5erts t%e SCII in $ac ed :C and uses :I S ser5ices to u$date t%e time! In S
or 3indo3s t%is time c%ange may not remain effecti5e after t%e com$letion of t%e
$rogram as t%e S or 3indo3s de5ice dri5ers 3ill re5ert t%e time to original e5en if it
%as been c%anged using t%is met%od!
8/9/2019 System Programming - CS609 Handouts.doc
153/337
14 - 'eal Time Cloc 'TC. II
Sam$le Program
8/9/2019 System Programming - CS609 Handouts.doc
154/337
14 - 'eal Time Cloc 'TC. II
To elaborate more on t%e $roblem $osed by t%e S de5ice dri5ers %ere is anot%er
$rogram! T%is $rogram first u$dates t%e time accessing t%e 6* byte ' M directly and
ta ing t%e ne3 time as in$ut from t%e user! fter u$dating t%e $rogram $roduces a delay
of "0 seconds and t%en reads time to dis$lay it! difference of "0 seconds 3ill be noticed
in t%e time entered and t%e time dis$layed! T%is s%o3s t%at during t%e e8ecution of t%e
$rogram t%e time 3as successfully c%anged and 3as being u$dated accordingly!
8/9/2019 System Programming - CS609 Handouts.doc
155/337
14 - 'eal Time Cloc 'TC. II
8/9/2019 System Programming - CS609 Handouts.doc
156/337
14 - 'eal Time Cloc 'TC. II
18 - *ea" Time +"oc3 *T+ III'eading t%e ate
8/9/2019 System Programming - CS609 Handouts.doc
157/337
14 - 'eal Time Cloc 'TC. II
Setting t%e ate
8/9/2019 System Programming - CS609 Handouts.doc
158/337
14 - 'eal Time Cloc 'TC. II
T%e abo5e sam$le $rogram ta es SCII in$ut from t%e user for t%e ne3 date! fter ta ing
all t%e date units as in$ut t%e $rogram sets t%e ne3 date using t%e :I S ser5ice 1 %/0+2!
Setting t%e larm
T%e alarm can be set using :I S function 1 %/06%! nce t%e alarm is set :I S 3ill
generate t%e interru$t * % 3%en t%e alarm time is reac%ed! T%e abo5e $rogram interce$ts
t%e interru$t * % suc% t%at ne3int . function is in5o ed at t%e time of alarm! T%e ne3int .
function 3ill >ust dis$lay a c%aracter Q on t%e u$$er left corner of t%e screen! :ut t%is
$rogram may not 3or in t%e $resence of S or Findo3s dri5ers!
not%er 3ay to set larm
8/9/2019 System Programming - CS609 Handouts.doc
159/337
14 - 'eal Time Cloc 'TC. II
8/9/2019 System Programming - CS609 Handouts.doc
160/337
14 - 'eal Time Cloc 'TC. II
T%is $rogram ta es t%e time of alarm as SCII in$ut 3%ic% is firstly con5erted into :C !
T%is :C time is $laced in t%e 6* byte ' M at t%e bytes 3%ic% %old t%e alarm time!
nce t%e alarm time is loaded t%e register is accessed to enable t%e interru$ts suc% t%at
ot%er bits are not disturbed! F%ene5er t%e 'TC generates an interru$t, t%e reason of t%e
interru$t needs to be establis%ed! T%is can be done by c%ec ing t%e 5alue of status register
C, if t%e +t% bit of register C is set it indicates t%at t%e interru$t 3as generated because t%e
alarm time %as been reac%ed! T%e reason of interru$t generation is establis%ed in t%e
function ne3int 0 .! If t%e interru$t 3as generated because of alarm t%en s$ea er is
turned on by t%e sound . function and a c%aracter Q is dis$layed on t%e u$$er left corner
of t%e screen!
t%er Configuration :ytes of :attery Po3ered ' M
8/9/2019 System Programming - CS609 Handouts.doc
161/337
14 - 'eal Time Cloc 'TC. II
8/9/2019 System Programming - CS609 Handouts.doc
162/337
etermining Systems Information
Interru$t 112 is used to determine t%e systems information! n return t%is ser5ice returns
t%e systems info in N register! T%e detail of t%e information in N register is s%o3n int%e slide abo5e!
8/9/2019 System Programming - CS609 Handouts.doc
163/337
19 - 'eal Time Cloc 'TC. III
Int 1#2 is used to determine t%e amount of con5entional memory interfaced 3it% t%e
$rocessor in ilobytes! T%e amount of memory abo5e con5entional memory e8tended
memory. can be determined using t%e ser5ice 1+2/442!
8/9/2019 System Programming - CS609 Handouts.doc
164/337
8/9/2019 System Programming - CS609 Handouts.doc
165/337
8/9/2019 System Programming - CS609 Handouts.doc
166/337
#0 - etermining system information
$ro$erty can be used to distinguis% bet3een "46 and *46! If t%e $re5ious tests %a5e failed
t%en t%ere is a $ossibility t%at t%e $rocessor is not 4046 or #46! To eliminate t%e
$ossibility of it being a "46 3e $erform t%e alignment test! s s%o3n in t%e slide abo5e
t%e 14t% bit of t%e 7)( ES register is t%e alignment bit, it sets if a double 3ord is mo5ed
onto a odd address or an address 3%ic% does not lie on a * byte boundary!
In t%e abo5e slide a double 3ord is mo5ed into a odd address! If t%e $rocessor is "46 t%en
t%e 14t% bit of t%e 7)( ES register 3ill not be set, it 3ill be set if t%e $rocessor is %ig%er
t%an "46!
8/9/2019 System Programming - CS609 Handouts.doc
167/337
#0 - etermining system information
istinguis%ing bet3een *46 and Pentium $rocessors
Pentium and *46 bot% 3ill $ass t%e alignment test! :ut a *46 does not su$$ort t%e
CP&I instruction! Fe 3ill ne8t incor$orate t%e CP&I instruction su$$ort test to find if
t%e $rocessor is *46 or a Pentium as Pentium does su$$ort CP&I instruction!
If t%e CP&I instruction is a5ailable t%e $rocessor is a Pentium $rocessor ot%er3ise it s a
*46!
8/9/2019 System Programming - CS609 Handouts.doc
168/337
#0 - etermining system information
More about CP&I Instruction
T%e CP&I instruction, if a5ailable, returns t%e 5endor name and information about t%e
model as s%o3n in t%e slide abo5e! :eside rest of t%e test t%e CP&I instruction can also
be used by t%e soft3are to identify t%e 5endor name!
8/9/2019 System Programming - CS609 Handouts.doc
169/337
#0 - etermining system information
Testing for Co$rocessor
Co$rocessor control 3ord
T%e co$rocessor control 3ord contains some control information about t%e co$rocessor!
T%e bit number of co$rocessor control 3ord is t%e Interru$t 7nable )lag and bit number
4 9 s%ould contain 11 on initiali;ation!
Co$rocessor Status Ford
T%e co$rocessor status register stores t%e status of t%e co$rocessor!
8/9/2019 System Programming - CS609 Handouts.doc
170/337
#0 - etermining system information
)ollo3ing test can be $erformed to test t%e $resence of co$rocessor!
nce its establis%ed t%at t%e co$rocessor is $resent t%en t%e model of t%e co$rocessor
s%ould be determined! In case an in5alid numerical o$eration is re uested t%e 404
co$rocessor generates an interru$t 3%ile t%e %ig%er co$rocessors does not use interru$ts
in fact t%ey ma e use of e8ce$tions! T%is feature can be used to distinguis% bet3een 404
and %ig%er $rocessor as s%o3n in t%e slide abo5e! T%e %ig%er $rocessor 3ill not res$ond
to an attem$t made to set t%e I7M flag 3%ile 404 3ill res$ond!
8/9/2019 System Programming - CS609 Handouts.doc
171/337
8/9/2019 System Programming - CS609 Handouts.doc
172/337
#0 - etermining system information
'eading t%e Com$uter configuration
In t%is $rogram t%e general configurations of t%e com$uter are read using interru$t 112,
1#2 and 1+2! )irst its determined if t%e Processor is and T ad5anced tec%nology all
$rocessors abo5e 4046. ty$e com$uter or not! T%is can be done easily by c%ec ing its
signature byte $laced at t%e location )000 )))72 3%ic% 3ill contain neit%er 08)) nor
08)7 if its an T com$uter! T%e $rogram s%o3s t%e si;e of con5entional ' M using t%e
interru$t 1#2, t%en if t%e com$uter is an T com$uter t%en t%e $rogram c%ec s t%e
e8tended memory si;e using int 1+2/442 and re$orts its si;e! nd ultimately t%e $rogram
calls int 112 to s%o3 t%e number and ind of I/ interfaces a5ailable!
8/9/2019 System Programming - CS609 Handouts.doc
173/337
#0 - etermining system information
'1 - ey oard Interface
Processor Identification
In t%e abo5e slide t%e test for 4046 or not is $erformed by clearing all t%e bits of flags
register t%en reading its 5alue by $us%ing flags and t%en $o$ing it in N, t%e bits 1+-1# of
a8 are c%ec ed if t%ey %a5e been set t%en it s a 4046!
8/9/2019 System Programming - CS609 Handouts.doc
174/337
8/9/2019 System Programming - CS609 Handouts.doc
175/337
#0 - etermining system information
CP&I Program
8/9/2019 System Programming - CS609 Handouts.doc
176/337
#0 - etermining system information
T%e abo5e $rogram $laces 0 in ea8 register before issuing t%e CP&I instruction! T%e
string returned by t%e instruction is t%en stored and $rinted moreo5er ot%er information
about family, model etc is also $rinted!
8/9/2019 System Programming - CS609 Handouts.doc
177/337
etecting a Co Processor
fter initiali;ation t%e control 3ord is read if t%e %ig%er byte contains t%e 5alue "!
In t%e code abo5e t%e I7M bit is set and t%en t%e 5alue of control 3ord is read to analyse
c%ange in t%e control 3ord! If t%e most significant bit is set t%en it s a 404 co $rocessor
ot%er3ise ot%er tests must be $erformed!
8/9/2019 System Programming - CS609 Handouts.doc
178/337
#1 - eyboard Interface
n o$eration li e di5ision by ;ero is $erformed. 3%ic% results in infinity! T%en t%e sign
of t%e result is re5ersed, if it can be re5ersed t%en its 40"4 co $rocessor ot%er3ise its
certainly 40#4 !
T%e eyboard interface as discussed earlier uses t%e I' 1 and t%e $ort 602 as data $ort, it
also uses anot%er $ort number 6*2 as a status $ort! T%e eyboard can $erform
sync%ronous serial I/ !
8/9/2019 System Programming - CS609 Handouts.doc
179/337
8/9/2019 System Programming - CS609 Handouts.doc
180/337
#1 - eyboard Interface
T%e in$ut c%aracter scan code is recei5ed at $ort 602! certain bit in t%e $ort 6*2 or
eyboard controller is used as t%e I:) in$ut buffer full. bit! de5ice dri5er can c%ec
t%is bit to see if a c%aracter %as been recei5ed from t%e eyboard on 3%ic% t%is bit 3ill
turn to 1!
Similarly some data as control information. can be send to t%e eyboard! T%e $rocessor
3ill 3rite on t%e $ort 602! T%e de5ice dri5er 3ill c%ec t%e :) out$ut buffer full bit of
$ort 6*2 3%ic% remains set as long as t%e byte is not recei5ed by t%e eyboard! n
recei$t of t%e byte from t%e $ort 602 t%e eyboard de5ice 3rite a code 08) on t%e $ort
602 to indicate t%at t%e byte %as been recei5ed $ro$erly!
8/9/2019 System Programming - CS609 Handouts.doc
181/337
#1 - eyboard Interface
'' - ey oard Interface, %M +ontro""er
&sing t%e described information 3e can design a $rotocol for correctly 3riting on t%e
eyboard de5ice as described belo3!
eyboard is a ty$ically an in$ut de5ice but some data can also be send to t%e eyboard
de5ice! T%is data is used as some control information by t%e eyboard! ne suc%
information is t%e ty$ematic rate! T%is ty$e matic rate can be con5eyed to t%e eyboard as
described by t%e slide belo3!
t%er suc% control information is t%e (7 status! 75ery eyboard %as t%ree (7 s for
re$resenting t%e status of um (oc , Ca$s (oc and t%e Scroll (oc ! If t%e de5ice dri5er
8/9/2019 System Programming - CS609 Handouts.doc
182/337
#1 - eyboard Interface
needs to c%ange t%e status t%en t%e (7 status byte s%ould be 3ritten on t%e eyboard as
described belo3! :ut before 3riting t%is byte t%e eyboard s%ould be told t%at t%e control
byte is to be 3ritten! T%is is done by sending t%e code 0N7 before sending t%e status
byte using t%e abo5e described $rotocol!
C%anging Ty$ematic 'ate
8/9/2019 System Programming - CS609 Handouts.doc
183/337
#1 - eyboard Interface
T%e abo5e $rogram %as function Send bd'ate .! T%is function ta es # $arameters, first
one is 5alue to be sent and t%e second one is t%e ma8imum number of retries it $erforms if
t%e byte cannot be sent! T%is function im$lements t%e described $rotocol! It first 3aits for
t%e I:) to be cleared and t%en starts trying to send t%e byte! T%e functions sto$s trying
eit%er if 08) is recei5ed success. or if t%e number of retries end failure.!
o3 t%is function is used to c%ange t%e ty$ematic rate! )irstly 0N)" is 3ritten to indicate
t%at t%e ty$ematic rate is to be c%anged t%en t%e ty$ematic rate is set to 08 ) and a strng
can be ty$e to e8$erience t%e ne3 ty$ematic rate! gain t%is rate is set to 0! T%is $rogram
3ill not 3or if you %a5e booted t%e system in 3indo3s! )irst boot t%e system in S
and t%en run t%is $rogram!
8/9/2019 System Programming - CS609 Handouts.doc
184/337
#1 - eyboard Interface
C%anging (7 s Status
8/9/2019 System Programming - CS609 Handouts.doc
185/337
#1 - eyboard Interface
gain t%e same function is being used in t%is $rogram to turn on t%e eyboard (7 s!
)irstly 087 is sent to indicate t%e o$eration and t%en is 3ritten to turn on all t%e (7 s!
:ut tuning on t%e (7 s li e t%is 3ill not c%ange t%e eyboard status indicated by t%e byte
at *0 1 2! If t%e status for t%e de5ice dri5er usage is to c%anges as 3ell t%en t%e
corres$onding at *0 1 2 can be set by 'ing it 3it% 08 0! T%is $rogram 3ill not 3or if
you %a5e booted t%e system in 3indo3s! )irst boot t%e system in S and t%en run t%is
$rogram!
8/9/2019 System Programming - CS609 Handouts.doc
186/337
#1 - eyboard Interface
M is a de5ice 3%ic% can ac uire com$lete control of t%e buses and %ence can be used
to transfer data directly from $ort to memory or 5ice 5ersa! Transferring data li e t%is can
$ro5e faster because a transfer 3ill consume # bus cycles if it is $erformed using t%e
$rocessor! So in t%is a$$roac% t%e $rocessor is by$asses and its cycles are stolen and are
used by t%e M controller!
8/9/2019 System Programming - CS609 Handouts.doc
187/337
#1 - eyboard Interface
'( - %irect Memory ccess %M
T%e latc% : of t%e M interface is used to %old t%e %ig%er * or 4 bits of t%e #0 or #* bit
absolute address res$ecti5ely! T%e lo3er 16bits are loaded in t%e base address register andt%e number of bytes to be loaded are $laced in t%e count register! T%e M re uests to
ac uire buses t%roug% t%e 2 ( signal, it recei5es a 2( 2old c no3ledge . signal
if no %ig%er $riority signal is a5ailable! n ac no3ledgment t%e M ac uires control of
t%e buses and can issue signals for read and 3rite o$erations to memory and I/ $orts
simultaneously! T%e '7 signals are used by 5arious de5ices to re uest a M
o$eration! nd if t%e M controller is successful in ac uiring t%e bus it sends bac t%e
C signal to signify t%at t%e re uest is being ser5iced! )or t%e re uest to be ser5iced $ro$erly t%e M c%annel must t%e $rogrammed accurately before t%e re uest!
single M can transfer 4bit o$erands to and from memory in a single a bus cycle! If
16bit 5alues are to be transmitted t%en t3o M controllers are re uired and s%ould be
cascaded as s%o3n abo5e!
8/9/2019 System Programming - CS609 Handouts.doc
188/337
#1 - eyboard Interface
T%e abo5e slides s%o3s t%e c%aracteristics of eac% register 3%en a M c%annel is to be
$rogrammed and also s%o3s t%e total number of registers in t%e M controller! Some of
t%e registers are common for all c%annels and some are indi5idual for eac% c%annel!
8/9/2019 System Programming - CS609 Handouts.doc
189/337
T%e M can 3or in abo5e listed modes! In bloc transfer mode t%e M is
$rogrammed to transfer a bloc and does not $ause or %alt until t%e 3%ole bloc is
transferred irres$ecti5e of t%e re uests recei5ed mean3%ile!
In Single transfer mode t%e M transfers a single byte on eac% re uest and u$dates t%e
counter registers on eac% transfer and t%e registers need not be $rogrammed again! n t%e
ne8t re uest t%e M 3ill again transfer a single byte beginning from t%e location it last
ended!
emand transfer is same as bloc transfer, only difference is t%at t%e '7 signal
remains acti5e t%roug%out t%e transfer and as soon as t%e signal deacti5ates t%e transfer
sto$s and on reacti5ation of t%e '7 signal t%e transfer may start from t%e $oint it left!
8/9/2019 System Programming - CS609 Handouts.doc
190/337
#" - irect Memory ccess M .
Programming t%e M
T%e abo5e table s%o3s t%e addresses of all t%e registers t%at s%ould be $rogrammed to
$erform a transfer! T%ese registers act as status and control registers and are common for
all t%e c%annels!
8/9/2019 System Programming - CS609 Handouts.doc
191/337
8/9/2019 System Programming - CS609 Handouts.doc
192/337
#" - irect Memory ccess M .
T%is is t%e command register! It is used to $rogram 5arious common $arameters of
transfer for all t%e c%annels!
8/9/2019 System Programming - CS609 Handouts.doc
193/337
#" - irect Memory ccess M .
' - %irect Memory ccess %M II
T%is register can be used to simulate a M re uest t%roug% soft3are in case of memory
to memory transfer.! T%e lo3er # bits contains t%e c%annel number to be re uested and
t%e bit H # is set to indicate a re uest!
8/9/2019 System Programming - CS609 Handouts.doc
194/337
8/9/2019 System Programming - CS609 Handouts.doc
195/337
#* - irect Memory ccess M . II
T%is register can also be used to mas t%e M c%annels! It contains a single bit for eac%
c%annel! T%e corres$onding bit is set to mas t%e re uests for t%at c%annel!
8/9/2019 System Programming - CS609 Handouts.doc
196/337
#* - irect Memory ccess M . II
T%is register can be used to set t%e mode on eac%! T%e slide s%o3s t%e detail of t%e 5alues
and bits 3%ic% s%ould be $laced in t%e register in order to $rogram a re uired mode!
8/9/2019 System Programming - CS609 Handouts.doc
197/337
#* - irect Memory ccess M . II
c%annel is $rogrammed for a start address and t%e count of bytes to be transferred
before t%e transfer can ta e $lace! :ot% t%ese 5alues are $laced in 5arious registers
according to t%e c%annel number as s%o3n by t%e slide abo5e! nce t%e transfer starts
t%ese 5alues start c%anging! T%e start address is u$dated in to t%e current address and t%e
count is also u$dates as bytes are transferred! uring t%e transfer t%e status of t%e transfer
can be analy;ed by getting t%e 5alues of t%ese registers listed In t%e slide abo5e for t%e
c%annel s. in5ol5ed in t%e transfer!
8/9/2019 System Programming - CS609 Handouts.doc
198/337
#* - irect Memory ccess M . II
T%e abo5e slide s%o3s t%e $ort number for eac% c%annel in 3%ic% t%e %ig%er * or 4 bits of
t%e absolute address is stored in case of #0 or #* bit address bus!
T%is $rogram, $rograms t%e M c%annel " for read cycle by $lacing 080: in mode
register 080:.! :efore t%e c%annel is unmas ed and t%e c%annel mode is $rogrammed t%e
base address t%e count and t%e %ig%er * or 4 bits of t%e address s%ould be $laced in base
register, count register and (atc% : res$ecti5ely! T%e #0 or #*. bit address is calculated!
T%e %ig%er * or 4. bits are $laced in t%e (atc% : for c%annel ", t%en t%e rest of t%e 16
bits of t%e base address are $laced in base register for c%anne" and ultimately t%e count is
8/9/2019 System Programming - CS609 Handouts.doc
199/337
#* - irect Memory ccess M . II
loaded into t%e count register for c%annel "!
8/9/2019 System Programming - CS609 Handouts.doc
200/337
#* - irect Memory ccess M . II
'. - #i"e Systems
T%is $rogram attem$ts to $erform memory to memory transfer o$eration! T%is $rogram
3ill only 3or for a 4046 $rocessor, %ig%er $rocessors M may not su$$ort memor to
memory transfer!
8/9/2019 System Programming - CS609 Handouts.doc
201/337
#* - irect Memory ccess M . II
8/9/2019 System Programming - CS609 Handouts.doc
202/337
T%is $rogram, $rograms t%e c%annel 0 and c%annel 1 of t%e M ! It loads t%e address of
Source string st in base register and t%e (atc% : and loads t%e count register for c%annel 0
and does t%e same for st1! It t%en $rograms t%e mode, mas and command register for
memory to memory transfer and to unmas c%annel 0 and c%annel 1!
)ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
203/337
8/9/2019 System Programming - CS609 Handouts.doc
204/337
#+ - )ile Systems
n addressable unit on dis can be addressed by t%ree $arameters i!e! %ead H, sector H and
trac H! T%e dis rotates and c%anging sectors and a %ead can mo5e to and fro c%anging
trac s! 7ac% addressable unit %as a uni ue combination of secH, %eadH and trac H as its
$%ysical address!
8/9/2019 System Programming - CS609 Handouts.doc
205/337
#+ - )ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
206/337
#+ - )ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
207/337
#+ - )ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
208/337
#+ - )ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
209/337
8/9/2019 System Programming - CS609 Handouts.doc
210/337
#+ - )ile Systems
8/9/2019 System Programming - CS609 Handouts.doc
211/337
#+ - )ile Systems
T%e abo5e $rogram reads a $%ysically addressed bloc from dis using bios dis .
function for first fi8ed dis ! T%e $rogram after reading t%e s$ecified bloc 3rites it to a
file and t%en closes t%e file!
2o3e5er t%ere are some limitation of t%is biosdis . 3%ile using large dis s! T%is
function uses t%e int 1"2 ser5ices listed in t%e slide abo5e!
8/9/2019 System Programming - CS609 Handouts.doc
212/337
#+ - )ile Systems
T%e $arameter si;es $ro5ided by t%ese ser5ices may not be sufficient to %old t%e trac
number of bloc to be accessed!
bo5e slide s%o3s for 3%ic% dis s e8tended ser5ices are re uired to access t%e bloc
efficiently!
8/9/2019 System Programming - CS609 Handouts.doc
213/337
#+ - )ile Systems
:ut I 7 dis interface can su$$ort dis s 3it% memory s$ace larger t%an +0*M: as s%o3n
in t%e ne8t slide!
8/9/2019 System Programming - CS609 Handouts.doc
214/337
#+ - )ile Systems
78tended ser5ices re uire t%at t%e address of t%e bloc is s$ecified as a (: address!
8/9/2019 System Programming - CS609 Handouts.doc
215/337
(: translation is done by numbering t%e bloc s 3it% a single inde8! T%e inde8es are
assigned to bloc s as s%o3n in t%e slide belo3! In terms of t%e dis geometry firstly all
t%e sectors of a trac 3ill be inde8ed se uentially, t%en t%e trac e8%austs t%e ne8t trac is
c%osen on t%e ot%er side of t%e dis and so on all t%e trac s in a cylinder are inde8ed!
F%en all t%e bloc s 3it%in a cylinder %as been inde8ed t%e same is done 3it% t%e ne8t
cylinder!
if t%e C2S cylinder, %ead , sector. address of a dis is no3n it can be translated in to t%e
(: address and 5ice 5ersa! )or t%is $ur$ose t%e total number of cylinders, %eads and
sectors must also be no3n!
8/9/2019 System Programming - CS609 Handouts.doc
216/337
8/9/2019 System Programming - CS609 Handouts.doc
217/337
#6 - 2ard is
is ddress Pac et is a data structure used by e8tended int 1"2 ser5ices to address a
bloc and ot%er information for accessing t%e bloc ! Its structure is defined in t%e slide
belo3!
8/9/2019 System Programming - CS609 Handouts.doc
218/337
#6 - 2ard is
'4 - 5ard %is3, Partition Ta "e
Interru$t 1"2/*#2 can be used to read a (: addressed bloc 3%ose (: address is
$laced in t%e is ddress $ac et as described in t%e slide abo5e!
Similarly int 1"2 / *"2 can be used to 3rite onto to (: addressed bloc as described in
t%e slide abo5e!
8/9/2019 System Programming - CS609 Handouts.doc
219/337
#6 - 2ard is
8/9/2019 System Programming - CS609 Handouts.doc
220/337
8/9/2019 System Programming - CS609 Handouts.doc
221/337
#6 - 2ard is
T%e data $art can contain information about four different $artitions for different
$erating systems! 7ac% $artition information c%un is 16 bytes long and t%e last t3o
bytes at t%e end of t%e $artition table data $art is t%e $artition table signature 3%ose 5alue
s%ould be ++ indicating t%at t%e code $art contains 5alid e8ecutable code!
8/9/2019 System Programming - CS609 Handouts.doc
222/337
8/9/2019 System Programming - CS609 Handouts.doc
223/337
#6 - 2ard is
8/9/2019 System Programming - CS609 Handouts.doc
224/337
#6 - 2ard is
2o3e5er if a single o$erating system is to be e$t for instance, t%en t%e dis can be
di5ided into $rimary and e8tended $artitions! Information about $rimary and e8tended
$artition is e$t in t%e first $%ysical bloc ! T%e e8tended $artition may again be di5ided
into a number of $artitions, information about furt%er $artitions 3ill be e$t in e8tended
$artition table 3%ic% 3ill be t%e first $%ysical bloc 3it%in e8tended $artition i!e! it 3ill
not t%e first bloc of $rimary $artition!.! Moreo5er t%ere can be e8tended $artitions 3it%in
e8tended $artitions and suc% t%at in t%en end t%ere are number of logical $artitions t%is
can go on till t%e last dri5e number in S!
8/9/2019 System Programming - CS609 Handouts.doc
225/337
#6 - 2ard is
'7 - Partition Ta "e II
8/9/2019 System Programming - CS609 Handouts.doc
226/337
8/9/2019 System Programming - CS609 Handouts.doc
227/337
#6 - 2ard is
T%e abo5e dum$ s%o3s t%e dum$ of t%e data $art of t%e first $artition table 3%ic% %as t3o
16 bytes entries, t%e 5alues in t%e entries can be inter$reted as t%e 5alues s%o3n in t%e
follo3ing slide!
8/9/2019 System Programming - CS609 Handouts.doc
228/337
#6 - 2ard is
2ere is t%e information found in t%e $artition table of first e8tended $artition table 3%ic%
im$lies anot%er e8tended and a logical $artition!
8/9/2019 System Programming - CS609 Handouts.doc
229/337
#6 - 2ard is
2ere is information in t%e $artition table of t%e second e8tended $artition t%at im$lies yet
anot%er e8tended $artition and a logical $artition 3it% t%e details s%o3n in t%e follo3ing
slide!
8/9/2019 System Programming - CS609 Handouts.doc
230/337
#6 - 2ard is
8/9/2019 System Programming - CS609 Handouts.doc
231/337
'8 - *eading 9:tended Partition
8/9/2019 System Programming - CS609 Handouts.doc
232/337
#9 - 'eading 78tended Partition
bo5e slides s%o3s t%e information collected as yet 3%ic% indicates t%e logical dri5e
t%ere starting (: bloc s, t%e number of bloc , t%e %idden bloc s etc! T%e follo3ing
slide s%o3s t%e contents of t%e data $art of $artition table of t%e last e8tended $artition!
It %as >ust one data entry for t%e logical dri5e indicating t%at t%is is t%e $artition table in
t%e c%ain! T%e detail of t%e contents t%is $artition table are s%o3n belo3!
8/9/2019 System Programming - CS609 Handouts.doc
233/337
#9 - 'eading 78tended Partition
T%e follo3ing slide s%o3s t%e summary of all t%e data collected as yet de$icting * logical
dri5es and t%e number of bloc s 3it%in!
8/9/2019 System Programming - CS609 Handouts.doc
234/337
#9 - 'eading 78tended Partition
8/9/2019 System Programming - CS609 Handouts.doc
235/337
#9 - 'eading 78tended Partition
8/9/2019 System Programming - CS609 Handouts.doc
236/337
#9 - 'eading 78tended Partition
bo5e is a listing of a sim$le $rogram t%at reads t%e $artition table using t%e e8tended
1"2 ser5ices! It t%en dis$lays t%e contents of t%e data $art of t%e $artition table read! )or
t%is $ur$ose it uses 5arious data structures designed in reflection of t%e $artition table and
16 bytes data entries 3it%in! T%e $rogram uses recursion and calls t%e get$art . function
recursi5ely 3%ene5er it finds an e8tended $artition to read t%e data 3it%in t%e e8tended
$artition table!
8/9/2019 System Programming - CS609 Handouts.doc
237/337
#9 - 'eading 78tended Partition
T%e $artition table data entry also stores t%e C2S address of t%e starting bloc ! :ut t%is
address is left insignificant if a (: enable dis is in uestion! 2o3e5er (: address can
be used in $lace of t%e C2S address, and in case C2S address is re uired it can be
calculated if t%e total number of trac s, sectors and %eads are no3n! To get t%e total
number of trac s, sectors and %ead t%e abo5e described ser5ice can be used!
8/9/2019 System Programming - CS609 Handouts.doc
238/337
#9 - 'eading 78tended Partition
(0 - #i"e System %ata Structures LS;,
8/9/2019 System Programming - CS609 Handouts.doc
239/337
8/9/2019 System Programming - CS609 Handouts.doc
240/337
#9 - 'eading 78tended Partition
T%e abo5e $rogram uses a '7S&(T:&))7' data structure in reflection of t%e result
buffer described in $re5ious slides! It uses t%e interru$t 1"2/*42 to get t%e dri5e
$arameters and t%en dis$lays t%e recei5ed total number of sectors, %eads and cylinders!
8/9/2019 System Programming - CS609 Handouts.doc
241/337
#9 - 'eading 78tended Partition
T%is is also a uite similar $rogram only difference is t%at it also translates a (: address
into C2S address and dis$lays it, for t%is $ur$ose it gets t%e dri5e $arameters to no3 t%e
total number of %eads, sectors and cylinders!
(S is also inde8ed li e (: t%e only difference is t%at (: is t%e address relati5e to t%e
start of $%ysical dri5e i!e! absolute., 3%ereas (S address is t%e address from t%e start of
logical $artition i!e relati5e!
8/9/2019 System Programming - CS609 Handouts.doc
242/337
#9 - 'eading 78tended Partition
s in t%e abo5e e8am$le it can be noticed t%at t%e (: ? 0 is not t%e same as (S ?0!
T%e (: ?0 bloc is t%e first bloc on dis ! F%ereas eac% logical $artition %as (S ?0
bloc 3%ic% is t%e first bloc in logical dri5e and is not necessarily t%e first bloc on
$%ysical dri5e! lso notice t%e %idden bloc s bet3een t%e first $%ysical bloc on eac%
$artition and its first (S bloc ! T%ese %idden bloc s are not used by t%e o$erating
system for storing any ind of data!
8/9/2019 System Programming - CS609 Handouts.doc
243/337
#9 - 'eading 78tended Partition
To understand t%e file systems of S and Findo3s t%e abo5e gi5en data structure
s%ould be understood 3%ic% are used by t%e o$erating system for file management! In t%e
coming lecture t%ese data structures 3ill be discussed in detail!
bo5e slide s%o3s t%e o5erall anatomy of a ) T based system! Starting bloc s. is /are
t%e boot bloc s., immediately after 3%ic% t%e ) T )ile allocation table. starts! ty$ical
5olume 3ill contain t3o co$ies of ) T! fter ) T t%e root directory is situated 3%ic%
contain information about t%e files and folders in t%e root directory! F%ole of t%is area
constitutes t%e systems area rest of t%e area is used to store user data and folders!
8/9/2019 System Programming - CS609 Handouts.doc
244/337
#9 - 'eading 78tended Partition
:I S $arameter bloc is a data structure maintained by S in t%e boot bloc for eac%
dri5e! T%e boot bloc is ty$ically a +1# byte bloc 3%ic% as seen t%e $re5ious slides is t%e
first logical bloc i!e! (S ? 0! It contains some code and data! T%e data $art constitutes
t%e :P:! etails for ) T 1# and 16 are s%o3n in follo3ing slides!
8/9/2019 System Programming - CS609 Handouts.doc
245/337
#9 - 'eading 78tended Partition
8/9/2019 System Programming - CS609 Handouts.doc
246/337
#9 - 'eading 78tended Partition
(1 - #i"e System %ata Structures II um$ to t%e code $art and s i$ t%e data $art so t%at it
is not inter$reted as instructions by t%e $rocessor!
8/9/2019 System Programming - CS609 Handouts.doc
247/337
#9 - 'eading 78tended Partition
bo5e is t%e dum$ of t%e boot bloc for a ) T 1# system! T%e contents of t%e :P: can be
read from it t%e follo3ing slide s%o3s t%e detail of t%e information obtained from t%e
abo5e :P:!
8/9/2019 System Programming - CS609 Handouts.doc
248/337
)ollo3ing is anot%er dum$ s%o3ing t%e boot bloc for a ) T 16 system!
8/9/2019 System Programming - CS609 Handouts.doc
249/337
"1 - )ile System ata Structures II :oot bloc .
)ollo3ing is t%e detail of information read from t%e abo5e dum$ 3%ic% describes t%e
5olume in uestion!
:esides t%e (: address a (S address can also be used to address a bloc ! If t%e (S
address is no3n t%e absread . function can be used to read a bloc and abs3rite . can be
used to 3rite on it as described in t%e slide belo3 3%ere nsect is t%e number of sector to
be read/3ritten!
8/9/2019 System Programming - CS609 Handouts.doc
250/337
"1 - )ile System ata Structures II :oot bloc .
8/9/2019 System Programming - CS609 Handouts.doc
251/337
"1 - )ile System ata Structures II :oot bloc .
(' - #i"e System %ata Structures III %Pust analy;e t%e contents of root directory of t%e same 5olume! If t%e I'
command is $erformed on t%e same 5olume its result 3ill be as belo3! ote t%e entry for
file named T7ST!TNT
o3 on t%e same 5olume t%e file T7ST!TNT is deleted! (ets analyse t%e contents of t%e
root directory no3!
8/9/2019 System Programming - CS609 Handouts.doc
279/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
T%e entry for T7ST!TNT still e8ists as can be seen from t%e ne8t slide! T%e only
difference t%at %a5e occurred is t%at t%e first c%aracter %as been re$laced by a byte 3it%
t%e 5alue 087+
:ut 3%en t%e I' command e8ecute on t%e same 5olume t%e file does not s%o3!
8/9/2019 System Programming - CS609 Handouts.doc
280/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
o3 let s see t%e contents of t%e file by con5erting t%e first cluster number in t%e )C:
into (S and ta ing its dum$! Fe get t%e follo3ing slide!
T%e contents of t%e file are still t%ere!
8/9/2019 System Programming - CS609 Handouts.doc
281/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
So 3e infer t%e follo3ing!
ot only t%e file is mar ed for deletion but also t%e c%ain of its cluster in ) T is
reclaimed by $utting ;eros in t%ere $lace! T%is also indicates t%at t%ese clusters are no3
free!
o3 let s %a5e some discussion about sub-directories! In t%e contents of t%e abo5e gi5en
root directory notice an entry named S7C ! T%e attribute byte of t%is entry is 08#0
3%ic% indicates t%at it s a directory, t%e si;e is 0 3%ic% s%o3s t%at t%ere is no3 user data
in it, but e5en t%oug% t%e si;e 0 its %as a first cluster 3%ic% is 081#! Con5erting 081# into
(S and t%en reading its contents 3e get t%e follo3ing dum$! T%is s%o3s t%at t%is cluster
contains t%e )C:s for all t%e file and folders 3it%in t%is directory!
8/9/2019 System Programming - CS609 Handouts.doc
282/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
In t%e entries 3it%in S7C 3e see an entry S&:#! Its starting cluster is 001 2! T%is
5alue is con5erted into (S and t%e contents read! T%e slide abo5e also s%o3s t%e
contents of S&:#!
Similarly t%e follo3ing slide s%o3s t%e contents of S&:" 3it%in S&:# and t%e contents
of S&:* 3it%in S&:"!
T%e follo3ing slide s%o3s t%e contents of S&:+ and also t%e contents of file
MG)I(7!TNT in S&:+!
8/9/2019 System Programming - CS609 Handouts.doc
283/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
In all t%e sub-directories one t%ing is 3ort% noticing! T%e first t3o entries are t%e ! and !!
entries! T%ese t3o are s$ecial entries as described in t%e slide belo3!
otice t%e contents of S7C directory! T%e ! entry %as t%e cluster number 001#2
3%ic% is t%e cluster number for t%e S7C directory and t%e !! entry %as cluster number
3%ic% indicates t%e %ig%er le5el directory 3%ic% is t%e root directory!
lso e8amine t%e contents of S&:# directory t%e ! directory %as cluster number 001 %
3%ic% t%e cluster number for S&:# and t%e !! entry %as t%e cluster number 001#2 3%ic%
is t%e cluster number of its $arent directory S7C
Same can be obser5ed for S&:", S&:*, S&:+ or any ot%er sub-directory in uestion!
8/9/2019 System Programming - CS609 Handouts.doc
284/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
So t%is %o3 C ! command gi5es t%e current $at% and C !! mo5es to t%e one %ig%er le5el
directory!
8/9/2019 System Programming - CS609 Handouts.doc
285/337
8/9/2019 System Programming - CS609 Handouts.doc
286/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
In t%e follo3ing slide t%e P: of t%e 5olume is being read!
&sing t%e information in P: t%e root directory entries are read and are being s%o3n in
t%e slide belo3!
8/9/2019 System Programming - CS609 Handouts.doc
287/337
"+ - ) T1# )ile System Selecting a 1#-bit entry 3it%in ) T1# System.
I n t%e abo5e slide it can be noticed t%at t%e long file name is also stored 3it% t%e )C:s!
lso t%e fragments of &nicode strings in t%e long file name forms a c%ain! T%e first byte
in t%e c%ain 3ill be 0801, t%e first byte of t%e ne8t fragment 3ill be 080# and so on till t%e
last fragment! If t%e last fragment is t%e nt% fragment starting from 0 suc% t%at n is
bet3een 0 and #+ t%e first byte of t%e last fragment 3ill be gi5en as SCII of Q $lus n!
8/9/2019 System Programming - CS609 Handouts.doc
288/337
o3 lets mo5e our discussion to ) T"#! In t%eory t%e ma>or difference bet3een ) T 16
and ) T "# is of course t%e ) T si;e! ) T"# e5idently 3ill contain more entries and can
%ence manage a 5ery large dis 3%ereas ) T16 can manage a s$ace of # E: ma8imum
$ractically!
)ollo3ing slide s%o3s t%e structure of t%e :P: for ) T"#! Clearly t%ere 3ould be some
additional information re uired in ) T"# so t%e structure for :P: used in ) T"# is
different!
8/9/2019 System Programming - CS609 Handouts.doc
289/337
" - ) T"# )ile System
8/9/2019 System Programming - CS609 Handouts.doc
290/337
" - ) T"# )ile System
T%ere can be different 5olumes 3it% different 5olume si;es! T%e de5ice dri5er for file
%andling 3ould re uire no3ing t%e ) T si;e! T%e follo3ing slide illustrates an algorit%m
t%at can be used to determine t%e ) T si;e in use after reading t%e :P:!
8/9/2019 System Programming - CS609 Handouts.doc
291/337
" - ) T"# )ile System
8/9/2019 System Programming - CS609 Handouts.doc
292/337
" - ) T"# )ile System
8/9/2019 System Programming - CS609 Handouts.doc
293/337
" - ) T"# )ile System
(7 - # T(' #i"e System II
)ollo3ing slide s%o3s %o3 t%e c%ain of clusters is maintained in a ) T"# based system!
8/9/2019 System Programming - CS609 Handouts.doc
294/337
" - ) T"# )ile System
)C: in ) T"# system %as an en%anced meaning as s%o3n by t%e slide belo3!
natomy of ) T"# based system differs from ) T16 based systems significantly as
e8$lained by t%e slide belo3!
8/9/2019 System Programming - CS609 Handouts.doc
295/337
8/9/2019 System Programming - CS609 Handouts.doc
296/337
" - ) T"# )ile System
8/9/2019 System Programming - CS609 Handouts.doc
297/337
" - ) T"# )ile System
So using all t%is information 3e calculate t%e (S for cluster number # as s%o3n t%e
slide belo3 for t%is $articular 5olume!
8/9/2019 System Programming - CS609 Handouts.doc
298/337
" - ) T"# )ile System
To e8amine t%e contents of a file first a file is created 3%ose contents are also s%o3n in
t%e slide!
and is stored as myfile!t8t on t%e root directory!
8/9/2019 System Programming - CS609 Handouts.doc
299/337
" - ) T"# )ile System
o3 3e e8amine t%e contents of cluster number # 3%ic% contains t%e root directory as
already seen in t%e $re5ious slides!
8/9/2019 System Programming - CS609 Handouts.doc
300/337
" - ) T"# )ile System
)rom t%e information from abo5e slides t%e lo3 and %ig% 3ords of t%e first cluster
number is obtained and is s%o3n in t%e slide belo3! T%e %ig%er * bits of t%e cluster
number s%ould be ignored as discussed earlier!
&sing t%e cluster number abo5e t%e (S for t%is cluster is determined as s%o3n in t%e
slide belo3!
8/9/2019 System Programming - CS609 Handouts.doc
301/337
" - ) T"# )ile System
T%e bloc s 3it%in t%e cluster are read and t%eir contents can be seen in t%e slide belo3!
In t%e ) T"# t%ere is anot%er s$ecial reser5ed bloc called )SInfo sector! T%e bloc
contains some information re uired by t%e o$erating system 3%ile cluster
allocation/deallocation to files! T%is information is also critical for ) T16 based systems!
:ut in ) T1# and 16 t%is information is calculated 3%en e5er re uired! T%is calculation at
t%e time of allocation is not feasible in ) T"# as t%e si;e of ) T"# is 5ery large and suc%
calculations 3ill consume a lots of time, so to sa5e time t%is information is stored in t%e
)SInfo bloc and is u$dated at t%e time of allocation/deallocation!
8/9/2019 System Programming - CS609 Handouts.doc
302/337
8/9/2019 System Programming - CS609 Handouts.doc
303/337
" - ) T"# )ile System
(8 - ;e6 Techno"ogy #i"e System ;T#S
T%e follo3ing slide s%o3s t%e anatomy of an T)S based system! T%e ) T and root
directory %as been re$laced by t%e M)T! It 3ill generally %a5e t3o co$ies t%e ot%er co$y
3ill be a mirror image of t%e original! 'ests of t%e bloc s are reser5ed for user data! In t%e
middle of t%e 5olume is a co$y of t%e first 16 MT) record 3%ic% are 5ery im$ortant to t%e
system!
8/9/2019 System Programming - CS609 Handouts.doc
304/337
T%e follo3ing slides s%o3 t%e :oot sector structure for a T)S based system!
8/9/2019 System Programming - CS609 Handouts.doc
305/337
"9 - e3 Tec%nology )ile System T)S.
T%e follo3ing slide s%o3s a sam$le of t%e boot bloc dum$! T%e follo3ing slides de$ict
5arious $arameters $laced in t%e :oot bloc !
T%e first 16 entries of t%e M)T are reser5ed! 'ests of t%e entries are used for user files!
T%ere is an entry for eac% file in t%e M)T! T%ere can be difference in t%e 3ay a file is
managed de$ending u$on t%e si;e of t%e file!
8/9/2019 System Programming - CS609 Handouts.doc
306/337
"9 - e3 Tec%nology )ile System T)S.
)ollo3ing slide s%o3s t%e detail about t%e first 16 system entries 3it%in t%e M)T!
8/9/2019 System Programming - CS609 Handouts.doc
307/337
"9 - e3 Tec%nology )ile System T)S.
8/9/2019 System Programming - CS609 Handouts.doc
308/337
"9 - e3 Tec%nology )ile System T)S.
0 - %isassem "ing the ;T#S ased fi"e
o3 in t%e follo3ing e8am$le a file is created and its entry is searc%ed in t%e M)T! T%e
follo3ing slide s%o3s t%at t%e name of t%e file created is T7ST!TNT!
T%is slide s%o3 t%e contents of t%e file created!
T%e first logical bloc is read to read t%e contents of t%e :P: in T)S! )ollo3ing s%o3s
t%e contents of boot bloc for t%is 5olume!
8/9/2019 System Programming - CS609 Handouts.doc
309/337
"9 - e3 Tec%nology )ile System T)S.
)ollo3ing slides s%o3s 5arious $arameters obtained from :P:!
8/9/2019 System Programming - CS609 Handouts.doc
310/337
)or T)S sim$ly t%e follo3ing formula 3ill be used to translate t%e sector number into
cluster number!
)ollo3ing slide s%o3s %o3 t%e sector number for t%e M)T on t%is 5olume 3as
calculated! T%e first bloc of M)T no t%is 5olume is 6#91*+6!
8/9/2019 System Programming - CS609 Handouts.doc
311/337
*0 - isassembling t%e T)S based file
)rom t%e bloc number 6#91*+6 entries 3ere searc%ed for T7ST!TNT and t%is file entry
3as found at t%e bloc number 6#91+#0!
T%e abo5e dum$ s%o3s t%e file name as 3ell as t%e contents of t%e file are stored in t%is
entry! 2as t%e file been larger it 3ould not %a5e been $ossible to store t%e content of t%e
file in t%is entry so ot%er clusters 3ould %a5e been used and t%ere 3ould inde8es 3ould
%a5e been e$t in t%e entry!
s an e8ercise one can try to find out t%e sub folders and t%e contents of t%e files stored in
it!
8/9/2019 System Programming - CS609 Handouts.doc
312/337
*0 - isassembling t%e T)S based file
T%e follo3ing slides e8$lain %o3 t%e T)S 5olume can be accessed in S! ormally it
can not be accessed if t%e system %as booted in S as t%e S de5ice dri5ers do not
understand T)S!
8/9/2019 System Programming - CS609 Handouts.doc
313/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
314/337
8/9/2019 System Programming - CS609 Handouts.doc
315/337
*0 - isassembling t%e T)S based file
T%e abo5e $rogram uses t%e P: to reac% t%e clusters of a file! T%e get P: . function
gets t%e far address of t%e P:! &sing t%is address t%e dri5e $arameters are used to
determine t%e location of ) T and root directory! T%e file is firstly searc%ed in t%e root
directory t%roug% se uential searc%! If t%e file name and e8tension is found t%e first
cluster number is used to loo u$ into t%e ) T for subse uent clusters! T%e $articular
bloc containing t%e ne8t cluster 3it%in t%e ) T is loaded and t%e entry is read, similarly
t%e 3%ole c%ain is tra5ersed till t%e end of file is encountered!
8/9/2019 System Programming - CS609 Handouts.doc
316/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
317/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
318/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
319/337
*0 - isassembling t%e T)S based file
' - Memory Management
T%e follo3ing slide s%o3s t%e memory ma$ of t%e first 1M: of ' M! T%e first 6*0 : is
called con5entional ' M and t%e %ig%er "4* : is called system memory! Some of t%e
memory areas are reser5ed for s$ecial $ur$oses as described by t%e slide rest is user area
3%ere user a$$lication can reside!
8/9/2019 System Programming - CS609 Handouts.doc
320/337
*0 - isassembling t%e T)S based file
In %ig%er $rocessors, t%e main memory may be greater t%an 1M:! In t%is slide it s%o3s
t%at t%e memory $ortion %ig%er t%an 1M: is called e8tended memory and some unused
$ortion in system memory is called t%e e8$anded memory!
8/9/2019 System Programming - CS609 Handouts.doc
321/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
322/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
323/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
324/337
*0 - isassembling t%e T)S based file
T%e follo3ing slide s%o3s t%at t3o MC:s are allocated for eac% $rogram ty$ically! T%e
first MC: controls t%e 7n5ironment :loc t%e ne8t MC: controls t%e PSP and t%e
$rogram! If t%is is t%e last $rogram in memory t%en t%e MC: after t%e $rogram %as Q in
its first byte indicating t%at it is t%e last MC: in t%e c%ain!
All the )C$ forms a chain. !f the address of first )C$ is 'nown the segment
address of ne t )C$ can be determined by adding the number of paragraph
controlled by )C$ D into the segment address of the )C$. ame is true for all
)C$s and hence the whole chain can be traversed.
8/9/2019 System Programming - CS609 Handouts.doc
325/337
*0 - isassembling t%e T)S based file
T%e abo5e slide s%o3s %o3 ser5ice #12/+#2 is used to get t%e address of first MC: in
memory!
In t%e follo3ing slide t%e dum$ of t%e first MC: is ta en! QM in t%e first byte at t%e
location read indicates t%e $lacement of MC: at t%is location! T%e address of ne8t MC:
can be calculated by adding t%e number of $aragra$%s controlled by MC: K 1 into t%e
segment address! &sing t%is met%od all t%e MC:s in memory are tra5ersed till t%e last
MC: 3it% first byte Q is encountered!
8/9/2019 System Programming - CS609 Handouts.doc
326/337
*0 - isassembling t%e T)S based file
( - ;on-+ontiguous memory a""ocation
T%is $rogram used t%e same met%od as discussed in $re5ious lecture to get t%e address of
first MC:, calculate t%e addresses of subse uent MC:s and tra5erse t%e MC:s to reac%
t%e last MC:!
8/9/2019 System Programming - CS609 Handouts.doc
327/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
328/337
*0 - isassembling t%e T)S based file
8/9/2019 System Programming - CS609 Handouts.doc
329/337
T%e follo3ing slide s%o3s t%e structure of descri$tors of 40#46 and 40"46 $rocessors
8/9/2019 System Programming - CS609 Handouts.doc
330/337
*" - on-Contiguous memory allocation
8/9/2019 System Programming - CS609 Handouts.doc
331/337
8/9/2019 System Programming - CS609 Handouts.doc
332/337
T%e %idden cac%e is illustrated in t%e slide belo3! T%e registers in dotted lines are %idden
i!e! are not accessible to any a$$lication directly!
8/9/2019 System Programming - CS609 Handouts.doc
333/337
** - ddress translation in Protected mode
8/9/2019 System Programming - CS609 Handouts.doc
334/337
** - ddress translation in Protected mode
. - $iruses
8/9/2019 System Programming - CS609 Handouts.doc
335/337
8/9/2019 System Programming - CS609 Handouts.doc
336/337
** - ddress translation in Protected mode
8/9/2019 System Programming - CS609 Handouts.doc
337/337
** - ddress translation in Protected mode
T%e follo3ing slide illustrates %o3 a C M file 5irus relocates itself to ma e itself
inde$endent in memory!