System Programming - CS609 Handouts
System Programming - CS609 Handouts
CS609
CS609-System Programming
VU
VU
0! - "ntro#u$tion% &eans of "'( )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))* 02 - "nterrupt &e$hanism)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!+ 0+ - Use of "S,s for C -i rary .un$tions))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2! 0/ - TS, programs an# "nterrupts))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))20 0* - TS, programs an# "nterrupts 12ey oar# interrupt3 )))))))))))))))))))))))))))))))))))))))))))))))))))+* 06 - TS, programs an# "nterrupts 14isk interrupt% 2ey oar# hook3)))))))))))))))))))))))))))))))))/2 05 - 6ar#7are "nterrupts))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/0 00 - 6ar#7are "nterrupts an# TS, programs)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))*6 09 - The interval Timer))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))5! !0 - Peripheral Programma le "nterfa$e 1PP"3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))59 !! - Peripheral Programma le "nterfa$e 1PP"3 "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))06 !2 - Parallel Port Programming))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))90 !+ - Serial Communi$ation)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!06 !/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3))))))))))))))))!!+ !* - C(& Ports))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!20 !6 - C(& Ports "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!20 !5 - ,eal Time Clo$k 1,TC3))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!+6 !0 - ,eal Time Clo$k 1,TC3 ""))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!/9 !9 - ,eal Time Clo$k 1,TC3 """)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!*0 20 - 4etermining system information))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!66 2! - 2ey oar# "nterfa$e))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!5* 22 - 2ey oar# "nterfa$e% 4&8 Controller)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!0+ 2+ - 4ire$t &emory 8$$ess 14&83)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!09 2/ - 4ire$t &emory 8$$ess 14&83 "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!9* 2* - .ile Systems))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))202 26 - 6ar# 4isk))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2!! 25 - 6ar# 4isk% Partition Ta le))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))220 20 - Partition Ta le "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))225 29 - ,ea#ing 9:ten#e# Partition))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2++ +0 - .ile System 4ata Stru$tures 1-S;% <P<3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2/0 +! - .ile System 4ata Stru$tures "" 1<oot lo$k3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2/0 +2 - .ile System 4ata Stru$tures """ 14P<3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2*+ ++ - ,oot 4ire$tory% .8T!2 .ile System)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))260 +/ - .8T!2 .ile System ""% .8T!6 .ile System))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))266 +* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3)))))))))))))))))))))25! +6 - .ile (rgani=ation)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))250 +5 - .8T+2 .ile System)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))205 +0 - .8T+2 .ile System "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))29* +9 - ;e7 Te$hnology .ile System 1;T.S3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+0* /0 - 4isassem ling the ;T.S ase# file))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+!0 /! - 4isk Utilities)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+!6 /2 - &emory &anagement)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+2! /+ - ;on-Contiguous memory allo$ation)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+20 // - 8##ress translation in Prote$te# mo#e))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+++ /* - Viruses))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))++5
CS609-System Programming
VU
Input Input
Process
Output Output
While designing software the programmer may determine the required inputs for that program, the wanted outputs and the processing the software would perform in order to give those wanted outputs. The implementation of the processing part is associated with application programming. Application programming facilitates the implementation of the required processing that software is supposed to perform; everything that is left now is facilitated by system programming. ystems programming is the study of techniques that facilitate the acquisition of data from input devices, these techniques also facilitates the output of data which may be the result of processing performed by an application. Three Layered !!roach
A system programmer may use a three layered approach for systems programming. As you can see in the figure the user may directly access the programmable hardware in order to perform !"# operations. The user may use the trivial $!# %$asic !nput #utput ystem& routines in order to perform !"# in which case the programmer need not 'now the internal wor'ing of the hardware and need only the 'nowledge $!# routines and their parameters.
4(S
<"(S
6'>
!n this case the $!# programs the hardware for required !"# operation which is hidden to the user. !n the third case the programmer may invo'e operating systems %(# or whatever& routines in order to perform !"# operations. The
0! - "ntro#u$tion% &eans of "'( operating system in turn will use $!# routines or may program the hardware directly in order to perform the operation. )ethods of !"# !n the three layered approach if we are following the first approach we need to program the hardware. The hardware can be programmed to perform !"# in three ways i.e. *rogrammed !"# !nterrupt driven !"# (irect )emory Access !n case of programmed !"# the C*+ continuously chec's the !"# device if the !"# operation can be performed or not. !f the !"# operations can be performed the C*+ performs the computations required to complete the !"# operation and then again starts waiting for the !"# device to be able to perform ne,t !"# operation. !n this way the C*+ remains tied up and is not doing anything else besides waiting for the !"# device to be idle and performing computations only for the slower !"# device. !n case of interrupt driven the flaws of programmed driven !"# are rectified. The processor does not chec' the !"# device for the capability of performing !"# operation rather the !"# device informs the C*+ that it-s idle and it can perform !"# operation, as a result the e,ecution of C*+ is interrupted and an !nterrupt ervice .outine %! .& is invo'ed which performs the computations required for !"# operation. After the e,ecution of ! . the C*+ continues with whatever it was doing before the interruption for !"# operation. !n this way the C*+ does not remain tied up and can perform computations for other processes while the !"# devices are busy performing !"# and hence is more optimal. +sually it ta'es two bus cycles to transfer data from some !"# port to memory or vice versa if this is done via some processor register. This transfer time can be reduced bypassing the C*+ as ports and memory device are also interconnected by system bus. This is done with the support of ()A controller. The ()A %direct memory access& controller can controller the buses and hence the C*+ can be bypassed data item can be transferred from memory to ports or vice versa in a single bus cycle.
I/O contro""ers
"'( #evi$e
"'( $ontroller
CPU
/o !"# device is directly connected to the C*+. To provide control signals to the !"# device a !"# controller is required. !"# controller is located between the C*+ and the !"# device. 0or e,ample the monitor is not directly collected to the C*+ rather the monitor is connected to a 12A card and this 12A card is in turn connected to the C*+ through busses. The 'eyboard is not directly connected to C*+ rather its connected to a 'eyboard controller and the 'eyboard controller is connected to the C*+. The function of this !"# controller is to provide !"# control signals $uffering 3rror Correction and (etection We shall discuss various such !"# controllers interfaced with C*+ and also the techniques and rules by which they can be programmed to perform the required !"# operation. ome of such controllers are ()A controller !nterrupt controller *rogrammable *eripheral !nterface %**!& !nterval Timer +niversal Asynchronous .eceiver Transmitter We shall discuss all of them in detail and how they can be used to perform !"# operations. O!erating systems ystems programming is not 4ust the study of programmable hardware devices. To develop effective system software one needs to the internals of the operating system as well. #perating systems ma'e use of some data structures or tables for management of computer resources. We will ta'e up different functions of the operating systems and discuss how they are performed and how can the data structures used for these operations be accessed. Copyright Virtual University of Pakistan 5
#i"e Management 0ile management is an important function of the operating systems. (# "Windows uses various data structures for this purpose. We will see how it performs !"# management and how the data structures used for this purpose can be directly accessed. The various data structures are popularly 'nown as 0AT which can be of 56, 57 and 86 bit wide, #ther data structures include $*$%$!# parameter bloc'&, (*$% drive parameter bloc'& and the 0C$s%file control bloc'& which collectively forms the directory structure. To understand the file structure the basic requirement is the understanding of the dis' architecture, the dis' formatting process and how this process divides the dis' into sectors and clusters. Memory management )emory management is another important aspect of operating systems. tandard *C operate in two mode in terms of memory which are .eal )ode *rotected )ode !n real mode the processor can access only first one )$ of memory to control the memory within this range the (# operating system ma'es use of some data structures called 0C$ %0ile control bloc' & * * %*rogram segment prefi,& We shall discuss how these data structures can be directly accessed, what is the significance of data in these data structures. This information can be used to traverse through the memory occupied by the processes and also calculate the total amount of free memory available. Certain operating systems operate in protected mode. !n protected mode all of the memory interfaced with the processor can be accessed. #perating systems in this mode ma'e use of various data structures for memory management which are 9ocal (escriptor Table 2lobal (escriptor Table !nterrupt (escriptor Table We will discuss the significance these data structures and the information stored in them. Also we will see how the logical addresses can be translated into physical addresses using the information these tables $iruses and $accines #nce an understanding of the file system and the memory )anagement is developed it is possible to understand the wor'ing of viruses. 1irus is a simple program which can embed itself within the computer resources and propagate itself. )ostly viruses when activated would perform something hazardous. Copyright Virtual University of Pakistan
0! - "ntro#u$tion% &eans of "'( We will see where do they embed themselves and how can they be detected. )oreover we will discuss techniques of how they can be removed and mostly importantly prevented to perform any infections. There are various types of viruses but we will discuss those which embed themselves within the program or e,ecutable code which are 3,ecutable file viruses *artition Table or boot sector viruses %e&ice %ri&ers :ust connecting a device to the *C will not ma'e it wor' unless its device drivers are not installed. This is so important because a device driver contains the routines which perform !"# operations on the device. +nless these routines are provided no !"# operation on the !"# device can be performed by any application. We will discuss the integrated environment for the development of device drivers for (# and Windows. We shall begin our discussion from means of !"#. #n a well designed device it is possible to perform !"# operations from three different methods *rogrammed !"# !nterrupt driven !"# ()A driven !"#
(utput 40 40 45 4, CPU
"nput
<usy
45 Stro e
CPU
"'( Controller
!n case of programmed !"# the C*+ is in a constant loop chec'ing for an !"# opportunity and when its available it performs the computations operations required for the !"# operations. As the !"# devices are generally slower than the C*+, C*+ has to wait for !"# operation to complete so that ne,t data item can be sent to the device. The C*+ sends data on the data lines. The device need to be signaled that the data has been sent this is done with the help of T.#$3 signal. An electrical pulse is sent to the device by turning this signal to ; and then 5. The device on getting the strobe signal receives the data and starts its output. While the device is performing the output it-s busy and cannot accept any further data on the other and C*+ is a lot faster device and can process lot more bytes during the output of previously sent data so it should be synchronized with the slower !"# device. This is usually done by another feed bac' signal of $+ < which is 'ept active as long as the device is busy. o the C*+ is only waiting for the Copyright Virtual University of Pakistan 9
0! - "ntro#u$tion% &eans of "'( device to get idle by chec'ing the $+ < signal as long as the device is busy and when the device gets idle the C*+ will compute the ne,t data item and send it to the device for !"# operation. imilar is the case of input, the C*+ has to chec' the (. %data .eady& signal to see if data is available for input and when its not C*+ is busy waiting for it. Interru!t %ri&en I/O The main disadvantage of programmed !"# as can be (utput "nput noticed is that the C*+ is busy waiting for an !"# 40 40 opportunity and as a result remain tied up for that !"# 45 45 operation. This disadvantage Stro e can be overcome by means <usy "<. ";T of interrupt driven !"#. !n ";T 8C2 *rogrammed !"# C*+ itself "'( CPU chec's for an !"# opportunity CPU "'( Controller but in case of interrupt Controller driven !"# the !"# controller interrupts the e,ecution of C*+ when ever and !"# operation is required for the computation of the required !"# operation. This way the C*+ can perform other computation and interrupted to perform and interrupt service routine only when an !"# operation is required, which is quite an optimal technique.
!0
! 2
9iterally to interrupt means to brea' the continuity of some on going tas'. When we tal' of computer interrupt we mean e,actly the same in terms of the processor. When an interrupt occurs the continuity of the processor is bro'en and the e,ecution branches to an interrupt service routine. This interrupt service routine is a set of instruction carried out by the C*+ to perform or initiate an !"# operation generally. When the routine is over the e,ecution of the C*+ returns to the point of interruption and continues with the on going process.
!!
0! - "ntro#u$tion% &eans of "'( !nterrupts can be of two types >ardware interrupts oftware interrupts #nly difference between them is the method by which they are invo'ed. oftware interrupts are invo'ed by means of some software instruction or statement and hardware interrupt is invo'ed by means of some hardware controller generally. Interru!t Mechanism !nterrupts are quite similar to procedures or function because it is also another form temporary e,ecution transfer, but there some differences as well. /ote that when procedures are invo'ed by there names which represents their addresses is specified whereas in case of interrupts their number is specified. This number can be any ? bit value which certainly is not its address. o the first question is what is the significance of this number= Another thing should also be noticed that procedures are part of the program but the interrupts invo'ed in the program are no where declared in the program. o the ne,t question is where do these interrupts reside in memory and if they reside in memory then what would be the address of the interrupt= 0irstly lets see where do interrupts reside. !nterrupts certainly reside somewhere in memory, the interrupts supported by the operating system resides in 'ernel which you already 'now is the core part of the operating system. !n case of (# the 'ernel is io.sys which loads in memory at boot time and in case of windows the 'ernel is 'ernel86.dll or 'ernel.dll. these files contain most of the !"# routines and are loaded as required. The interrupts supported by the .#) $!# are loaded in .#) part of the main memory which usually starts at the address 0;;;@;;;;>. )oreover it is possible that some device drivers have been installed these device drivers may provide some !"# routines so when the system boots these !"# routines get memory resident at interrupt service routines. o these are the three possibilities. econdly a program at compile time does not 'now the e,act 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. !nterrupt 1ector Table %!1T& in short is a 5;6A bytes sized table which can hold 6B7 far addresses as each far address occupies A bytes. o its possible to store the addresses of 6B7 interrupts hence there are a ma,imum of 6B7 interrupt in a standard *C. The interrupt number is used as an inde, into the table to get the address of the interrupt service routine.
!2
"nt 2!h
&oreover 7hen an interrupt is invoke# three registers are pushe# as the return a##ress i)e) the values of "P% CS an# .lags in the #es$ri e# or#er 7hi$h are restore# on return) 8lso Copyright Virtual University of Pakistan !+
0! - "ntro#u$tion% &eans of "'( no parameters are pushe# onto the sta$k on invo$ation parameters $an only e passe# through registers) The interrupt ve$tor ta le The interrupt num er spe$ifie# in the interrupt $all is use# as an in#e: into the interrupt ve$tor ta le) "nterrupt ve$tor ta le is a glo al ta le situate# at the a##ress 0000D00006) The si=e of interrupt ve$tor ta le is !02/ ytes or ! 2<) 9a$h entry in the "VT is si=e# / ytes hen$e 2*6 interrupt ve$tors are possi le num ere# 10-..63) 9a$h entry in the ta le $ontains a far a##ress of an interrupt han#lers hen$e there is a ma:imum of 2*6 han#lers ho7ever ea$h han#lers $an have a num er of servi$es 7ithin itself) So the num er operations that $an e performe# y $alling an interrupt servi$e routine 1"S,3 is in#efinite #epen#ing upon the nature of the operating system) 9a$h ve$tor $ontains a far a##ress of an interrupt han#ler) The a##ress of the ve$tor an# not the a##ress of interrupt han#ler $an e easily $al$ulate# if the interrupt num er is kno7n) The segment a##ress of the 7hole "VT is 00006 the offset a##ress for a parti$ular interrupt han#ler $an e #etermine# y multiplying its num er 7ith / eg) The offset a##ress of the ve$tor of ";T 2!6 7ill e 2!6 E / @ 0/6 an# the segment for all ve$tors is 0 hen$e its far a##ress is 0000D000/6%1 this is the far a##ress of the interrupt ve$tor an# not the interrupt servi$e routine or interrupt han#ler3) The ve$tor in turn $ontains the a##ress of the interrupt servi$e routine 7hi$h is an ar itrary value #epen#ing upon the lo$ation of the "S, resi#ing in memory) .ig 2 1"nterrupt Ve$tor Ta le3
";T..
0000D0+..6
&oreover it is important to un#erstan# the meaning of the four ytes 7ithin the interrupt ve$tor) 9a$h entry 7ithin the "VT $ontains a far a##ress the first t7o ytes 1lo7er 7or#3 of 7hi$h is the offset an# the ne:t t7o ytes 1higher 7or#3 is the segment a##ress)
!/
";T 0
0000D000!
0000D000+ 0000D000/
";T !
0000D0005
.ig + 1.ar a##ress 7ithin "nterrupt ve$tor3 -o$ation of "S,s 1"nterrupt servi$e routines3 Fenerally there are three kin# of "S, 7ithin a system #epen#ing upon the entity 7hi$h implements it <"(S 1<asi$ "'( servi$es3 "S,s 4(S "S,s "S,s provi#e# y thir# party #evi$e #rivers >hen the system has oote# up an# the appli$ations $an e run all these kin# of "S,s may e provi#e# y the system) Those provi#e# y the ,(&-<"(S 7oul# e typi$ally resi#ent at any lo$ation after the a##ress .000D00006 e$ause this the a##ress 7ithin memory from 7here the ,(&-<"(S starts% the "S,s provi#e# y 4(S 7oul# e resi#ent in the 4(S kernel 1mainly "()SGS an# &S4(S)SGS loa#e# in memory3 an# the "S, provi#e# y thir# party #evi$e #rivers 7ill e resi#ent in the memory o$$upie# y the #evi$e #rivers)
"()SGS 4evi$e 4river Comman#) C(& US9, P,(F,8&
,om <ios
.000D0000
.ig / 1"S,s in memory3 This fa$t $an e pra$ti$ally analy=e# y the 4(S $omman# mem'# 7hi$h gives the status of the memory an# also points out 7hi$h memory area o$$upie# y 7hi$h pro$ess as sho7n in the te:t elo7) The information given y this $omman# in#i$ates the a##ress Copyright Virtual University of Pakistan !*
0! - "ntro#u$tion% &eans of "'( 7here "()SGS an# other #evi$e #rivers have een loa#e# ut the lo$ation of ,(& <"(S is not sho7n y this $omman#)
C:\>mem /d Address ------000000 000400 000#00 000&00 Name -------Size -----000400 000100 000$00 000'&0 C!N A)* + N C,!C-. C!"1 ,+T1 ,+T$ ,+T' C!"$ C!"' C!"4 000A&0 00$000 "S%!S 001/10 Type -----Interrupt Vector !" Communication Area %!S Communication Area System %ata System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %e(ice System %ata System %ata System +ro3ram %2VIC25 Insta66ed %e(ice %ri(er 8I,2S5 8C1S5 ,AST% IV25 STAC-S5 +ro3ram -- 8ree -2n(ironment +ro3ram 2n(ironment +ro3ram -- 8ree -System +ro3ram System %ata System +ro3ram -- 8ree -+ro3ram +ro3ram %ata -- 8ree -%ri(er %ri(er %ri(er %ri(er %ri(er %ri(er %ri(er %ri(er %ri(er %ri(er %ri(er
I!
0040C0 004A80 0041&0 00#$#0 00%A00 0020$0 0$##10 078880 0C8000 0%$110 0%$&$0 0%$700 0%''00 0%'410
I! 00$0'0 -1% 000C20 4I"2" 000420 *"S****0 000470 000070 0001$0 000&%0 C!""AN% 000A$0 "S%!S 0000&0 C!""AN% 000/%0 %!S* 000&A0 "2" 000/10 "2" 01&420 "S%!S 0&AA%0 S9ST2" 0$8000 I! "!)S2 "S%!S "SC%2*NT 2%I %!S* "S%!S 00'100 00'080 000/00 0001%0 000A&0 000000 00C120
/##'/0 :ytes tota6 con(entiona6 memory /##'/0 :ytes a(ai6a:6e to "S-%!S #7&7#$ 6ar3est e;ecuta:6e pro3ram size 1040#&/ :ytes tota6 conti3uous e;tended memory 0 :ytes a(ai6a:6e conti3uous e;tended memory 7410#/ :ytes a(ai6a:6e *"S memory "S-%!S resident in 4i3< "emory Area
"nterrupt "nvo$ation 8lthough har#7are an# soft7are interrupts are invoke# #ifferently i)e har#7are interrupts are invoke# y means of some har#7are 7hereas soft7are interrupts are invoke# y means of soft7are instru$tion or statement ut no matter ho7 an interrupt has een invoke# pro$essor follo7s a $ertain set steps after invo$ation of interrupts in e:a$tly same 7ay in oth the $ases) These steps are liste# as elo7 Push .lags% CS% "P ,egisters% Clear "nterrupt .lag Use 1";TH3E/ as (ffset an# Iero as Segment Copyright Virtual University of Pakistan !6
0! - "ntro#u$tion% &eans of "'( This is the a##ress of interrupt Ve$tor an# not the "S, Use lo7er t7o ytes of interrupt Ve$tor as offset an# move into "P Use the higher t7o ytes of Ve$tor as Segment 8##ress an# move it into CS@0D JoffsetK2L <ran$h to "S, an# Perform "'( (peration ,eturn to Point of "nterruption y Popping the 6 ytes i)e) .lags CS% "P) This $an e analy=e# pra$ti$ally y the use of #e ug program% use# to #e ug assem ly language $o#e% y assem ling an# #e ugging ";T instru$tions
C:\>de:u3 -d 0:04 0000:0000 0000:0070 0000:00A0 0000:0010 0000:00C0 0000:00%0 0000:0020 0000:0080 0000:0100
1& 10 10 2A 10 10 10 0A
0' 10 10 A2 10 10 10 04
0# 00 00 A& 00 00 00 0$
&C 0/ #4 10 00 10 10 10
10 10 0$ 10 20 10 10 10
0' 10 04 01 10 10 10 10
0# 00 CC 04 00 00 00 00
0A 7A 10 #0 C4 10 10 10
0' 10 10 07 $' 10 10 10
0# 00 00 %4 C7 00 00 00
-a 0A81:0100 int $1 0A81:010$ -r A*50000 1*50000 %S50A81 2S50A81 0A81:0100 C%$1 -t A*50000 1*50000 %S50A81 2S50A81 00A&:10&C 70 -d ss:CCe0 0A81:8820 0A81:8880 00
C*50000 %*50000 SS50A81 CS50A81 INT $1 C*50000 %*50000 SS50A81 CS500A& N!+
0$ 01 81 0A 0$ 8$ 00 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
The #ump at the a##ress 0000D000/ 6 sho7s the value of the ve$tor of the interrupt H 2!6 i)e) 2!6 E / @ 0/6) This a##ress hol#s the value !05C6 in lo7er 7or# an# 00856 in the higher 7or# 7hi$h in#i$ates that the segment a##ress of interrupt H 2! is 00856 an# the offset a##ress of this "S, is !05C6) &oreover the instru$tion ";T 2!6 $an e assem le# an# e:e$ute# in the #e ug program% on #oing e:a$tly so the instru$tion is tra$e# through an# the result is monitore#) "t $an e seen that on e:e$ution of this instru$tion the value of "P is $hange# to !05C6 an# the value of CS is $hange# to 00856 7hi$h $ause the e:e$ution to ran$h to the "nterrupt H 2!6 in memory an# the previous values of flags% CS an# "P registers are temporarily save# onto the sta$k as the value of SP is re#u$e# y 6 an# the #ump at the lo$ation SSDSP 7ill sho7 these save# values as 7ell) Parameter passing into Soft7are interrupts "n $ase of pro$e#ures or fun$tion in various programming languages parameters are passe# through sta$k) "nterrupts are also kin# of fun$tion provi#e# y the operating system ut they #o not a$$ept parameters y sta$k rather they nee# to passe# parameters through registers) Soft7are interrupts invo$ation ;o7 letMs see ho7 various interrupts $an e invoke# y means of soft7are statements) .irst there shoul# e 7ay to pass parameters into a soft7are interrupt efore invoking the Copyright Virtual University of Pakistan !5
0! - "ntro#u$tion% &eans of "'( interruptA there are several metho#s for #oing this) (ne of the metho#s is the use of pseu#o varia les) 8 varia le $an e #efine# a spa$e 7ithin the memory 7hose value $an e $hange# #uring the e:e$ution of a program ut a pseu#o varia le a$ts very mu$h like a varia le as its value $an e $hange# any7here in the program ut is not a true varia le as it is not store# in memory) C programming language provi#es the use of pseu#o varia les to a$$ess various registers 7ithin the pro$essor) The are various registers like 8N% <N% CN an# 4N 7ithin the pro$essor they $an e #ire$tly a$$esse# in a program y using their respe$tive pseu#o varia le y ?ust atta$hing a BOC 1un#ers$ore3 efore the registerMs name eg> DA* 5 #E A 5 D1* ) 8fter passing the appropriate parameters the interrupt $an e #ire$tly invoke# y $alling the 3eninterrupt 13 fun$tion) The interrupt num er nee#s to e passe# as parameter into the 3eninterrupt13 fun$tion) "nterrupt H 2!6% Servi$e H 09 #es$ription ;o7 lets learn y means of an e:ample ho7 this $an e a$$omplishe#) <efore invoking the interrupt the programmer nee#s to kno7 ho7 the interrupt ehaves an# 7hat parameters it rePuires) -ets take the e:ample of interrupt H 2!6 an# servi$e H 09 7ritten as 2!6'096 in short) "t is use# to print a string en#ing y a QRM $hara$ter an# other parameters #es$ri ing the string are as elo7 "nputs 86 @ 0:09 4S @ Segment 8##ress of string 4N @ (ffset 8##ress of string (utput The QRM terminate# string at the a##ress 4SD4N is #isplaye# (ne thing is note 7orthy that the servi$e H is pla$e# in 86 7hi$h is $ommon 7ith almost all the interrupts an# its servi$e) 8lso this servi$e is not returning any siginifi$ant #ata% if some servi$e nee#s to return some #ata it too is re$eive# in registers #epen#ing upon the parti$ular interrupt) 9:ampleD Ainc6udeFstdio><> Ainc6udeF1I!S>4> Ainc6udeF%!S>4> Ainc6udeFconio><> c<ar stG00H 5IJ4e66o Kor6d.JLE (oid mainMN I c6rscrMNE //to c6ear t<e screen contents D%* 5 Munsi3ned intN stE DA4 5 0;07E 3eninterruptM0;$1NE 3etc<MNE //Oaits Cor t<e user to press any Pey L this is a simple e:ample in 7hi$h the parameters of int 2!6'096 are loa#e# an# then int 2!6 is invoke#) 4N an# 86 registers are a$$esse# through pseu#o varia les an# then Copyright Virtual University of Pakistan !0
0! - "ntro#u$tion% &eans of "'( 3eninterruptMNis $alle# to invoke the "S,) 8lso note that O4S is not loa#e#) This is the $ase as the string to e loa#e# is of glo al s$ope an# the C language $ompiler automati$ally loa#s the segment a##ress of the glo al #ata into the 4S register) 8nother ðo# for invoking soft7are interrupts This metho# makes use of a Union) This union is forme# y t7o stru$ture 7hi$h $orrespon# to general purpose registers 8N% <N% CN an# 4N) 8n# also the half register 86% 8-% <6% <-% C6% C-% 46% 4-) These stru$tures are $om ine# su$h that through this stru$ture the fiel# a: $an e a$$esse# to loa# a value an# also its half $omponents al an# ah $an e a$$esse# in#ivi#ually) The #e$laration of this stru$ture goes as elo7) "f this union is to e use# a programmer nee# not #e$lare the follo7ing #e$laration rather #e$laration alrea#y availa le through its hea#er file B#os)hC struct Cu66 I unsi3ned int a;E unsi3ned int :;E unsi3ned int c;E unsi3ned int d;E LE struct <a6C I unsi3ned c<ar a6E unsi3ned c<ar a<E unsi3ned c<ar :6E unsi3ned c<ar :<E unsi3ned c<ar c6E unsi3ned c<ar c<E unsi3ned c<ar d6E unsi3ned c<ar d<E LE typedeC union ta3 2QS I struct Cu66 ;E struct <a6C <E L 2QSE This union $an e use# to signify any of the full or half general purpose register sho7s if the fiel# a: in : stru$t is to e a$$esse# then a$$essing the fiel#s al an# ah in h 7ill also have the same effe$t as sho7 in the e:ample elo7) 9:ampleD Ainc6udeF%!S>4> union 2QS re3sE (oid main M(oid N I re3s><>a6 5 0;##E re3s><>a< 5 0;77E printC MRS;TUre3s>;>a;NE L Copyright Virtual University of Pakistan !9
0! - "ntro#u$tion% &eans of "'( output: 77## The int0/MN fun$tion The signifi$an$e of this ,9FS union $an only e un#erstoo# after un#erstan#ing the int0613 fun$tion) The int0613 has three parameters) The first parameter is the interrupt num er to e invoke#% the se$on# parameter is the referen$e to a ,9FS type union 7hi$h $ontains the value of parameters that shoul# e passe# as inputs% an# thir# parameter is a referen$e to a ,9FS union 7hi$h 7ill $ontain the value of registers returne# y this fun$tion) 8ll the rePuire# parameters for an "S, are pla$e# in ,9FS type of union an# its referen$e is passe# to an int0613 fun$tion) This fun$tion 7ill put the value in this union into the respe$tive register an# then invoke the interrupt) 8s the "S, returns it might leave some meaningful value in the register 1"S, 7ill return values3% these values $an e retrieve# from the ,9FS union 7hose referen$e 7as passe# into the fun$tion as the thir# parameter) 9:ample using interrupt H 2!6 servi$e H /26 To make it more meaningful 7e $an again ela orate it y means of an e:ample) 6ere 7e make use of "S, 2!6'/26 7hi$h is use# to move the file pointer) "ts #etail is as follo7s "nt H 2! "nputs Servi$e H /26 8- @ &ove Te$hniPue <N @ .ile 6an#le CN-4N @ ;o of <ytes .ile to e move# 86 @ Servi$e H @ /26 (utput 4N-8N @ ;o of <ytes .ile pointer a$tually move#)
BOF BOF
cp cp
EOF EOF
-------------------
--------------------
This servi$e is use# to move the file pointer to a $ertain position relative to a $ertain point) The value in 8- spe$ify the point relative to 7hi$h the pointer is move#) "f the value of 8- @ 0 then file pointer is move# relative to the <(. 1 egin of .ile3 if 8-@! then its move# relative to $urrent position an# if 8- @ 2 then its move# relative to the 9(. 1en# of file3) CN-4N spe$ify the num er of ytes to move a #ou le 7or# is nee#e# to spe$ify this value as the si=e of file in 4(S $an e up to 2 F<) (n return of the servi$e 4N-8N 7ill $ontain the num er of ytes the file pointer is a$tually move# eg) "f the file pointer is move# relative to the 9(. =ero ytes the 4N-8N on return 7ill $ontain the si=e of file if the file pointer 7as at <(. efore $alling the servi$e) Copyright Virtual University of Pakistan 20
2!
0! - "ntro#u$tion% &eans of "'( "nt H !06 9ntry 86 @ 0! C6 @ <eginning S$an -ine C- @ 9n#ing S$an -ine (n 9:it Un$hange# The si=e of the $ursor #epen#s upon the num er of net s$an lines use# to #isplay the $ursor if the eginning s$an line is greater than the en#ing s$an line the $ursor 7ill #isappear) The follo7ing tries to a$$omplish ?ust that (oid mainMN I c<ar stG00HE union 2QS re3sE re3s><>a< 5 0;01E re3s><>c< 5 0;01E re3s><>c6 5 0;00E int0/M0;10UVre3sUVre3sNE //corrected 3etsMstNE L The program is Puite self e:planatory as it puts the starting s$an line to e ! an# the en#ing s$an line to e 0) 6en$eforth 7hen the servi$e e:e$ute the $ursor 7ill #isappear) Use of "S,s for C -i rary fun$tions There are various li rary fun$tion that a programmer 7oul# typi$ally use in a program to perform input output operations) These li rary fun$tions perform trivial "'( operations like $hara$ter input 1putc<MN3 an# $hara$ter output 13etc<MNU 3etcMN et$3) 8ll these fun$tion $all various "S,s to perform this "'() "n <"(S an# 4(S #o$umentation num er of servi$es $an e foun# that lie in $orrespon#en$e 7ith some C li rary fun$tion in terms of its fun$tionality) >riting S'> "S,s -ets no7 see ho7 $an a programmer 7rite an "S, routine an# 7hat nee#s to e #one in or#er make the servi$e 7ork properly) To e:hi it this 7e 7ill make use of an interrupt 7hi$h is not use# y 4(S or <"(S so that our e:periment #oes not put any interferen$e to the normal fun$tions of 4(S an# <"(S) (ne su$h interrupt is interrupt H 6*6) The ve$tor of int 6*6 is typi$ally fille# 7ith =eros another in#i$ation that it is not eing use#) Fetting interrupt ve$tor 8s 7e have #is$usse# earlier "VT is a ta le $ontaining / yte entries ea$h of 7hi$h is a far a##ress of an interrupt servi$e routine) 8ll the ve$tors are arrange# serially su$h that the interrupt num er $an e use# as an in#e: into the "VT) Fetting interrupt ve$tor refers to the operation 7hi$h use# to rea#ing the far a##ress store# 7ithin the ve$tor) The ve$tor is #ou le 7or#% the lo7er 7or# of it eing the offset a##ress an# the higher 7or# eing the segment a##ress) &oreover the a##ress rea# from a ve$tor $an e use# as a fun$tion pointer) The C li rary fun$tion use# to #o the e:a$tly Copyright Virtual University of Pakistan 22 Servi$e H 0!6
0! - "ntro#u$tion% &eans of "'( same is 3et(ectMintAN 7hi$h rePuires the interrupt num er a parameter an# returns the value of its ve$tor) .ig ! 1Ve$tor eing rea# from "VT 3
";T H
far Intproc
.un$tion pointers 8nother thing rePuire# to e un#erstoo# are the fun$tion pointers) C language is a very fle:i le language ?ust like there are pointers for integers% $hara$ters an# other #ata types there are pointers for fun$tions as 7ell as illustrate# y the follo7ing e:ample (oid myCuncMN I L (oid MWCuncptrN M N
Cuncptr 5 myCuncE MWCuncptrN M NE myCuncMNE There are three fragments of $o#e in this e:ample) The first fragment sho7s the #e$laration of a fun$tion myCuncMN The se$on# fragment sho7 #e$laration of a pointer to fun$tion name# Cuncptr 7hi$h is a pointer to a fun$tion that returns voi#) "n the thir# fragment Cuncptr is assigne# the a##ress of myCunc as the name of the fun$tion $an e use# as its a##ress ?ust like in the $ases of arrays in C) Then the fun$tion pointe# y Cuncptr y the statement MWCuncptrNMNE is $alle# an# then the original myCuncMN is $alle#) The user 7ill o serve in oth the $ases same fun$tion myprocMN 7ill e invoke#)
2+
0! - "ntro#u$tion% &eans of "'( "nterrupt pointers an# fun$tions "nterrupt fun$tions are spe$ial fun$tion that as $ompare# to simple fun$tions for reasons #is$usse# earlier) "t $an e #e$lare# using the key7or# interrupt as sho7n in the follo7ing e:amples) (oid interrupt neOint M N I >>> >>> L Similarly a pointer to su$h interrupt type fun$tion $an also e #e$lare# as follo7ing (oid interrupt MWintptrN M NE 7here intptr is the interrupt pointer an# it $an e assigne# an a##ress using the 3et(ectMN fun$tion intptr 5 3et(ectM0;00NE ;o7 interrupt num er 0 $an e invoke# using the interrupt ve$tor as follo7ing MWintptrN M NE Setting "nterrupt Ve$tor Setting interrupt ve$tor is ?ust the reverse pro$ess of getting interrupt ve$tor) To set the interrupt ve$tor means is to $hange the #ou le 7or# si=e# interrupt ve$tor 7ithin the "VT) This task $an e a$$omplishe# using the fun$tion set(ectMint AU neOintN 7hi$h rePuires the num er of interrupt 7hose ve$tor is to e $hange# an# the ne7 value of the ve$tor)
";T H
far
2/
0! - "ntro#u$tion% &eans of "'( "n the follo7ing e:ample a $ertain interrupt type fun$tion has een #e$lare#) The a##ress of this fun$tion $an e pla$e# on to the ve$tor of any interrupt using set(ectMN fun$tion as follo7ing) The follo7ing $o#e pla$es the a##ress of neOint fun$tion at the ve$tor of int 0 (oid interrupt neOint M N I Y Y L set(ectM0;00U neOintNE C program making use of "nt 6*6 6ere is a listing of a program that makes use of int 6*6 to e:hi it ho7 soft7are interrupts nee#s to e programme#) (oid c<ar (oid (oid I interrupt MWo6dint/#NM NE stG00H 5 IR4e66o Kor6d.TLE interrupt neOint/#M(oidNE mainMN o6dint/# 5 3et(ectM0;/#NE set(ectM0;/#U neOint/#NE 3eninterrupt M0;/#NE 3eninterrupt M0;/#NE 3eninterrupt M0;/#NE set(ectM0;/#U o6dint/#NE L (oid interrupt neOint/#M N I DA4 5 0;07E D%*5Munsi3ned intNstE 3eninterrupt M0;$1NE L The a ove listing saves the a##ress of original int 6*6 in the pointer o6dint/#) "t then pla$es the a##ress of its o7n fun$tion neOint/# at the ve$tor of interrupt num er 6*6) .rom this point on7ar#s 7henever int 6*6 is invokes the fun$tion neOint/# 7ill e invoke#) "nt 6* is invoke# thri$e 7hi$h 7ill for$e the neOint/# fun$tion to e invoke# thri$e a$$or#ingly) 8fter this the original value of the ve$tor store# in ol#int6* is restore#) The neOint/# fun$tion only #isplays the string st) 8s the interrupt 6* is invoke# thri$e this string 7ill e printe# thri$e) The 2eep fun$tion (ne #efi$ien$y in the a ove listing is that it is not goo# enough for other appli$ation i)e) after the termination of this program the neOint/# fun$tion is #e-allo$ate# from the memory an# the interrupt ve$tor nee#s to e restore# other7ise it 7ill a$t as a #angling Copyright Virtual University of Pakistan 2*
0! - "ntro#u$tion% &eans of "'( pointer 1pointing to a pla$e 7here there is gar age or 7here there is no meaningful fun$tion3) To make the effe$t of this program permanent the neOint/# fun$tion nee# to e memory resi#ent) This $an e a$hieve# y the fun$tion Peep13 7hi$h is Puite similar to e;it13 fun$tion) The e;it13 fun$tion returns the e:e$ution to the parent shell program an# #e-allo$ates the memory allo$ate# to the program 7hereas the Peep13 fun$tion also returns the e:e$ution to the parent program ut the memory allo$ate# to the pro$ess may still remain allo$ate#) Peep Mreturn codeU no> oC parasNE the Peep13 fun$tion rePuires the return $o#e 7hi$h is usually =ero for normal termination an# the num er of paragraphs rePuire# to e allo$ate#) 9a$h paragraph is !6 ytes in si=e) TS, Programs .ollo7ing is a listing of a TS, 1Terminate an# Stay ,esi#ent3 program 7hi$h programs the interrupt num er 6*6 ut in this $ase the ne7 interrupt 6*6 fun$tion remains in memory even after the termination of the program an# hen$e the ve$tor of int 6*h #oes not e$ome a #angling pointer) Ainc6udeF1I!S>4> Ainc6udeF%!S>4> c<ar (oid (oid (oid I stG00H 5IJ4e66o Kor6d.JLE interrupt MWo6dint/#NM NE interrupt neOint/#M NE mainMN o6dint/# 5 3et(ectM0;/#NE set(ectM0;/#U neOint/#NE PeepM0U 1000NE L (oid interrupt neOint/#M N I DA4 5 0;07E D%*5Munsi3ned intNstE 3eninterrupt M0;$1NE L
The mainMNfun$tion gets an# sets the ve$tor of int 6*6 su$h that the a##ress of neOint/# is pla$e# at its ve$tor) "n this $ase the program is ma#e memory resi#ent using the keep fun$tion an# !000 paragraphs of memory is reserve# for the program 1the amount of paragraphs is ?ust a $al$ulate# guess 7ork ase# upon the si=e of appli$ation3) ;o7 if any appli$ation as in the follo7ing $ase invokes int 6*6 the string st 7hi$h is also no7 memory resi#ent 7ill e #isplaye#)
26
0! - "ntro#u$tion% &eans of "'( Ainc6udeF1I!S>4> Ainc6udeF%!S>4> (oid mainMN I 3eninterrupt M0;/#NE 3eninterrupt M0;/#NE L This program invokes the interrupt 6*6 t7i$e 7hi$h has een ma#e resi#ent)
25
0/ - TS, programs an# "nterrupts 3eninterrupt M0;/#NE DA4 5 0E 3eninterrupt M0;/#NE L "nterrupt stealing or interrupt hooks Previously 7e have #is$usse# ho7 a ne7 interrupt $an e 7ritten an# implemente#) "nterrupt stealing is a te$hniPue y 7hi$h alrea#y implemente# servi$es $an e altere# y the programmer) This te$hniPue makes use of the fa$t that the ve$tor is store# in the "VT an# it $an e rea# an# 7ritten) The interrupt 7hi$h is to e hooke# its 1original routine 3 ve$tor is first rea# from the "VT an# then store# in a interrupt pointer type varia le% after this the ve$tor is $hange# to point to one of the interrupt fun$tion 1ne7 routine3 7ithin the program) "f the interrupt is invoke# no7 it 7ill for$e the ne7 routine to e e:e$ute# provi#e# that its memory resi#ent) ;o7 t7o things $an e #one% the original routine might e performing an important task so it also nee#s to invoke#% it $an either e invoke# in the start of the ne7 routine or at the en# of the ne7 routine using its pointer as sho7n in the follo7ing e:e$ution $harts elo7 .ig ! 1;ormal 9:e$ution of an "S,3
0/ - TS, programs an# "nterrupts .ig 2 1The original "S, eing $alle# at he en# of ne7 routine3
;e7 ,outine
(riginal ,outine
"nterrupt "nter$eption
.ig + 1The original "S, invoke# at the start of ne7 "S,3
(riginal ,outine
;e7 ,outine
The a ove program gets the a##ress store# at the ve$tor of interrupt 0 an# stores it in the pointer ol#int) The a##ress of the interrupt fun$tion ne7int is then pla$e# at the ve$tor of int 0 an# the program is ma#e memory resi#ent) .rom this point on7ar#s 7henever interrupt 0 o$$urs the interrupt fun$tion ne7int is invoke#) This fun$tion after performing its operation $alls the original interrupt 0 7hose a##ress has een store# in ol#int pointer) Timer "nterrupt "n the $oming fe7 e:amples 7e 7ill inter$ept interrupt 0) This is the timer interrupt) The timer interrupt has follo7ing properties) "ts an 6ar#7are "nterrupts "t is "nvoke# y &eans of 6ar#7are "t appro:imately o$$urs !0)2 times every se$on# y means of har#7are) <"(S 4ata 8rea <"(S $ontains trivial "'( routines 7hi$h have een programme# into a ,(& type #evi$e an# is interfa$e# 7ith the pro$essor as a part of main memory) 6o7ever the <"(S routines 7oul# rePuire a fe7 varia les% these varia les are store# in the <"(S #ata arera at the lo$ation 00/0D00006 in the main memory) (ne su$h yte store# in the <"(S #ata area is the key oar# status yte at the lo$ation /0D!56) This $ontains the status of various keys like alt% shift% $aps lo$k et$) This yte $an e #es$ri e# y the #iagram elo7 .ig / 12ey oar# status yte3 #$%&'( C 7 B A 8
Insert key Caps Lock Key !"m Lock key Scro ock key
8nother 9:ample Ainc6ude Fdos><> (oid interrupt MWo6dNMNE (oid interrupt neOMNE c<ar Car Wscr5Mc<ar CarW N 0;0040001&E (oid mainMN I o6d53et(ectM0;00NE set(ectM0;00UneONE PeepM0U1000NE
0/ - TS, programs an# "nterrupts L (oid interrupt neO MNI Wscr5/4E MWo6dNMNE L This fairly simple e:ample inter$epts the timer interrupt su$h that 7henever the timer interrupt o$$urs the fun$tion ne713 is invoke#) ,emem er this is )C program an# not a )CPP program) Save the $o#e file 7ith )C e:tension after 7riting this $o#e) (n o$$urren$e of interrupt 0 the fun$tion ne7 sets the $aps lo$k it in key oar# status y pla$ing 6/ at this position through its far pointer) So even if the user turns of the $aps lo$k on the ne:t o$$urren$e of int 0 1 almost imme#iately3 the $aps lo$k 7ill e turne# on again 1turing on the $aps lo$k on like this 7ill not effe$t its -94 in the key oar# only letters 7ill e type# in $aps3) &emory &appe# "'( an# "solate# "'( 8 #evi$e may e interfa$e# 7ith the pro$essor to perform memory mappe# or isolate# "'() &ain memory an# "'( ports oth are physi$ally a kin# of memory #evi$e) "n $ase of "solate# "'(% "'( ports are use# to hol# #ata temporary 7hile sen#ing're$eiving the #ata to'from the "'( #evi$e) "f the similar fun$tion is performe# using a #e#i$ate# part of main memory then the "'( operation is memory mappe#) .ig * 1"solate# "'(3
OU,
&
"'(
MOV
0/ - TS, programs an# "nterrupts &emory &appe# "'( on &onitor (ne of the #evi$es in stan#ar# PCs that perform memory mappe# "'( is the #isplay #evi$e 1&onitor3) The output on the monitor is $ontroller y a $ontroller $alle# vi#eo $ontroller 7ithin the PC) (ne of the reason for a#opting memory mappe# "'( for the monitor is that a large amount of #ata is nee#e# to e $onveye# to the vi#eo $ontroller in or#er to #es$ri e the te:t or that graphi$s that is to e #isplaye#) Su$h large amount of #ata eing output through isolate# "'( #oes not form into a feasi le i#ea as the num er of port in PCs is limite# to 6**+6) The memory area starting from the a##ress 000D00006) T7o ytes 1a 7or#3 are reserve# for a single $hara$ter to e #isplaye# in this area) The lo7 yte $ontains the 8SC"" $o#e of the $hara$ter to e #isplaye# an# the high yte $ontains the attri ute of the $hara$ter to e #isplaye#) The a##ress 000D0000h $orrespon#s to the $hara$ter #isplaye# at the top left $orner of the s$reen% the ne:t 7or# 000D0002 $orrespon#s to the ne:t $hara$ter on the same ro7 of the te:t s$reen an# so on as #es$ri e# in the #iagram elo7) .ig 5 1&emory mappe# "'( on monitor3
fore $olor
D D D D D D D D
<a$k Color <ol# Color
To un#erstan# all #es$ri e a ove lets take a look at this e:ample) unsi3ned int Car Wscr50;:0000000E (oid mainMN I MWscrN50;0&#/E MWMscrX1NN50;&0##E L This e:ample 7ill generate the output V) The far pointer s$r is assigne# the value 0: 0006 in the high 7or# 7hi$h is the segment a##ress an# value 0:00006 in the lo7 7or# 7hi$h is the offset a##ress) The 7or# at this a##ress is loa#e# 7ith the value 0:05*66 an# the ne:t 7or# is loa#e# y the value 0:50**6% 0:05 is the attri ute yte meaning la$k a$k $olor an# 7hite fore $olor an# the yte 0:50h means 7hite a$k $olor an# la$k fore $olor) 3)0:*6 an# 0:** are the 8SC"" value of BVC an# BUC respe$tively)
0/ - TS, programs an# "nterrupts Cor Mi50EiF$000EiXXN //corrected I Wscr50;$0E //corrected WMscrX1N50;0&E //corrected scr5scrX$E L L Usually the in te:t mo#e there are 00 $olumns an# 2* ro7s making a total of 2000 $hara$ters that $an e sho7n simultaneously on the s$reen) This program runs a loop 2000 times pla$ing 0:20 8SC"" $o#e of spa$e $hara$ter in 7hole of the te:t memory in this te:t mo#e) 8lso the attri ute is set to 7hite fore$olor an# la$k a$k$olor) 8nother 9:ample "n the follo7ing e:ample memory mappe# "'( is use# in $om ination 7ith interrupt inter$eption to perform an interesting task) Ainc6ude Fdos><> (oid interrupt MWo6dNMNE (oid interrupt neOCuncMNE c<ar Car Wscr5Mc<ar CarW N 0;:0000000E (oid mainMN I o6d53et(ectM0;00NE set(ectM0;00UneOCuncNE PeepM0U1000NE L (oid interrupt neOCunc MN I Wscr50;41E //corrected WMscrX1N50;0&E //corrected MWo6dNMNE L "n the a ove e:ample the timer interrupt is inter$epte# su$h that 7henever the timer interrupt is invoke# 1 y means of har#7are3 the memory resi#ent neOCunc13 is invoke#) This fun$tion simply #isplays the 8SC"" $hara$ter 0:/! or Q8M in the top left $orner of the te:t s$reen) 6ere is another e:ample) Ainc6ude Fstdio><> (oid interrupt MWo6dNMNE (oid interrupt neOCuncMNE c<ar Car Wscr5Mc<ar CarW N 0;:0000000E int ZE (oid mainM N I o6d53et(ectM0;00NE set(ectM0;00UneOCuncNE //corrected
0/ - TS, programs an# "nterrupts PeepM0U1000NE L (oid interrupt neOCunc M N I Cor M Z50EZF4000EZX5$NI //corrected iCMWMscrXZN55[1\NI WMscrXZN5[7\E L L MWo6dNMNE L This program s$ans through all the ytes of te:t #isplay memory 7hen int 0 o$$urs) "t on$e resi#ent 7ill repla$e all the Q!M on the s$reen y Q9M) "f even someho7 a Q!M is #isplaye# on the s$reen it 7ill e $onverte# to Q9M on o$$urren$e of interrupt 0 7hi$h o$$urs !0)2 times every se$on#) The key oar# "nterrupt 2ey oar# is a har#7are #evi$e an# it makes use of interrupt num er 9 for its input operations) >henever a key is presse# interrupt H 9 o$$urs) The operating system pro$esses this interrupt in or#er to pro$ess the key presse#) This interrupt usually rea#s the s$an $o#e from the key oar# port an# $onverts it into the appropriate 8SC"" $o#e an# pla$es the 8SC"" $o#e in the key oar# uffer in <"(S #ata area as #es$ri e# " nthe #iagram elo7 //corrected
Any Process I!, 0 ,ea#s S$an Co#e $onverts to 8SC"" S pla$e it in 2ey oar# <uffer S returns
K)*
-ets no7 e:periment on the key oar# interrupt to un#erstan# its ehavior 9:ample Ainc6ude Fdos><> (oid interrupt MWo6dNM NE (oid interrupt neOCuncM NE (oid mainM N I o6d 5 3et(ectM0;07NE
0/ - TS, programs an# "nterrupts set(ectM0;07UneOCuncNE PeepM0U1000NE L (oid interrupt neOCunc M N I MWo6dNM NE MWo6dNM NE MWo6dNM NE L This program simply inter$epts the key oar# interrupt an# pla$es the a##ress of neOint in the "VT) The neOint simply invokes the original interrupt 9 thri$e) Therefore the same $hara$ter input 7ill e pla$e# in the key oar# uffer thri$e i)e three $hara$ters 7ill e re$eive# for ea$h $hara$ter input) 9:ample Ainc6ude Fdos><> (oid interrupt MWo6dNM NE (oid interrupt neOCuncM NE c<ar Car Wscr 5 Mc<ar CarW N 0;0040001&E
(oid mainM N I o6d 5 3et(ectM0;07NE set(ectM0;07UneOCuncNE PeepM0U1000NE L (oid interrupt neOCunc M N I Wscr 5 /4E MWo6dNM NE L The a ove program is Puite familiar it 7ill ?ust set the $aps lo$k status 7henever a key is presse#) "n this $ase the key oar# interrupt is inter$epte#) 9:ample (oid interrupt MWo6dNM NE (oid interrupt neOCuncM NE c<ar Car Wscr 5 Mc<ar CarW N 0;10000000E int ZE (oid mainM N I o6d 5 3et(ectM0;07NE set(ectM0;07UneOCuncNE PeepM0U1000NE
0/ - TS, programs an# "nterrupts L (oid interrupt neOCunc M N I CorM Z 5 0EZ F 4000E Z X5 $N I iC MWMscr XZN 55 [1\N WMscr X ZN 5 [7\E L MWo6dNM NE L This too is a familiar e:ample) >henever a key is presse# from the key oar# the ne7fun$ fun$tions runs through 7hole of the test #isplay memory an# repla$es the 8SC"" Q!M #isplaye# y 8SC"" Q9M)
This program 7orks like a s$reen saver) The neOTimer fun$tion in$rements t 7henever it is invoke# so the value of t rea$hes !02 after ten se$on#) 8t this moment the fun$tion saves the value in #isplay te:t memory in a $hara$ter array an# fills the s$reen 7ith spa$es an# sets a flag m) The neO-ey fun$tion is invoke# 7hen a key press o$$urs) The flag is $he$ke# if the itMs set then the s$reen is restore# from the values save# in that $hara$ter array) ,eentrant Pro$e#ures S "nterrupt "f on return of a fun$tion the values 7ithin the registers are un$hange# as $ompare# to the values 7hi$h 7ere store# in registers on entry into the pro$e#ures then the pro$e#ure is $alle# reentrant pro$e#ure) Usually interrupt pro$e#ures are reentrant pro$e#ures espe$ially those interrupt pro$e#ure $ompile# using C language $ompiler are reentrant) This $an e un#erstoo# y the follo7ing e:ample
0/ - TS, programs an# "nterrupts "n the a ove e:ample the fun$tion Pro$!13 is invoke#) (n invo$ation the register 8N $ontaine# the value !2+/6% the $o#e 7ithin the fun$tion Pro$!13 $hanges the value in 8N to ..**6) (n return 8N 7ill $ontain the value !2+/6 if the fun$tion have een implemente# as a reentrant pro$e#ure i)e a reentrant pro$e#ure 7oul# restore the values in registers their previous value 1save# in the sta$ke#3 efore returning) C language reentrant pro$e#ures save the registers in sta$k follo7ing the or#er 8N% <N% CN% 4N% 9S% 4S% S"% 4"% <P on invo$ation an# restores in reverse or#er efore return) This fa$t a out reentrant pro$e#ures $an e analyse# through follo7ing e:ample) Ainc6ude Fstdio><> (oid interrupt Wo6dMNE (oid interrupt neOintMN (oid main MN I o6d 5 3et(ectM0;/#NE set(ectM0;/#UneOintNE DA*50;C00CE 3eninterruptM0;/#NE a 5 DA* printCMRS;TUaNE L (oid interrupt neOintMN I DA*50;1$'4E L .irstly its important to compi e this a)o;e an* a the rest of the e<amp es as 2C fi es an* not as 2CPP fi e) "t these $o#es are $ompile# using )CPP e:tension then there is no surety that this program $oul# e $ompile#) 8gain int 6*6 is use# for this e:periment) The int 6*6 ve$tor is ma#e to point at the fun$tion neOint13) <efore $alling the interrupt 6*6 value 0:.00. is pla$e# in the 8N register) 8fter invo$ation of int 6*6 the value of 8N register is $hange# to 0:!2+/) <ut after return if the value of 8N is $he$ke# it 7ill not e 0:!2+/ rather it 7ill e 0:.00. in#i$ating that the values in registers are save# on invo$ation an# restore efore return an# also that the interrupt type pro$e#ures are reentrant)
---------------Int ----------------
P"sh A3= P"sh .3= P"sh C3= P"sh D3= P"sh >S= P"sh DS= P"sh SI= P"sh DI= P"sh .P ?????????? ?????????? ?????????? ?????????? Pop .P= Pop DI= Pop SI = Pop DS= Pop >S= Pop D3= Pop C3= Pop .3= Pop A3= IR>,
The registers .lags% CS an# "P are pushe# on e:e$ution of ";T instru$tion an# e:e$utions ran$hes to the interrupt pro$e#ure) The interrupt pro$e#ure pushes register 8N% <N% CN% 4N% 9S% 4S% S"% 4"% <P in this or#er) The interrupt pro$e#ure then e:e$utes% efore returning it pops all the registers in the reverse or#er as <P% 4"% S"% 4S% 9S% 4N% CN% <N an# 8N) "P% CS an# flags are pope# on e:e$ution of the ",9T instru$tion) ;e:t #iagram sho7s the status of the sta$k after invo$ation of the interrupt pro$e#ure)
.P DI SI DS >S D3 C3 .3 A3 IP CS 9 ags
The arguments in simple pro$e#ure or fun$tions are save# in the sta$k for the s$ope of the fun$tion'pro$e#ure) >hen an argument is a$$esse# in fa$t sta$k memory is a$$esse#) ;o7 7e 7ill take a look ho7 sta$k memory $an e a$$esse# for instan$e in $ase of interrupt pro$e#ures to mo#ify the value of register in sta$k)
0/ - TS, programs an# "nterrupts 8$$essing Sta$k 9:ample (oid interrupt neOint M unsi3ned int 1+Uunsi3ned int %IU unsi3ned int SIUunsi3ned int %SU unsi3ned int 2SUunsi3ned int %*U unsi3ned int C*Uunsi3ned int 1*U unsi3ned int A*Uunsi3ned int I+U unsi3ned int CSUunsi3ned int C6a3sN //corrected I a 5 A*E : 5 1*E d 5 2SE L 8lthough interrupt #o not take parameters through sta$k ut an interrupt pro$e#ure $an still have parameters) This parameter list $an e use# to a$$ess the sta$k) The leftmost parameter a$$esses the item on top of the sta$k an# the rest of the parameters a$$esses #eeper into the sta$k a$$or#ing to its or#er to7ar# left) "n the a ove e:ample value of 8N in sta$k is move# in a% the value of <N is move# into an# the value of 9S is move# into #)
9:ampleD (oid interrupt neOint M unsi3ned 1+Uunsi3ned int %IU unsi3ned int int %SU unsi3ned int 2SUunsi3ned unsi3ned int C*Uunsi3ned int 1*U A*Uunsi3ned int I+U unsi3ned int int C6a3sN //corrected I A* 5 0;8008E L (oid main M N I set(ectM0;/#UneOintNE DA* 5 0;1$'4E 3eninterrupt M0;/#NE a 5 DA*E printC MRS;TU aNE L "n this e:ample the value on invo$ation in 8N is 0:!2+/% the interrupt pro$e#ure #oes not $hange the $urrent value of the register through pseu#o varia les rather it $hanges the $orrespon#ing of 8N in sta$k 7hi$h 7ill e restore# in 8N efore return) 4isk "nterrupt The follo7ing e:ample makes use of #isk interrupt !+6 an# its servi$e +6) The #etails of this servi$e are as un#er) (n 9ntry int SIUunsi3ned int %*U unsi3ned int CSUunsi3ned
0/ - TS, programs an# "nterrupts 86 @ Servi$e H @ 0+ 8- @ ;o of <lo$ks to 7rite <N @ (ffset 8##ress of 4ata C6 @ Tra$k H % C- @ Se$tor H 46 @ 6ea# H 4- @ 4rive H1Starts from $<@$ for fi:e# #isk S $ for remova le #isks3 9S @ Segment 8##ress of #ata uffer) (n 9:it 86 @ return Co#e Carry flag @ 0 1 ;o 9rror 86 @ 03 Carry flag @ ! 1 9rror 86 @ 9rror Co#e3 <oot lo$k is a spe$ial lo$k on #isk 7hi$h $ontains information a out the operating system to e loa#e#) "f the #ata on oot lo$k is someho7 #estroye# the #isk 7oul# e ren#ere# ina$$essi le) The a##ress of partition lo$k on har# #isk is hea# H @!% tra$kH @ 0 an# se$tor H @ !) ;o7 letMs 7rite an appli$ation that 7ill prote$t the oot lo$k to e 7ritten y any other appli$ation)
Apra3ma in6ine Ainc6ude Fdos><> Ainc6ude F:ios><> (oid interrupt MWo6dtsrN M NE (oid interrupt neOtsr Munsi3ned int 1+U YU C6a3sNE //must pro(ide a66 t<e ar3uments (oid main M N I o6dtsr 5 3et(ect M0;1'NE set(ectM0;1'U neOtsrNE //corrected Peep M0U 1000NE L (oid interrupt neOtsrMunsi3ned int 1+U unsi3ned int %IU unsi3ned int SIU unsi3ned int %SU unsi3ned int 2SU unsi3ned int %*U unsi3ned int C*U unsi3ned int 1*U unsi3ned int A*U unsi3ned int I+U unsi3ned int CSU unsi3ned int C6a3sN //corrected I iC M DA4 55 0;0'N iCMM D%4 55 1 VV DC4 55 0 VV DC, 55 1NVV D%, >5 0;00N I asm c6cE asm pus<CE asm pop C6a3sE returnE L D 2S 5 2SE D%* 5 %*E DC* 5 C*E D1* 5 1*E DA* 5 A*E
0/ - TS, programs an# "nterrupts Wo6dtsrE asm pus<CE asm pop C6a3sE A* 5 DA*E 1* 5 D1*E C* 5 DC*E %* 5 D%*E 2S 5 D2SE L The a ove program inter$epts interrupt !+6) The ne7 interrupt pro$e#ure first $he$k 86 for servi$e num er an# other parameters for the a##ress of oot lo$k) "f the oot lo$k is to e 7ritten it simply returns an# $lears the $arry flag efore returning to fool the $alling program that the operation 7as su$$essful) 8n# if the oot lo$k is not to e 7ritten then it pla$es the original parameters a$k into the registers an# $alls the original interrupt) The values returne# y the original routine are then restore# to the $orrespon#ing register values in the sta$k so that they may e up#ate# into the registers on return)
The key oar# 6ook The servi$e !*6'/.6 is $alle# the key oar# hook servi$e) This servi$e #oes not perform any useful output% it is there to e inter$epte# y appli$ations 7hi$h nee# to alter the key oar# layout) "t $alle# y interrupt 96 after it has a$Puire# the s$an $o#e of input $hara$ter from the key oar# port 7hile the s$an $o#e is in 8- register) >hen this servi$e returns interrupt 96 translates the s$an $o#e into 8SC"" $o#e an# pla$es it in uffer) This servi$e normally #oes nothing an# returns as it is ut a programmer $an inter$ept it in or#er to $hange the s$an $o#e in 8- an# hen$e altering the input or key oar# layout)
Key Presse*
Mo;e Scan Co*e from 1$( port to Int &:( AL Ser;ice #9(
0/ - TS, programs an# "nterrupts I o6dint1# 5 3et(ect M0;1#NE set(ect M0;1#U neOint1#NE Peep M0U 1000NE L (oid interrupt neOint1#Munsi3ned int 1+U unsi3ned int %IU unsi3ned int SIU unsi3ned int %SU unsi3ned int 2SU unsi3ned int %*U unsi3ned int C*U unsi3ned int 1*U unsi3ned int A*U unsi3ned int I+U unsi3ned int CSU unsi3ned int C6a3sN I iC MWMMMc<arWNVA*N X 1N 55 0;48 N I iC MWMMc<arWNVA*N 55 0;$CN WMMMc<arWNVA*NN 5 0;12E e6se iC MWMMc<arWNVA*N 55 0;12N WMMc<arWNVA*N 5 0;$CE //corrected L e6se MWo6dint1#NMNE L The appli$ation inter$epts interrupt !*6) The ne7int!* fun$tion $he$ks for the servi$e H /. in the high yte of 8N% if this value is /. the #efinitely the value in 8- 7ith e the s$an $o#e) 6ere a simple su stitution have een performe# 0:!9 is the s$an $o#e of Q8M an# 0:2C is the s$an $o#e of QIM) "f the s$an $o#e is 8- is that of Q8M it is su stitute# 7ith the s$an $o#e of QIM an# vi$e versa) "f some other servi$e of !*6 is invoke# the original interrupt fun$tion is invoke#)
04 - 5ard6are Interru!ts
The mi$ropro$essor pa$kage has many signals for #ata% $ontrol an# a##resses) Some of these signals may e input signals an# some might e output) 6ar#7are interrupts make use of t7o of su$h input signals namely ;&" 1;on maska le "nterrupt3 S ";T,1"nterrupt ,ePuest3)
&i$ropro$essor
0/ - TS, programs an# "nterrupts &ost of the #evi$es use the ";T, line) ;&" signal is use# y #evi$es 7hi$h perform operations of the utmost nee# like the #ivision y =ero interrupt 7hi$h is generate# y 8-U $ir$uitry 7hi$h performs #ivision) 4efinitely this operation is not possi le an# the $ir$uitry generates an interrupt if it re$eives a 0 as #ivisor from the $ontrol unit) ";T, is use# y other #evi$es like C(& ports -PT ports% key oar#% timer et$) Sin$e only one signal is availa le for mi$ropro$essor interruption% this signal is ar itrate# among various #evi$es) This ar itration $an e performe# y a spe$ial har#7are $alle# the Programma le "nterrupt Controller 1P"C3)
"nterrupt Controller 8 single interrupt $ontroller $an ar itrate among 0 #ifferent #evi$es)
40
",T0
8s it $an e seen from the #iagram a ove the P"C #evi$e has 0 inputs ",T0-",T5) ",T0 has the highest priority an# ",T5 has the lo7est) 9a$h ",T input is atta$he# to an "'( #evi$e 7henever the #evi$e rePuires an "'( operation it sen#s a signal to the P"C) The P"C on the asis of its priority an# presen$e of other rePuests #e$i#es 7hi$h rePuest to serve) >henever a rePuest is to e serve# y P"C it interrupt the pro$essor 7ith the ";T output $onne$te# to the ";T, input of the pro$essor an# sen# the interrupt H to e generate# the #ata lines $onne$te# to the lo7er 0 #atelines of the #ata us to inform the pro$essor a out the interrupt num er) "n $ase no higher priority signal is availa le to the pro$essor an# the pro$essor is su$$essfully interrupte# the mi$ropro$essor sen#s a$k an ";T8 1interrupt 8$kno7le#ge3 signal to inform the P"C that the pro$essor has een interrupte#)
0/ - TS, programs an# "nterrupts The follo7ing #iagram also sho7s the typi$al $onne$tivity of the ",T lines 7ith various #evi$es
"nterval Timer 2<4 Controller 0 ",T! ! 2 C(&2 C(&! (ther Controllers Printer Controller + / * 6 5 ",T5 ";T8 P"C ";T 45 &"C,( P,(C9SS(, ";T, 4(
"n stan#ar# PCs there may e more than 0 #evi$es so generally t7o P"C are use# for ";T, line ar itration) These 2 P"Cs are $as$a#e# su$h that they $olle$tively are a le to ar itrate among !6 #evi$es in all as sho7n in the follo7ing #iagram)
4(
&8ST9,
",T(
45 ";T8
",T5
4( 45 ";T8
The P"Cs are $as$a#e# su$h that a total of !6 ",T levels $an e provi#e# num er ",T0",T!*) The ",T level 2 is use# to $as$a#e oth of the P"C #evi$es) The 4ata lines are multiple:e# su$h that the interrupt num er is issue# y the $on$erne# P"C) The ",T 2 input of the &aster P"C is $onne$te# to the ";T output of the Slave P"C) "f the slave P"C
0/ - TS, programs an# "nterrupts is interrupte# y a #evi$e its rePuest ins propagate# to the master P"C an# the master P"C ultimately interrupts the pro$essor on ";T, line a$$or#ing to the priorities) "n a stan#ar# PC the P"Cs are programme# su$h that the master P"C generate# the interrupt num er 0-!* for ",T0 U",T5 respe$tively an# the slave P"C generates interrupt num er 50-556 for ",T0-",T!* 6ar#7are "nterrupts are ;on-Preemptive 8s #es$ri e# earlier ",T 0 has the highest priority an# ",T !* has the lo7est priority) "f a num er of rePuests are availa le instantaneously the rePuest 7ith higher priority 7ill e sent for servi$e first y the P"C) ;o7 7hat 7ill happen if a lo7er priority interrupt is eing servi$e an# a higher priority interrupt rePuest o$$urs% 7ill the lo7er priority interrupt e preempte#V The ans7er is that the interrupt eing servi$e# 7ill not e preempte# no matter 7hat) The reason for this non-preemptive $an e un#erstoo# y the e:ample illustrate# as elo7) -etMs first $onsi#er that the har#7are interrupts are preemptive for argument sake) "f a $hara$ter Q8M is input a 6'> interrupt 7ill o$$ur to pro$ess it% 7hile this interrupt is eing pro$esse# another $hara$ter is input say Q<M in $ase the interrupts have een preemptive the previous instan$e 7ill e preempte# an# another instan$e for the 6'> interrupt $all 7ill e generate#% an# similarly $onsi#er another $hara$ter is input QCM an# the same happene# for this input as 7ell) "n this $ase the $hara$ter first to e fully pro$esse# an# re$eive# 7ill e QCM an# then Q<M 7ill e pro$esse# an# then Q8M) So the sePuen$e of input 7ill $hange to C<8 7hile the $orre$t sePuen$e 7oul# e 8<C)
C P,9SS94 8 P,9SS94
< P,9SS94 "nput re$eive# C < 8 -ogi$ally Corre$t -ogi$ally "n$orre$t 8<C
The input 7ill e re$eive# in $orre$t sePuen$e only if the 6'> interrupts are nonpreemptive as illustrate# in the #iagram elo7)
8 P,9SS94
< P,9SS94
C P,9SS94
-ogi$ally Corre$t
6ar#7are interrupts rePuires something more to e programme# into them as $ompare# 7ith soft7are interrupts) The ma?or #ifferen$e is e$ause of the reason given a ove that the 6'> interrupts are non-preemptive) To make them non-preemptive the P"C shoul# kno7 7hen the previously issue# interrupt returns) The P"C $annot issue the ne:t pen#ing interrupt unless it is notifie# that the previous interrupt has returne#) >ho ;otifies 9(" 19n# of interrupt3 The P"C has to e notifie# a out the return of the previous interrupt y the "S, routine) .rom programmer point of vie7 this is the ma?or #ifferen$e et7een 6'> an# soft7are interrupt) 8 soft7are interrupt 7ill not rePuire any su$h notifi$ation) 8s the #iagram elo7 illustrates that every interrupt returns 7ith an ",9T instru$tion) This instru$tion is e:e$ute# y the mi$ropro$essor an# has no linkage 7ith the P"C) So there has to e a #ifferent metho# to notify the P"C a out the 9n# of interrupt) Pen#ing 6ar#7are interrupts) >hile a har#7are interrupt is eing pro$esse# a num er of various other interrupt may e pen#ing) .or the su tle 7orking of the system it is ne$essary for the "n-servi$e har#7are interrupt to return early an# notify the P"C on return) "f this operation takes long an# the pen#ing interrupt rePuests o$$ur repeate# there is a $han$e of loosing #ata) Programming the P"C To un#erstan# ho7 the P"C is notifie# a out the en# of interrupt lets take a look into the internal registers of P"C an# their signifi$an$e) 8 P"C has a num er of initiali=ation $ontrol 7or#s 1"C>3 an# operation $ontrol 7or#s 1(C>3% follo7ing is $hara$teristi$ of "C> an# (C>s W "C> programme# at time of oot up W "C> are use# to program the operation mo#e like $as$a#e mo#e or not also it is use# to program the fun$tion of P"C i)e if it is to invoke interrupts 00X 0.6 or 50-556 on ",T rePuest) W (C> are use# at run-time) W (C> is use# signal P"C 9(" W (C> are also use# to rea#'7rite the value of "S,1"n-servi$e register3% "&,1interrupt mask register3% ",,1interrupt rePuest register3)
To un#erstan# the "S,% "&, an# ",, lets take a look at the follo7ing #iagram illustrating an e:ample)
5 6 *
"S,
/ +
5 ; ; ;
2
;
! 0
; 5 ; ;
; ;
; ;
5
"&,
6 * *
;
/ + /
;
2
;
! 0 !
;
5 6
",,
+
;
2
5
0
5
The values sho7n in the various registers illustrate that the $urrently in-servi$e interrupt is that generate# through ",T/ of the P"C 1int 0C6 in $ase of mater P"C3% also the interrupt through ",T! has een maske# 1int 9h 1key oar# interrupt3 in $ase of master P"C3 7hi$h means that even though a rePuest for this interrupt is re$eive# y the P"C ut this rePuest is ignore# y the P"C until this it is $leare#) 8n# the rePuests through ",T5% ",T6% ",T2 an# ",T0 are pen#ing an# 7aiting for the previously issue# interrupt to return) Port 8##resses .e7 of the operation $ontrol 7or#s $an e altere# after oot time) The a##resses for these (C> are liste# as elo7 W &aster P"C has t7o ports 206@(C> for 9(" 2!6@(C> for "&, Slave P"C has t7o ports as 7ell 806@(C> for 9(" $o#e 8!6@(C> for "&,
-etMs no7 #is$uss an e:ample that a$$esses these ports to $ontrol the P"C Ainc6ude Fstdio><> Ainc6ude F:ios><> (oid mainMN I outportM0;$1U0;0$NE L This e:ample simply a$$esses the it H ! of "&, in the master P"C) "t sets the it H! in "&, 7hi$h masks the key oar# interrupt) 8s a result no input $oul# e re$eive# from the key oar# after running this program)
0/ - TS, programs an# "nterrupts -etMs no7 look at another e:ample Ainc6ude Fdos><> Ainc6ude Fstdio><> Ainc6ude F:ios><> (oid interruptMWo6dintsNMNE (oid interrupt neOint0MNE int t50E //corrected (oid mainMN I o6dints53et(ectM0;00NE set(ectM0;00UneOint0NE PeepM0U1000NE L (oid interrupt neOint0MN I tXX: iC Mt5510$N I outportM0;$1U$NE L e6seI iC Mt55'/4N I outportM0;$1U0NE t50E L L MWo6dintsNMNE L The e:ample a ove is also an interesting e:ample) This program inter$epts the timer interrupt) The timer interrupt makes use of a varia le to keep tra$k of ho7 mu$h time has passe#A t is in$remente# ea$h time int 0 o$$urs) "t the rea$hes the !02 after !0 se$on#% at this point the key oar# interrupt is maske# an# remains maske# for su sePuent !0 se$on# at 7hi$h point the value of t 7ill e +6/% also t is $leare# to 0 for another su$h roun#) Ainc6ude Fdos><> (oid interruptMWo6dNMNE (oid interrupt neOint7MNE c<ar Car Wscr5Mc<ar Car WN 0;0040001&E (oid mainMN I o6d53et(ectM0;07NE set(ectM0;07UneOint7NE PeepM0U1000NE L (oid interrupt neOint7MN I iC Minport:M0;/0N550'
0/ - TS, programs an# "nterrupts VVMMMWscrNV1$N551$NN //corrected I outport:M0*$0U0;$0NE returnE L MWo6dNMNE L The a ove program #isa les the CT,-K8-TK49- $om ination in the 4(S environment 1if 7in#o7s (S is also running this $om ination 7ill not e #isa le# for its environment3) The key oar# interrupt has een inter$epte#% 7henever the key oar# interrupt o$$urs the ne7int9 fun$tion re$eives the s$an key $o#e from the key oar# port 0:60% 0+ is the s$an key $o#e of 49- key) 8lso the program $he$ks if the 8-T an# CT,- utton has een presse# as 7ell from the status of the /0D!56 key oar# status yte) "f it $onfirms that the $om ination presse# is CT,-K8-TK49- then it #oes not invoke the real int 9 1 Eol#int13 7hi$h 7ill make the $omputer re oot in 4(S environment ha# the $omputer een oote# through 4(S3 an# simply returns) <ut noti$e that efore returning it notifies the P"C that the interrupt has en#e#) The 9(" $o#e sent to the (C> at the a##ress 0:20 is also 0:20) This is eing #one e$ause int 9 is a har#7are interrupt% ha# this een a soft7are interrupt this 7oul# have not een rePuire#)
Ainc6ude Fdos><> (oid interruptMWo6dNMNE (oid interrupt neOint7MNE (oid mainMN I o6d53et(ectM0;07NE set(ectM0;07UneOint7NE PeepM0U1000NE L (oid interrupt neOint7MN I iC Minport:M0;/0N550;18N //corrected I outport:M0*$0U0;$0NE
0/ - TS, programs an# "nterrupts returnE L MWo6dNMNE L The a ove C language program suppresses the QsM input from the key oar#) The key oar# interrupt has een inter$epte#) >hen a key is presse# ne7int9 is invoke#) This servi$e $he$ks the value through the import statement of the key oar# port num ere# 0:60) "f he s$an $o#e 1 an# not the 8SC"" $o#e3 is 0:!. then it in#i$ates that the QsM key 7as presse#) This program in this $ase simply returns the ne7int9 hen$e suppressing this input y not $alling the real int 9) <efore return it also notifies the P"C a out the en# of interrupt)
Eeyboard $uffer
F Eeyboard $uffer is located in $!# (ata Area. F tarts at A;@ !3> F 3nds at A; @ 8(> F >as 86 byes of memory 6 bytes for each character. F >ead pointer is located at address A; @ 5A to A;@!$> F Tail pointer located at address A; @ !C to A;@!(>
The key oar# uffer is a memory area reserve# in the <"(S #ata area) This area stores the 8SC"" or spe$ial key $o#es presse# from the key oar#) "t 7orks as a $ir$ular uffer an# t7o ytes are reserve# for ea$h $hara$ter% moreover 2 ytes are use# to store a single $hara$ter) The first $hara$ter stores the 8SC"" $o#e an# the se$on# yte stores 0 in $ase an 8SC"" key is presse#) "n $ase a e:ten#e# key like .!- .!2 or arro7 key is presse# the first yte stores a 0 in#i$ating a e:ten#e# key an# the se$on# yte stores its e:ten#e# key $o#e)
Cir$ular uffer
/0D!96
/0D+46
The $ir$ular key oar# uffer starts at the a##ress /0D!96 an# $ontains +2 ytes) The a##ress /0D!86 stores the hea# of this $ir$ular uffer 7hile the a##ress /0D!C6 stores the tail of this uffer) "f the uffer is empty the hea# an# tail points at the same lo$ation as sho7n in the #iagram a ove) Storing $hara$ters in the key oar# uffer
Tail
GA;G$; ; ?8
0:!9
00 - 6ar#7are "nterrupts an# TS, programs The a ove sli#e sho7s ho7 $hara$ters are store# in the uffer) "f Q8A is to e store# then the first yte in the uffer 7ill store its 8SC"" $o#e an# the se$on# 7ill store 0% an# if e:ten#e# key like 49- is to e store# the first yte 7ill store 0 an# the se$on# yte 7ill store its s$an $o#e i)e) 0+) The #iagram also sho7s that hea# points to the ne:t yte 7here the ne:t input $hara$ter $an e store#) 8lso noti$e that hea# $ontain the offset from the a##ress /0D006 an# not from a##ress /0D!96) i)e) it $ontain 0:2/ 7hi$h is the a##ress of the ne:t yte to e store# relative to the start of <"(S #ata area an# not the key oar# uffer) Position of tail
0:"9
Tail@0:20
G$; ; ?8
6ea# @ 2/
8s #is$usse# earlier the key oar# uffer is a $ir$ular uffer therefore the tail nee# to e pla$e# appropriately) "n the given e:ample the input Q8M store# in the uffer is $onsume#) (n $onsumption of this $hara$ter the tail in#e: is up#ate# so that it points to the ne:t $hara$ter in the uffer) "n rief the tail 7oul# point to the ne:t yte to e $onsume# in the uffer 7hile hea# points to the pla$e 7here ne:t $hara$ter $an e store#)
F o E$( buffer acts as a circular buffer. F The tail value should be e,amined to get to the start of the buffer.
9:ample
Hinclude Idos.hJ void interrupt %Kold&%&; void interrupt new5%&L unsigned char far Kscr M %unsigned char far K& ;,;;A;;;5C void main%& N oldMgetvect%;,;O&; setvect%;,;O,new5&; 'eep%;,5;;&; P
void interrupt new5 %& N if%inportb%;,7;&MM?8& N K%%unsigned char farK&;,;;A;;;;;QKscr&M6B; if%%Kscr&MM7;& KscrM8;; else KscrQM6; outportb%;,6;,;,6;&; return; PP
The program liste# in the sli#es a ove inter$epts interrupt 9) >henever the interrupt 9 o$$urs it rea#s the key oar# port 0:60) "f the port $ontains 0+ then it means 49- 7as presse#% if so it pla$es the $o#e 2* in the uffer an# then up#ates the hea# in $ir$ular manner) The $o#e 2* pla$e# instea# of 0+ represents the $om inations CT,-KG) The program 7hen resi#ent 7ill $ause the program to re$eive CT,-KG $om ination 7henever 49- is presse# y the user) i)e in <orlan# C environment CT,-KG $om ination is use# to #elete a line% if this program is resi#ent then in <orlan# C environment a line 7ill e #elete# 7henever 49- is presse# y the user) <ut the thing 7orth noti$ing is that the interrupt fun$tion returns an# #oes not $all the real interrupt 9 after pla$ing 2* in the uffer% rather it returns #ire$tly) <ut efore returning as it has inter$epte# a har#7are interrupt it nee#s to notify the P"C% this is #one y outport10:20%0:203A statement) 0:20 is the a##ress of the (C> that re$eives the 9(" $o#e 7hi$h in$i#entally is also 0:20)
8s #is$usse# earlier the slave P"C is $as$a#e# 7ith the master P"C) "f the har#7are interrupt to e pro$esse# is issue# y the master P"C then the "S, nee#s to sen# the 9(" $o#e to the master P"C ut if the interrupt rePuest is issue# y the slave P"C then the "S, nee#s to inform oth master an# slave P"Cs as oth of them are $as$a#e# as sho7n in the sli#e)
#CW6S #CW8
6 D
5 D
; D
00 "f 9(" is to e sent 00! .(, ;on Spe$ifi$ 9(" 0! "f other ,egisters are to e a$$esse#
The same port i)e 0:20 is use# to a$$ess the (C>s) 00 is pla$e# in its num er / an# + to in#i$ate an 9(" is eing re$eive# an# 0! is pla$e# to in#i$ate that a internal register is to e a$$esse#)
6 ;
The value in its num er ! an# 0 in#i$ate 7hi$h ,egister is to a$$esse#) !0 is for ",, an# !! is for "S,)
00 - 6ar#7are "nterrupts an# TS, programs 8$$essing the "S, an# ",,)
C ;
7 ;
B ;
A ;
8 5
6 ;
5 ;
; ;
;o 9(" relevant
4onMt Care
8 value is pla$e# in the port 0:20 as sho7n in the a ove sli#e to in#i$ate that a register is to e a$$esse#)
C ;
7 ;
B ;
A ;
8 5
6 ;
5 5
; ;
Then again a value in that same port is pla$e# to in#i$ate 7hi$h register is to e a$$esse#% as in the a ove sli#e ",, is to e a$$esse#)
C ;
7 ;
B ;
A ;
8 5
6 ;
5 5
; 5
8n# in this sli#e a value is forme# 7hi$h $an e programme# in the port 0:20 to a$$ess the "S,) 8 sample program
Hinclude Istdio.hJ Hinclude Idos.hJ Hinclude Ibios.hJ void main %void& N char a; outport%;,6;,?&; outport%;,6;,;,;A&; aMinport%;,6;&; printf %Tvalue of !.. is U,V; ,a&; outport%;,6;,;,;?&; outport%;,6;,;,;$&; aMinport%;,6;&; printf %Tvalue of ! . is U,V; ,a&; P
The a ove program makes use of the te$hniPue #es$ri e# to a$$ess the "S, an# ",,) .irstly 0:00 is pla$e# to spe$ify that a register is to e a$$esse# then 0:08 is pla$e# to in#i$ate that ",, is to a$$esse#) ;o7 this port 0:20 $an e rea# 7hi$h 7ill $ontain the value in ",,) Similarly it is #one again y pla$ing the 0:0< in port 0:20 to a$$ess the "S,)
F A T . need to be loaded once in memory F )ultiple loading will leave redundant copies in memory
o we need to have some chec' which will load the program only once
int flag; flag M5; 'eep%;,5;;;&; if %flagMM5& )a'e T . else e,it *rogram
This 7ill not 7ork as this glo al varia le is only glo al for this instan$e of the program) (ther instan$es in memory 7ill have their o7n memory spa$e) So the
Answers is to use a memory area as flag that is global to all programs. i.e. !1T
int 6*6 is empty% 7e $an use its ve$tor as a flag) 8##ress of ve$tor seg @ 0 offset @ 6*6 E /
3,ample@
Hin$lu#eYst#io)hZ Hin$lu#eY<"(S)6Z Hin$lu#eY4(S)6Z unsigne# int far E int6*ve$ @ 1unsigne# far E3 &2O.P10%0:6*E/3 voi# interrupt 1Eol#int3 1 3A voi# interrupt ne7fun$ 1 3A voi# main13 [ if11Eint6*ve$3 \@ 0:.00.3 ''$orre$te# [ ol#int @getve$t 10:003A setve$t10:00% ne7int3A 1Eint6*ve$3 @ 0:.00.A keep 10%!0003A ]else [ puts 1BProgram 8lrea#y ,esi#entC3A ]] voi# interrupt ne7fun$ 13 [ DDDDDDD DDDDDDD 1Eol#int3 1 3A ]
00 - 6ar#7are "nterrupts an# TS, programs The a ove template sho7s ho7 the ve$tor of int 0:6* $an e use# as a flag) This template sho7s that a far pointer is maintaine# 7hi$h is assigne# the a##ress of the int 0:6* ve$tor) <efore $alling the keep13 fun$tion i)e making the program resi#ent a value of 0:f00f is pla$e# at this ve$tor1 this ve$tor $an e tempere# as it is not eing use# y the (S or #evi$e #rivers3) ;o7 if another instan$e of the program attempts to run the if statement at the start of the program 7ill $he$k the presen$e of 0:0f00f at the int ve$tor of 0:6*% if foun# the program 7ill simply e:it other7ise it 7ill make itself resi#ent) (r in other 7or# 7e $an say that 0:f00f at the int 0:6* ve$tor in this $ase in#i$ate that the program is alrea#y resi#ent)
Another )ethod
ervice H ;,00 usually does not e,ist for ! .-s. Eey is to create another service H ;,00 for the ! . interrupt besides other processing.
3,ample@
Hin$lu#eYst#io)hZ Hin$lu#eY<"(S)6Z Hin$lu#eY4(S)6Z voi# interrupt 1Eol#int3 1 3A voi# interrupt ne7fun$ 1 unsigne# int <P%))^%flags3A voi# main13 [ O4" @ 0A O86 @ 0:..A geninterrupt 10:!+3A if 1O4" @ @ 0:.00.3 [ puts 1BProgram 8lrea#y ,esi#entC3A e:it 103A ]
00 - 6ar#7are "nterrupts an# TS, programs The implements the servi$e 0:ff of interrupt 0:!+ su$h that 7henever this servi$e is $alle# it returns 0:f00f in 4" an# if this value #oes not return then it means that this program is not resi#ent)
9lse [
3,ample@
ol#int @ getve$t 10:!+3A setve$t 10:!+% ne7int3A keep 10% !0003A
else [ ]
!nterval Timer
PCLK /&2&05&@ M(B Ck PCLK 6for periphera Synchrono"s De;ices7 "nterval Timer Ch0 to ",T0 C6! T( 4,8& $ontroller Ch2 to PC Speaker
The interval timer is use# to #ivi#e an input frePuen$y) The input frePuen$y use# y the interval timer is the PC-2 signal generate# y the $lo$k generator) The interval timer has three #ifferent ea$h 7ith an in#ivi#ual output an# memory for storing the #ivisor value)
Counter .egisters@
F Counter registers can be used to divide frequency. 5 6 * / + 2 ! 0
co"nt
/&1 /@ /#
/4
8 $ounter register $an e use# to #ivi#e the $lo$k signal) 8s sho7n in the sli#e a ove% 0 of the $lo$k register is use# to #ivi#e the $lo$k frePuen$y y 2 su sePuently it ! is use# to #ivi#e it y / an# so on) The 4ivision me$hanism
;;;; ;;;; ;;;; ;;;5 ;;;; ;;5; ;;;; ;;55 ;;;; ;5;; ;;;; ;5;5 ;;;; ;55; ;;;; ;555
;;;; 5;;; ;;;; 5;;5 ;;;; 5;5; ;;;; 5;55 ;;;; 55;; ;;;; 55;5 ;;;; 555; ;;;; 5555
The a ove sli#e sho7s a sePuen$e of output that a 0 it $lo$k register 7ill generate in sePuen$e 7henever it re$eives the $lo$k signal) ( serve it H!% its value $hanges et7een
09 - The interval Timer 0 an# ! et7een t7o $lo$k $y$les so it $an e use# to #ivi#e the asi$ frePuen$y y 2) Similarly o serve it H2 its value transits et7een 0 an# ! 7ithin / $lo$k $y$les hen$e it #ivi#es the frePuen$y y / an# so on) Timing #iagram
Timing (iagram
.it $ 6/47 .it & 6/#7 .it 4 6/@7 .it 5 6/&17 %%%% % %%%% % %%%% %
6ere is the timing #iagram for a ove e:ample) <it H! performs one $y$le in et7een 2 $lo$k $y$les) Similarly it H2 performs one $y$le in et7een / $lo$k $y$les an# so on)
09 - The interval Timer Comman# registers 7ithin the programma le interval timer
Comman# register an# the $hannels nee# to e programme# for the interval timer to generate a 7ante# frePuen$y) Comman# ,egister
Comman# register is an 0 it register 7hi$h shoul# e programme# as #es$ri e# in the sli#e a ove efore loa#ing the #ivisor value) "t signifies the $hannel to e programme#% si=e of #ivisor value% the mo#e in 7hi$h the $hannel is to e operate# an# also 7hether the $ounter is to e use# a inary or <C4 $ounter)
Di;isor / # Mo*e / $ Di;isor / # Mo*e / & Di;isor / # Mo*e / 4 Di;isor / # Mo*e / 5 -----/-----
-----/---------+-----
-----/---------+-----
---2--- ---2---
-----/-----
The interval timer $an operate in si: mo#es) 9a$h mo#e has a #ifferent sPuare 7ave pattern a$$or#ing to nee# of the appli$ation) Some mo#es might e suita le to $ontrol a motor an# some might e suita le to $ontrol the speaker) <inary $ounter
$inary Count@
5
& &
;
$ $
;
$ $
;
$ $
5
& &
;
$ $
;
& &
5
$ &
$ount
<C4 C(U;T@09
5
& & 99@ & $
;
$ $ $ $
;
$ $ $ $
;
& & & $
5
$ $ & $
;
$ $ $ $
;
$ $ $ $
5
$ & & $
The interval timer $hannels $an e use# as a inary as 7ell as a <C4 $ounter) "n $ase its use# in inary mo#e its $ounter registers 7ill $ount in inary sePuen$e an# if its use# as a <C4 $ounter its registers 7ill $ount in <C4 sePuen$e as #es$ri e# a ove)
*orts S Channels@
F 8WChannels 57Wbit wide divisor value i.e ;X7BB8B ?Wbit port for each channel therefore the divisor word is loaded serially byte by byte.
*ort Addresses
A8> M Command *ort A;> M ?Wbit port for Channel ; A5> M ?Wbit port for Channel 5 A6> M ?Wbit port for Channel 6
The interval timer has + $hannels ea$h $hannel is !6 it 7i#e) The port /+6 is an 0 it port use# as the $omman# register) Ports /0h% /!6 an# /26 are asso$iate# 7ith the $hannels o% ! an# 2 respe$tively) Channels are !6 it 7i#e 7hereas the ports are 0 it 7i#e) 8 !6 it value $an e loa#e# serially through the ports into the register) Steps for programming the interval timer
F 9oad the Command byte into command register required to program the specific channel. F The divisor word is then erially loaded byte by byte.
1&( Port
the port 6!h is use# to $ontrol the speaker only the least signifi$ant 2 its are important) <it 0 is use# to $onne$t the interval timer to the speaker an# the it H! is use# to turn the speaker on off) ,est of the its are use# y other #evi$es) 9:ample
''Program loa#s #ivisor value of 0:2!.. ''Turns (; the speaker an# $onne$ts it to "nterval Timer Hin$lu#eY<"(S)6Z Hin$lu#eY4(S)6Z voi# main13 [ outport 10:/+%0:</3A outport 10:/2%0:..3A outport 10:/2%0:2!3A outport 10:6!%inport 10:6!3 _ +3A get$h13A outport 10:6!%inport 10:6!3 S 0:.C3A ]
3,ample@
The a ove programs the interval timer an# then turns it on) 8 value of 0: / is loa#e# into the $omman# register 0:/+) This value signifies that the $hannel 2 is to programme#%
09 - The interval Timer oth the ytes of #ivisor value are to loa#e#% the interval timer is to e programme# in mo#e 2 an# is to e use# as a inary $ounter) Then the #ivisor value say 0:2!ff6% is loa#e# serially) .irst 0:.. lo7 yte an# then the high yte 0:2! is loa#e#) <oth the least signifi$ant its of 0:6! port are set to turn on the speaker an# $onne$t it to the interval timer) (n a key press the speaker is again #is$onne$te# an# turne# off) Pro#u$ing a 4elay in a Program
Timer Count@
voi# main13 [ unsigne# long int t:A t: @ 1Etime3A t: @ t: K!0A puts1B<eforeC3A 7hile11Etime3 Y@ t:3A puts1B8fterC3A ]
4elay $an e pro#u$e# using #ou le 7or# varia le in the <"(S 4ata area pla$e# at the lo$ation 00/0D006C) This value $ontains a timer $ount an# is in$remente# every !'!0th of a se$on#) "n this program the this #ou le 7or# is rea#% pla$e# in a program varia le an# in$remente# y !0) The value of /0D6$6 is $ompare# 7ith this varia le in a loop) This loop iterates until the value of /0D6$6 is not greater) "n this 7ay this loop 7ill keep on iterating for a se$on# appro:imately)
voi# main13 [ unsigne# long int t:A unsigne# int #ivisor @ 0:2!..A 7hile 1#ivisor Z@ 0:*03 [ outport 10:/+%0:</3A outport 10:/2%E11$harE31S#ivisor333A outport 10:/2%E111$harE31S#ivisor33K!33A outport 10:6!%inport 10:6!3 _ +3A t: @ EtimeA t: @ t: K /A 7hile 1Etime Y@ t:3A #ivisor @#ivisor -+0A ] ]
The inner 7hile loop in the program is use# to in#u$e #elay) The outer loop simply reloa#s the #ivisor value ea$h time it iterates after re#u$ing this value y +0) "n this 7ay the output frePuen$y of the interval timer $hanges after every Puarter of a se$on# appro:imately) The speaker 7ill turn on 7ith a lo7 frePuen$y pit$h an# this frePuen$y 7ill in$rease gra#ually pro#u$ing a spe$trum of various soun# pit$hes)
Sample Program
Hin$lu#e Y#os)hZ Hin$lu#e Y ios)hZ voi# interrupt 1Eol#int!*3 1 3A voi# interrupt ne7int!* 1unsigne# int <P% unsigne# int 4"% unsigne# int S"% unsigne# int 4S% unsigne# int 9S% unsigne# int 4N% unsigne# int CN% unsigne# int <N% unsigne# int 8N% unsigne# int "P% unsigne# int CS% unsigne# int flags3A voi# main 1 3 [ ol#int!* @ getve$t 10:!*3A setve$t 10:!*% ne7int!*3A keep 10% !0003A ]
voi# interrupt ne7int!*1 unsigne# int <P% unsigne# int 4"% unsigne# int S"% unsigne# int 4S% unsigne# int 9S% unsigne# int 4N% unsigne# int CN% unsigne# int <N% unsigne# int 8N% unsigne# int CS% unsigne# int "P% unsigne# int flags3 [ if 1O86 @ @ 0:/.3 [ if 1O8- @@ 0:!.3 [ outport 10:/+% 0:</3A outport 10:/2% 0:..3A outport 10:/2% 0:2!3A outport 10:6!% inport10:6!3 ` +3A ] ] else 1Eol#int!*3 1 3A ]
The a ove program is a TS, program that $an e use# to turn the speaker on'off) The a ove program inter$epts the int !*h) >henever this interrupt o$$urs it looks for servi$e H 0:/f 1key oar# hook3) "f QSM10:!f s$an $o#e3 has een presse# it toggles the speaker)
Sample Program
Hin$lu#e Y#os)hZ Hin$lu#e Y ios)hZ unsigne# int #ivisorsJ/L@[0:2!ff%0:!#/*%0:! 0a%%0:!e/$]A unsigne# long int far Etime @1unsigne# long int far E30:00/0006CA voi# main 13 [ unsigne# long int t:A int i@0A 7hile 1\k hit 133 [ 7hile 1iY/3 [ outport10:/+%0:</3A outport10:/2%E11$har E31S# ivisorJiL333A outport10:/2%E111$har E31S#iv isorJiL33K!33A outport10:6!% inport10:6!3_+3A t:@EtimeA t:@t :K/A 7hile 1t : Z@ 1Etime33A iKKA ] i@0A ] outport10:6!%inport10:6!3S0:.C3A ]
This program generates a tune 7ith / #ifferent pit$hes) This program is Puite similar to the one #is$usse# earlier) The only ma?or #ifferen$e is that in that program the pit$h 7as gra#ually altere# from lo7 to high in this the pit$hes $hange perio#i$ally until a key is presse# to terminate the outer loop) .our various pit$hes are maintaine# an# their #ivisor values are pla$e# in the #ivisorsJL array) 8ll these #ivisor values are loa#e# one y one after a #elay of appro:imately Puarter of a se$on# an# this $ontinues until a key is presse#)
Hin$lu#e Yst#io)hZ Hin$lu#e Y#os)hZ Hin$lu#e Y ios)hZ stru$t tagTones [ unsigne# int #ivisorA unsigne# int #elayA ]A stru$t tagTones TonesJ/L@[ [0:2!ff%+]%[0:!#/*%2]%[0:! 0a%+]%[0:!e/$%/]]A int i%ti$ks%flag@0 A voi# interrupt 1Eol#int!*313A voi# interrupt 1Eol#int0313A voi# interrupt ne7int!*13A voi# interrupt ne7int013A
unsigne# $har far Es$r @ 1unsigne# $har far E310:00/000!53A voi# main 13 [ ol#int!*@getve$t10:!*3A setve$t10:!*%ne7int!*3A ol#int0@getve$t10:003A setve$t10:00%ne7int03A keep10%!0003A ]
This is an interrupt #riven version of the previous program) This program makes use of the timer interrupt rather than a loop to vary the #ivisor value) &oreover interrupt !* is use# to turn the speaker on 'off)
The speaker turns on 7henever QSM 1s$an $o#e 0:!f3 is presse# an# turns off 7henever Q8M 1s$an $o#e 0:!93 is presse#)
voi# interrupt ne7int013 [ if 1flag@@!3 [ ti$ksKKA if 1ti$ks @@ TonesJiL)#elay3 [ if 1i@@+3 i@0A else iKKA outport 10:/+% 0:</3A outport10:/2%E11$har E31STonesJiL)#ivisor333A outport10:/2%E111$har E31STonesJiL)#ivisor33K!33A outport10:6!%inport10:6!3_+3A ti$ks @ 0A ] ] 1Eol#int0313A ]
The timer interrupt shift the #ivisor value store# in the tones stru$ture 7henever the rePuire# num ere# of ti$ks1 timer $ounts3 have passe# as rePuire# y the value store# in the #elay fiel# of the tone stru$ture) &ore su$h #ivisor values an# their #elays $an e initiali=e# in the tones stru$ture to generate an alluring tune)
*arallel Communication
O"tp"t 40 4! 42 45 <usy Stro e
CPU
PP" is use# to perform parallel $ommuni$ation) 4evi$es like printer are generally ase# on parallel $ommuni$ation) The prin$iple of parallel $ommuni$ation is e:plaine# in the sli#e a ove) "tMs $alle# parallel e$ause a num er of its are transferre# from one point ot another parallel on various lines simultaneously)
*arallel Communication
Inp"t 40 4! 42 CPU 45 4, Para e Inp"t De;ice
CPU
I/O Contro er
CPU
PP"
The PP" a$ts as an interfa$e et7een the CPU an# a parallel "'( #evi$e) 8 "'( #evi$e $annot e #ire$tly $onne$te# to the uses so they generally rePuire a $ontroller to e pla$e# et7een the CPU an# "'( #evi$e) (ne su$h $ontroller is the PP") 6ere 7e 7ill see ho7 7e $an program the PP" to $ontrol the #evi$e $onne$te# to the PP" 7hi$h generally is the printer)
"nt !56
"nt !56 is use# to $ontrol the printer via the <"(S) The <"(S fun$tions that perform the printer "'( are liste# in the sli#e a ove 7ith its other parameter i)e 4N 7hi$h $ontains the -PT num er) 8 stan#ar# PC $an have / PP" name# -PT!% -PT2% -PT+ an# -PT/)
C
Printer <usy
;
Time out
The a ove liste# fun$tion returns a status yte in the 86 register 7hose meaning is #es$ri e# in the sli#e a ove) Various its of the yte #es$ri e the status of the printer) Time out <yte
Accessing the Parallel Port Through BIOS Functions
The <"(S servi$e on$e invoke# 7ill try to perform the rePueste# operation on the printer repeate# for a $ertain time perio#) "n $ase if the operation is ren#ere# unsu$$essful #ue to any reason <"(S 7ill not Puit trying an# 7ill try again an# again until the num er of tries spe$ifie# in the timeout ytes sho7n a ove runs out)
pecify the number of Attempts $!# perform before giving a time out 3rror F This byte 1aries (epending upon the speed of the *C F $usy M; *rinter is $usy F $usy M5 *rinter is not $usy
The status of the printer $an e use# in the a ove #es$ri e# manner to $he$k if the printer $an perform printing or not) "n $ase there is a transfer error% the printer is out of paper or there is a timeout the printer $oul# not e a$$esse#) (r if the printer is usy or if the printer is offline the printer $annot e a$$esse#) The pseu#o is ?ust performing these $he$ks)
&'(/$4( Eet Printer Stat"s on entry A(/$4= D3/InterfaceD On e<it A(/Stat"s .yte
*rinting *rograms
Sample Program
*rinting *rogram
"nion R>ES regsF 9IL> GfptrF ;oi* main6;oi*7 H fptr/fopen6Ic%JJtempJJa)c2t<tK=Kr)K7F regs2h2ah/&F regs2<2*</$F int@16$<&'=Aregs=Aregs7F -hi e6Lfeof6fptr77 Hregs2h2ah/4F regs2<2*</$F int@16$<&'=Aregs=Aregs7F if 66regs2h2ah A $<@$7//$<@$7 H regs2h2ah/$F regs2h2a /getc6fptr7F int@16$<&'=Aregs=Aregs7F MMM
The a ove program performs programme# "'( on the printer using <"(S servi$es) The program firstly initiali=es the printer int !56'0!) The 7hile loop 7ill en# 7hen the en# of file is rea$he#% in the loop it $he$ks the printer status 1int !5h'023 an# 7rite the ne:t yte in the file if the printer is foun# i#le y $he$king the most signifi$ant it of the status yte) Sample Program
Dinc "*e N*os2hO *rinting *rogram ;oi* interr"pt 6Go *76 7F ;oi* interr"pt ne-int 6 7F main6 7 H o * / get;ect6$<&'7F set;ect6$<&'=ne-int7F keep6$=&$$$7F M ;oi* interr"pt ne- 67 H if 6PA(//$7 H if 66PAL//QAQ7 RR 6PAL//QSQ77 //correcte* ret"rnF 6Go *767F M M
!! - Peripheral Programma le "nterfa$e 1PP"3 "" The a ove program inter$epts int !56) >henever a $ertain program issues int !56 to print a $hara$ter the a ove TS, program 7ill inter$ept the servi$e an# #o nothing if 8 or I is to e printe# rest of the $hara$ters 7ill e printe# normally) (nly the 8s an# the Is in the printing #o$ument 7ill e omitte#) Sample Program
Dinc "*e N*os2hO ;oi* interr"pt 6Go *76 7F ;oi* interr"pt ne -f"nc 6 7F main6 7 H o */get;ect6$<&'7F set;ect6$<&'=ne-f"nc7F keep6$=&$$$7F M ;oi* interr"pt ne -f"nc6 7 H if 6PA(//$7 H if 6 PAL L/ T T 7 6Go *767F M M
*rinting *rogram 6
"n this sample program again int !56 is inter$epte#) The ne7 interrupt fun$tion 7ill ignore all the spa$es in the print #o$ument)
*rinting *rogram 8
"n this program interrupt !5h is again inter$epte#) >henever a $hara$ter is to printe# the ne7 fun$tion $all the ol# fun$tion thri$e) 8s a result a single $hara$ter in the print #o$ument 7ill e repeate# / times)
;o7 7e 7ill see ho7 the register 7ithin the PP" $an e a$$esse# #ire$tly to $ontrol the printer)
8 ove sli#e list the a##resses 7ithin the <"(S #ata area 7here the ase a##ress 1starting port num er3 of -PT #evi$es is store#) 4ump of <"(S #ata area
The #ump of <"(S #ata area a##ress spe$ifie# in the previous sli#e for a $ertain $omputer sho7s that the ase port a##ress of -PT! is 0:0+ $% for lpt2 it is 0:0+50% for -pt+ it is 0:0250) These values nee# not e the same for all the $omputer an# $an vary from $omputer to $omputer)
The -PTs $an e s7appe# i)e -PT! $an e ma#e -PT2 an# vi$e versa for -PT2) This $an e a$$omplishe# simply y s7apping their a##resses in the <"(S #ata area as sho7n in the sli#e a ove)
C 7 B A 8 6 5 ;
.ase U&/Printer Stat"s
9usy;0 +0;0 P:;1 SL;1 :**;0
(ut of Paper
Printer (nline
The first port 1<ase K03 is the #ata port) 4ata to e sent're$eive# is pla$e# in this port) "n $ase of printer the 1<ase K !3 is the printer status port as #es$ri e# in the sli#e) 9a$h it represents the various status of the printer Puite similar to the status yte in $ase of <"(S servi$e) Printer Control ,egister
C ;
7 ;
B ;
A !.R
8 !
6 !/
5 ; A90 T
initiali=e
1<ase K23 is the printer $ontrol register it is use# to pass on some $ontrol information to the printer as #es$ri e# in the sli#e)
The a ove program #ire$tly a$$esses the registers of the PP" to print a file) The 7hile loop terminates 7hen the file en#s) The if statement only s$he$ks if the printer is usy of not) "f the printer is i#le the program 7rites the ne:t yte in file on to the #ata port an# then turns the stro e it to ! an# then 0 to in#i$ate that a yte has een sent to the printer) The loop then again starts $he$king the usy status of the printer an# the pro$ess $ontinue)
*rinter !nterface
Printer Interface
ACK
Printer
The printer interfa$e uses the ",T 5 as sho7n in the sli#e a ove) Therefore if interrupt #riven "'( is to e performe# int 0:0f nee# to e programme# as an har#7are interrupt)
$har uf J!02/LA int i @ 0A voi# interrupt 1Eol#int31 3A voi# interrupt ne7int 13A voi# main 1voi#3 [ outport11 Elpt3% inport1 Elpt3 _ /3A
outport11 Elpt3% inport1 Elpt3 _ 0:!03A ol#int @getve$t 10:0.3A setve$t 10:0.% ne7int3A outport10:2!% inport1 0:2!3 S 0:5.3A''$orre$te# keep10%!0003A
8 ove is a listing of a program that uses int 0:0f to perform interrupt #riven "'() To ena le the interrupt 0:0f three things are rePuire# to e #one) The interrupt shoul# e ena le# in the printer $ontrol registerA se$on#ly it shoul# also e unmaske# in the "&, in P"C) The program $an then inter$ept or set the ve$tor of interrupt 0:0f y pla$ing the a##ress of its fun$tion ne7int13A The ne7int13 7ill no7 e $alle# 7henever the printer $an perform output) This ne7int13 fun$tion 7rites the ne:t yte in uffer to the #ata registers an# then sen# a pulse on the stro e signal to tell the printer that #ata has een sent to it) >hen 7hole of the uffer has een sent the int 0:0f ve$tor is restore#% interrupt is maske# an# the memory for the program is #e-allo$ate#) The a ove listing might not 7ork) ;ot all of the printer interfa$es are #esigne# as #es$ri e# a ove) Some mo#ifi$ations in the printer interfa$e 7ill not allo7 the interrupt #riven "'( to 7ork in this manner) "f this #oes not 7ork the follo7ing strategy $an e a#opte# to sen# printing to the printer in a$kgroun#)
Hin$lu#e Yst#io)hZ Hin$lu#e Y#os)hZ Hin$lu#e Y ios)hZ Hin$lu#e Y$onio)hZ Hin$lu#e Yst#li )hZ voi# interrupt 1Eol#int313A voi# interrupt ne7int13A unsigne# int far E lpt @ 1unsigne# int far E30:00/00000A $har stJ00L@ athis is a test print string \\\\\\\\\\\aA int i A voi# main 13 [ ol#int @ getve$t10:003A setve$t10:00%ne7int3A keep10%!0003A ]
voi# interrupt ne7int13 [ if 111 inport11Elpt3 K!33 S 0:003 @@ 0:003 [ outport 1Elpt%stJiKKL3A outport 11Elpt3K2% inport11Elpt3K23 S 0:fe3A outport 11Elpt3K2% inport11Elpt3K23 _ !3A ] if 1i@@+23 [ setve$t 10:00%ol#int3A freemem1Opsp3A ] 1Eol#int3 13A ]
This program uses the timer interrupt to sen# printing to the printer in the a$k groun#) >henever the timer interrupt o$$urs the interrupt fun$tion $he$ks if the printer is i#le or not) "f itMs the printer is i#le it takes a yte from the uffer an# sen#s it to the #ata port of the printer interfa$e an# then sen#s a pulse through the stro e signal) >hen the uffer is full the program restores the int 0 ve$tor an# the relinPuishes the memory o$$upie# y the program)
Printer Ca le Conne$tivity
;ot all the its of the internal registers of the PP" are availa le in stan#ar# PCs) "n stan#ar# PCs the PP" is $onne$te# to a 4<2* $onne$tor) 8n# some of the its of its internal registers are availa le as pin outs as #es$ri es in the sli#e a ove)
"t might e #esira le to $onne$t one $omputer to another via PP"s to transfer #ata) (ne might #esire to $onne$t them su$h that one port of PP" at one en# is $onne$te# to another port of the other PP" at the other en#) <ut inter$onne$ting the 7hole 0 its of PP" $annot e ma#e possi le as all the its of the internal ports are not availa le as pinouts) So the ans7er is to $onne$t a ni le 1/- its3 at one en# to the ni le at the other) "n this 7ay t7o 7ay $ommuni$ation $an e performe#) The ni les are $onne$te# as sho7n in the sli#e a ove)
P$ P& P4 P5 P# V5 V# V: V1 V'
V5 V# V: V1 V' P$ P& P4 P5 P#
The pins that are inter$onne$te# are sho7n in the sli#e a ove) 8nother thing 7orth noti$ing is that the /th it of the #ata port is $onne$te# to the <USG an# vi$e versa) The <USG is inverte# efore it $an e rea# from the status port) So the /th it in #ata port at PC! 7ill e inverte# efore it $an e rea# at the 5th it of status register at PC2) .lo7 Control 8n algorithm shoul# e #evise# to $ontrol the flo7 of #ata so the re$eiver an# sen#er may kno7 7hen the #ata is to e re$eive# an# 7hen it is to e sent) The follo7ing sli#es illustrate one su$h algorithm)
D#
D5
D4
D&
D$
;
Sen*er sen*s LO+ !i)) e an* D# / $ recei;e* as .USW / &
$8
$6
$5
$;
Sen#er
$8
$6
$5
$;
,e$eiver
!2 - Parallel Port Programming .irst the lo7 ni le of the yte is sent from the sen#er in it 40 to 4+ of the #ata port) 4/ it is $leare# to in#i$ate the lo7 ni le is eing sent) The re$eiver 7ill kno7 the arrival of the lo7 ni le 7hen its $he$ks <USG it 7hi$h shoul# e set 1 y the interfa$e3 on arrival)
.USW ACK Recei;er sen* )ack LO+ !i)) e an* D#/$ recei;e* as .USW / & )y Sen*er
P>
SLC >R
$8
$6
$5
$;
Sen#er
;
D#
$8
D5
$6
D4
$5
D&
$;
D$
,e$eiver
The re$eiver then sen#s a$k the ni le turning its 4/ it to 0 as an a$kno7le#gement of the re$eipt of the lo7 ni le) This 7ill turn the <USG it to ! at the sen#er si#e)
D#
D5
D4
D&
D$
5
Sen*er sen*s (i !i)) e an* t"rns D# / & recei;e* as .USW / $ )y Recei;er
$C
$7
$B
$A
Sen#er
$C
$7
P>
$B
SLC
$A
>R
,e$eiver
.USW ACK
!2 - Parallel Port Programming The sen#er then sen# the high ni le an# turns its 4/ it to ! in#i$ating the transmission of high ni le) (n the re$eiver si#e the <USG it 7ill turn to 0 in#i$ating the re$eipt of high ni le)
The re$eiver then sen#s a$k the high ni le to the sen#er as an a$kno7le#gment)
.USW ACK Recei;er sen* )ack (i !i)) e an* t"rns D# / & recei;e* as .USW / $ )y Sen*er
P>
SLC >R
$C
$7
$B
$A
Sen#er
5
D#
$C
D5
$7
D4
$B
D&
$A
D$
,e$eiver
1( - Seria" +ommunication
Program implementing the #es$ri e# proto$ol
int i/ $F char ."fX&$4#YF -hi e 6&7 H ch / ."f XiYF if 66inport66G pt7 U &7A $<@$7 // $7 H ch / ."f XiYF ch / ch A $<>9F -hi e66inport66G pt7 U &7 A$<@$7 // $7F M e se H ch / ."f XiYF ch / ch OO #F ch / ch R $<&$F o"tport 6G pt= ch7F iUUF -hi e66inport66G pt7 U &7 A$<@$7 // @$7F M M
This is the sen#er program) This program if fin# the <USG it $lear sen#s the lo7 ni le ut turns the 4/ it to 0 efore sen#ing) Similarly it right shifts the yte / times sets the 4/ it an# then sen#s the high ni le an# 7aits for a$kno7le#gment until the <USG is $leare#)
int iF -hi e 6&7 H if 66inport6G pt U &7A $<@$7 // $<@$7 H < / inport 66G pt7 U &7F < / < OO 5F < / < A $<$9F o"tport66G pt7= <7F -hi e66inport6G pt U &7 A$<@$7 // $<@$7F M e se H y / inport 66G pt7 U &7F y / y NN &F temp / yF y / y A $<9$F //instr"ction a**e* y / y R <F
temp / temp OO 5F temp / temp R $<&$F iUUF o"tport 6G pt= temp7F ."f XiY / yF -hi e66inport66G pt7 U &7 A$<@$7 // $7F M M
This is re$eiver program) "f the <USG it is $lear it re$eives the lo7 ni le an# stores it in :) Similarly if the <USG it is 0 it re$eives the high ni le an# $on$atenates the oth ni le to form a yte)
Serial Communi$ation
erial Communication
W 8#vantages W 4isa#vantages
Types #f erial Communication
W Syn$hronous W 8syn$hronous
"n $ase of serial $ommuni$ation the its travel one after the other in serial pattern) The a#vantage of this te$hniPue is that in this $ase the $ost is re#u$e# as only ! or 2 lines may e rePuire# to transfer #ata) The ma?or #isa#vantage of Serial $ommuni$ation is that the spee# of #ata transfer may e re#u$e# as #ata is transferre# in serial pattern) There are t7o kin#s of serial $ommuni$ations) Syn$hronous Communi$ation
ynchronous Communication
W Timing signal is use# to i#entify start an# en# of a it)
LS. & & $ & $ & & MS. $
0!!0 !0!!
!+ - Serial Communi$ation "n $ase of syn$hronous $ommuni$ation as sho7n in the sli#e a timing signal is rePuire# to i#entify the start an# en# of a it)
ynchronous Communication
W Sampling may e e#ge triggere#) W Spe$ial line may e rePuire# for timing signal 1rePuires another line3) W (r the timing signal may e en$o#e# 7ithin the original signal 1rePuires #ou le the an#7i#th3)
8syn$hronous Communi$ation
Asynchronous Communication
W 4oes not use make use of timing signal) W 9a$h yte 17or#3 nee#s to en$apsulate# in start an# en# it)
"n $ase of asyn$hronous $ommuni$ation no timing signal is rePuire# ut ea$h yte nee#s to e en$apsulate# to kno7 the en# an# start of a yte)
!+ - Serial Communi$ation
Start ,it
W !)* Stop it
The U8,T is a #evi$e use# for asyn$hronous $ommuni$ations) U8,T is $apa le o en$apsulating a yte that might e *% 6% 5 or 0 its 7i#e in start an# stop its) &oreover it $an atta$h an e:tra parity it 7ith the #ata for error #ete$tion) The 7i#th of stop its may also vary)
ampling .ate
<it rate @ 9600 8 it is sample# after @ !'9600 -- <ut start an# en# its of a parti$ular <yte $annot e re$ogni=e#) -- So !)* stop it 1high3 is use# to en$apsulate a yte) 8 lo7 start it at the start of <yte is use# to i#entify the start of a <yte)
!+ - Serial Communi$ation
ampling .ate
-- <it rate an# other settings shoul# e the same at oth en#s i)e) - 4ata its per <yte) 1* U 0 3 - Parity $he$k - Parity 9ven'(## - ;o) of stop its)
ampling .ate
1/1(00 sec
8 @ /!6 @ 0!00 000! < Parity @ (## 4ata @ 0 Stop it @! 4ata rate @ +00 its'se$
!+ - Serial Communi$ation
. ] 686C tandard
W Stan#ar# for physi$al #imensions of the $onne$tors)
*S < '('+ +a,"e
*C %(T3&
/%+:1
Modem
+onnected &ia seria" !ort
,S2+2C is a stan#ar# for physi$al #imension of the $onne$tor inter$onne$ting a 4T914ata terminal ePuipment3 an# 4C9 14ata $ommuni$ation ePuipment3)
The pin outs of the 4<2* $onne$tor use# 7ith ,S2+2C is sho7n in the sli#e a ove)
!+ - Serial Communi$ation
. ] 686C tandard
W Stan#ar# for physi$al #imensions of the $onne$tors)
*S < '('+ +a,"e
*C %(T3&
/%+:1
Modem
+onnected &ia seria" !ort
.!
%T* /S5O)L% *:M I@ 5I?5 T5*O)?5 O)T T5: S:SSIO@ 1 +TS /+ @ 9: )S :% #O* #LOW +O@T*OL 1
4ata is re$eive# through the ,:4 line) 4ata is sen# through the T:4 line) 4T, 1#ata terminal rea#y3 in#i$ates that the #ata terminal is live an# ki$king) 4S,1#ata set rea#y3 in#i$ates that the #ata set is live) >henever the sen#er $an sen# #ata it sen#s the signal ,TS1 ,ePuest to sen#3 if as a result the re$eiver is free an# $an re$eive #ata it sen# the sen#er an a$kno7le#ge through CTS1 $lear to sen#3 in#i$ating that its $lear to sen# no7) 4< 9 Conne$tor for U8,T
%98 +onnector
5 +% 6 *> % 8 T> % A %T * B ?@% O *I ? +TS 7 %S* C *TS
U8,T internals
+A.T !nternals
.eceiver $uffer .egister !nterrupt 3nable .egister 9ine tatus .egister !nterrupt !( .egister (ivisor 9atch .egister 9ine Control .egister )odem Control .egister )odem tatus .egister Transmitter >olding .egister Transmit hift .egister 5..T 6.(T. 5.CT !nterrupt to *arity 9#2!C .eceiver hift .egister
. ,(
This sli#e sho7s the various internal registers 7ithin a U8,T #evi$e) The programmer only nee#s to program these registers effi$iently in or#er to perform asyn$hronous $ommuni$ation) ,egister summary
9ase B
Transmitter >olding .egister .eceiver (ata $and .ate (i visor %9ow $yte& $and .ate (i visor %>igh $yte& !nterrupt 3nable 0!0# Control .egister !nterrupt !( 9ine Cont rol )ode Control 9ine tatus )odem tatus cratch *ad T>. .$. (99 (9) !3. 0C. !!. 9C. )C. 9 . ) . * ; ; ; 5 5 6 6 8 A B 7 C
The a ove ta le lists the registers 7ithin the U8,T ans also sho7s their a reviation) 8lso it sho7s there offsets 7ith respe$t to the ase register)
)emory *ort $ase Address ;;A;@;;;; ;80?> ;;A;@;;;6 60?> ;;A;@;;;A 83?> ;;A;@;;;7 63?>
Te,t (ump
Wd -0C0 00-0C0000 00-0C0010 00-0C00'0 00-0C00(0 00-0C00-0 00-0C00.0 00-0C0020 00-0C0040 -E #7 0( #7 0' :7 0( :7 0'-9+ 0( 47 0( 47 0' +0 8# ==========>=>=== '( +7 '0 70 0' 7. 00 '0-00 00 (- 00 (- 00 41 10 D= ==== ==-=-=E= 0% 1+ 41 10 0% 1+ 2- '0-'0 (8 (- 0. (0 09 ( '4 ==E===d 8-=0=CF (0 09 0% 1+ 00 00 00 00-00 00 00 00 00 00 00 00 0=============== %7 00 +( 00 00 00 00 00-00 0( .0 00 00 10 00 00 ==========P===== 00 0 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ================ 0# 0+ 00 %- 0( '8 (0 00-00 00 00 00 0' +8 09 00 =====10========= 00 00 00 00 00 00 07 00-1- 1- 1- 1- 01 01 01 01 ================
The a ove #ump of the <"(S #ata area for a $ertain $omputer sho7s that the a##ress of C(&! is 0+.0 % the a##ress of C(&2 is 02.0 an# the a##ress of C(&+ is 0+90) These a##resses may not e same for all the $omputers an# may vary $omputer to $omputer)
!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3 Setting the <au# rate
etting the $aud .ate 5.?A86 )>^Mfrequency generating by +A.T internally 9aud rate ;1=7-(' M5G / /12H%i&isor1 (ivisor value loaded in (99 % $ase Q; & and (9) % $ase Q5 & (ivisor M 5, $aud .ate M 55B6;; (ivisor M ;C>, $aud .ate M O7;; (ivisor M 5?;>, $aud .ate M 8;;
The au# rate is set in a$$or#an$e 7ith the #ivisor value loa#e# 7ithin the U8,T internal registers ase K0 an# ase K!) -ine Control ,egister
;
>or# -ength
;; M B $!T ;5 M 7 $!T 5; M C $!T 55 M ? $!T
top Comm unication M5 .esum e Communication M; Constant *arity ; M/# constant *arity 5 MConstant *arity ; if bit A M5 *arity 5 if bit A M; ; M odd 5 M 3ven.
9ength of top $!T ; M one $!T 5 M5.B for B bit Word *arity Chec' and generation on
The line $ontrol register $ontains important information a out the ehaviour of the line through 7hi$h the #ata 7ill e transferre#) "n it various its signify the 7or# si=e% length of stop its% parity $he$k% parity type an# also the a $ontrol it to loa# the #ivisor value) The it 5 if set in#i$ates that the ase K0 an# ase K ! 7ill a$t as the #ivisor register other7ise if $leare# 7ill in#i$ate that ase K 0 is the #ata register)
*arity 3rror M5
Transfer 3rror %0raming 3rror& top Communication ignal from #ther end M5
-ine status register illustrates the status of the line) "t in#i$ates if the #ata $an e sent or re$eive#) "f it * an# 6 oth are set then 2 $onse$utive ytes $an e sent for output) 8lso this register in#i$ates any error that might o$$ur #uring $ommuni$ation) "nterrupt 9na le ,egister
"f interrupt #riven output is to e performe# then this register is use# to ena le interrupt for the U8,T) "t $an also use# to sele$t the events for 7hi$h to generate interrupt as #es$ri e# in the sli#e)
!nterrupt !( .egister
6 5 ;
Trigger Triggere# &o#em'-ine 00 @Change in &o#em Status 0! @ T6, is 9mpty !0 @ 4ata is ,ea#y !! @9rror in 4ata
(n$e an interrupt o$$urs it may e rePuire# to i#entify the $ase of the interrupt) This register is use# to i#entify the $ause of the interrupt)
1. - +OM Ports
&o#em Control ,egister
*TS
"n $ase soft7are oriente# flo7 $ontrol te$hniPue is use# the its 0 an# ! nee# to e set in that $ase) <it H+ nee# to e set to ena le interrupts) &oreover if a single $omputer is availa le to a #eveloper the U8,T $ontains a self test mo#e 7hi$h $an e use# y the programmer to self test the soft7are) "n self test mo#e the output of the U8,T is route# to its input) So you re$eive 7hat you sen#)
;
+hange in +TS +hange in %S*
+hange in *I
+TS
+hange in +%
This register in#i$ates the status of the mo#em status line or any $hange in the status of these lines) .".( Tueue
This feature is availa le in the ne7er version of the U8,T num ere# !6*00) 8 Pueue or a uffer of the input or output ytes is maintaine# 7ithin the U8,T in or#er to fa$ilitate more effi$ient "'() The si=e of the Pueue $an e $ontrolle# through this register as sho7n y the sli#e)
!* - C(& Ports
5M !nterrupt Triggered $ecause $uffer is not full $ut other side has stop sending data. %Time #+T&
The follo7ing sli#e sho7s ho7 int !/6 servi$e 0 $an e use# to set the line parameter of the U8,T or C(& port) This illustrates the various its of 8- that shoul# e set a$$or#ing efore $alling this servi$e)
!* - C(& Ports
Ser;ice D $ AL /
.a"* Rate Parity Check Data Length $$ / !one $$$ / &&$ )a"*s $$ / :)its $& / O** $$& / &:$ )a"*s $& / 1)its &$ / Parity $&$ / 5$$ )a"*s Disa) e &$ / ')its $&& / 1$$ )a"*s && / >;en && / @)its &$$ / &4$$ )a"*s D of stop )its &$& / 4#$$ )a"*s $ / & stop )it &&$ / #@$$ )a"*s & / &2: or 4 stop )it &&& / 01$$ )a"*s
The Servi$e on return pla$es the line status in 86 register as sho7n in the sli#e elo7)
A( / Line Stat"s
!* - C(& Ports 8n# pla$es the mo#em status in the 8- register as sho7n in sli#e elo7)
AL / Mo*em Stat"s
(ther servi$e of !/h in$lu#e servi$e H! 7hi$h is use# to sen# a yte an# servi$e H2 7hi$h is use# to re$eive a yte as sho7n in the sli#e elo7)
Ser&ice D 01 #/ 3/T.< A9 M A C!! character to send #/ .3T+./ A> M 3rror Code !f Cth bit in A> M 5 M +nsuccessful ; M uccessful Ser&ice D 0' #/ .3T+./ A9 M A C!! character received A> M 3rror Code
)odem
PC
UAR,
&o#em
Digita Data
,e Line
Ana og
&o#em
Ana og Digita Data
PC
UAR,
&o#em is generally use# to sen#'re$eive #ata to'from an analog telephone) 6a# the telephone line een purely #igital there 7oul# have een no nee# of a mo#em in this form) "f #ata is to e transferre# from one $omputer to another through some me#ia 7hi$h $an $arry #igital #ata then the mo#em $an e eliminate# an# the U8,T on oth $omputers $an e inter$onne$te#) Su$h arrangement is $alle# a ;U-- mo#em)
/+99 )odem
PC
UAR,
PC
UAR,
Ca) e
The a ove sli#e sho7s the $onfiguration use# to inter$onne$t t7o U8,Ts "n this 7ay a full #uple: $ommuni$ation $an e performe# an# moreover flo7 $ontrol $an also e performe# using 4S,% 4TS% ,TS an# CTS signals) Sample Program
3,ample@
Hin$lu#eY<"(S)6Z Hin$lu#eY4(S)6Z $har $h!% $h2A voi# initiali=e 1int pno3 [ O86@0A O8-@0:*5A O4N@pnoA geninterrupt10:!/3A ]
!* - C(& Ports
char receivechar %int pno& N char ch; Y(D M pno; YA> M 6; geninterrupt %;,5A&; ch M YA9; return ch; P
voi# sen#$har 1$har $h% int pno3 [ O4N @ pnoA O86 @ !A O8- @ $hA geninterrupt 10:!/3A ] unsigne# int get$omstatus 1int pno3 [ unsigne# int tempA O4N @ pnoA O86 @ 0+A geninterrupt 10:!/3A E11$harE31Stemp33 @ O8-A E111$harE31Stemp33 K !3 @ O86A return tempA ]
!* - C(& Ports
12 - +OM Ports II
Sample Program using <"(S routines
3,ample@
Hin$lu#eY<"(S)6Z Hin$lu#eY4(S)6Z $har $h!% $h2A voi# initiali=e 1int pno3 [ O86@0A O8-@0:*5A O4N@pnoA geninterrupt10:!/3A ]
char receivechar %int pno& N char ch; Y(D M pno; YA> M 6; geninterrupt %;,5A&; ch M YA9; return ch; P
The initiali=e 13 fun$tion initiali=es the C(& port 7hose num er is passe# as parameter using <"(S servi$es) The re$ieve$har13 fun$tion uses the C(& port num er to re$eive a yte from the C(& port using <"(S servi$es)
!* - C(& Ports
voi# sen#$har 1$har $h% int pno3 [ O4N @ pnoA O86 @ !A O8- @ $hA geninterrupt 10:!/3A ] unsigne# int get$omstatus 1int pno3 [ unsigne# int tempA O4N @ pnoA O86 @ 0+A geninterrupt 10:!/3A E11$harE31Stemp33 @ O8-A E111$harE31Stemp33 K !3 @ O86A return tempA ]
The sen#$har13 fun$tion sen#s a $hara$ter to the C(& port using <"(S servi$e 7hose num er is passe# as parameter) 8n# the get$omstatus13 fun$tion retrieves the status of the C(& port 7hose num er has een spe$ifie# an# returns the mo#em an# line status in an unsigne# int)
voi# main13 [ 7hile1!3 [ i @ get$omstatus 103A if 111E111$harE31Si33 K !3S0:203 @@ 0:203 SS 1k hit1333 [ $h! @ get$he13A sen#$har 1$h!% 03A ] if 11E111$harE31Si33 K!3 S 0:0!3 @@ 0:0!3 [ $h2 @ re$eive$har 103A put$h 1$h23A ] if 11$h! @@ 253 __ 1$h2 @@2533 reakA ] ]
-etMs suppose t7o U8,Ts are inter$onne$te# using a ;U-- mo#em "n the main 13 fun$tion there is a 7hile loop 7hi$h retrieves the status of the C(& port) (n$e the status has een retrieve# it $he$ks if a yte $an e transmitte#% if a key has een presse# an# its is $lear to sen# a yte the $o#e 7ithin the if statement sen#s the input yte to the C(& port using sen#$har13 fun$tion)
!* - C(& Ports The se$on# if statement $he$ks if a yte $an e rea# from the C(& port) "f the 4ata rea#y it is set then it re$eives a yte from the #ata port an# #isplays it on the s$reen) &oreover there is another $he$k to en# the program) The program looks for an es$ape $hara$ter 8SC"" @ 25 either in input or in output) "f this is the $ase then it simply reaks the loop) Sample Program This program #oes more or less the same as the previous program ut the only #ifferen$e is that in this $ase the "'( is #one #ire$tly using the ports an# also that the Self Test fa$ility is use# to $he$k the soft7are)
Hinclude Idos.hJ Hinclude Ibios.hJ void initialize %unsigned int far Kcom& N outportb % %Kcom&Q8, inport %%Kcom&Q8& \ ;,?;&; outportb % %Kcom&,;,?;&; outportb% %Kcom& Q5, ;,;5&; outportb % %Kcom&Q8, ;,5b&; P void elfTest#n%unsigned int far K com& N outportb%%Kcom&QA,inport%%Kcom&QA&\;,5;&; P
The initiali=e13 loa#s the #ivisor value of 0:0!00 high yte in ase K! an# lo7 yte in ase K0) "t also programs the line $ontrol register for all the rePuire# line parameters) The SelfTest(n13 fun$tion simply ena les the self test fa$ility 7ithin the mo#em $ontrol register)
!* - C(& Ports
void elfTest#ff%unsigned int far K com& N outportb% %Kcom&QA, inport%%Kcom&QA& S ;,3f&; P void writechar% char ch, unsigned int far K com& N while % L%%inportb%%Kcom&QB& S ;,6;& MM ;,6;&&; outport%Kcom,ch&; P char readchar% unsigned int far Kcom& N while %L%%inportb%%Kcom&QB& S ;,;5&MM;,;5&&; return inportb%Kcom&; P
The SelfTest(ff13 fun$tion turns this fa$ility off) The 7rite$har13 fun$tion 7rites the a yte passe# to this fun$tion on the #ata port) The rea#$har13 fun$tion rea#s a yte from the #ata port)
unsigned int far KcomM%unsigned int farK& ;,;;A;;;;;; void main %& N char ch M ;; int i M 5;int 4M 5; char ch6M_A_; initialize% com&; elfTest#n%com&; clrscr%&; while %chLM6C& N if %iMM?;& N 4QQ; iM;; P
The main fun$tion after initiali=ing an# turning the self test mo#e on enters a loop 7hi$h 7ill terminate on input of the es$ape $hara$ter) This loop also $ontrols the position of the $ursor su$h the $ursor goes to the ne:t line right after a full line has een type#)
!* - C(& Ports
if %4MM58& 4M;; goto,y%i,4&; chMgetche%&; writechar%ch,com&; ch6Mreadchar%com&; goto,y%i,4Q5A&; putch%ch6&; iQQ; P elfTest#ff %com&; P
8ll the input from the key oar# is #ire$te# to the output of the U8,T an# all the input from the U8,T is also #ire$te# to the lo7er part of the s$reen) 8s the U8,T is in self test mo#e the output e$omes the input) 8n# hen$e the user $an see output sen# to the U8,T in the lo7er part of the s$reen as sho7n in the sli#e elo7
Hinclude Idos.hJ Hinclude Ibios.hJ void initialize %unsigned int far Kcom& N outportb % %Kcom&Q8, inport %%Kcom&Q8& \ ;,?;&; outportb % %Kcom&,;,?;&; outportb% %Kcom& Q5, ;,;5&; outportb % %Kcom&Q8, ;,5b&; P void elfTest#n%unsigned int far K com& N outportb%%Kcom&QA,inport%%Kcom&QA&\;,5?&; P
void elfTest#ff%unsigned int far K com& N outportb% %Kcom&QA, inport%%Kcom&QA& S ;,3C&; P void writechar% char ch, unsigned int far K com& N
""while % L%%inportb%%Kcom&QB& S ;,6;& MM ;,6;&&;
return inportb%Kcom&; P
!* - C(& Ports
unsigned int far KcomM%unsigned int farK& ;,;;A;;;;;; unsigned char far KscrM%unsigned char farK& ;,$?;;;;;;; int i M;,4M;;char ch;i nt '; void interrupt %Koldint&%&; void interrupt newi nt%&; void main %& N initialize%com&; elfTest#n%com&; oldint M getvect%;,;c&; setvect%;,;c,newint&; outport%%Kcom&Q5,5&; outport%;,65,inport%;,65&S;,30&; 'eep%;,5;;;&; P
This si program is also Puite similar to the previous one) The only #ifferen$e is that in this the "'( is performe# in an interrupt #riven patter using the "nt 0:0C as the C(&! uses ",T/) 8lso to use it in this 7ay ",T/ must e unmaske# from the "&, register in P"C) 8lso efore returning from the "S, the P"C must e signale# an 9(" $o#e)
void interrupt newint%& N chM readchar%com&; if %iMM?;& N 4QQ; iM;; P if %4MM58& 4M;; ' M iK6Q%4Q5A&K?;K6; K%scrQ'&Mch; iQQ; outport%;,6;,;,6;&; P
!* - C(& Ports
Hinclude Ibios.hJ Hinclude Idos.hJ void interrupt %Koldint&%&; void interrupt newint%&;
void initialize %unsigned int far Kcom& N outportb % %Kcom&,;,?;&; outportb% %Kcom& Q5, ;,;5&; outportb % %Kcom&Q8, ;,5b&;
void main %void& N oldint M getvect%;,;C&; setvect %;,;C,newint&; initialize %Kcom&; outport %%Kcom&QA, inport %%Kcom&QA& \ ;,;?&; outport %;,65,inport %;,65&S;,30&; outport %%Kcom& Q 5, 5&; 'eep%;,5;;;&; P void interrupt newint %& N Kscr M inport%Kcom&; outport %;,6;,;,6;&; P
!* - C(& Ports
Hinclude Idos.hJ Hinclude Ibios.hJ char ch5,ch6; void initialize %unsigned int com& N outportb % comQ8, inport %comQ8& \ ;,?;&; outportb % com,;,?;&; outportb% com Q5, ;,;5&; outportb % comQ8, ;,5b&; P
void main % & N initialize%;,8f?&; while %5& N if % %%inport%;,8fd&S;,6;&MM;,6;& SS %'bhit%&&& N ch5Mgetche%&; outport%;,8f?,ch5&; P if %% %inport%;,8fd&S;,;5&MM5&& N ch6M i nport%;,8f?&; putch%ch6&; P if %% ch5MM6C& \\ %ch6MM6C&& brea'; P P
This program is same fun$tionally as one of the previous programs 7hi$h use# <"(S servi$es to get the input #ata an# sen# the output #ata) The only #ifferen$e is that in this $ase it #oes the same #ire$tly a$$essing the ports)
!* - C(& Ports
(nly t7o or three of the lines are eing use# to sen# re$eive #ata rest of the lines are eing use# for flo7 $ontrol) The $ost of these lines $an e re#u$e# y re#u$ing the lines use# to flo7 $ontrol an# in$orporating soft7are oriente# flo7 $ontrol rather than har#7are oriente# flo7 $ontrol as sho7 in the sli#e elo7)
The 4T,% 4S,% ,TS an# CTS lines have een eliminate# to re#u$e $ost ut in this flo7 $ontrol 7ill e performe# in a soft7are oriente# manner)
!* - C(& Ports
N(; 7henever re$eive# in#i$ates the start of $ommuni$ation an# N(.. 7henever re$eive# in#i$ates a temporary pause in the $ommuni$ation) .ollo7ing is a pseu#o $o#e 7hi$h $an e use# to implement the soft7are oriente# flo7 $ontrol)
while %5& N receivedchar M readchar %com&; if %receivedchar MM D#/& N .ead tatus M T.+3; continue; P if %receivedchar MM D#00& N .ead tatus M 0A9 3; continue; P if %.ead tatus MM T.+3& $uf ZiQQ[ M receivedchar; P
the re$eive# $hara$ter is firstly analyse# for N(; or N(.. $hara$ter) "f N(; is re$eive# the status is set to T,U9 an# if N(.. is re$eive# the status is set to .8-S9) The $hara$ters 7ill only e re$eive# if the status is T,U9 other7ise they 7ill e #is$ar#e#)
F F F F
$attery powered device +pdates time even if *C is shutdown .TC has 7A byte battery powered .A) !/T 5A> used to get"set time.
,eal time $lo$k is a #evi$e in$orporate# into the PC to up#ate time even if the $omputer is off) "t has the $hara$teristi$s sho7n in the sli#e a ove 7hi$h ena les it to up#ate time even if the $omputer is off) The <"(S interrupt 0:!8h $an e use# to $onfigure this $lo$k as sho7n in the sli#e elo7 it has various servi$e for getting'setting time'#ate an# alarm)
Cloc' Counter 5A>";; %hoursK7;K7; Q minK7; Q sec& K 5?.6;7B #/ 3/T.< A> M ;; #/ 3D!T A9 M )idnight flag CD M Cloc' count %>i word& (D M Cloc' count %9ow word& 5BC8;A; Times !ncrement 5BC8;A;"5?.6;7B M ?78OO.O565 sec Whereas ?7A;; sec represent 6A hrs.
#/ 3/T.< A> M ;5 CD M Cloc' count %>i word& (D M Cloc' count %9ow word&
#/ 3/T.< A> M ;6 #/ 3D!T C> M >ours %$C(& C9 M )inutes %$C(& (> M econds %$C(&
et Time 5A>";8 #/ 3/T.< A> M ;8 C> M >ours %$C(& C9 M )inutes %$C(& (> M econds %$C(& (9 M (ay 9ight saving M 5 tandard Time M ;
.ead (ate 5A>";A #/ 3/T.< A> M ;A #/ 3D!T C> M Century %$C(& C9 M <ear %$C(& (> M )onth %$C(& (9 M (ay %$C(&
et (ate 5A>";B #/ 3/T.< A> M ;B C> M Century %$C(& C9 M <ear %$C(& (> M )onth %$C(& (9 M (ay %$C(&
et Alarm 5A>";7 #/ 3/T.< A> M ;7 C> M >ours %$C(& C9 M )inutes %$C(& (> M econds %$C(&
#/ 3/T.< A> M ;C
415
I@T
Control Circuitry
The ,TC internally has an array of registers 7hi$h $an e use# to a$$ess the 6/ yte attery po7ere# C&(S ,8&)
C; ] C0> %57 ports& #nly C; S C5> are important from programming point of view
!nternal *orts
!5 - ,eal Time Clo$k 1,TC3 The follo7ing sli#e sho7s the fun$tion of some of the ytes in the attery po7ere# ,8& use# to store the units of time an# #ate)
Wee' (ay
;5> M unday ;6> M )onday ;8> M Tuesday ;A> M Wednesday ;B> M Thursday ;7> M 0riday ;C> M aturday
The value in the #ays of the 7eek yte in#i$ates the #ay a$$or#ing to sli#e sho7n a ove) Fenerally <C4 values are use# to represent the units of time an# #ate)
<ear
$attery *owered .A) is accessed in two steps F pecify the $yte no. in C;> port. F .ead"write port C5> to get"set the value of specified byte.
.ollo7ing sli#e sho7n a fragment of $o#e that $an e use# to rea# or 7rite onto any yte 7ithin the 6/ yte attery po7ere# ,8&)
Accessing the $attery *owered .A) outport %;,C;, ;&; sec M inport %;,C5&; outport %;,C;, A&; outport %;,C5,hrs&;
tatus .egister A
4 2 . ( ' 1 0
Interr"pt freZ"ency ,ime freZ"ency $ / ,ime is not "p*ate* & / ,ime is "p*ate*
The lo7er / its of this register stores a $o#e in#i$ating the frePuen$y 7ith 7hi$h the ,TC har#7are interrupt $an interrupt the pro$essor) The ne:t fiel# is use# to spe$ify the time frePuen$y i)e) the frePuen$y 7ith the time is sample# an# hen$e up#ate#) The most signifi$ant it in#i$ates that after time sampling if the time has een up#ate# in to the 6/ yte ,8& or not)
tatus .egister $
4 2 . ( ' 1 0
Up*ate time Ca pe rio*ic interr"pt Ca A arm interr"pt Ca interr"pt on time "p*ate . ock generator
$ / Day ight sa;ing time 4#/&4 [ ho"r co"nter $ / &4 ho"r format & / 4# ho"r format ,ime A *ate format $ / .CD & / .inary
The status register < is the main $ontrol register) "t is use# to spe$ify the #ate time formats an# is also use# to ena le interrupt on various events like alarm time an# time up#ation) 8nother feature of ,TC is perio#i$ interrupt 7hi$h o$$ur 7ith a frePuen$y spe$ifie# in the 8 register)
tatus .egister C
4 2 . ( ' 1 0
& / ,ime "p*ate comp ete & / A arm time reache* & / Perio*ic interr"pt ca
Status register is use# to i#entify the reason of interrupt generation as #es$ri e# in the sli#e a ove)
tatus .egister (
4 2 . ( ' 1 0
$ / .attery Dea*
(nly the most signifi$ant yte in status register 4 is important 7hi$h on eing 0 in#i$ates that the attery is #ea#) Sample Program)
void main %& N unsigned int hours, months, seconds; YA> M6; geninterrupt%;,5a&; hours M YC>; minutes M YC9; seconds M Y(>; hours M hours IIA; K%%unsigned char K&%S hours&& M %K%%unsigned char K& %S hours&&& JJA; hours M hours Q ;,8;8;; seconds M seconds IIA; K%%unsigned char K&%S seconds&& M %K%%unsigned char K&%S seconds&&& JJA; seconds M seconds Q ;,8;8;;
minutes M minutes IIA; K%%unsigned char K&%S minutes&& M %K%%unsigned char K&%S minutes&&& JJA; minutes M minutes Q ;,8;8;; clrscr%&; printf%aUcUcWUcUcWUcUcUcUca, K%%%unsigned charK&%Shours&&Q5&, K%%unsigned charK&%Shours&&, K%%%unsigned charK&%Sminutes&&Q5&, K%%unsigned charK&%Sminutes&&, K%%%unsigned charK&%Sseconds&&Q5&, K%%unsigned charK&%Sseconds&&, getch%&; P
The a ove program uses the servi$e int !8h'026 to rea# the time from the real time $lo$k) "t rea#s the time an# $onverts the pa$ke# <C4 values into unpa$ke# <C4 values) These values are then $onverte# into 8SC"" an# #isplaye# using the printf13 statement)
,ea# time from ,TC 1Sample Program3 This sample program #ire$tly a$$esses the 6/ yte ,8& to a$$ess the units of time) <efore rea#ing the time it makes sure y $he$king the value of Status register 8 an# $he$king its most signifi$ant it for time up#ate $ompletion) "f the up#ation is $omplete time $an e rea# from the respe$tive registers in the 6/ yte ,8&)
Hinclude Ibios.hJ Hinclude Idos.hJ void main %& N int hrs,mins,secs; char temp; do N outportb%;,C;,;,;a&; tempMinportb%;,C5&; Pwhile %%temp S ;,?;& MM ;&; outportb%;,C;,;&; secsMinport%;,C5&; outportb%;,C;,6&; minsMinport%;,C5&; outportb%;,C;,A&; hrsMinport%;,C5&;
hrs M hrs IIA; K%%unsigned char K&%Shrs&& M %K%%unsigned char K&%Shrs&&& JJA; hrs M hrs Q ;,8;8;; mins M mins IIA; K%%unsigned char K&%Smins&& M %K%%unsigned char K&%Smins&&& JJA; mins M mins Q ;,8;8;; secs M secs IIA; K%%unsigned char K&%Ssecs&& M %K%%unsigned char K&%Ssecs&&& JJA; secs M secs Q ;,8;8;; clrscr%&;
printf%aUcUc@UcUc@UcUca, K%%%unsigned charK&%Shrs&&Q5&, K%%unsigned charK&%Shrs&&, K%%%unsigned charK&%Smins&&Q5&, K%%unsigned charK&%Smins&&, K%%%unsigned charK&%Ssecs&&Q5&, K%%unsigned charK&%Ssecs&&&; getch%&; P
The time units are similarly rea# an# $onverte# to 8SC"" an# #isplaye#) >rite the Time on ,TC
Hinclude Ibios.hJ Hinclude Idos.hJ unsigned char A C!!to$C(%char hi, char lo& N hi M hi W ;,8;; lo M lo W ;,8;; hi M hi II A; hi M hi \ lo; return hi; P unsigned long int far Ktm M %unsigned long int far K&;,;;A;;;7c;
void main %& N unsigned char hrs,mins,secs; char ch5, ch6; puts%abn3nter the hours to update@ a&; ch5Mgetche%&; ch6Mgetch%&; hrs M A C!!to$C(%ch5, ch6&; puts%abn3nter the minutes to update@ a&; ch5Mgetche%&; ch6Mgetch%&; mins M A C!!to$C(%ch5, ch6&;
puts%abn3nter the seconds to update@ a&; ch5Mgetche%&; ch6Mgetch%&; secs M A C!!to$C(%ch5, ch6&; Ktm M ;; YC> M hrs; YC9Mmins; Y(>M secs; Y(9M;; YA> M8; geninterrupt%;,5a&; puts%aTime +pdateda&; P
The a ove listing of the program inputs the time from the user 7hi$h is in 8SC"" format) "t $onverts the 8SC"" in pa$ke# <C4 an# uses <"(S servi$es to up#ate the time) "n 4(S or 7in#o7s this time $hange may not remain effe$tive after the $ompletion of the program as the 4(S or 7in#o7s #evi$e #rivers 7ill revert the time to original even if it has een $hange# using this metho#)
Hinclude Ibios.hJ Hinclude Idos.hJ unsigned char A C!!to$C( %unsigned char hi, unsigned char lo& N hi M hi W ;,8;; lo M lo W ;,8;; hi M hi II A; hi M hi \ lo; return hi; P void main %& N unsigned int hrs,mins,secs; char ch5, ch6; int temp;
puts%abn3nter the hours to update@ a&; ch5Mgetche%&; ch6Mgetche%&; hrs M A C!!to$C(%ch5, ch6&; puts%abn3nter the minutes to update@ a&; ch5Mgetche%&; ch6Mgetche%&; mins M A C!!to$C(%ch5, ch6&; puts%abn3nter the seconds to update@ a&; ch5Mgetche%&; ch6Mgetche%&; secs M A C!!to$C(%ch5, ch6&; outportb%;,C;,;,;b&; temp M inport%;,C5&;
temp M temp \ ;,?;; outportb%;,C;,;,;b&; outportb%;,C5,temp&; outport outport outport outport outport outport %;,C;,;&; %;,C5,secs&; %;,C;,6&; %;,C5,mins&; %;,C;,A&; %;,C5,hrs&;
delay %8;;;;&; do N outportb%;,C;,;,;a&; tempMinportb%;,C5&; Pwhile %%temp S ;,?;& MM ;&; outportb%;,C;,;&; secsMinport%;,C5&; outportb%;,C;,6&; minsMinport%;,C5&; outportb%;,C;,A&; hrsMinport%;,C5&; hrs M hrs IIA; K%%unsigned char K&%Shrs&& M %K%%unsigned char K&%Shrs&&& JJA; hrs M hrs Q ;,8;8;;
To ela orate more on the pro lem pose# y the (S #evi$e #rivers here is another program) This program first up#ates the time a$$essing the 6/ yte ,8& #ire$tly an# taking the ne7 time as input from the user) 8fter up#ating the program pro#u$es a #elay of +0 se$on#s an# then rea#s time to #isplay it) 8 #ifferen$e of +0 se$on#s 7ill e noti$e# in the time entere# an# the time #isplaye#) This sho7s that #uring the e:e$ution of the program the time 7as su$$essfully $hange# an# 7as eing up#ate# a$$or#ingly)
mins M mins IIA; K%%unsigned char K&%Smins&& M %K%%unsigned char K&%Smins&&& JJA; mins M mins Q ;,8;8;; secs M secs IIA; K%%unsigned char K&%Ssecs&& M %K%%unsigned char K&%Ssecs&&& JJA; secs M secs Q ;,8;8;; printf%abn+pdated time is M UcUc@UcUc@UcUca, K%%%unsigned charK&%Shrs&&Q5&, K%%unsigned charK&%Shrs&&, K%%%unsigned charK&%Smins&&Q5&, K%%unsigned charK&%Smins&&, K%%%unsigned charK&%Ssecs&&Q5&, K%%unsigned charK&%Ssecs&&&; getch%&; P
Hinclude Ibios.hJ Hinclude Idos.hJ void main %& N unsigned int cen,yrs,mons,days; YA> MA; geninterrupt%;,5a&; cenMYC>; yrsMYC9; monsMY(>; daysMY(9; cen M cen IIA; K%%unsigned char K&%Scen&& M %K%%unsigned char K&%Scen&&& JJA; cen M cen Q ;,8;8;;
mons M mons IIA; K%%unsigned char K&%Smons&& M %K%%unsigned char K&%Smons&&& JJA; mons M mons Q ;,8;8;; yrs M yrs IIA; K%%unsigned char K&%Syrs&& M %K%%unsigned char K&%Syrs&&& JJA; yrs M yrs Q ;,8;8;; days M days IIA; K%%unsigned char K&%Sdays&& M %K%%unsigned char K&%Sdays&&& JJA; days M days Q ;,8;8;; clrscr%&;
printf%aUcUcWUcUcWUcUcUcUca, K%%%unsigned charK&%Sdays&&Q5&, K%%unsigned charK&%Sdays&&, K%%%unsigned charK&%Smons&&Q5&, K%%unsigned charK&%Smons&&, K%%%unsigned charK&%Scen&&Q5&, K%%unsigned charK&%Scen&&, K%%%unsigned charK&%Syrs&&Q5&, K%%unsigned charK&%Syrs&&&; getch%&; P
puts%abn3nter the yrs to update@ a&; ch5Mgetche%&; ch6Mgetche%&; yrs M A C!!to$C(%ch5, ch6&; puts%abn3nter the month to update@ a&; ch5Mgetche%&; ch6Mgetche%&; mons M A C!!to$C(%ch5, ch6&; puts%abn3nter the days to update@ a&; ch5Mgetche%&; ch6Mgetche%&; days M A C!!to$C(%ch5, ch6&; YC> M cen;YC9Myrs;Y(>M mons; Y(9Mdays; YA> MB; geninterrupt%;,5a&; puts%a(ate +pdateda&; P
The a ove sample program takes 8SC"" input from the user for the ne7 #ate) 8fter taking all the #ate units as input the program sets the ne7 #ate using the <"(S servi$e !8h'0*6) Setting the 8larm
void interrupt %Koldi nt&%&; void interrupt newi nt%&; unsigned int far K scr M %unsigned int far K&;,b?;;;;;;; void main %& N oldint M getvect%;,Aa&; setvect%;,Aa, newint&; YA>M7; YC> M;,68; YC9M;,B;; Y(>M;; geninterrupt%;,5a&; 'eep%;,5;;;&; P void interrupt newi nt%& N KscrM;,C;A5; sound%;,65ff&; P
The alarm $an e set using <"(S fun$tion !8h'06h) (n$e the alarm is set <"(S 7ill generate the interrupt /8h 7hen the alarm time is rea$he#) The a ove program inter$epts the interrupt /8h su$h that ne7int13 fun$tion is invoke# at the time of alarm) The ne7int13 fun$tion 7ill ?ust #isplay a $hara$ter Q8M on the upper left $orner of the s$reen) <ut this program may not 7ork in the presen$e of 4(S or >in#o7s #rivers) 8nother 7ay to set 8larm
Hinclude Ibios.hJ Hinclude Idos.hJ void interrupt newintC;%&; void interrupt %Koldi ntC;&%&; unsigned int far Kscr M %unsigned int far K&;,b?;;;;;;; unsigned char A C!!to$C(%char hi, char lo& N hi M hi W ;,8;; lo M lo W ;,8;; hi M hi II A; hi M hi \ lo; return hi; P
void main %void& N int temp; unsigned char hrs,mins,secs; char ch5, ch6; puts%abn3nter the hours to update@ a&; ch5Mgetche%&; ch6Mgetch%&; hrs M A C!!to$C(%ch5, ch6&; puts%abn3nter the minutes to update@ a&; ch5Mgetche%&; ch6Mgetch%&; mins M A C!!to$C(%ch5, ch6&;
puts%abn3nter the seconds to update@ a&; ch5Mgetche%&; ch6Mgetch%&; secs M A C!!to$C(%ch5, ch6&; outportb%;,C;,5&; outportb%;,C5,secs&; outportb%;,C;,8&; outportb%;,C5,mins&; outportb%;,C;,B&; outportb%;,C5,hrs&; outportb%;,C;,;,;b&;
temp M inport%;,C5&; temp M temp \ ;,C;; outportb%;,C;,;,;b&; outportb%;,C5,temp&; oldintC; M getvect%;,C;&; setvect%;,C;, newintC;&; 'eep%;,5;;;&; P void interrupt newintC;%& N outportb%;,C;,;,;c&; if %% inport%;,C5& S ;,6;& MM ;,6;& sound%;,65ff&; KscrM;,C;A5; %KoldintC;&%&; P
!0 - ,eal Time Clo$k 1,TC3 "" This program takes the time of alarm as 8SC"" input 7hi$h is firstly $onverte# into <C4) This <C4 time is pla$e# in the 6/ yte ,8& at the ytes 7hi$h hol# the alarm time) (n$e the alarm time is loa#e# the register is a$$esse# to ena le the interrupts su$h that other its are not #istur e#) >henever the ,TC generates an interrupt% the reason of the interrupt nee#s to e esta lishe#) This $an e #one y $he$king the value of status register C% if the *th it of register C is set it in#i$ates that the interrupt 7as generate# e$ause the alarm time has een rea$he#) The reason of interrupt generation is esta lishe# in the fun$tion ne7int5013) "f the interrupt 7as generate# e$ause of alarm then speaker is turne# on y the soun#13 fun$tion an# a $hara$ter Q8M is #isplaye# on the upper left $orner of the s$reen) (ther Configuration <ytes of <attery Po7ere# ,8&
#n 3ntry
call 55>
#n 3,it
AD M ystem !nfo.
"nterrupt !!6 is use# to #etermine the systems information) (n return this servi$e returns the systems info in 8N register) The #etail of the information in 8N register is sho7n in the sli#e a ove)
!/T 5B>"??>
.eturns M /o. of E$ above 5)$ mar'.
"nt !26 is use# to #etermine the amount of $onventional memory interfa$e# 7ith the pro$essor in kilo ytes) The amount of memory a ove $onventional memory 1e:ten#e# memory3 $an e #etermine# using the servi$e !*6'006)
1.
1'
+nused in ?;?7
*ushing or *oping the flags register will set these AWbits in ?;?7.
(etermining the *rocessor Type mov AD, ; push AD popf pushf pop AD Test the bits 5B ] 56 of AD if all set, the processor is ?;?7 else higher processor.
The a ove sli#es sho7 the test that $an e use# to #etermine if the un#erlying pro$essor is 0006 or not) "f its not 0006 some test for it to e 00206 shoul# e performe#)
(etermining the *rocessor Type 0lags test for 70'72 mov AD, C;;;> push AD popf pushf pop AD !f the bits 5A ] 56 are cleared the processor is 6?7 only.
"f the its !/-!2 are $leare# on pushing the flags register then the pro$essor is 00206) This $an e $he$ke# as sho7n in the sli#e a ove)
Alignment Chec'@
mov dword ptr Z56[, 3(D
"n +2- it pro$essors it is more optimal in terms of spee# if #ou le 7or# are pla$e# at a##resses 7hi$h ate multiples of /) "f #ata items are pla$e# at o## a##resses the a$$ess to su$h #ata items is slo7er y the virtue of the memory interfa$e of su$h PCs) So it more optimal to assign su$h varia les a##resses 7hi$h are multiple of /) The +06 an# /06 are
20 - 4etermining system information oth +2 it pro$essors ut /06 has alignment $he$k 7hi$h +06 #oes not have) This property $an e use# to #istinguish et7een +06 an# /06) "f the previous tests have faile# then there is a possi ility that the pro$essor is not 0006 or 206) To eliminate the possi ility of it eing a +06 7e perform the alignment test) 8s sho7n in the sli#e a ove the !0th it of the 9.-8FS register is the alignment it% it sets if a #ou le 7or# is move# onto a o## a##ress or an a##ress 7hi$h #oes not lie on a / yte oun#ary)
pushfd pop ea, mov ec,, ea, mov dword ptr Z58[, 3(D pushfd pop ea,
Alignment Test
"n the a ove sli#e a #ou le 7or# is move# into a o## a##ress) "f the pro$essor is +06 then the !0th it of the 9.-8FS register 7ill not e set% it 7ill e set if the pro$essor is higher than +06)
F A?7 will pass the alignment test. F To distinguish A?7 with *entium C*+!( Test is used.
C*+!( Test
8 Pentium an# /06 oth 7ill pass the alignment test) <ut a /06 #oes not support the CPU"4 instru$tion) >e 7ill ne:t in$orporate the CPU"4 instru$tion support test to fin# if the pro$essor is /06 or a Pentium as Pentium #oes support CPU"4 instru$tion)
C*+!( Test
'1
3flags F !f a program can set and also clear bit 65 of 3flags, then processor supports C*+!( instructions. F et bit 65 of 3flags and read value of 3flags and store it. F Clear bit 65 of 3flags, read the value of 3flags. F Compare both the value if bit 65 has changed the C*+!( instruction is available.
"f the CPU"4 instru$tion is availa le the pro$essor is a Pentium pro$essor other7ise itMs a /06)
$efore
3AD M ;
C*+!( !nstruction
3AD M 5 3$D ] 3(D ] 3CD 3$D M T2enuV 3(D M Tine!V 3CD M TntelV 3AD %bit 8 ] ;& M tepping !( 3AD %bit C ] A& M )odel 3AD %bit 55 ] ?& M 0amily 3AD %bit 58 ] 56& M Type 3AD %bit 5A ] 85& M .eserved
3AD M 5
The CPU"4 instru$tion% if availa le% returns the ven#or name an# information a out the mo#el as sho7n in the sli#e a ove) <esi#e rest of the test the CPU"4 instru$tion $an also e use# y the soft7are to i#entify the ven#or name)
Interr"pt ena) e f ag && after initia iBation signifies e<ten*e* precision operation
The $opro$essor $ontrol 7or# $ontains some $ontrol information a out the $opro$essor) The it num er 5 of $opro$essor $ontrol 7or# is the "nterrupt 9na le .lag an# it num er 0 S 9 shoul# $ontain !! on initiali=ation) Copro$essor Status >or#
C8 ; ; 5
C6 ; ; ;
The $opro$essor status register stores the status of the $opro$essor) Very mu$h like the flags register in the mi$ropro$essor the Copro$essor status 7or# $an e use# to #etermine the result of a $omparison as sho7n in the sli#e)
20 - 4etermining system information .ollo7ing test $an e performe# to test the presen$e of $opro$essor)
(n$e its esta lishe# that the $opro$essor is present then the mo#el of the $opro$essor shoul# e #etermine#) "n $ase an invali# numeri$al operation is rePueste# the 0005 $opro$essor generates an interrupt 7hile the higher $opro$essors #oes not use interrupts in fa$t they make use of e:$eptions) This feature $an e use# to #istinguish et7een 0005 an# higher pro$essor as sho7n in the sli#e a ove) The higher pro$essor 7ill not respon# to an attempt ma#e to set the "9& flag 7hile 0005 7ill respon#)
F !3) can be set in ?;?C. F !3) cannot be set in ?;6?C, ?;8?C as they use e,ception to inform the software about any invalid instruction. F !f an attempt to set this bit using 0(! ! fails then it implies, its not a ?;?C coprocessor .
F ?;8?C only allows to reverse the sign of infinity. F *erform a division by zero. F !f the sign of result can be reversed then the coprocessor is ?;8?C.
"f the sign of infinity $an e reverse# than the $opro$essor is 00+05 other7ise its 00+05
&oid Print+onfig/ &oid 1 I union *:?S *egisterJ 9KT: TJ c"rscr/1J T ; /!ee3,/0>#000, 0>###:1 ;; 0>#+1J !rintf/LKour P+ +onfiguration MnL1J !rintf/L----------------------------------------------MnL1J !rintf/LP+ ty!e C L1J s6itch/ !ee3,/0>#000, 0>###:1 1 I case 0>## C !rintf/LP+MnL1J ,rea3J case 0>#: C !rintf/LATMnL1J ,rea3J defau"t C !rintf/L T or higherMnL1J ,rea3J N
!rintf/L+on&entiona" * M C L1J int72/0>1', O*egister, O*egister1J !rintf/LPd 0MnL,*egister=>=a>1J if / T 1 I *egister=h=ah ; 0>77J int72/0>1., O*egister, O*egister1J !rintf/L dditiona" * M C Pd 0 o&er 1 mega,yteMnL, *egister=>=a>1J N int72/0>11, O*egister, O*egister1J !rintf/L%efau"t &ideo mode C L1J !rintf/L%is3 dri&es C PdMnL, /*egister=>=a> QQ 2 O (1 B 11J !rintf/LSeria" interfaces C PdMnL, *egister=>=a> QQ 8 O 0>0(1J !rintf/LPara""e" interfaces C PdMnMnL, *egister=>=a> QQ 1-1J N &oid main/1 I Print+onfig/1J N
"n this program the general $onfigurations of the $omputer are rea# using interrupt !!6% !26 an# !*6) .irst its #etermine# if the Pro$essor is an# 8T 1a#van$e# te$hnology all pro$essors a ove 00063 type $omputer or not) This $an e #one easily y $he$king its signature yte pla$e# at the lo$ation .000D...96 7hi$h 7ill $ontain neither 0:.. nor 0:.9 if its an 8T $omputer) The program sho7s the si=e of $onventional ,8& using the interrupt !26% then if the $omputer is an 8T $omputer then the program $he$ks the e:ten#e# memory si=e using int !*6'006 an# reports its si=e) 8n# ultimately the program $alls int !!6 to sho7 the num er an# kin# of "'( interfa$es availa le)
J;; %etermine 6hether mode" came ,efore or after 70'72 ;;;; >or a>,a> JSet A to 0 !ush a> Jand !ush onto stac3 !o!f JPo! f"ag register off of stac3 !ushf JPush ,ac3 onto stac3 !o! a> Jand !o! off of A and a>,0f000h J%o not c"ear the u!!er four ,its cm! a>,0f000h J re ,its 1' - 1. a"" eEua" to 1? Se notR'72R(72 JK:S --Q @ot 70(72 or 70'72
"n the a ove sli#e the test for 0006 or not is performe# y $learing all the its of flags register then rea#ing its value y pushing flags an# then poping it in 8N% the its !*-!2 of a: are $he$ke# if they have een set then itMs a 0006)
J-- Test for determining 6hether 70-72, 70(72 or 70'72 -----mo& d",!R70'72 JIn any case, itFs one of the mo& a>,04000h Jthree !rocessors !ush a> JPush 04000h onto stac3 !o!f JPo! f"ag register off !ushf Jand !ush ,ac3 onto the stac3 !o! a> JPo! into A register and a>,04000h JMas3 e&erything e>ce!t ,its 1'-1Se !ende J re ,its 1' - 1- a"" eEua" to 0? JK:S --Q ItFs an 70'72 inc d" J@o --Q itFs either an 70(72 or an J70-72= #irst set to (72 J-- The fo""o6ing test to differentiate ,et6een 70(72 and --J-- 70-72 is ,ased on an e>tension of the :#"ag register on J-- the 70-72 in ,it !osition 17= J-- The 70(72 doesnFt ha&e this f"ag, 6hich is 6hy you J-- cannot use soft6are to change its contents=
20 - 4etermining system information The a ove sli#e further performs the test for 00206 if the previous test fails) "t sets the it !/-!2 of flags an# then again rea#s a$k the value of flags through sta$k) "f the its !/-!2 have een $leare# then itMs a 00/06)
c"i J@o interru!ts no6 mo& e,>,offset array mo& Te,>U,ea> !ushfd !o! ea> mo& first,ea>J mo& Te,>B1U,ea> !ushfd !o! ea> shr first,17 shr ea>,17 and first,1 and ea>,1 cm! first,ea> inc d" sti Sne !ende
The a ove $o#e performs the alignment test as #is$usse# efore y test the !0th it after a##ressing a #ou le 7or# at an o## a##ress)
!ushfd !o! ea> mo& tem!, ea> mo& ea>,1 sh" ea>,'1 !ush ea> !o!fd !ushfd !o! ea> shr ea>,'1 shr tem!,'1 cm! tem!, ea> inc d" Se !ende Sm! !ende JTest is ended
the a ove $o#e performs a test to see if CPU"4 instru$tion is availa le or not for 7hi$h the it num er 2! of flags is set an# then rea# a$k)
!ende
J:nd testing JPo! %I off of stac3 JPo! f"ag register off of stac3 JSet high ,yte of !roc= code to 0 JProc= code ; return &a"ue of funct= J*eturn to ca""er J:nd of !rocedure
Rget!roc end!
8 CPU"4 Program
Dinc"ude Lstdaf>=hL Dinc"ude Vstdio=hQ Dinc"ude Vdos=hQ unsigned "ong int idT(UJ unsigned char ch;FM0FJ unsigned int ste!!ingid J unsigned int mode",fami"y,ty!e1 J unsigned int c!c6J int main/int argc, charH arg&TU1 I Rasm >or ea>,ea> Rasm c!uid Rasm mo& idT0U, e,> J Rasm mo& idT-U, ed> J Rasm mo& idT7U, ec>J !rintf/L PsMn L, /char H1 /id11J Rasm mo& ea>,1 Rasm c!uid Rasm mo& ec>,ea> Rasm @% ea>,0>fJ Rasm mo& ste!!ingid,ea>J Rasm mo& ea>, ec>
Rasm shr ea>,Rasm and ea>, 0>fJ Rasm mo& mode",ea> Rasm mo& ea>,ec> Rasm shr ea>,7 Rasm and ea>, 0>f Rasm mo& fami"y,ea>J Rasm mo& ea>,ec> Rasm shr ea>,1' Rasm and ea>, 0>(J Rasm mo& ty!e1, ea>J !rintf/LMnste!!ing is PdMn mode" is PdMn#ami"y is PdMnTy!e is PdMnL,ste!!ingid,mode",fami"y,ty!e11J N
The a ove program pla$es 0 in ea: register efore issuing the CPU"4 instru$tion) The string returne# y the instru$tion is then store# an# printe# moreover other information a out family% mo#el et$ is also printe#)
4ete$ting a Co Pro$essor
Rasm finit Rasm mo& ,yte !tr c!c6B1, 0J Rasm fstc6 c!c6 if / H///char H1 /Oc!c611B11;;(1 !uts/L+o!rocessor foundL1J e"se !uts /L+o!rocessor not foundL1J
8fter initiali=ation the $ontrol 7or# is rea# if the higher yte $ontains the value +)
mo& ,yte !tr csC6ait1,@OPR +O%: JW IT-instruction on 7074 mo& ,yte !tr csC6ait',@OPR +O%: J*e!"ace ,y @OP 6ait1C finit JInitia"iWe +o! mo& ,yte !tr c!WB1,0 JMo&e high ,yte contro" 6ord to 0 6ait'C fstc6 c!W JStore contro" 6ord cm! ,yte !tr c!WB1,( J5igh ,yte contro" 6ord ; (? Sne gcende J@o ---Q @o co!rocessor J-- +o!rocessor e>ists= Test for 7074 ----------------------inc d> and c!W,0 ##4 #h JMas3 interru!t ena,"e mas3 f"ag f"dc6 c!W JLoad in the contro" 6ord fdisi JSet I:M f"ag fstc6 c!W JStore contro" 6ord test c!W,70h JI:M f"ag set? Sne gcende JK:S ---Q 7074, end test
"n the $o#e a ove the "9& it is set an# then the value of $ontrol 7or# is rea# to analyse $hange in the $ontrol 7or#) "f the most signifi$ant it is set then itMs a 0005 $o pro$essor other7ise other tests must e performe#)
J-- Test for 70'74/70(74 -----------------------------------inc d> finit JInitia"iWe co! f"d1 J@um,er 1 to co! stac3 f"dW J@um,er 0 to co! stac3 fdi& J%i&ide 1 ,y 0, erg to ST f"d st JMo&e ST onto stac3 fchs J*e&erse sign in ST fcom!! J+om!are and !o! ST and ST/11 fsts6 c!W JStore resu"t from status 6ord mo& ah,,yte !tr c!WB1 Jin memory and mo&e A register sahf Jto f"ag register Se gcende JGero-#"ag ; 1 C 70'74 inc d> gcendeC mo& a>,d> ret Rgetco end! J@ot 70'74, must ,e 70(74 or inteJgrated co!rocessor on 70-72 JMo&e function resu"t to A J*eturn to ca""er
8n operation 1like #ivision y =ero is performe#3 7hi$h results in infinity) Then the sign of the result is reverse#% if it $an e reverse# then its 00+05 $o pro$essor other7ise its $ertainly 00205)
Eey$oard !nterface
205 Proce ssor 2-5
I@T*
I*X1
PI+
The key oar# interfa$e as #is$usse# earlier uses the ",T! an# the port 606 as #ata port% it also uses another port num er 6/6 as a status port) The key oar# $an perform syn$hronous serial "'()
& / Parity >rror & / ,ime O"t >rror *"ring inp"t & / ,ime O"t >rror *"ring o"tp"t
& / O"tp"t ."ffer f" & / Inp"t ."ffer f" & / Key)oar* Acti;e
The a ove sli#e sho7s the #etaile# meaning of its in port 6/6)
Typematic .ate
4 2 . ( ' 1 0
,ypematic Rate
11111 ; ' char/s 11110 ; '=1 char/s 11101 ; '=( char/s 11010 ; ( char/s CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC 00100 ; '0 char/s 00011 ; '1=7 char/s 00010 ; '- char/s 00001 ; '2=4 char/s 00000 ; (0 char/s
The typemati$ rate of the key oar# $an e $ontrolle# y a $ontrol 7or# as #epi$te# in the sli#e a ove) The #elay an# typemati$ rates nee# to e spe$ifie# in this $ontrol 7or#) The #elay in#i$ates the #elay et7een first an# se$on# $hara$ter input 7henever a key is presse#) The timing of rest of the su$$essive $hara$ter inputs for the same key is #etermine# y the typemati$ rate)
2-5
The input $hara$ter s$an $o#e is re$eive# at port 606) 8 $ertain it in the port 6/6 or key oar# $ontroller is use# as the "<. 1input uffer full3 it) 8 #evi$e #river $an $he$k this it to see if a $hara$ter has een re$eive# from the key oar# on 7hi$h this it 7ill turn to !)
Similarly some #ata 1as $ontrol information3 $an e sen# to the key oar#) The pro$essor 7ill 7rite on the port 606) The #evi$e #river 7ill $he$k the (<.1 output uffer full it of port 6/6 7hi$h remains set as long as the yte is not re$eive# y the key oar#) (n re$eipt of the yte from the port 606 the key oar# #evi$e 7rite a $o#e 0:.8 on the port 606 to in#i$ate that the yte has een re$eive# properly)
2ey oar# is a typi$ally an input #evi$e ut some #ata $an also e sen# to the key oar# #evi$e) This #ata is use# as some $ontrol information y the key oar#) (ne su$h information is the typemati$ rate) This type mati$ rate $an e $onveye# to the key oar# as #es$ri e# y the sli#e elo7)
0:.+
&eans Typemati$ rate 7ill e sent in the ne:t yte)
(ther su$h $ontrol information is the -94 status) 9very key oar# has three -94s for representing the status of ;um -o$k% Caps -o$k an# the S$roll -o$k) "f the #evi$e #river
2! - 2ey oar# "nterfa$e nee#s to $hange the status then the -94 status yte shoul# e 7ritten on the key oar# as #es$ri e# elo7) <ut efore 7riting this yte the key oar# shoul# e tol# that the $ontrol yte is to e 7ritten) This is #one y sen#ing the $o#e 0N94 efore sen#ing the status yte using the a ove #es$ri e# proto$ol)
Eeyboard 93(s
L>D Stat"s )yte
;
Scro Lock !"m Lock Caps Lock
if %chMM;,fa& N puts%asuccessbna&; brea'; P ma,try M ma,try W 5; P while %ma,try LM ;&; if %ma,tryMM;& return 5; else return ;; P
The a ove program has fun$tion Sen#2 #,ate13) This fun$tion takes 2 parameters% first one is value to e sent an# the se$on# one is the ma:imum num er of retries it performs if the yte $annot e sent) This fun$tion implements the #es$ri e# proto$ol) "t first 7aits for the "<. to e $leare# an# then starts trying to sen# the yte) The fun$tions stops trying either if 0:.8 is re$eive# 1su$$ess3 or if the num er of retries en# 1failure3)
void main %& N ""clrscr%&; endEbd.ate%;,f8,8&; endEbd.ate%;,Cf,8&; gets%st&; endEbd.ate%;,f8,8&; endEbd.ate%;,8&; gets%st&; P
;o7 this fun$tion is use# to $hange the typemati$ rate) .irstly 0N.+ is 7ritten to in#i$ate that the typemati$ rate is to e $hange# then the typemati$ rate is set to 0:5. an# a strng $an e type to e:perien$e the ne7 typemati$ rate) 8gain this rate is set to 0) This program 7ill not 7ork if you have oote# the system in 7in#o7s) .irst oot the system in 4(S an# then run this program)
doN ch M inport%;,7A&; Pwhile %chS;,;5&; chMinport%;,7;&; if %chMM;,fa& N puts%asuccessbna&; brea'; P ma,try M ma,try W 5; P while %ma,try LM ;&; if %ma,tryMM;& return 5; else return ;; P
void main %& N ""clrscr%&; endEbd.ate%;,ed,8&; endEbd.ate%;,C,8&; puts%a3nter a string a&; gets%st&; K'bdM%K'bd &\;,C;; puts%a3nter a string a&; gets%st&; P
8gain the same fun$tion is eing use# in this program to turn on the key oar# -94s) .irstly 0:94 is sent to in#i$ate the operation an# then 5 is 7ritten to turn on all the -94s) <ut tuning on the -94s like this 7ill not $hange the key oar# status in#i$ate# y the yte at /0D!56) "f the status for the #evi$e #river usage is to $hanges as 7ell then the $orrespon#ing at /0D!56 $an e set y (,ing it 7ith 0:50) This program 7ill not 7ork if you have oote# the system in 7in#o7s) .irst oot the system in 4(S an# then run this program)
()A Controller
I/O
Proce ssor Main Memory
%M
2! - 2ey oar# "nterfa$e 4&8 is a #evi$e 7hi$h $an a$Puire $omplete $ontrol of the uses an# hen$e $an e use# to transfer #ata #ire$tly from port to memory or vi$e versa) Transferring #ata like this $an prove faster e$ause a transfer 7ill $onsume 2 us $y$les if it is performe# using the pro$essor) So in this approa$h the pro$essor is ypasses an# its $y$les are stolen an# are use# y the 4&8 $ontroller)
()A Cascading
8 single 4&8 $an transfer 0 it operan#s to an# from memory in a single a us $y$le) "f !6 it values are to e transmitte# then t7o 4&8 $ontrollers are rePuire# an# shoul# e $as$a#e# as sho7n a ove)
W The &o#e register is $onveye# 7hi$h Channel is to e programme# an# for 7hat purpose i)e) ,ea# Cy$le% >rite Cy$le% &emory to memory transfer) W 8 rePuest to 4&8 is ma#e to start itMs transfer)
!nternal .egisters
W ;o of !6 S 0 it "nternal registers W Total of 25 internal registers in 4&8 Register !"m)er +i*th
Starting ddre ss +ounter +urrent ddre ss +urrent +ounter Tem!orary ddre ss Tem!orary +ounter Status +ommand Intermediate Memory Mode Mas3 *eEuest 1 1 1 1 1 1 1 12 12 12 12 12 12 7 7 7 7 7 7
The a ove sli#es sho7s the $hara$teristi$s of ea$h register 7hen a 4&8 $hannel is to e programme# an# also sho7s the total num er of registers in the 4&8 $ontroller) Some of the registers are $ommon for all $hannels an# some are in#ivi#ual for ea$h $hannel)
()A )odes
The 4&8 $an 7ork in a ove liste# mo#es) "n lo$k transfer mo#e the 4&8 is programme# to transfer a lo$k an# #oes not pause or halt until the 7hole lo$k is transferre# irrespe$tive of the rePuests re$eive# mean7hile) "n Single transfer mo#e the 4&8 transfers a single yte on ea$h rePuest an# up#ates the $ounter registers on ea$h transfer an# the registers nee# not e programme# again) (n the ne:t rePuest the 4&8 7ill again transfer a single yte eginning from the lo$ation it last en#e#) 4eman# transfer is same as lo$k transfer% only #ifferen$e is that the 4,9T signal remains a$tive throughout the transfer an# as soon as the signal #ea$tivates the transfer stops an# on rea$tivation of the 4,9T signal the transfer may start from the point it left)
The a ove ta le sho7s the a##resses of all the registers that shoul# e programme# to perform a transfer) These registers a$t as status an# $ontrol registers an# are $ommon for all the $hannels)
Terminal $ount if rea$he# signifies that the 7hole of the lo$k as rePueste# through some 4&8 $hannel has een transferre#) The a ove status register maintains the status of Terminal $ount 1TC3 an# 4,9T for ea$h $hannel 7ithin the 4&8)
This is the $omman# register) "t is use# to program various $ommon parameters of transfer for all the $hannels)
This register $an e use# to simulate a 4&8 rePuest through soft7are 1in $ase of memory to memory transfer3) The lo7er 2 its $ontains the $hannel num er to e rePueste# an# the it H 2 is set to in#i$ate a rePuest)
This register $an e use# to mask'unmask rePuests from a #evi$e for a $ertain 4&8 $hannel) The lo7er 2 its $ontains the $hannel num er an# the it H2 is set if the $hannel is to e maske#)
This register $an also e use# to mask the 4&8 $hannels) "t $ontains a single it for ea$h $hannel) The $orrespon#ing it is set to mask the rePuests for that $hannel)
This register $an e use# to set the mo#e on ea$h) The sli#e sho7s the #etail of the values an# its 7hi$h shoul# e pla$e# in the register in or#er to program a rePuire# mo#e)
8 $hannel is programme# for a start a##ress an# the $ount of ytes to e transferre# efore the transfer $an take pla$e) <oth these values are pla$e# in various registers a$$or#ing to the $hannel num er as sho7n y the sli#e a ove) (n$e the transfer starts these values start $hanging) The start a##ress is up#ate# in to the $urrent a##ress an# the $ount is also up#ates as ytes are transferre#) 4uring the transfer the status of the transfer $an e analy=e# y getting the values of these registers liste# "n the sli#e a ove for the $hannel1s3 involve# in the transfer)
The a ove sli#e sho7s the port num er for ea$h $hannel in 7hi$h the higher / or 0 its of the a solute a##ress is store# in $ase of 20 or 2/ it a##ress us)
Hinclude Idos.hJ Hinclude Ibios.hJ char stZ?;[; unsigned long int temp; unsigned int i; unsigned int countMA?; void main %void& N tempM%unsigned long int&Y( ; temp M temp II A9; i M K%%unsigned int K&%Stemp&&; temp M tempJJ579;
This program% programs the 4&8 $hannel + for rea# $y$le y pla$ing 0:0< in mo#e register 10:0<3) <efore the $hannel is unmaske# an# the $hannel mo#e is programme# the ase a##ress the $ount an# the higher / or 0 its of the a##ress shoul# e pla$e# in ase register% $ount register an# -at$h < respe$tively) The 20 1or 2/3 it a##ress is $al$ulate#) The higher / 1 or 03 its are pla$e# in the -at$h < for $hannel +% then the rest of the !6 its of the ase a##ress are pla$e# in ase register for $hanne+ an# ultimately the $ount is
2/ - 4ire$t &emory 8$$ess 14&83 "" loa#e# into the $ount register for $hannel +)
outportb %;,?5,K%%unsigned char K&%Stemp&&&; outportb%;,;7,K%%%unsigned char K&%Si&&&&; outportb%;,;7,K%%%unsigned char K&%Si&&Q5&&; countWW; outportb%;,;C,K%%unsigned char K&%Scount&&&;
outportb%;,;C,K%%%unsigned charK&%Scount&&Q5&&;
char st5Z6;A?[Ma,yza; unsigned long int temp; unsigned int i; void main %void& N tempMY( ; temp M tempIIA; i M K%%unsigned int K&%Stemp&&; temp M temp JJ57;
outportb%;,?C,K%%unsigned char K&%Stemp&&&; outportb%;,K%%unsigned char K&%Si&&&; outportb%;,K%%%unsigned char K&%Si&&Q5&&; outportb%5,;,ff&; outportb%5,;,;C&; outportb%;,;b,;,??&; tempMY( ; tempM tempQ56?; tempMtempIIA; iM K%%unsigned int K&%Stemp&&; tempMtempJJ57; outportb%;,?8,K%%unsigned char K&%Stemp&&&; outportb%6,K%%unsigned char K&%Si&&&; outportb%6,K%%%unsigned char K&%Si&&Q5&&;
This program% programs the $hannel 0 an# $hannel ! of the 4&8) "t loa#s the a##ress of Sour$e string st in ase register an# the -at$h < an# loa#s the $ount register for $hannel 0 an# #oes the same for st!) "t then programs the mo#e% mask an# $omman# register for memory to memory transfer an# to unmask $hannel 0 an# $hannel !)
out!ort,/(,0>ff1J out!ort,/(,0>041J out!ort,/0>0,,0>7.1J out!ort,/0>07,11J out!ort,/0>0f,0>0c1J out!ort,/0>08,0>0-1J 6hi"e /Y3,hit/11 I !rintf/L+hanne" 0 ; P>,P >MnL,in!ort,/0>011,in!ort,/0>0111J !rintf/L+hanne" 1 ; P>,P >MnL,in!ort,/0>0(1,in!ort,/0>0(11J !rintf/LStatus ; P >MnL,in!ort,/0>0711J N !uts/st11J N
.ile Systems
0ile ystem
W4isk 8r$hite$ture W4isk Partitioning W.ile systems
2* - .ile Systems
(is' Architecture
W4isk is a $ir$ular 7hi$h is hollo7 from the $enter WThis shape is inherently useful for ran#om a$$ess)
Tra$ks are the $ir$ular #ivision of the #isk an# the se$tors are the longitu#inal #ivision of the #isk as sho7n in the #iagram a ove)
2* - .ile Systems
8n a##ressa le unit on #isk $an e a##resse# y three parameters i)e) hea# H% se$tor H an# tra$k H) The #isk rotates an# $hanging se$tors an# a hea# $an move to an# fro $hanging tra$ks) 9a$h a##ressa le unit has a uniPue $om ination of se$H% hea#H an# tra$kH as its physi$al a##ress)
$loc's
W <lo$ks are the se$tors per tra$k WSmallest a##ressa le unit in memory W8##ress of lo$k is spe$ifie# as a uniPue $om ination of three parameters 1i)e) tra$k% hea#% se$3
2* - .ile Systems
>ard (is's
W Freater amounts of #ata $an resi#e on har# #isk
W8s greater amount of magneti$ me#ia $an resi#e on the har# surfa$e of the #isk W8lso e$ause the surfa$e area of the #isk is in$rease# y in$reasing the num er of platters as sho7n in the #iagram
2* - .ile Systems
Cylinders
W "n $ase of har# #isk 7here there are num er of platters the term tra$k is repla$e# y $ylin#er WCylin#er is a $olle$tion of $orrespon#ing tra$ks if tra$k on platter $hanges so 7ill the tra$ks on rest of the platters as all the hea#s move simultaneously
.otational (elay
W >hile a$$essing a sele$te# lo$k the time rePuire# y the #isk to rotate to the spe$ifie# se$tor is $alle# rotational #elay
2* - .ile Systems
ee' Time
W >hile a$$essing a sele$te# lo$k Time rePuire# y the hea# to rea$h the parti$ular tra$k'$ylin#er is $alle# seek time
Access Time
W The a$$umulative time that is rePuire# to a$$ess the sele$te# lo$k is $alle# a$$ess time W8$$ess time in$lu#es the #elay rePuire# y #isk rotation as 7ell as hea# movement)
2* - .ile Systems
2* - .ile Systems
;o7 7e esta lish ho7 a lo$k $an e rea# or 7ritten if its a##ress is kno7n) The fun$tion ios#isk13 $an e use# to rea# or 7rite a physi$al lo$k) The sli#e sho7s its parameter) "t takes the $omman# 1$m#3% #rive num er% hea# num er% tra$k num er% num er of se$tors to e rea# or 7ritten an# the memory from 7here the #ata is to rea# from or 7ritten to) Comman# signifies the operation that is to e performe#)
4rive num er is #es$ri e# in the sli#e elo7 it starts from 0 for first remova le #isk an# starts from 0:00 for first fi:e# #isk)
2* - .ile Systems
Contc
gets%st&; fpMfopen%st,awba&; printf%a>ead a&; gets%headno&; puts %headno&; printf%abnsector a&; gets%secno&; puts%secno&; printf%abntrac' a&; gets%trac'no&; puts%trac'no&;
2* - .ile Systems
Contc
i M biosdis'%6,;,?;,atoi%headno&, atoi%trac'no&,atoi%secno&,5,buf& ; if %K%%%char K&%Si&&Q5&MM;& N fwrite%buf,5,B56,fp&; fclose%fp&; P else printf%aCannot .ead 3rrorH M U,a,i&; P
The a ove program rea#s a physi$ally a##resse# lo$k from #isk using ios #isk13 fun$tion for first fi:e# #isk) The program after rea#ing the spe$ifie# lo$k 7rites it to a file an# then $loses the file)
9imitation of biosdis'
W <ios#isk13 $alls int !+6'0'!'2'+'/'* W4etails of !+6 servi$es use# y <ios#isk13 W(n 9ntry
86 @ servi$e H 8-@;o) of se$tors <N @ offset a##ress of #ata uffer C6 @ tra$k H C- @ se$tor H 46 @ hea#'si#e H 4- @ 4rive H 9S @ Segment 8##ress of uffer)
6o7ever there are some limitation of this ios#isk13 7hile using large #isks) This fun$tion uses the int !+6 servi$es liste# in the sli#e a ove)
2* - .ile Systems
9imitation of biosdis'%&
W -arge si=e# #isk are availa le no7 7ith thousan#s of tra$ks W<ut this <"(S routine only is $apa le of a$$essing a ma:) of !02/ tra$ks) W6en$e if a large #isk is eing use# not 7hole of the #isk $an e a$$esse# using this routine)
The parameter si=es provi#e# y these servi$es may not e suffi$ient to hol# the tra$k num er of lo$k to e a$$esse#)
8 ove sli#e sho7s for 7hi$h #isks e:ten#e# servi$es are rePuire# to a$$ess the lo$k effi$iently)
2* - .ile Systems
<ut "49 #isk interfa$e $an support #isks 7ith memory spa$e larger than *0/&< as sho7n in the ne:t sli#e)
2* - .ile Systems
9:ten#e# servi$es rePuire that the a##ress of the lo$k is spe$ifie# as a -<8 a##ress)
-<8 translation is #one y num ering the lo$ks 7ith a single in#e:) The in#e:es are assigne# to lo$ks as sho7n in the sli#e elo7) "n terms of the #isk geometry firstly all the se$tors of a tra$k 7ill e in#e:e# sePuentially% then the tra$k e:hausts the ne:t tra$k is $hosen on the other si#e of the #isk an# so on all the tra$ks in a $ylin#er are in#e:e#) >hen all the lo$ks 7ithin a $ylin#er has een in#e:e# the same is #one 7ith the ne:t $ylin#er)
if the C6S 1$ylin#er% hea# % se$tor3 a##ress of a #isk is kno7n it $an e translate# in to the -<8 a##ress an# vi$e versa) .or this purpose the total num er of $ylin#ers% hea#s an# se$tors must also e kno7n)
)athematical /otation for 9$A translation W -<8 a##ress @ 1C E 6M K63E SM K S U ! >here C @ Sele$te# $ylin#er num er 6M @ ;o) of hea#s 6 @ Sele$te# hea# num er SM@&a:imum Se$tor num er S@ Sele$te# Se$tor num er
26 - 6ar# 4isk 8lso $onversely -<8 to C6S translation $an also e #one using the formulae #is$usse# in the follo7ing sli#e ut for this the total num er of $ylin#ers% hea#s an# se$tors 7ithin the #isk geometry shoul# e kno7n)
26 - 6ar# 4isk 4isk 8##ress Pa$ket is a #ata stru$ture use# y e:ten#e# int !+6 servi$es to a##ress a lo$k an# other information for a$$essing the lo$k) "ts stru$ture is #efine# in the sli#e elo7)
ize
$yte $yte $yte $yte (ouble Word Ruad word
(escription
ize, hould not be less than 57 .eserved /o. of bloc's to transfer, )a, value no greater than C0> .eserved 0ar address of buffer 9$A address
26 - 6ar# 4isk
(n 9:it
"f C.@0 86@0@ Su$$ess "f C.@! 86@ 9rror $o#e
"nterrupt !+6'/26 $an e use# to rea# a -<8 a##resse# lo$k 7hose -<8 a##ress is pla$e# in the 4isk 8##ress pa$ket as #es$ri e# in the sli#e a ove)
3,tended Write
W Servi$e use# for e:ten#e# 7rite is int !+h'/+h (n 9ntry
86@/+6 8-@0%! 7rite 7ith verify off 2 7rite 7ith verify on 4-@#rive H 4SDS"@ far a##ress of 4isk a##ress pa$ket
(n 9:it
"f C.@0 86@0@ Su$$ess "f C.@! 86@ 9rror $o#e
Similarly int !+6 ' /+6 $an e use# to 7rite onto to -<8 a##resse# lo$k as #es$ri e# in the sli#e a ove)
26 - 6ar# 4isk
&oid main /&oid1 I !uts /Lenter the ",a "o6 dou,"e 6ordC L1J gets /st1J da!=",a"od;ato"/st1J !uts /Lenter the ",a high dou,"e 6ordC L1J gets /st1J da!=",ahid;ato"/st1J da!=siWe;12J da!=reser&ed1;0J da!=,"oc3s;1J da!=reser&ed';0J da!=,uffer ; /unsigned char far H1M0R#P/R%S,,uf1J
R 5;0>-'J R%L;0>70J RSI;/unsigned int1Oda!J geninterru!t/0>1(1J !uts /Lenter the !athC L1J gets /st1J f!tr ; fo!en/st,L6,L1J f6rite/,uf,.1',1,f!tr1J fc"ose /f!tr1J N
26 - 6ar# 4isk The a ove sli#es list a program that that performs a lo$k rea# operation using the interrupt !+6'/26) 8 stru$ture of type 48P is $reate an appropriate values are pla$e# into it 7hi$h in$lu#es its -<8 a##ress) The offset a##ress of #ap is pla$e# in S" register an# the 4S alrea#y $ontains its segment a##ress as it has een #e$lare# a glo al varia le) The #rive num er is also spe$ifie# an# the interrupt is invoke#) The interrupt servi$e rea#s the $ontents of the lo$k an# pla$es it in a uffer 7hose a##ress 7as spe$ifie# in #ap) The $ontents of this uffer are then 7ritten on to a file) Sli#e 5
(is' *artitioning
W Partition Ta le $ontains information pertaining to #isk partitions) W Partition Ta le is the first physi$al se$tor
>ead M ; Trac'"Cylinder M ; ec M 5 or 9$A M ; F *artition Table at C> M ;;5 is also called )$. %)aster $oot .ecord&.
26 - 6ar# 4isk
(escription
*artition into of 5st partition. *artition into of 6nd partition. *artition into of 8rd partition. *artition into of Ath partition. ignature
The #ata part $an $ontain information a out four #ifferent partitions for #ifferent (perating systems) 9a$h partition information $hunk is !6 ytes long an# the last t7o ytes at the en# of the partition ta le #ata part is the partition ta le signature 7hose value shoul# e 88** in#i$ating that the $o#e part $ontains vali# e:e$uta le $o#e)
26 - 6ar# 4isk The stru$ture of the information store# in ea$h !6 yte for partition is sho7n in the sli#es elo7
ize
$yte $yte $yte
(escription
?;> if $ootable, ; if /ot >ead H for first bloc' in the partition ; ] B bits are sector H for first bloc' within the partition and bits 7 WC are higher bits of cylinder H 9ow ?Wbits of cylinder H for last bloc' within the partition.. 0ile ystem !(
$yte $yte
ize
$yte $yte
(escription
>ead H for last bloc' in the partition ; ] B bits are sector H for last bloc' within the partition and bits 7 WC are higher bits of cylinder H 9ow ?Wbits of cylinder H for last bloc' within the partition. .elati ve address of the boot record for the partition with respect to the first bloc' in partition in terms of 9$A address. Count of total bloc's within the partition.
The yte at the offset / in the !6 yte #ata part $ontains the file system "4 7hi$h $an have various values #epen#ing upon the type of (S in use as #es$ri e# y the sli#es elo7)
26 - 6ar# 4isk
0ile ystem !(
; X 00 for various #. . $it H (escription
;; ;5 ;6 ;8 ;A ;B 3mpty (# 56Wbit partition Deni, root Deni,"usr ) W(# 57Wbits I 86)$ ) W(# e,tended partition can manage dis's of sizes up to ?.A 2$
;7 ;C
) W(# 57Wbits 0AT JM 86)$ # "6, 50 M !nstallable file system Advanced +ni , Windows /T /T0 A!D $oot partitions A!D (ata partitions # "6 $oot )anager Win OB Win OB Win OB 0AT 86 0AT 86 0AT 57 9$A )apped 9$A )apped
;? ;O ;A ;$ ;C ;3 ;0
26 - 6ar# 4isk
*rimary *artition
W Partition #efine# in the &<, 1&aster <oot ,e$or#3 are primary partition) W 9a$h Primary Partition $ontains information a out its respe$tive ()S) W 6o7ever if only one ()S) is to e installe# then e:ten#e# partitions)
3,tended *artitions
M9*
*rimary *artition
3,tended *artition
6o7ever if a single operating system is to e kept for instan$e% then the #isk $an e #ivi#e# into primary an# e:ten#e# partitions) "nformation a out primary an# e:ten#e# partition is kept in the first physi$al lo$k) The e:ten#e# partition may again e #ivi#e# into a num er of partitions% information a out further partitions 7ill e kept in e:ten#e# partition ta le 7hi$h 7ill e the first physi$al lo$k 7ithin e:ten#e# partition 1i)e) it 7ill not the first lo$k of primary partition)3) &oreover there $an e e:ten#e# partitions 7ithin e:ten#e# partitions an# su$h that in then en# there are num er of logi$al partitions this $an go on till the last #rive num er in 4(S)
26 - 6ar# 4isk
*rimary *artition
3,tended *artition
3,tended *artition
26 - 6ar# 4isk
9ogical (rive
3,tended *artition
6ere it $an e seen that the first partition ta le maintains information a out the primary an# e:ten#e# partitions) The se$on# partition ta le similarly stores information a out a logi$al an# a e:ten#e# partition 7ithin the previous e:ten#e# partition) Similarly for ea$h su$h e:ten#e# partition there 7ill e a partition ta le that stores information a out the logi$al partition an# may also $ontain information a out any further e:ten#e# partition) "n this 7ay the partition ta les form a $hain as #epi$te# in the sli#e elo7) The last partition ta le 7ithin the $hain $ontains ?ust a single entry signifying the logi$al #rive)
26 - 6ar# 4isk
Logica" %ri&e
:>tended Partition
0000
Logica" %ri&e
00 01 C1 00 00
00 00 FF 00 00
00 0C 0F 00 00
00 A4 4A 00 00
00 FF FF 00 00
2C FF FF 00 00
44 3F 3B 00 00
E0 00 01 00 00
48 FC 0A 00 00
E0 8A 62 00 00
00 38 90 00 00
00 01 03 00 00
80 00 00 00 55
01 A5 00 00 AA
The a ove #ump sho7s the #ump of the #ata part of the first partition ta le 7hi$h has t7o !6 ytes entries% the values in the entries $an e interprete# as the values sho7n in the follo7ing sli#e)
26 - 6ar# 4isk
#irst Partition System I% ; 0c ; Windo6s # T(' !artition /L9 first ,"oc3 ; (# @o= of ,"oc3s ; 01(77afc end cy"inderD ; 10'( end sec D ; 2( indicating a L9 dis3
M !!ed1
Second Partition System I% ; 0f ; :>tended 6indo6s !artition Start ,"oc3 /re"ati&e to the start1 ; 01(77,(, ; '0-7'74. @o= of ,"oc3s ; 0(802'0a ; .848(8(0
-d 10 0 ' 00 1'A 2: 010 0 1'A 2: 011 0 1'A 2: 01$ 0 1'A 2: 01' 0 1'A 2: 014 0 1'A 2: 01# 0 1'A 2: 01/ 0 1'A 2: 01& 0 1'A 2: 010 0 1'A 2: 017 0 1'A 2: 01A 0 1'A 2: 011 0 1'A 2: 01C 0 1'A 2: 01% 0 1'A 2: 012 0 1'A 2: 018 0 1'A 2: 0$0 0 1'A 2: 0$1 0 1'A 2: 0$$ 0 1'A 2: 0$' 0 1'A 2: 0$4 0 1'A 2: 0$# 0 1'A 2: 0$/ 0 1'A 2: 0$& 0 1'A 2: 0$0 0 1'A 2: 0$7 0 1'A 2: 0$A 0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >>
00 C1 C1 00 00
00 FF FF 00 00
00 0B 05 00 00
00 59 0E 00 00
00 FF FF 00 00
00 FF FF 00 00
00 3F 3B 00 00
00 00 01 00 00
00 FC 3B 00 00
00 8A 8B 00 00
00 38 38 00 00
00 01 01 00 00
00 00 00 00 55
A6 5A 00 00 AA
6ere is the information foun# in the partition ta le of first e:ten#e# partition ta le 7hi$h implies another e:ten#e# an# a logi$al partition)
26 - 6ar# 4isk
#irst Partition System I% ; 0, ; Windo6s # T(' !artition first ,"oc3 ; ( # #irst ,"oc3 !hysica" address ; (# B 01(77,(, @o= of ,"oc3s ; 01(77afc end cy"inderD ; 10'( end sec D ; 2( indicating a L9 dis3 Second Partition System I% ; 0. ; :>tended %OS !artition Start ,"oc3 /re"ati&e to the start1 ; 01(77,(, ; '0-7'74. Start ,"oc3 /!hysica" 1 ; 01(77,(, B 01(77,(, ; '4112425 ; -082.4.0 @o= of ,"oc3s ; 01(77,(, ; '0-7'74.
-d 10 0 ' 00 1'A 2: 010 0 1'A 2: 011 0 1'A 2: 01$ 0 1'A 2: 01' 0 1'A 2: 014 0 1'A 2: 01# 0 1'A 2: 01/ 0 1'A 2: 01& 0 1'A 2: 010 0 1'A 2: 017 0 1'A 2: 01A 0 1'A 2: 011 0 1'A 2: 01C 0 1'A 2: 01% 0 1'A 2: 012 0 1'A 2: 018 0 1'A 2: 0$0 0 1'A 2: 0$1 0 1'A 2: 0$$ 0 1'A 2: 0$' 0 1'A 2: 0$4 0 1'A 2: 0$# 0 1'A 2: 0$/ 0 1'A 2: 0$& 0 1'A 2: 0$0 0 1'A 2: 0$7 0 1'A 2: 0$A 0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00 00 -00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >> >> >> >>> >> >>> >> >>
00 C1 C1 00 00
00 FF FF 00 00
00 0B 05 00 00
00 0E 4A 00 00
00 FF FF 00 00
00 FF FF 00 00
00 3F 76 00 00
00 00 02 00 00
00 FC 94 00 00
00 8A 4B 00 00
00 38 1F 00 00
00 01 01 00 00
00 00 00 00 55
5B 0F 00 00 AA
6ere is information in the partition ta le of the se$on# e:ten#e# partition that implies yet another e:ten#e# partition an# a logi$al partition 7ith the #etails sho7n in the follo7ing sli#e)
26 - 6ar# 4isk
#irst Partition System I% ; 0, ; Windo6s # T(' !artition first ,"oc3 ; ( # #irst ,"oc3 !hysica" address ; (# B 01(77,(, B1(77,(, @o= of ,"oc3s ; 01(77afc end cy"inderD ; 10'( end sec D ; 2( indicating a L9 dis3 Second Partition System I% ; 0. ; :>tended %OS !artition Start ,"oc3 /re"ati&e to the start of e>tended !artition1 ; '4112425 ; -082.4.0 Start ,"oc3 /!hysica" 1 ; 01(77,(,5 B '4112425 ; ( 8 1 915 ; 21--72'. @o= of ,"oc3s ; 11f-,8- ; 177'7170
L9 ;0 /M9*1
L9
;1(779(9
(# Logica" %ri&e
1(779(9
'4112425
@e>t Partition Ta,"e in +hain Logica" %ri&e Logica" %ri&e Logica" %ri&e :>tended Partition
'4112425
( 8 1915
8 ove sli#es sho7s the information $olle$te# as yet 7hi$h in#i$ates the logi$al #rive there starting -<8 lo$ks% the num er of lo$k % the hi##en lo$ks et$) The follo7ing sli#e sho7s the $ontents of the #ata part of partition ta le of the last e:ten#e# partition)
1'A 2: 010 0
00 0 0 00 00 00 0 0 00 00 -00 0 0 00 00 00 0 0 00 00
sPipped 13AE:02B0 13AE:02C0 13AE:02D0 13AE:02E0 13AE:02F0 00 C1 00 00 00 00 FF 00 00 00 00 07 00 00 00 00 4A 00 00 00 00 FF 00 00 00 00 FF 00 00 00 00 3F 00 00 00 00-00 00-00 00-00 00-00 00-00 00 00 00 00 00 00 55 00 00 00 00 4B 00 00 00 00 1F 00 00 00 00 01 00 00 00 00 00 00 00 55 10 00 00 00 AA ................ ...E../...UJ.... ................ ................ ..............U.
"t has ?ust one #ata entry for the logi$al #rive in#i$ating that this is the partition ta le in the $hain) The #etail of the $ontents this partition ta le are sho7n elo7)
#irst Partition System I% ; 04 ; Windo6s # T(' !artition first ,"oc3 ; (# #irst ,"oc3 !hysica" address ; (# B 01(77,(, B1(77,(, B 1(77,(, /9"oc3s in !re&ious !artions1 @o= of ,"oc3s ; 011f-,.. end cy"inderD ; 10'( end sec D ; 2( indicating a L9 dis3 Second Partition System I% ; 0 ; )nused
The follo7ing sli#e sho7s the summary of all the #ata $olle$te# as yet #epi$ting / logi$al #rives an# the num er of lo$ks 7ithin)
(#
(#
(#
(#
1(779(9
1(779(9
1(779(9
11#-98-
M9*
@u""
Dinc"ude Vdos=hQ Dinc"ude V,ios=hQ s truct % P I uns igned uns igned uns igned uns igned uns igned uns igned uns igned N da! J s truct Part:ntry I uns igned uns igned uns igned uns igned uns igned uns igned uns igned uns igned uns igned uns igned NJ
siWeJ reser&ed1J ,"oc3sJ reser&ed'J far H,ufferJ int ",a"odJ int ",ahidJ
char char char char char char char char "ong "ong
9oota,"e#"agJ Start5eadJ StartSectorJ Start+y"inderJ System I%J :nd 5ead J :nd SectorJ :nd+ y"inderJ ,s9eginJ Sect+ountJ
s truct PartTa,"e I uns igned char code T--2UJ struct Part:ntry eT-UJ uns igned int signatureJ NJ s truct % P da! J &oid *eadL9 /unsigned int dri&e, uns igned "ong int ",a"o, unsigned "ong int ",ahi, uns igned char far H ,uffer, int nsects1 I da!=",a"od ; ",a"o J da!=",ahid;",ahiJ da!=siWe;12J da!=reser&ed1;0J da!=,"oc3s;nsectsJ da!=reser&ed';0J da!=,uffer ;,ufferJ// /unsigned char far H1M0R#P/R%S,,uf1J R 5;0>-'J R%L;dri&eJ RSI;/unsigned int1Oda!J geninterru!t/0>1(1J N
&oid ?etPart /unsigned char dri&e, uns igned "ong int "o6 , unsigned "ong int high1 I struct PartTa,"e !J uns igned int Sse c, :se cJ uns igned int Scy", :cy"J uns igned "ong int 9SecJ int i J *eadL9 /dri&e,"o6 ,high, /unsigned char H1 O!,11J if /!=signature ;; 0>aa..1 I for /i;0J iV-Ji BB1 I if /!=eTiU=SystemI% Y; 01 I Ssec ; !=eTiU=StartSectorJ Ssec ; Ssec VV 'J Scy" ; !=eTiU=Start+y"inderJ H///unsigned char H1/O Scy"11B11 ; H///unsigned char H1/OSsec11B11J :sec ; !=eTiU=:ndSectorJ :sec ; :sec VV 'J :cy" ; !=eTiU=:nd+y"inderJ
H///uns igned char H1/O :cy"11B11; H///unsigned char H1/O:sec11B11J !rintf/ LStart 5ead ; Pd Mn Start Sector ; Pd Mn Start +y"inder ; PdMn :nd 5ead ; Pd Mn :nd Sector ; Pd Mn :nd +y"inder ; PdMn 9oot *ecord 6 ith res!ect to start of !artition ; P"dMn +ount of sectors from ,oot sector ; P"dMn Sys tem I%; P> L 9 /Lo6 1 ; P"dL, !=eTiU=Start5ead, !=eTiU=StartSe ctor O 0>(f, Scy",!=eTiU=:nd 5ead, !=e TiU=:ndSector O 0>(f, :cy", !=eTiU= ,s9egin, !=e TiU=Sect+ount,!=eTiU=System I%,"o6 1J if /!=eTiU=SystemI% ;; 0>0f1 ?e tPart/dri&e,"o6 B!=eTiU= ,s9egin,01J 9Sec ; !=eTiU= ,s9eginJ getch/1J N e"se !rintf /LParTition unused or un3no6nMnL1J N N e"se !rintf/L@ot a Partition Ta,"eMnL1J N
8 ove is a listing of a simple program that rea#s the partition ta le using the e:ten#e# !+6 servi$es) "t then #isplays the $ontents of the #ata part of the partition ta le rea#) .or this purpose it uses various #ata stru$tures #esigne# in refle$tion of the partition ta le an# !6 ytes #ata entries 7ithin) The program uses re$ursion an# $alls the getpart13 fun$tion re$ursively 7henever it fin#s an e:ten#e# partition to rea# the #ata 7ithin the e:ten#e# partition ta le)
The partition ta le #ata entry also stores the C6S a##ress of the starting lo$k) <ut this a##ress is left insignifi$ant if a -<8 ena le #isk is in Puestion) 6o7ever -<8 a##ress $an e use# in pla$e of the C6S a##ress% an# in $ase C6S a##ress is rePuire# it $an e $al$ulate# if the total num er of tra$ks% se$tors an# hea#s are kno7n) To get the total num er of tra$ks% se$tors an# hea# the a ove #es$ri e# servi$e $an e use#)
8 ove sli#es sho7s the stru$ture of result uffer use# y e:ten#e# !+6 servi$es) "f a e:ten#e# servi$e returns a value it 7ill e store# in the result uffer as #es$ri e# a ove)
Hinclude Ibios.hJ Hinclude Idos.hJ struct .3 +9T$+003. N unsigned int size; unsigned int infoflags; unsigned long int cylinders; unsigned long int heads; unsigned long int sectors; unsigned long int locount; unsigned long int hicount; unsigned int bytespersector; unsigned long int configptr; P rb;
&oid main/1 I c"rscr/1J R 5 ; 0>-7J R%L ; 0>70J r,=siWe ; (0J RSI ; /unsigned int1 Or,J geninterru!t /0>1(1J !rintf/L 5eads ; P"dMn Sectors ; P"dMn Trac3s/+y"inders ; P"dMn 9yte s !er sector ; PdMn 9"oc3 count Lo6 6ord ; P"dMn 9"oc3 count 5i Word ; P"dMnL, r,=heads, r,=sectors, r,=cy"inders, r,=,yte s!ersector,r,="ocount,r,=hicount1J N
The a ove program uses a ,9SU-T<U..9, #ata stru$ture in refle$tion of the result uffer #es$ri e# in previous sli#es) "t uses the interrupt !+6'/06 to get the #rive parameters an# then #isplays the re$eive# total num er of se$tors% hea#s an# $ylin#ers)
Dinc"ude V,ios=hQ Dinc"ude Vdos=hQ struct *:S)LT9)##:* I unsigned int siWeJ unsigned int infof"ags J unsigned "ong int c y"indersJ unsigned "ong int headsJ unsigned "ong int sectorsJ unsigned "ong int "ocountJ unsigned "ong int hicountJ unsigned int ,ytes!ersectorJ unsigned "ong int config!trJ N r,J &oid getdr &!aram /unsigned int dri&e, struct *:S)LT9)##:* H r,!tr1 I c"rscr/1J R 5 ; 0>-7J R%L ; dri&e J r,!tr-QsiWe ; (0J RSI ; /unsigned int1 r,!trJ geninterru!t /0>1(1J N
&oid main /1 I char stT1.UJ unsigned "ong int ",ainde>J unsigned int cy"inder, head , sector, tem!J !uts /L:nter the L9 addressL1J gets /st1J ",ainde> ; ato"/st1J getdr&!aram /0>70,Or,1J cy"inder ; ",ainde> / /r,=headsHr,=sectors1J tem! ; ",ainde> P /r,=headsHr,=sectors1J head ; tem! / r,=sectorsJ sector ; tem! P r,=sectors B 1J !rintf /L5eads ; Pd sectors ; Pd c y"inders ; PdL , head, sector, cy"inder1J N
This is also a Puite similar program only #ifferen$e is that it also translates a -<8 a##ress into C6S a##ress an# #isplays it% for this purpose it gets the #rive parameters to kno7 the total num er of hea#s% se$tors an# $ylin#ers)
C ; ;
> ; 5
5 5
; Partition Ta,"e
; 9oot 9"oc3
$oot $loc' has 9 / M ; F !f the bloc's are inde,ed from the boot bloc' such that the boot bloc' has inde, M ;,Then this inde, is called 9 /. F 9 / is relative inde, from the start of logical drive, not the physical drive.
-S; is also in#e:e# like -<8 the only #ifferen$e is that -<8 is the a##ress relative to the start of physi$al #rive 1i)e) a solute3% 7hereas -S; a##ress is the a##ress from the start of logi$al partition i)e relative)
3,ample
LS@;1 L9 ;1(779(9 @o LS@
Logica" %ri&e
Logica" %ri&e
L9 ;0
LS@;'
LS@;1 LS@;'
8s in the a ove e:ample it $an e noti$e# that the -<8 @ 0 is not the same as -S;@0) The -<8@0 lo$k is the first lo$k on #isk) >hereas ea$h logi$al partition has -S;@0 lo$k 7hi$h is the first lo$k in logi$al #rive an# is not ne$essarily the first lo$k on physi$al #rive) 8lso noti$e the hi##en lo$ks et7een the first physi$al lo$k on ea$h partition an# its first -S; lo$k) These hi##en lo$ks are not use# y the operating system for storing any kin# of #ata)
Conclusion
F 9$A is physical or absolute address. F 9 / is relative address with respect to the start of 9ogical (rive.
To un#erstan# the file systems of 4(S an# >in#o7s the a ove given #ata stru$ture shoul# e un#erstoo# 7hi$h are use# y the operating system for file management) "n the $oming le$ture these #ata stru$tures 7ill e #is$usse# in #etail)
System
0AT 0AT
9oot 9"oc3
8 ove sli#e sho7s the overall anatomy of a .8T ase# system) Starting lo$k1s3 is 'are the oot lo$k1s3% imme#iately after 7hi$h the .8T 1.ile allo$ation ta le3 starts) 8 typi$al volume 7ill $ontain t7o $opies of .8T) 8fter .8T the root #ire$tory is situate# 7hi$h $ontain information a out the files an# fol#ers in the root #ire$tory) >hole of this area $onstitutes the systems area rest of the area is use# to store user #ata an# fol#ers)
Clusters
F A cluster is a collection of contiguous bloc's. F +ser (ata is divided into clusters F /umber of bloc's within a cluster is in power of 6. F Cluster size can vary depending upon the size of the dis'. F (# has a built in limit of 56? bloc's per cluster. F $ut practically limit of 7A bloc's per cluster has been established. F We will learn more about the size of clusters, later.
<"(S parameter lo$k is a #ata stru$ture maintaine# y 4(S in the oot lo$k for ea$h #rive) The oot lo$k is typi$ally a *!2 yte lo$k 7hi$h as seen the previous sli#es is the first logi$al lo$k i)e) -S; @ 0) "t $ontains some $o#e an# #ata) The #ata part $onstitutes the <P<) 4etails for .8T !2 an# !6 are sho7n in follo7ing sli#es)
"#"$
OR!
"#1"
B* T$
"#11
OR!
"#15
OR!
Small Sectors. The number of sectors on the volume if the number fits in 14 bits 24--5-3. For volumes larger than 4--54 sectors, this field has a value of " and the 0arge Sectors field is used instead. /edia T)'e. Provides information about the media being used. A value of "#F7 indicates a hard dis(. Sectors 'er file allocation table 2FAT3. 1umber of sectors occu'ied b) each of the file allocation tables on the volume. Sectors 'er Trac(. 1umber of 6eads. 6idde n Sectors. 0arge Sectors. If the Small Sectors field is &ero, this field contains the total number of sectors in the volume. If Small Sectors is non&ero, this field contains &ero..
"#1-
B* T$
"#14
OR!
"#.8
B*T$
Ph)sical !is( 1umber. This is related to the BIOS 'h)sical dis( number. Flo'') drives are numbered starting +ith "#"" for the A dis(. Ph)sical hard dis(s are numbered starting +ith "#7". The value is t)'icall) "#7" for hard dis(s, regardless of ho+ man) 'h)sical dis( drives e#ist, because the value is onl) relevant if the device is the startu' dis(. %urrent 6ead. 1ot used b) the FAT file s)stem. 2Reserved3 Signature. /ust be either "#.;, "#.7 or "#.< in order to be recogni&ed b) indo+s. 9olume Serial 1umber. A uni:ue number that is created +hen )ou format the volume. 9olume 0abel. S)stem I!. $ither FAT1. or FAT14, de'ending on the format of the dis(.
"#."#.4
B*T$ B*T$
"#.;
8 b)tes
"#.B "#54
11 b)tes 7 b)tes
# T SiWe
0AT
0AT
.oot (ir
+ser (ata
*eser&ed 9"oc3s
The -S; of the oot lo$k is 0) The information $ontaine# 7ithin the <P< in oot lo$k $an e use# to $al$ulate the -S; of the lo$k from 7here the user #ata starts) "t $an e simply $al$ulate# y a##ing the num er of reserve# se$tor% se$tors o$$upie# y .8T $opies E num er of .8T $opies an# the the num er of lo$ks reserve# for root #ir)
The a ove sli#e sho7s the lo$ation of <P< 7ithin the oot lo$k) 8 ?ump instru$tion 1near ?ump of + ytes si=e3 is use# to ?ump to the $o#e part an# skip the #ata part so that it is not interprete# as instru$tions y the pro$essor)
1 / 1 2 & 2 8 ' 4 # 0 1 ' A 0 A 0 0 ' ' 1 0 1 ' 0 1 # / # 2 4 / 0 & & 4 8 ' 0 ' % % & 8 4 0 1 1 0 $ 2 1 C % 0 % 0 ' 2 0 & 0 / A 0 # 8 & 0 A C C & # $ 4 & # & & 4 7 & ' / 7 & ' & $ / # / 0 $ 0 / 2 / 1 0 A $ 0 4 4 # ' / 0 0 0
0 & # / 0 0 A 4 8 2 C 1 / / # & # / C 7 7 0 # / & / 8 2 0 1 8 C 2 0 1 & A / C & 8 2 & % & 4 0 & & % C % 1 7 4 # 4 / C $ 0 0 1 0 7 / 8 / 8 $ 1 0 0 4 C % 0 1 C ' / 2 & 7 & ' / 1 & $ & 0 / # / 1 $ 0 / 2 0 0 $ 0 4 8 & 8 / / # #
21 47 0$ 1$ 00 /C $0 #4
1% 1/ 07 0/ 08 77 A1 8C 0$ 82 8& 12 11 10 0' 11 $0 /0 /1 $0 02 AC 0C 00 21 1/ 12 82 8C 00 #$ 71 7$ 4$ 0A 01 14 1' 4$ 0' &/ &' /1 $0 /8 /C $0 /2 &0 &7 00 $0 #' 01 /A AA > ; ) N > 0 > > u > > C > _ > N > > t E > > 4 > > ` > > > r + > ' > > > 1 a > > a t > I r a d d r I S > > > > > N ^ = > > > > 8 > > 4 > r > 5 > L > t > > > L N V > > 8 > > > > > a ` > 6 e > / > c i
" S%!S S 9S>> > A >> >_CZ > > E> >>)>
> > J > > . > C > > L > > 8 > > a > > N r I > > > > C > > > > S > > > > ^ > r > a i m > ! > e s t e s P e ! 9 S
> ( > > = L > E > s > 8 > > > > > 0 > t > > > > > L > L > > > Z > > ( > > > > I > d % > P < s y
I>> >>V >^> >>> >2> >> >:C >>K >>V >'> 8>> >>V >>( >V> >`> >8> >>> - t> L>> >>> >>> >>L >?t >>> >>L >>> >>> >>2 >>8 >>> >p> >Z> V>> >>> >>> >>> >u> V.> ?u> uO> >In sy dis isP err ep t<e U a en an >>>
70 4' 00 0$ 00 $A $0 '$
$A 00 40 00 00 $0 $0 $0
$% 0$ 01 00 00 $0 $0 $0
&/ 01 80 00 00 $0 $0 $0
'4 01 07 00 $7 $0 4/ ''
#/ 00 00 00 21 $0 41 C7
T 1 $
8 A ' >
8 ove is the #ump of the oot lo$k for a .8T !2 system) The $ontents of the <P< $an e rea# from it the follo7ing sli#e sho7s the #etail of the information o taine# from the a ove <P<)
9ogical drive@ A ize@ 5 )b %popularly 5 )b& 9ogical sectors@ bA;h M 6??; $ytes per sector@ B56 ectors per Cluster@ 5 Cluster size@ B56 0ile system@ 0AT56 /umber of copies of 0AT@ 6 ectors per 0AT@ O tart sector for 0AT5@ reserved sectors M 5 tart sector for 0AT6@ reserved sectors Q size of 0AT M 5 Q O M5; .oot (!. ector@ reserved sectors Q 6 K %size of 0AT& M 5 Q 6 K O M 5O
.oot (!. 3ntries@ 3; M 66A ize of .oot dir @ 66A K 86 M C57? $loc's occupied by root dir M C57? " B56 M 5A 6Wnd Cluster tart ector@ root dir sectors Q size of root dir in bloc's M 5O Q 5A M 88 3nding Cluster@ 6??; W 88 " sector per cluster Q 5 M 6??;"88 Q 5 M 6?A? )edia (escriptor@ 0; >eads@ 6 >idden sectors@ ; erial1olume!(@ 6A?C7C35 1olume 9abel@
.ollo7ing is another #ump sho7ing the oot lo$k for a .8T !6 system)
&1 8C $4 1C $/ &# 00 4/ 1C %1 07 01 01 00 '0 A1 &4 2/ 01 &4 10 A0 17 11 #1 8C 84 07 2A // // #2 0% 1' #' 10 8& 0A CC &# $4 &# 0/ // 44 0% $0 &$ /% 0A &$ /# /1 /# 00 C1
0 2 1 % 0 1 0 ' / / 0 / C ' 1 0 1 ' 0 1 # / # 2 4 / 0 0 $ % & % 0 7 2 1 8 0 1 ' 2 1 8 C $ / 0 0 0 A C & $ 7 4 2 0 ' 0 1 0 1 0 8 ' $ # / / A 7 / 8 / 8 $ 1 0 0 4 C % 0 1 8 0 / A # $ 0 A / 4 $ 0 / # 4 4 / 8 & ' / # & ' 0 0 % 0
% 7 0 0 C 1 2 1 ' 1 0 0 1 0 7 0 # / & / 8 2 0 1 8 C 2 0 & 4 8 ' 0 ' % C A C 1 4 2 8 & % 0 1 0 0 # / 4 / & % 8 / 0 0 4 / % 0 1 / 2 4 8 2 0 1 7 $ 4 $ 0 A 0 1 1 4 1 ' 4 $ C ' 0 0 $ 0 # $ / 7 / 8 / 4 / 7 & $ & ' & 7 & 4 0 0 # #
21 '# 0$ '8 #1 1C 4% #4
10 &C 77 'A 0& CA &' 8& 12 11 10 0' 11 2/ 1& A/ C& A0 70 02 A0 21 ## 20 $4 80 0C C/ 00 80 // C0 8& 21 /A '' 0& 20 0$ 4$ /1 0' 41 21 $0 /# &' &4 /7 &' 88 $0 $0 /1 00 AA > > 0 > C V > > C > _ > N > _ a > ? > > > > E > 5 > > C > c > c > > > > > > a ` > > m P < a P > a t r >
> > > N . F > > > > K > V ' > > > 8 > > 8 > > 4 > > a r 7 > > t $ E > L > t > > > L > > > > > r > = L > > N > L > > > 8 > > c > > 8 + > > > > > ( > > ^ > > > r > > I > > N T
> > L r = > > > 8 > > > > > V > N r L 4 > > > > > > 8 > > > > > 8 > > 8 > > > > V ? u _ ,
'C $2 00 00 #8 A# 4# '1
I > . > V u > 8 > > > > > > 0 > t > > t > > > > G > > > > C C ` > > S > > > > u . u > C % > r m > r e P e > > > > > > C > > > > > V ` 8 > L > > > > > > V > > > N N > > > > $ V Z > > > > > > > > Z > > > > E > > > V ( > > > > t > > > > > > L > > V 8 L > > 8 > > > > > > 1 > > > > 1 > > > = > : > > s > > > > > > > > > > > > > > > ) > . > > > > > C > > > Z ' > > > 1 a > A > e s t i s > a > >
70 '0 0$ 88 0/ $C $0 '/
4% 00 00 00 00 42 $0 $0
#' 0$ 00 '8 00 48 $0 $0
44 00 80 00 00 $0 $0 $0
48 00 CC 00 $7 42 4/ ''
#' 00 00 00 '# 41 41 C7
+! - .ile System 4ata Stru$tures "" 1<oot lo$k3 .ollo7ing is the #etail of information rea# from the a ove #ump 7hi$h #es$ri es the volume in Puestion)
9ogical sectors@ M ;;;7BfBb M A5C76C $ytes per sector@ 6;;h M B56 ectors per Cluster@ ? Cluster size@ ?KB56 M A;O7 0ile system@ 0AT57 /umber of copies of 0AT@ 6 ectors per 0AT@ CC> M 6;A tart sector for 0AT5@ reserved bloc's M ? tart sector for 0AT6@ reserved bloc's Q bloc's per 0AT M ? Q CC> M (A M 656 .oot (!. ector@ reserved bloc's Q 6K%size of 0AT& M ? Q6KCC M 5A; M A57 .oot (!. 3ntries@ 6;;> M B56 ize of .oot (ir B56 K 86 M 578?A M 86 bloc's
ize of .oot (ir B56 K 86 M 578?A M 86 bloc's 6Wnd Cluster tart ector@ root dir start bloc's Q bloc's in root dir M 5A; Q 6;> M A57 Q 86 M AA? 3nding Cluster@ %%logical bloc's W start of user data bloc's&"bloc's per cluster& Q 5 M% A5C76C W AA? &"? Q 5 M B65A? )edia (escriptor@ 0? >eads@ 6BB >idden sectors@ 78 erial1olume!(@ 6CAB$C8B 1olume 9abel@ /# /A)3
<esi#es the -<8 a##ress a -S; a##ress $an also e use# to a##ress a lo$k) "f the -S; a##ress is kno7n the a srea#13 fun$tion $an e use# to rea# a lo$k an# a s7rite13 $an e use# to 7rite on it as #es$ri e# in the sli#e elo7 7here nse$t is the num er of se$tor to e rea#'7ritten)
The 4P< $ontains the information sho7n in the ta le elo7) This information $an e #erive# from the <P< ut is pla$e# in memory in the form of 4P<)
1Fh
OR!
The follo7ing $o#e sho7s ho7 the servi$e 2!6'+26 is invoke# an# the registers in 7hi$h it returns a value) "t also sho7s the $ontents of the 4P< y taking the #ump at the lo$ation returne# y the servi$e for a .8T !2 volume 1i)e) .loppy #isk3)
-5 13A6:0100 Ao7 58#32 13A6:0102 :n" 21 13A6:0104 -< AKL3200 BKL0000 DML13A6 EML13A6 13A6:0102 CD21 -< AKL3200 BKL13D2 DML00A7 EML13A6 13A6:0104 D3E3 -; 57:13;2 00A7:13D0 00A7:13E0 00A7:13F0 00A7:1400 00A7:1410 00A7:1420 00A7:1430 00A7:1440 00A7:1450 00 00 06 00 00 00 00 4D 00 13 00 00 00 00 00 5A 00 00 00 00 00 00 00 9A 02 56 00 00 00 00 00 00 00 34 00 00 00 00 00 29 00-01 12-00 00-00 00-00 00-00 00-00 0C-00 00-00 00 F0 00 00 00 00 00 00 02 0A 00 00 00 00 80 20 E0 FF 00 00 00 00 00 00 00 FF 00 00 00 00 B0 C5 21 FF 00 00 00 00 13 00 00 FF 00 00 00 00 10 FF 20 00 00 00 00 00 00 FF ...........*. .....)4......... ................ ................ ................ ................ ................ ..BH..P... ..... ..
0B 00 00 00 00 00 D8 A7
09 C9 00 00 00 00 12 05
The #etails of the information rea# from the #ump of the 4P< are sho7n elo7)
(rive H M ; unit H M ; $ytes per sector M ;6;;> M B56 bytes highest sec no within a cluster M ; hift count to convert sec to clust M ; .eserved sectors at the begining of drive M ;;;5 0AT copies M ;6 .oot directory entries M 3; M 66A 0irst sector containing user data M 65> M 88 >ighest cluster number M ;b6; M 6?A? /umber of sectors per fat M ;;;O M O ector number of first directory M ;;58 M 5O
The follo7ing $o#e sho7s ho7 the servi$e 2!6'+26 is invoke# an# the registers in 7hi$h it returns a value) "t also sho7s the $ontents of the 4P< y taking the #ump at the lo$ation returne# y the servi$e for a .8T !6 volume 1i)e) har# #isk partition smaller than 2 F< appro:)3)
-5 13A6:0100 Ao7 58#32 13A6:0102 :n" 21 13A6:0104 -< AKL3200 BKL0000 DML13A6 EML13A6 13A6:0102 CD21 -< AKL3200 BKL13D2 DML00A7 EML13A6 13A6:0104 0000 -; 57:13;2 00A7:13D0 00A7:13E0 00A7:13F0 00A7:1400 00A7:1410 00A7:1420 00A7:1430 00A7:1440 00A7:1450 05 00 CB 00 00 00 00 4D 05 A0 00 00 00 00 00 5A 00 01 00 00 00 00 00 9A 02 56 00 00 00 00 00 00 07 34 00 00 00 00 00 29 03-08 12-00 00-00 00-00 00-00 00-00 0C-00 00-00 00 F8 00 00 00 00 00 00 02 0A 00 00 00 00 80 20 00 FF 00 00 00 00 00 00 02 FF 00 00 00 00 B0 C5 C0 FF 00 00 00 00 13 00 01 FF 00 00 00 00 10 FF B4 00 00 00 00 00 00 FF .............. .....)4......... ................ ................ ................ ................ ................ ..BH..P... ..... ..
CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P2 %C ADD IBK4M!Q#AN DM:13D2L05
CB 00 00 00 00 00 D8 A7
CC AA 00 00 00 00 12 05
+2 - .ile System 4ata Stru$tures """ 14P<3 The #etails of the information rea# from the #ump of the 4P< are sho7n elo7)
drive no M ;B M 0 drive unit no M ;B bytes per sector M 6;;> M B56 >ighest sector number within a cluster M C >ence ec. per cluster M highest sec. within a cluster Q 5 M C Q 5 M ? shift count M 8 reserved sectors M ;;;? /umber of 0ats M 6 .oot (ir 3ntries M ;6;;> M B56 0irst sector containing user data M ;5C; M AA? >ighest cluster number M cbbA> M B65A? /o of sectors per 0AT M CC M 6;A ector number of 0irst directory M ;5A; M A57
Dinc"ude V,ios=hQ Dinc"ude Vdos=hQ struct 9P9 I unsigned int ,ytes!ersecJ unsigned char sec!erc"ustJ unsigned int reser&edsecsJ unsigned char fatsJ unsigned int rootdirentsJ unsigned int sma""secsJ unsigned char mediaJ unsigned int fatsecsJ unsigned int secs!ertrac3J unsigned int headsJ
unsigned "ong int hiddensecsJ unsigned "ong int hugesecsJ unsigned char dri&enoJ unsigned char reser&edJ unsigned char ,ootsignatureJ unsigned "ong int &o"umeidJ unsigned char &o"ume"a,e"T11UJ unsigned char fi"esystemT7UJ NJ struct ,oot,"oc3 I unsigned char Sum!instructionT(UJ unsigned char osnameT7UJ struct 9P9 ,!,J unsigned char codeT--7UJ NJ
&oid n!uts/ char H!, int n1 I int i J for /i ;0JiVnJiBB1 !utch/!TiU1J N &oid main/ &oid1 I struct ,oot,"oc3 ,,J c"rscr/1J a,sread/0,1,0,O,,1J !rintf/LSum! instruction ; P >MnL , ,,=Sum!instruction1J !rintf/LOS ; L1J n!uts /,,=osname,71J !uts/LMnL1J
!rintf/L@o of ,ytes !er sector ; P d Mn@o of sectors !er c"uster ; P dMn @o of reser&ed sectors ; PdL , ,,=,!,=,ytes!ersec, ,,=,!,=sec!erc"ust, ,,=,!,=reser&edsecs1J !rintf/L@o of # Ts ; P dMn@o of *oot %irectory entry ; P d Mn@o of Sma"" sectors ; P d MnMedia descri!tor ; P >5 Mn# T sectors ; PdSectors !er trac3 ; P d Mn@o of 5eads ; Pd Mn@o of hidden sectors ; P "d Mn@o= of huge sectors ; P "d Mn%ri&e num,er ; P > Mn*eser&ed ; P >5 Mn9oot Signature ; P >5 Mn$o"ume I% ; P "> MnL , ,,=,!,=fats, ,,=,!,=rootdirents, ,,=,!,=sma""secs, ,,=,!,=media, ,,=,!,=fatsecs, ,,=,!,=secs!ertrac3, ,,=,!,=heads, ,,=,!,=hiddensecs, ,,=,!,=hugesecs, ,,=,!,=dri&eno, ,,=,!,=reser&ed, ,,=,!,=,ootsignature,,,=,!,=&o"umeid1J
!uts /L $o"ume @ame ;L1J n!uts /,,=,!,=&o"ume"a,e",111J !uts /LMnL1J !uts /L #i"e system ;L1J n!uts /,,=,!,=fi"esystem,71J !uts/LMnL1J getch/1J N
The a ove program $reates a #ata stru$ture in refle$tion of the <P< an# rea#s the oot re$or# of the volume using a srea#13) "t e:tra$ts the #ata part of the oot lo$k an# #isplays all the values store# in it)
Dinc"ude Vdos=hQ Dinc"ude V,ios=hQ struct %P9 I unsigned char dri&enoJ unsigned char unitnoJ unsigned int ,ytes!ersecJ unsigned char highestsecinc"ustJ unsigned char shiftcountJ unsigned int reser&edsecsJ unsigned char fatsJ unsigned int rootentriesJ unsigned int firstuserdatasecJ unsigned int highestc"ustnum,erJ //on"y for 12 and 1' ,it # Ts unsigned int secs!erfatJ unsigned int firstdirsecJ unsigned int ddheaderoffJ unsigned int ddheadersegJ
unsigned char mediaJ unsigned char accessedJ unsigned int ne>td!,offJ unsigned int ne>td!,segJ unsigned int searchstartJ unsigned int freec"ustJ NJ &oid main /&oid1 I struct %P9 far H!trJ struct %P9 d!,J c"rscr/1J Rasm !ush %SJ Rasm !ush 9AJ R 5;0>('J R%L;1J geninterru!t /0>'11J
!tr ; /struct %P9 far H1M0R#P/R%S,R9A1J d!,;H!trJ Rasm !o! 9AJ Rasm !o! %SJ !rintf/L%ri&e @o ; P>MnL,d!,=dri&eno1J !rintf/L)nit @o ; P>MnL,d!,=unitno1J !rintf/L9ytes !er sector ; PdMnL,d!,=,ytes!ersec1J !rintf/L5ighest sector num,er 6ithin a c"uster ; PdMnL,d!,=highestsecinc"ust1J !rintf/LShift +ount ; PdMnL,d!,=shiftcount1J !rintf/L*eser&ed sectors ; PdMnL,d!,=reser&edsecs1J !rintf/Lnum,er of # Ts ; PdMnL,d!,=fats1J !rintf/L*oot enteries ; PdMnL,d!,=rootentries1J !rintf/L#irst )ser data sec ; PdMnL,d!,=firstuserdatasec1J !rintf/L5ighest +"uster num,er ; PdMnL,d!,=highestc"ustnum,er1J !rintf/L@o of Sectors !er # T ; PdMnL,d!,=secs!erfat1J !rintf/L#irst directory Sector ; PdMnL,d!,=firstdirsec1J
!rintf/L%% header offset ; P>MnL,d!,=ddheaderoff1J !rintf/L%% header segment ; P>MnL,d!,=ddheaderseg1J !rintf/LMedia I%; PdMnL,d!,=media1J !rintf/L%is3 accessed recent"y; PdMnL,d!,=accessed1J !rintf/L@e>t %P9 offset address ; PdMnL,d!,=ne>td!,off1J !rintf/L@e>t %P9 segment address ; PdMnL,d!,=ne>td!,seg1J !rintf/LPoint 6here to start the search for ne>t c"uster; PdMnL,d!,=searchstart1J !rintf/L#ree c"uster; PdMnL,d!,=freec"ust1J getch/1J N
The a ove program is #oing is the same using the 4P< rather than <P<)
root
The 4(S #ire$tory stru$ture is a Tree like stru$ture) The top most level of the tree eing the root #ire$tory) The root #ire$tory $ontains files an# fol#ers) 9a$h fol#er $an $ontains more files an# fol#ers an# so on it $ontinues re$ursively as sho7n y the sli#e)
0ile
F !s logically viewed as an organization of (ata. F *hysically it can be a collection of clusters or bloc's. F #. . needs to maintain information about the cluster numbers of which a file may be comprised of.
Control information a out files are maintaine# in a #ata stru$ture $alle# the .ile $ontrol lo$k 1.C<3) The .C< for ea$h file is $reate# an# store# in the #isk)
The root #ire$tory $onsists of .C<s for all the files an# fol#ers store# on the root #ire$tory) To o tain these .C<s% the portion on #isk reserve# for root #ire$tory $an e rea#)
0AT
0AT
.oot (ir
+ser (ata
9oot 9"oc3
0B 00 00 00 00 00 DF A7
09 C8 00 00 00 00 12 05
00 00 06 00 00 00 00 4D
00 13 00 00 00 00 00 5A
00 00 00 00 00 00 00 9A
02 56 00 00 00 00 00 00
00 34 00 00 00 00 00 29
00 F0 00 00 00 00 00 00
02 0A 00 00 00 00 80 20
E0 FF 00 00 00 00 00 00
00 FF 00 00 00 00 B7 C5
21 FF 00 00 00 00 13 00
00 FF 00 00 00 00 10 FF
20 00 00 00 00 00 00 FF
"n the a ove t7o sli#es first the $ontents of 4P< are rea# to fin# the start of the root #ire$tory) Using this lo$k num er the $ontents of root #ire$tory are rea#% as it $an e seen they $ontain num er of .C<s ea$h $ontaining information a out a file 7ithin the #ire$tory) The user #ata area is #ivi#e# into $lusters) The first $luster in user #ata area is num ere# 2 in a .8T ase# systems) 8 $luster is not the same as lo$k an# also there are no system $alls availa le 7hi$h use the $luster num er) 8ll the system $alls use the -S; a##ress) "f the $luster num er is kno7n it shoul# e $onverte# into -S; to a$$ess the lo$ks 7ithin the $luster) &oreover all the information a out file management uses the $luster num er
+2 - .ile System 4ata Stru$tures """ 14P<3 rather than the -S; for simpli$ity an# for the purpose of managing large #isk spa$e) So here 7e #evise a formula to $onvert the $luster num er into -S;)
0AT 0AT
*e ser&ed 9"oc3
*oot %irectory
)ser %ata
using the information the a ove sli#e the follo7ing formula $an e #evise# as sho7n in the sli#e elo7 to $onvert the $luster num er into -S;)
/o. of ystem Area $loc's M .eserved $loc' Q ector per 0AT K /o. of 0AT-s Q /o. of entries K 86 " $ytes per $loc' 0irst +ser $loc' /o. M /o. of ystem Area $loc's ector /o. M %ClustYno ] 6&K $loc's per Clust Q 0irst +ser $loc' H
The follo7ing memory #ump e:tra$ts the starting $luster num er from the .C< of a file an# then $onverts the $luster num er in se$tor to get its starting lo$k)
#i"e +ontents ;
F:9> C9 &">, - L 45 F:9> M"5," M>C"o, - L S45 Y 2 P'1 4 21D L 69D
The $ontents of the lo$ks'$luster at the start of file are then e:amine# y loa#ing the se$tors 7ithin the first $luster to that file in the follo7ing sli#e) 6ere the $ontents of the file $an e seen on the right si#e $olumn)
Cluster (ump
-9 1000 0 69 1 -; 1000 13AD:1000 13AD:1010 13AD:1020 13AD:1030 13AD:1040 13AD:1050 13AD:1060 13AD:1070 -q 74 69 65 2E 00 00 00 00 68 6C 20 00 00 00 00 00 69 65 73 00 00 00 00 00 73 20 6F 00 00 00 00 00 20 75 6D 00 00 00 00 00 69 73 65 00 00 00 00 00 73 65 20 00 00 00 00 00 20-61 64-20 74-65 00-00 00-00 00-00 00-00 00-00 20 74 73 00 00 00 00 00 74 6F 74 00 00 00 00 00 65 20 20 00 00 00 00 00 78 73 74 00 00 00 00 00 74 74 65 00 00 00 00 00 20 6F 78 00 00 00 00 00 66 72 74 00 00 00 00 00 "8:& :& 5 ">T" f :9> &>; "o &"o, > &oA> ">&" ">T" ................ ................ ................ ................ ................
+2 - .ile System 4ata Stru$tures """ 14P<3 6ere is another e:ample using a .8T !6 system)
CB 00 00 00 00 00 DF A7
CC 98 00 00 00 00 12 05
05 00 CB 00 00 00 00 4D
05 A0 00 00 00 00 00 5A
00 01 00 00 00 00 00 9A
02 56 00 00 00 00 00 00
07 34 00 00 00 00 00 29
00 F8 00 00 00 00 00 00
02 0A 00 00 00 00 80 20
00 FF 00 00 00 00 00 00
02 FF 00 00 00 00 B7 C5
C0 FF 00 00 00 00 13 00
01 FF 00 00 00 00 10 FF
B4 00 00 00 00 00 00 FF
CB 00 00 00 00 00 DF A7
CC 98 00 00 00 00 12 05
05 00 CB 00 00 00 00 4D
05 A0 00 00 00 00 00 5A
00 01 00 00 00 00 00 9A
02 56 00 00 00 00 00 00
07 34 00 00 00 00 00 29
00 F8 00 00 00 00 00 00
02 0A 00 00 00 00 80 20
00 FF 00 00 00 00 00 00
02 FF 00 00 00 00 B7 C5
C0 FF 00 00 00 00 13 00
01 FF 00 00 00 00 10 FF
B4 00 00 00 00 00 00 FF
(n$e the 4P< has een rea# the lo$ks reserve# for root #ire$tory are #etermine# an# are then rea# to get the $ontents of the root #ire$tory)
(irectory (ump
-9 1000 5 150 20 -; 1000 4000
13AD:100 0 13AD:101 0 13AD:102 0 13AD:103 0 13AD:104 0 13AD:105 0 13AD:106 0 13AD:107 0 13AD:108 0 13AD:109 0 13AD:10A 0 13AD:10B 0 13AD:10C 0 13AD:10D 0 4E 00 41 65 52 2F 42 6D 01 20 53 2F 41 78 45 00 52 00 45 33 20 00 53 00 59 33 64 00 57 00 00 64 43 2F 00 61 00 56 53 2F 00 74 20 00 65 00 59 33 49 00 79 00 54 33 50 00 56 00 00 00 43 00 00 74 00 6F 45 00 00 00 4F 00 63 00 4C 00 6E 00 73 00 4D 00 62 00 4C 61 00 FF 45 7A 00 69 00 6C 7E 7A 00 FF 55-4D 76-2D 79-00 FF-FF 44-20 5E-2F 66-00 00-6F 74-00 00-75 31-20 5E-2F 31-00 FF-FF 45 33 63 FF 20 33 6F 00 65 00 20 33 2E FF 20 00 00 00 20 02 00 00 00 00 20 03 00 00 08 00 0F 00 16 00 0F 00 0F 00 16 00 0F 00 00 00 00 FF 00 00 00 6E 00 6D 00 00 00 FF 00 00 21 FF 4E 00 72 00 72 00 4E 00 6A FF 00 00 6C FF 79 00 72 00 6D 65 79 00 74 FF 00 00 00 FF 5E 00 00 00 00 00 5E 00 00 FF % EW )2N UBE .. ... . .....5 7-3... ... A U.>.C. @.C... *9. > .;.... ...... ... U ECGCNE D .. %@Z [ 3[3..\ Z[3... ... B .!.n. f.o... ,,. A .5.".: .o...n ... . M.@.&. ".>... ,A. .).o.9 . ...A .>. M GMOEB( 1 .. %@Z [ 3[3..\ Z[3... ... A ;.P.=. 1..... 6". T .".... ...... ...
44 36 44 36 46 3C 53 3C
50 33 50 33 49 33 45 33
42 36 42 36 52 3C 43 3C
31 33 32 33 53 33 4F 33
20 00 20 00 54 00 4E 00
20 00 20 00 20 00 44 00
20 07 20 03 20 EE 20 F0
58 33 58 33 20 33 20 33
54 0A 54 0B 20 0C 20 12
20 00 20 00 10 00 10 00
00 8A 18 5F 08 00 08 00
57 06 12 06 6F 00 50 00
81 00 AE 00 ED 00 EF 00
69 00 69 00 56 00 56 00
DPB1 OKO .W.: 6363...T63...... DPB2 OKO ...: 6363... 63..R... F!UMO ..o.) $3$3...)$3...... MEC2%D ..P.) $3$3...)$3......
The root #ire$tory $ontains a $olle$tion of .C<s) The .C< for the file in Puestion is sear$he# from 7here the first $luster of the file $an e get)
Contc
13AD:12C0 13AD:12D0 13AD:12E0 13AD:12F0 13AD:1300 13AD:1310 13AD:1320 13AD:1330 13AD:1340 13AD:1350 F:9> F:9> F:9> F:9> 43 3C E5 78 E5 78 E5 3C 54 3C 50 33 6D 00 4E 00 45 33 45 33 41 3C 00 74 00 74 57 3C 53 3C 50 33 65 00 65 00 54 33 54 33 45 00 00 00 00 20 45 00 20 00 52 00 6E 00 77 00 58 00 20 00 20 60 00 FF 00 44 7E 0A 20 17 20-54 05-72 74-00 FF-FF 20-00 00-6F 31-54 73-3C 20-54 73-3C 58 28 2E FF 54 00 58 33 58 33 54 29 00 00 00 00 54 00 54 45 20 00 0F 00 0F 00 20 00 20 00 00 4F 00 FF 00 63 00 00 18 27 9D 8F 9F FF 9F 00 32 00 32 00 7D 00 74 FF 65 75 09 00 09 00 6F 00 00 FF 00 00 73 00 73 00 CPAPEU OKO ..+o $3$3..3.,SP.2... .A.>.n."......". T."............. .%.>.0. .O....>. T.". .D.o...C. . .EWOEK(1OKO .2.& $3$3...&$3...... OEMO OKO .2.& $3$3...&$3E.]...
Con">n"& M:\> L 39D L27D C9 &">, - L 45D M>C - L S45D Y 2 P'8 4 01C0 L 3D8D
8fter $al$ulating the se$tor num er for the $luster the $ontents of the file $an e a$$esse# y rea#ing all the lo$ks 7ithin the $luster) "n this 7ay only the starting $luster 7ill e rea#) "f the file $ontains a num er of $luster the su sePuent $lusters num ers 7ithin the file $hain $an e a$$esse# from the .8T)
0ile (ump
-9 1000 5 3;8 8 -; 1000 13AD:1000 13AD:1010 13AD:1020 13AD:1030 13AD:1040 13AD:1050 13AD:1060 13AD:1070 -q 74 65 62 00 00 00 00 00 68 78 69 00 00 00 00 00 69 74 74 00 00 00 00 00 73 20 20 00 00 00 00 00 20 66 46 00 00 00 00 00 69 69 41 00 00 00 00 00 73 6C 54 00 00 00 00 00 20-61 65-20 00-00 00-00 00-00 00-00 00-00 00-00 20 66 00 00 00 00 00 00 74 6F 00 00 00 00 00 00 65 72 00 00 00 00 00 00 73 20 00 00 00 00 00 00 74 31 00 00 00 00 00 00 20 36 00 00 00 00 00 00 74 20 00 00 00 00 00 00 "8:& :& 5 ">&" " >T" f:9> fo, 16 =:" FAO......... ................ ................ ................ ................ ................
0AT56
F 0AT is a simple table which contains cluster number of each file. F 0AT56 will have 56Wbit wide entries and can have 6`56 entries ma,imum. F Although some of these entries may be reserved.
0ile #rganization
56 ] bit ; . . 5 6 8 C A B ; 7 55 C O
0C$
Start +"uster D
Contc
? O 5; 55 7 3#0
6`56
8 ove sli#es sho7 ho7 a $luster $hain for a file is maintaine# in the .8T) The first $luster num er is in the .C<) Su sePuent $lusters 7ill e a$$esse# from the .8T using the previous $luster num er as in#e: to look up into the .8T for the ne:t $luster num er) 8 .8T theoreti$ally 7ill $ontain 2n entries 7here n is !2 for .8T !2 an# !6 for .8T!6) <ut all the entries are not use# some of the entries are reserve# follo7ing sli#e sho7s its #etail)
There $an various volume 7ith various si=es 7ith .8T!2 or .8T!6) The num er of entries for .8T !2 or .8T!6 are limite# then the Puestion arises ho7 $an a $ertain volume 7ith mo#erate spa$e an# another volume 7ith large spa$e $an e manage# y the same .8T system) The ans7er is that the num er of entries might e same ut the si=e of $luster may e #ifferent) The $luster si=e $an vary from *!2 ytes to +22 in po7ers of 2 #epen#ing upon the volume si=e) The a ove sli#e sho7s ho7 the $luster si=e an# the e:a$t num er of rePuire# .8T entries $an e #etermine#)
3,ample
?Bh 75h 5?h
5?Ah K 8 " 6 M
6A7h
Contents of (*$
-5 13A6:0100 Ao7 58#32 13A6:0102 :n" 21 13A6:0104 -< AKL3200 BKL0000 DML13A6 EML13A6 13A6:0102 CD21 -< AKL3200 BKL13D2 DML00A7 EML13A6 13A6:0104 0000 DM:13D2L00 -; 57:13;2 00A7:13D0 00A7:13E0 00A7:13F0 00A7:1400 00A7:1410 00A7:1420 00A7:1430 00A7:1440 00A7:1450 00 00 0A 00 00 00 00 4D 00 13 00 00 00 00 00 5A 00 00 00 00 00 00 00 9A 02 56 00 00 00 00 00 00 00 34 00 00 00 00 00 29 00-01 12-00 00-00 00-00 00-00 00-00 0C-00 00-00 00 F0 00 00 00 00 00 00 02 0A 00 00 00 00 80 20 E0 FF 00 00 00 00 00 00 00 FF 00 00 00 00 B0 C5 21 FF 00 00 00 00 13 00 00 FF 00 00 00 00 10 FF 20 00 00 00 00 00 00 FF ...........*. .....)4......... ................ ................ ................ ................ ................ ..BH..P... ..... ..
CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P2 %C ADD IBK4M!Q#AN
0B 00 00 00 00 00 D8 A7
09 CF 00 00 00 00 12 05
43 3C 44 3D 44 3D
50 33 50 33 44 33
41 3D 42 3D 20 3D
50 33 44 33 20 33
45 00 55 00 20 00
52 00 4D 00 20 00
20 43 50 02 20 3B
58 33 58 33 58 33
54 93 54 02 54 05
20 00 20 00 20 00
00 54 18 C4 18 0E
BB 0B 72 04 A4 00
19 00 EC 00 13 00
70 00 64 00 65 00
CPAPEU OKO ...< $3L3..CWL3..O... DPBDUBP OKO .,.; L3L3...>L3...... DD OKO ...> L3L3..F>L3......
6ere a familiar operation has een performe#) 8fter rea#ing the 4P< the root #ire$tory is rea# to sear$h for the entry of file CP8P9,)TNT)
.ollo7ing sli#e sho7s the #ump for the .8T!2 for the parti$ular volume)
Contents of 0AT
-9 1000 0 1 9 -; 1000 2200 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 13A6:1080 13A6:1090 13A6:10A0 13A6:10B0 13A6:10C0 13A6:10D0 13A6:10E0 F0 C0 01 21 C0 03 41 CF 05 61 C0 07 81 C0 09 FF 00 17 20 02 37 20 04 57 20 06 77 20 08 97 FF 0D 80 02 2D 80 04 4D 80 06 6D 80 08 8D 80 03 E0 01 23 E0 03 43 E0 05 63 E0 07 83 E0 09 40 00 19 40 02 39 40 04 59 40 06 79 40 08 FF 00 0F A0 02 2F A0 04 4F A0 06 6F A0 08 8F AF FF 00 01 25 00 03 45 00 05 65 00 07 85 00 09 6F-00 01-11 1B-C0 60-02 03-31 3B-C0 90-09 05-51 5B-C0 60-06 07-71 7B-C0 60-08 09-FF 9B-C0 07 20 01 27 20 03 00 20 05 67 20 07 87 2F 09 80 01 1D 80 03 3D 00 05 5D 80 07 7D 80 09 9D 00 13 E0 02 33 E0 00 53 E0 06 73 E0 08 FF F0 09 40 01 29 40 03 00 40 05 69 40 07 89 4F FF A0 01 1F A0 03 3F 00 05 5F A0 07 7F A0 09 FF 00 15 00 02 35 00 00 55 00 06 75 00 08 95 0F 0B 60 02 2B 60 04 FF 60 06 6B 60 08 8B 60 00 ...._..o........ ......... .._..3 ................ * .-_.X3.]..P..4 ..-..[..1 .3_.53 .7..9..F..L../.. A .C_.E......... ..B..2..1 .M_.U3 .W..G..I..Q..R.. 5 .C_.>3.?..:..` ..A..o..q .&_. 3 .0..@..^..+..... . .._..3........ .........[..2..3 ................
Using the root #ire$tory entry an# the .8T $ontents the $ontents of the file $an e a$$esse#)
Contents of 0!93
-9 1000 0 =2 1 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 -9 1000 =3 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 0D 64 6F 3A 0A 70 2C 0D 0A 20 66 0D 09 72 20 0A 0D 62 20 0A 69 69 61 41 0A 65 74 0D 6E 6E 2C 6E 31 20 68 0A 74 74 20 73 2E 74 65 6D 20 66 26 2E 20 68 20 61 61 20 61 0D 57-68 65-20 66-6F 69-6E 5B-31 28-20 20-29 0A-09 61 6F 6C 28 30 22 20 49 74 75 6C 20 5D 25 3B 66 20 74 6F 29 20 75 0D 20 77 70 77 0D 3B 20 0A 74 6F 75 69 0A 0D 25 7D 68 75 74 6E 7B 0A 75 0D 65 6C 20 67 0D 09 22 0A 20 ....1. W85" 0o 9 ; => "8> o "< " of "8> fo99o0:n? :....A5:nS P..^. ..:n" 5I10Q F... <,:n"f S VX X V # 5# W5 P F..+.. ..An&....!f "8> 0D 64 6F 3A 0A 70 2C 0D 1 0A 20 66 0D 09 72 20 0A 0D 62 20 0A 69 69 61 41 0A 65 74 0D 6E 6E 2C 6E 31 20 68 0A 74 74 20 73 2E 74 65 6D 20 66 26 2E 20 68 20 61 61 20 61 0D 57-68 65-20 66-6F 69-6E 5B-31 28-20 20-29 0A-09 61 6F 6C 28 30 22 20 49 74 75 6C 20 5D 25 3B 66 20 74 6F 29 20 75 0D 20 77 70 77 0D 3B 20 0A 74 6F 75 69 0A 0D 25 7D 68 75 74 6E 7B 0A 75 0D 65 6C 20 67 0D 09 22 0A 20 ....1. W85" 0o 9 ; => "8> o "< " of "8> fo99o0:n? :....A5:nS P..^. ..:n" 5I10Q F... <,:n"f S VX X V # 5# W5 P F..+.. ..An&....!f "8>
Contc
-9 1000 0 =4 1 -; 1000 13A6:1000 65 20 13A6:1010 64 20 13A6:1020 65 6E 13A6:1030 72 20 13A6:1040 2D 2D 13A6:1050 2D 2D 13A6:1060 2D 2D 13A6:1070 2D 2D -9 1000 0 =5 1 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 6E 20 6E 65 68 20 61 61 67 6E 6F 72 69 62 74 74 20 6F 72 6D 73 65 69 6F 70 74 6D 69 20 63 6E 72 6F 20 61 6E 65 61 67 20 69 6C 6C 61 72 75 20 69 6E 69 20 74 72 73 70 73 74-20 6E-6B 70-72 69-6F 6F-72 65-20 6F-69 20-6E 66 65 6F 6E 20 74 6E 6F 6F 64 67 0D 6F 68 74 74 72 0D 72 0A 63 65 20 20 6D 0A 61 0D 63 20 65 69 61 09 6D 0A 75 66 6D 6E 74 41 20 09 72 6C 75 69 73 62 74 54 73 6F 6C 74 n? <o:n" fo,A5"& no" 9:n`>;...A= no,A59 <,o?,5A " >,A:n5":on.....O 8:& >,,o, oCC ,& =>C5 &> "8> f9o 5":n? <o:n" >A 9 5"o, :& no" :n:" 69 62 63 45 2D 2D 2D 2D 73 79 65 72 2D 2D 2D 2D 20 20 20 72 2D 2D 2D 2D 6E 23 74 6F 2D 2D 2D 2D 6F 69 68 72 2D 2D 2D 2D 74-20 6E-63 65-0D 2E-0D 2D-2D 2D-2D 2D-2D 2D-2D 69 6C 0A 0A 2D 2D 2D 2D 6E 75 09 2D 2D 2D 2D 2D 63 64 4C 2D 2D 2D 2D 2D 6C 65 69 2D 2D 2D 2D 2D 75 2C 6E 2D 2D 2D 2D 2D 64 20 6B 2D 2D 2D 2D 2D 65 68 65 2D 2D 2D 2D 2D > :& no" :nC9 ;> ; =@ -:nC9 ;># 8 >nC> "8>...N:n`> , E,,o,...------------------------------------------------------------------
Contc
-9 1000 0 =6 1 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 -q 74 0D 6E 2C 20 30 20 20 68 0A 74 20 32 20 22 31 65 6D 20 32 2C 7D 5C 2C 20 61 61 2C 20 20 6E 20 66 69 5B 20 31 3B 20 26 6F 6E 33 33 2C 0D 25 61 6C 28 5D 2C 20 0A 75 20 6C-6F 20-29 5B-34 20-34 37-2C 09-70 20-25 2B-20 77 0D 5D 2C 20 72 75 31 69 0A 20 20 38 69 22 20 6E 7B 3D 34 2C 6E 2C 29 67 0D 20 2C 20 74 20 20 3A 0A 7B 20 39 66 61 3B 0D 09 20 33 2C 20 20 0D 0A 69 31 2C 20 28 2B 0A "8> fo99o0:n?:.. ..A5:nS P..^...: n" 5I3QI4Q L ^ 1 # 2# 3# 4# 4# 3# 2# 1# 7# 8# 9# 0 + F...<,:n"f S V\n X X V# 5 4 1# W5 4 1 P F..
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 .ollo7ing sli#e sho7s the file organi=ation in a .8T!6 system) The starting $luster num er is the .C< entry an# the su sePuent $lusters $an e #etermine# y traversing the $hain for that file in the .8T!6 #ata stru$ture)
0ile #rganization
57 ] bit . . 5 6 8 C A B ; 7 55 C O ;
0C$
Start +"uster D
Contc
? O 5; 55 7 3#0
6`57
;ot all the entries in .8T!6 7ill e use#% the follo7ing sho7s 7hi$h ones of the entry are reserve#)
The follo7ing sli#e sho7s the $ontent of the 4P< for a .8T!6 volume) Same int 2!h'+26 is use# to #etermine its a##ress an# the parameters $an e #etermine# y taking #ump of the memory at the a##ress returne#)
Contents of (*$
-5 13A6:0100 Ao7 58#32 13A6:0102 :n" 21 13A6:0104 -< AKL3200 BKL0000 DML13A6 EML13A6 13A6:0102 CD21 -< AKL3200 BKL13D2 DML00A7 EML13A6 13A6:0104 D3E3 -; 57:13;2 00A7:13D0 00A7:13E0 00A7:13F0 00A7:1400 00A7:1410 00A7:1420 00A7:1430 00A7:1440 00A7:1450 -q 05 00 CB 00 00 00 00 4D 05 A0 00 00 00 00 00 5A 00 01 00 00 00 00 00 9A 02 56 00 00 00 00 00 00 07 34 00 00 00 00 00 29 03-08 12-00 00-00 00-00 00-00 00-00 0C-00 00-00 00 F8 00 00 00 00 00 00 02 0A 00 00 00 00 80 20 00 FF 00 00 00 00 00 00 02 FF 00 00 00 00 B0 C5 C0 FF 00 00 00 00 13 00 01 FF 00 00 00 00 10 FF B4 00 00 00 00 00 00 FF .............. .....)4......... .+.............. ................ ................ ................ ................ ..BH..P... ..... ..
CB 00 00 00 00 00 D8 A7
CC 7D 00 00 00 00 12 05
6ere the sli#e sho7s the $ontents of the root #ire$tory #epi$ting the .C< of a file name# CP8P9,)TNT) The $ontrol information a out this file $an e rea# from the #ump)
13A6:1320 13A6:1330 13A6:1340 13A6:1350 13A6:1360 13A6:1370 13A6:1380 13A6:1390 13A6:13A0 13A6:13B0
Contc
E5 3C 54 3C 46 3C E5 3D 41 2E 45 33 45 33 49 33 30 33 43 00
57 3C 53 3C 4C 3C 58 3D 00 74
54 33 54 33 45 33 58 33 70 00
45 00 20 00 20 00 20 00 00 78
58 00 20 00 20 00 20 00 61 00
7E 0A 20 17 20 8D 20 A7 00 74
31-54 73-3C 20-54 73-3C 20-54 73-3C 20-54 68-3D 70-00 00-00
58 33 58 33 58 33 4D 33 65 00
54 00 54 45 54 54 50 08 00 00
20 00 20 00 20 00 20 00 0F 00
00 00 18 27 18 99 18 12 00 FF
32 00 32 00 81 02 65 63 54 FF
09 00 09 00 83 00 A6 00 72 FF
73 00 73 00 73 00 68 00 00 FF
.EWOEK(1OKO .2.& $3$3...&$3...... OEMO OKO .2.& $3$3...&$3E.]... F!NE OKO ...& $3$3...&$3O..... .0KK OBP .>.8 L3L3...8L3...C.. AC.<.5.<.>...O,. ..".T.".........
43 3C 46 3D 46 3D
50 33 44 33 44 33
41 3D 50 3D 44 3D
50 33 42 33 20 33
45 00 20 00 20 00
52 00 20 00 20 00
20 A7 20 BD 20 23
58 33 58 33 58 33
54 08 54 29 54 2A
20 00 20 00 20 00
00 12 18 BA 18 13
9D 63 05 04 48 00
7D 00 56 00 E4 00
6F 00 69 00 75 00
CPAPEU OKO ..+o $3L3...8L3...C.. FDPB OKO ..): L3L3...:L3P..... FDD OKO .D. L3L3..-7L3'.....
The a ove sli#es sho7s that the first $luster of the file is 0000) The follo7ing sli#e sho7s the $ontents of .8T) The .8T is loa#e# firstly in memory at the offset a##ress !0006) 9a$h entry o$$upies 2 ytes) So the in#e: 0000 7ill e lo$ate# at !0006 K 0000E2 @ !0!06) 8t !0!06% 0009 is store# 7hi$h is the ne:t $luster of the file% using 00096 as in#e: 7e look up at !0!26% 7hi$h stores 00**6% 7hi$h means 00**6 is the ne:t $luster)
Contents of 0AT
-9 1000 5 8 CC -; 1010 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 13A6:1080 -; 1055 13A6:10A0 13A6:10B0 13A6:10C0 13A6:10D0 13A6:10E0 13A6:10F0 13A6:1100 13A6:1110 -q 56 5E 66 FF 00 00 00 00 00 00 00 FF 00 00 00 00 57 5F 67 00 00 00 00 00 00 00 00 00 00 00 00 00 58 60 68 00 00 00 00 00 00 00 00 00 00 00 00 00 1.U.M.....).W.K. G...I.\.Q.Z.R.3. 5.=.C.;.>.f.?.8. :.6.`.9......... ................ ................ ................ ................ 09 00 FF 21 00 00 00 00 00 00 FF 00 00 00 00 00 55 00 FF FF FF 00 00 00 00 00 FF FF FF 00 00 00 FF FF FF FF 5A 00 00 00 FF FF FF FF 00 00 00 00 FF FF FF FF 00 00 00 00 FF-FF FF-FF FF-FF FF-46 00-00 00-00 00-00 00-00 FF FF FF 00 00 00 00 00 FF FF 1E 00 00 00 00 FF FF FF 00 00 00 00 00 FF FF FF 1F 00 00 00 00 47 FF FF 00 00 00 00 00 00 FF FF 20 00 00 00 00 48 FF FF 00 00 00 00 00 00 ..U............. ................ .............. . *.......F....... ....H........... ................ ................ ............G.D.
59 61 69 00 00 00 00
00 00 00 00 00 00 00
FF 62 6A 00 00 00 00
FF 00 00 00 00 00 00
5B 63 6B 00 00 00 00
00 00 00 00 00 00 00
5C 64 6C 00 00 00 00
00 00 FF 00 00 00 00
using 00**6 as in#e: 7e look up at !0886 to fin# the ne:t $luster num er an# so on)
(2 - #i"e OrganiWation
;o7 $onverting all those $luster num er in previous le$ture into -S; 7e get the starting -S; for ea$h $luster) .or $luster H 00096 an# **h
Contents of 0!93
-9 1000 5 1f8 8 -; 1000 13A6:1000 65 13A6:1010 64 13A6:1020 75 13A6:1030 61 13A6:1040 69 13A6:1050 69 13A6:1060 20 13A6:1070 63 -9 1000 5 458 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 20 71 0A 3D 3E 20 0A 0A 2A 20 09 20 20 6C 0D 0D 2F 21 09 71 6C 69 0A 0A 0D 3D 73 20 69 6E 09 2F 0A 20 20 3B 6E 6B 2A 2A 0D 4E 3D 0D 6B 20 78 20 0A 55 20 0A 20 3D 20 64 09-77 4C-4C 72-20 09-09 3B-0D 20-73 3D-20 69-73 68 20 3B 71 0A 20 72 70 69 29 0D 20 09 3B 20 6C 6C 0D 0A 3D 09 0D 3B 61 65 0A 09 20 72 0A 0D 79 20 09 09 71 20 09 0A 73 28 7B 72 20 2D 7D 7D 20 20 0D 20 2D 3E 0D 0D 74 '[.....08:9> S q *L %UNN P...^. ...& L , F...., L q F....q L q > 9:n` F...., -> 9:n` L & F...+. ....'T L , F..+. ...[' ;:&<95@& " 65 65 0D 6C 6C 66 79 6F 8 6E 6E 0A 6C 65 69 6F 6D 20 74 77 20 73 65 75 70 64 6C 61 65 20 64 20 69 65 79 6E 78 74 20 68 6C 6C 20 74 65 6F 64 61 65 65-74 61-6E 20-74 63-75 20-74 69-72 76-65 20-61 65 64 6F 74 68 65 20 6C 64 20 20 61 65 63 74 6C 20 69 63 62 20 74 6F 20 61 66 6F 6C 73 6F 0D 74 63 20 70 65 70 72 0A 68 63 79 79 20 65 79 72 65 69 6F 20 66 63 2C 65 20 >>n ;>9>">; 5CC: ;>n"9@ 5n; :f @o ..05n" "o Co<@ 599 >T>C "5=9> f :9>& "o "8> &<>C :f:>; ;:,>C"o,@# @o 857> "o..,> CoA<:9> 599 "8>
-9 1000 5 468 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 -q 09 09 7D 22 0D 2D 2D 2D 09 62 0D 2C 0A 2D 2D 2D 09 72 0A 20 0D 2D 2D 2D 09 65 09 72 0A 2D 2D 2D 72 61 70 65 2D 2D 2D 2D 20 6B 72 73 2D 2D 2D 2D 3D 20 69 75 2D 2D 2D 2D 20-30 3B-0D 6E-74 6C-74 2D-2D 2D-2D 2D-2D 2D-2D 20 0A 66 20 2D 2D 2D 2D 3B 09 20 29 2D 2D 2D 2D 0D 09 28 20 2D 2D 2D 2D 0A 7D 20 3B 2D 2D 2D 2D 09 0D 22 0D 2D 2D 2D 2D 09 0A 25 0A 2D 2D 2D 2D 09 09 64 7D 2D 2D 2D 2D ...., L 0 F..... .=,>5` F....+... +...<,:n"f S VX; V# ,>& 9" P F..+ ....---------------------------------------------------------
Contc
13A6:1180 13A6:1190 13A6:11A0 13A6:11B0 13A6:11C0 13A6:11D0 13A6:11E0 13A6:11F0 13A6:1200 13A6:1210 13A6:1220 13A6:1230 13A6:1240 13A6:1250 13A6:1260 13A6:1270 13A6:1280 13A6:1290 13A6:12A0 13A6:12B0 13A6:12C0 13A6:12D0 13A6:12E0 13A6:12F0 13A6:1300 13A6:1310 E5 3C E5 3C E5 3C E5 3C E5 3C 44 3C 54 3C 52 3C E5 3C E5 2E E5 3C E5 78 E5 78 52 33 52 33 52 33 4F 33 4F 33 52 33 52 33 4F 33 5F 33 43 00 50 33 6D 00 4E 00 45 3C 56 3C 56 3C 4F 3C 4F 3C 56 3C 45 3C 4F 3C 41 3C 00 74 41 3D 00 74 00 74 45 33 50 33 50 33 54 33 54 33 50 33 45 33 54 33 4E 33 70 00 50 33 65 00 65 00 20 00 42 00 42 00 46 00 46 00 42 00 20 00 46 00 53 00 00 78 45 00 00 00 00 20 20 00 46 00 46 00 20 00 20 00 46 00 20 00 20 00 20 00 61 00 52 00 6E 00 77 00 20 4D 20 62 20 83 20 F8 20 F8 20 83 20 4D 20 36 20 60 00 74 20 60 00 FF 00 44 20-54 57-3C 20-54 6C-3C 20-54 6D-3C 20-54 6D-3C 20-54 6D-3C 20-54 6D-3C 20-54 57-3C 20-54 73-3C 20-54 05-72 70-00 00-00 20-54 05-72 74-00 FF-FF 20-00 00-6F 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 28 65 00 58 28 2E FF 54 00 54 1D 54 10 54 10 54 11 54 1D 54 22 54 23 54 24 54 29 00 00 54 29 00 00 00 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 0F 00 20 00 0F 00 0F 00 18 F8 18 AF 18 BA 18 6F 18 6F 18 BA 18 F8 18 67 10 4F 00 FF 00 4F 00 FF 00 63 89 00 85 00 08 04 45 4F 04 4F 04 04 05 00 04 ED 9D 8F 54 FF 9D 8F 9F FF 9F 00 4C 00 43 00 BB 00 D3 00 CF 00 CF 00 CF 00 CF 00 7D 00 72 FF 7D 00 74 FF 65 75 57 00 6C 00 6C 00 6D 00 6E 00 6E 00 6E 00 6E 00 6F 00 00 FF 6F 00 00 FF 00 00 .UEE OKO ..NW $3$3..BW$3...... .U)PBF OKO ..C9 $3$3..=9$3...... .U)PBF OKO ...9 $3$3...A$3...... .22OF OKO .E.A $3$3...A$3..o2.. .22OF OKO ...n $3$3...A$3..o2.. DU)PBF OKO ...n $3$3...A$3V..... OUEE OKO ...n $3$3..BW$3-..... U22OF OKO ...n $3$3..6&$3..?... .RA%M OKO ..+o $3$3..3.,SP.2... .C.<.5.<.>...O,. ..".T."......... .PAPEU OKO ..+o $3L3..3.,SP.2... .A.>.n."......". T."............. .%.>.0. .O....>. T.". .D.o...C. .
Contc
13A6:1320 13A6:1330 13A6:1340 13A6:1350 13A6:1360 13A6:1370 13A6:1380 13A6:1390 13A6:13A0 13A6:13B0 13A6:13C0 13A6:13D0 13A6:13E0 13A6:13F0 13A6:1400 13A6:1410 E5 3C 54 3C 46 3C E5 3D 41 2E 43 3C 46 3D 46 3D 45 33 45 33 49 33 30 33 43 00 50 33 44 33 44 33 57 3C 53 3C 4C 3C 58 3D 00 74 41 3D 50 3D 44 3D 54 33 54 33 45 33 58 33 70 00 50 33 42 33 20 33 45 00 20 00 20 00 20 00 00 78 45 00 20 00 20 00 58 00 20 00 20 00 20 00 61 00 52 00 20 00 20 00 7E 0A 20 17 20 8D 20 A7 00 74 20 A7 20 BD 20 23 31-54 73-3C 20-54 73-3C 20-54 73-3C 20-54 68-3D 70-00 00-00 20-54 68-3D 20-54 69-3D 20-54 76-3D 58 33 58 33 58 33 4D 33 65 00 58 33 58 33 58 33 54 00 54 45 54 54 50 08 00 00 54 08 54 29 54 2A 20 00 20 00 20 00 20 00 0F 00 20 00 20 00 20 00 00 00 18 27 18 99 18 12 00 FF 00 12 18 BA 18 13 32 00 32 00 81 02 65 63 54 FF 9D 63 05 04 48 00 09 00 09 00 83 00 A6 00 72 FF 7D 00 56 00 E4 00 73 00 73 00 73 00 68 00 00 FF 6F 00 69 00 75 00 .EWOEK(1OKO .2.& $3$3...&$3...... OEMO OKO .2.& $3$3...&$3E.]... F!NE OKO ...& $3$3...&$3O..... .0KK OBP .>.8 L3L3...8L3...C.. AC.<.5.<.>...O,. ..".T."......... CPAPEU OKO ..+o $3L3...8L3...C.. FDPB OKO ..): L3L3...:L3P..... FDD OKO .D. L3L3..-7L3'.....
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 ;o7 letMs ?ust analy=e the $ontents of root #ire$tory of the same volume) "f the 4", $omman# is performe# on the same volume its result 7ill e as elo7) ;ote the entry for file name# T9ST)TNT
;o7 on the same volume the file T9ST)TNT is #elete#) -ets analyse the $ontents of the root #ire$tory no7)
-9 1000 5 150 20 -;1000 5000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 13A6:1080 13A6:1090 13A6:10A0 13A6:10B0 13A6:10C0 13A6:10D0 13A6:10E0 13A6:10F0 13A6:1100 13A6:1110 13A6:1120 13A6:1130 13A6:1140 13A6:1150 13A6:1160 13A6:1170 4E 00 41 65 52 2F 42 6D 01 20 53 2F 41 78 44 36 44 36 46 3C 53 3C 54 3C
Contc
13A6:1180 13A6:1190 13A6:11A0 13A6:11B0 13A6:11C0 13A6:11D0 13A6:11E0 13A6:11F0 13A6:1200 13A6:1210 13A6:1220 13A6:1230 13A6:1240 13A6:1250 13A6:1260 13A6:1270 13A6:1280 13A6:1290 13A6:12A0 13A6:12B0 13A6:12C0 13A6:12D0 13A6:12E0 13A6:12F0 13A6:1300 13A6:1310 E5 3C E5 3C E5 3C E5 3C E5 3C 44 3C 54 3C 52 3C E5 3C E5 2E E5 3C E5 78 E5 78 52 33 52 33 52 33 4F 33 4F 33 52 33 52 33 4F 33 5F 33 43 00 50 33 6D 00 4E 00 45 3C 56 3C 56 3C 4F 3C 4F 3C 56 3C 45 3C 4F 3C 41 3C 00 74 41 3D 00 74 00 74 45 33 50 33 50 33 54 33 54 33 50 33 45 33 54 33 4E 33 70 00 50 33 65 00 65 00 20 00 42 00 42 00 46 00 46 00 42 00 20 00 46 00 53 00 00 78 45 00 00 00 00 20 20 00 46 00 46 00 20 00 20 00 46 00 20 00 20 00 20 00 61 00 52 00 6E 00 77 00 20 4D 20 62 20 83 20 F8 20 F8 20 83 20 4D 20 36 20 60 00 74 20 60 00 FF 00 44 20-54 57-3C 20-54 6C-3C 20-54 6D-3C 20-54 6D-3C 20-54 6D-3C 20-54 6D-3C 20-54 57-3C 20-54 73-3C 20-54 05-72 70-00 00-00 20-54 05-72 74-00 FF-FF 20-00 00-6F 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 28 65 00 58 28 2E FF 54 00 54 1D 54 10 54 10 54 11 54 1D 54 22 54 23 54 24 54 29 00 00 54 29 00 00 00 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 0F 00 20 00 0F 00 0F 00 18 F8 18 AF 18 BA 18 6F 18 6F 18 BA 18 F8 18 67 10 4F 00 FF 00 4F 00 FF 00 63 89 00 85 00 08 04 45 4F 04 4F 04 04 05 00 04 ED 9D 8F 54 FF 9D 8F 9F FF 9F 00 4C 00 43 00 BB 00 D3 00 CF 00 CF 00 CF 00 CF 00 7D 00 72 FF 7D 00 74 FF 65 75 57 00 6C 00 6C 00 6D 00 6E 00 6E 00 6E 00 6E 00 6F 00 00 FF 6F 00 00 FF 00 00 .UEE OKO ..NW $3$3..BW$3...... .U)PBF OKO ..C9 $3$3..=9$3...... .U)PBF OKO ...9 $3$3...A$3...... .22OF OKO .E.A $3$3...A$3..o2.. .22OF OKO ...n $3$3...A$3..o2.. DU)PBF OKO ...n $3$3...A$3V..... OUEE OKO ...n $3$3..BW$3-..... U22OF OKO ...n $3$3..6&$3..?... .RA%M OKO ..+o $3$3..3.,SP.2... .C.<.5.<.>...O,. ..".T."......... .PAPEU OKO ..+o $3L3..3.,SP.2... .A.>.n."......". T."............. .%.>.0. .O....>. T.". .D.o...C. .
The entry for T9ST)TNT still e:ists as $an e seen from the ne:t sli#e) The only #ifferen$e that have o$$urre# is that the first $hara$ter has een repla$e# y a yte 7ith the value 0:9*
Contc
13A6:1320 13A6:1330 13A6:1340 13A6:1350 13A6:1360 13A6:1370 13A6:1380 13A6:1390 13A6:13A0 13A6:13B0 13A6:13C0 13A6:13D0 13A6:13E0 13A6:13F0 13A6:1400 13A6:1410 13A6:1420 13A6:1430 13A6:1440 13A6:1450 13A6:1460 13A6:1470 13A6:1480 13A6:1490 13A6:14A0 13A6:14B0 13A6:14C0 13A6:14D0 E5 3C E5 3C 46 3C E5 3D 41 2E 43 3C 46 3D 46 3D E5 3D 46 3D 46 3D 44 3D 44 3D 44 3D 45 33 45 33 49 33 30 33 43 00 50 33 44 33 44 33 46 33 46 33 46 33 49 33 49 33 44 33 57 3C 53 3C 4C 3C 58 3D 00 74 41 3D 50 3D 44 3D 41 3D 41 3D 49 3D 52 3D 52 3D 44 3D 54 33 54 33 45 33 58 33 70 00 50 33 42 33 20 33 54 33 54 33 4C 33 20 33 44 33 45 33 45 00 20 00 20 00 20 00 00 78 45 00 20 00 20 00 20 00 20 00 45 00 20 00 20 00 4C 00 58 00 20 00 20 00 20 00 61 00 52 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 7E 0A 20 17 20 8D 20 A7 00 74 20 A7 20 BD 20 31 20 37 20 50 20 D3 20 9B 20 C1 20 F8 31-54 73-3C 20-54 73-3C 20-54 73-3C 20-54 68-3D 70-00 00-00 20-54 68-3D 20-54 69-3D 20-54 76-3D 20-54 78-3D 20-54 78-3D 20-54 78-3D 20-54 7E-3D 20-54 7E-3D 20-54 7E-3D 58 33 58 33 58 33 4D 33 65 00 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 33 58 33 54 00 54 45 54 54 50 08 00 00 54 08 54 29 54 2A 54 6D 54 6E 54 6D 54 6F 54 45 54 70 20 00 20 00 20 00 20 00 0F 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 00 00 18 27 18 99 18 12 00 FF 00 12 18 BA 18 67 18 1A 18 19 18 61 18 AC 18 AC 18 13 32 00 32 00 81 02 65 63 54 FF 9D 63 05 04 48 3C 96 05 96 05 11 0A 49 03 7B 03 49 00 09 00 09 00 83 00 A6 00 72 FF 7D 00 56 00 E4 01 2C 00 2C 00 97 00 9A 00 C0 00 F7 00 73 00 73 00 73 00 68 00 00 FF 6F 00 69 00 75 00 78 00 78 00 78 00 7E 00 7E 00 7E 00 .EWOEK(1OKO .2.& $3$3...&$3...... .EMO OKO .2.& $3$3...&$3E.]... F!NE OKO ...& $3$3...&$3O..... .0KK OBP .>.8 L3L3...8L3...C.. AC.<.5.<.>...O,. ..".T."......... CPAPEU OKO ..+o $3L3...8L3...C.. FDPB OKO ..): L3L3...:L3P..... FDD OKO .D. L3L3..17L3'.?$.. .FAO OKO ..#T L3L3..7TL3A..... FFAO OKO ..#T L3L3..PTL3n..... FF!NE OKO ...T L3L3...TL3A.5... D!U OKO .!.( L3L3...(L3o..... D!UD OKO .^.( L3L3...(L3E..... DDDEN OKO .!.( L3L3...(L3<.....
<ut 7hen the 4", $omman# e:e$ute on the same volume the file #oes not sho7)
;o7 letMs see the $ontents of the file y $onverting the first $luster num er in the .C< into -S; an# taking its #ump) >e get the follo7ing sli#e)
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 So 7e infer the follo7ing)
(eleted 0iles
F ;,3B at the start of file entry is used to mar' the file as deleted. F The contents of file still remain on dis'. F The contents can be recovered by placing a valid file name, character in place of 3B and then recovering the chain of file in 0AT. F !f somehow the clusters used by deleted file has been overwritten by some other file, it cannot be recovered.
;ot only the file is marke# for #eletion ut also the $hain of its $luster in .8T is re$laime# y putting =eros in there pla$e) This also in#i$ates that these $lusters are no7 free) ;o7 letMs have some #is$ussion a out su -#ire$tories) "n the $ontents of the a ove given root #ire$tory noti$e an entry name# S9C(;4) The attri ute yte of this entry is 0:20 7hi$h in#i$ates that itMs a #ire$tory% the si=e is 0 7hi$h sho7s that there is no7 user #ata in it% ut even though the si=e 0 its has a first $luster 7hi$h is 0:!2) Converting 0:!2 into -S; an# then rea#ing its $ontents 7e get the follo7ing #ump) This sho7s that this $luster $ontains the .C<s for all the file an# fol#ers 7ithin this #ire$tory)
Contents of ubW(irectories
-9 1000 5 240 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 53 3C 20 33 2E 33 55 33 55 33 20 3C 20 3C 42 3C 42 3D 20 33 20 33 31 33 32 33 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 F0 20 F0 20 08 20 0B 20-20 56-3C 20-20 56-3C 20-20 57-3C 20-20 57-3C 20 33 20 33 20 33 20 33 20 12 20 00 20 16 20 17 10 00 10 00 10 00 10 00 00 00 00 00 08 00 08 00 50 00 50 00 B1 00 23 00 EF 00 EF 00 07 00 0A 00 56 00 56 00 57 00 57 00 . ..P.) $3$3...)$3...... .. ..P.) $3$3...)$3...... MUB1 ....W $3$3...W$3...... MUB2 ..-.W $3L3...W$3......
-9 1000 5 268 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 33 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 0B 20 0B 20 0F 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 17 20 12 20 18 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 23 00 23 00 9A 00 00 00 0A 00 0A 00 0E 00 00 00 57 00 57 00 57 00 00 00 . ..-.W $3$3...W$3...... .. ..-.W $3$3...W$3...... MUB3 ....W $3L3...W$3...... ................ ................
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 "n the entries 7ithin S9C(;4 7e see an entry SU<2) "ts starting $luster is 00!56) This value is $onverte# into -S; an# the $ontents rea#) The sli#e a ove also sho7s the $ontents of SU<2) Similarly the follo7ing sli#e sho7s the $ontents of SU<+ 7ithin SU<2 an# the $ontents of SU</ 7ithin SU<+)
Contc
-9 1000 5 270 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 34 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 0F 20 0F 20 13 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 18 20 17 20 19 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 9A 00 9A 00 AF 00 00 00 0E 00 0E 00 12 00 00 00 57 00 57 00 57 00 00 00 . ....W $3$3...W$3...... .. ....W $3$3...W$3...... MUB4 ....W $3L3...W$3...... ................ ................
-9 1000 5 278 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 35 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 13 20 13 20 18 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 19 20 18 20 1A 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 AF 00 AF 00 0D 00 00 00 12 00 12 00 17 00 00 00 57 00 57 00 57 00 00 00 . ....W $3$3...W$3...... .. ....W $3$3...W$3...... MUB5 ....W $3L3...W$3...... ................ ................
The follo7ing sli#e sho7s the $ontents of SU<* an# also the $ontents of file &G."-9)TNT in SU<*)
Contc
-9 1000 5 280 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 4D 3C 00 00 20 33 2E 33 59 33 00 00 20 3C 20 3C 46 3C 00 00 20 33 20 33 49 33 00 00 20 00 20 00 4C 00 00 00 20 00 20 00 45 00 00 00 20 18 20 18 20 25 00 00 20-20 57-3C 20-20 57-3C 20-54 57-3C 00-00 00-00 20 33 20 33 58 33 00 00 20 1A 20 19 54 1B 00 00 10 00 10 00 20 00 00 00 00 00 00 00 18 15 00 00 0D 00 0D 00 00 00 00 00 17 00 17 00 23 00 00 00 57 00 57 00 57 00 00 00 . ....W $3$3...W$3...... .. ....W $3$3...W$3...... BGF!NE OKO ..-W $3$3..XW$3...... ................ ................
-9 1000 5 288 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 -q 73 73 00 00 00 00 00 00 6E 64 00 00 00 00 00 00 66 63 00 00 00 00 00 00 6B 0D 00 00 00 00 00 00 73 0A 00 00 00 00 00 00 6E 00 00 00 00 00 00 00 66 00 00 00 00 00 00 00 73-6E 00-00 00-00 00-00 00-00 00-00 00-00 00-00 66 00 00 00 00 00 00 00 61 00 00 00 00 00 00 00 73 00 00 00 00 00 00 00 6E 00 00 00 00 00 00 00 7A 00 00 00 00 00 00 00 78 00 00 00 00 00 00 00 63 00 00 00 00 00 00 00 &nf`&nf&nf5&n\TC &;C............. ................ ................ ................ ................ ................ ................
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 "n all the su -#ire$tories one thing is 7orth noti$ing) The first t7o entries are the ) an# )) entries) These t7o are spe$ial entries as #es$ri e# in the sli#e elo7)
cd .
gives the current path
cd . .
goes one level bac'wards.
;oti$e the $ontents of S9C(;4 #ire$tory) The ) entry has the $luster num er 00!26 7hi$h is the $luster num er for the S9C(;4 #ire$tory an# the )) entry has $luster num er 7hi$h in#i$ates the higher level #ire$tory 7hi$h is the root #ire$tory)
. and .. ubW(irectories
-9 1000 5 240 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 53 3C 20 33 2E 33 55 33 55 33 20 3C 20 3C 42 3C 42 3D 20 33 20 33 31 33 32 33 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 F0 20 F0 20 08 20 0B 20-20 56-3C 20-20 56-3C 20-20 57-3C 20-20 57-3C 20 33 20 33 20 33 20 33 20 12 20 00 20 16 20 17 10 00 10 00 10 00 10 00 00 00 00 00 08 00 08 00 50 00 50 00 B1 00 23 00 EF 00 EF 00 07 00 0A 00 56 00 56 00 57 00 57 00 . ..P.) $3$3...)$3...... .. ..P.) $3$3...)$3...... MUB1 ....W $3$3...W$3...... MUB2 ..-.W $3L3...W$3......
-9 1000 5 268 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 33 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 0B 20 0B 20 0F 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 17 20 12 20 18 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 23 00 23 00 9A 00 00 00 0A 00 0A 00 0E 00 00 00 57 00 57 00 57 00 00 00 . ..-.W $3$3...W$3...... .. ..-.W $3$3...W$3...... MUB3 ....W $3L3...W$3...... ................ ................
8lso e:amine the $ontents of SU<2 #ire$tory the ) #ire$tory has $luster num er 00!5h 7hi$h the $luster num er for SU<2 an# the )) entry has the $luster num er 00!26 7hi$h is the $luster num er of its parent #ire$tory S9C(;4 Same $an e o serve# for SU<+% SU</% SU<* or any other su -#ire$tory in Puestion)
Contc
-9 1000 5 270 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 34 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 0F 20 0F 20 13 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 18 20 17 20 19 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 9A 00 9A 00 AF 00 00 00 0E 00 0E 00 12 00 00 00 57 00 57 00 57 00 00 00 . ....W $3$3...W$3...... .. ....W $3$3...W$3...... MUB4 ....W $3L3...W$3...... ................ ................
-9 1000 5 278 8 -; 1000 13A6:1000 13A6:1010 13A6:1020 13A6:1030 13A6:1040 13A6:1050 13A6:1060 13A6:1070 2E 3C 2E 3C 53 3C 00 00 20 33 2E 33 55 33 00 00 20 3C 20 3C 42 3D 00 00 20 33 20 33 35 33 00 00 20 00 20 00 20 00 00 00 20 00 20 00 20 00 00 00 20 13 20 13 20 18 00 00 20-20 57-3C 20-20 57-3C 20-20 57-3C 00-00 00-00 20 33 20 33 20 33 00 00 20 19 20 18 20 1A 00 00 10 00 10 00 10 00 00 00 00 00 00 00 08 00 00 00 AF 00 AF 00 0D 00 00 00 12 00 12 00 17 00 00 00 57 00 57 00 57 00 00 00 . ....W $3$3...W$3...... .. ....W $3$3...W$3...... MUB5 ....W $3L3...W$3...... ................ ................
So this ho7 C4) $omman# gives the $urrent path an# C4)) moves to the one higher level #ire$tory)
9ong 0ile/ame
$o"ume in dri&e 5 is @:W $OL)M: $o"ume Seria" @um,er is 70((-(#48 %irectory of 5CM 08/1-/'00. 10C00 M V%I*Q @e6 #o"der 10/'(/'00. 11C'0 M 0 I am ne6 fi"e to e>!eriment "ong fi"e names=t>t 1 #i"e/s1 0 ,ytes 1 %ir/s1 -08,8--,02- ,ytes free
+* - .8T!2 .ile System 1Sele$ting a !2- it entry 7ithin .8T!2 System3 "n the follo7ing sli#e the 4P< of the volume is eing rea#)
C3 00 00 00 00 00 2E A7
C4 7A 00 00 00 00 0A 05
Using the information in 4P< the root #ire$tory entries are rea# an# are eing sho7n in the sli#e elo7)
(irectory 3ntry
-9 1000 7 190 20 -; 1000 0AFC:1000 0AFC:1010 0AFC:1020 0AFC:1030 0AFC:1040 0AFC:1050 0AFC:1060 0AFC:1070 0AFC:1080 0AFC:1090 0AFC:10A0 0AFC:10B0 0AFC:10C0 0AFC:10D0 0AFC:10E0 0AFC:10F0 0AFC:1100 0AFC:1110 0AFC:1120 0AFC:1130 0AFC:1140 0AFC:1150 0AFC:1160 4E 00 41 6C 4E 2E 42 6D 01 20 53 2E E5 78 E5 78 E5 2E E5 74 E5 66 E5 45 00 4E 00 45 33 20 00 53 00 59 33 6D 00 4E 00 45 33 79 00 6C 00 66 57 00 00 64 57 2E 00 61 00 56 53 2E 00 74 00 74 57 2E 00 78 00 61 00 20 00 65 00 46 33 49 00 79 00 54 33 65 00 65 00 54 33 73 00 20 00 69 56 00 00 65 4F 00 00 74 00 6F 45 00 00 00 00 20 45 00 00 74 00 74 00 4F 00 77 00 4C 00 6E 00 73 00 4D 00 6E 00 77 00 58 00 74 00 74 00 6C 4C 04 00 72 7E 0A 00 69 00 6C 7E 0A 00 FF 00 44 7E 12 00 00 00 31 00 55-4D 4F-2E 20-00 00-00 31-20 50-2E 66-00 00-6F 74-00 00-75 31-20 50-2E 74-00 FF-FF 20-00 00-6F 31-54 50-2E 65-00 00-FF 68-00 00-36 65-00 45 33 46 00 20 33 6F 00 65 00 20 33 2E FF 54 00 58 33 6D FF 65 00 20 20 00 00 00 20 02 00 00 00 00 20 03 00 00 00 00 54 00 00 00 00 00 00 08 00 0F 00 10 00 0F 00 0F 00 16 00 0F 00 0F 00 20 00 0F 00 0F 00 0F 00 00 00 FF 00 00 00 6E 00 6D 00 00 00 FF 00 63 00 00 00 FF 00 20 00 00 00 DD FF 41 00 72 00 72 00 44 00 9F FF 9F 00 9D 00 A4 FF A4 00 A4 00 00 6F FF 09 00 72 00 6D 65 09 00 74 FF 65 75 11 00 2E FF 20 73 74 00 00 00 FF 50 00 00 00 00 00 50 00 00 FF 00 00 50 00 00 FF 00 00 00 %EW )2NUBE ..... .......2.3...... A%.>.0. .F....o. 9.;.>.,......... %EWF2N(1 ..A.P .3.3...P.3...... B .!.n.f.o...,,. A.5.".:.o...n... .M.@.&.".>...,A. .).o.9. ...A.>. MGMOEB(1 ..D.P .3.3...P.3...... .A.>.n."......". T."............. .%.>.0. .O....>. T.". .D.o...C. . .EWOEK(1OKO ...P .3.3...P.3...... .@.&.".>.A...... ".T."........... .9. .".8.>.... . f.5.".1.6... .&. .f.:.9.>. ....".
Contc
0AFC:1170 0AFC:1180 0AFC:1190 0AFC:11A0 0AFC:11B0 0AFC:11C0 0AFC:11D0 0AFC:11E0 0AFC:11F0 0AFC:1200 0AFC:1210 0AFC:1220 0AFC:1230 0AFC:1240 0AFC:1250 0AFC:1260 0AFC:1270 0AFC:1280 0AFC:1290 0AFC:12A0 0AFC:12B0 0AFC:12C0 0AFC:12D0 0AFC:12E0 0AFC:12F0 0AFC:1300 6F E5 20 E5 2E 41 65 52 3C E5 78 E5 78 E5 57 E5 74 E5 20 E5 74 E5 73 E5 57 E5 00 74 00 48 33 52 00 45 33 6D 00 4E 00 45 33 61 00 6B 00 20 00 74 00 48 33 6D 20 00 61 49 2E 00 64 43 3C 00 74 00 74 57 57 00 00 00 66 00 6F 00 20 49 57 00 00 68 00 53 33 65 00 59 33 65 00 65 00 54 33 6D 00 20 00 66 00 68 00 53 33 65 63 00 20 49 00 00 00 43 00 00 00 00 20 45 00 00 FF 00 69 00 20 00 61 49 00 00 00 69 00 53 00 63 00 4C 00 6E 00 77 00 58 00 65 FF 6C 00 69 00 69 00 53 00 6E 68 00 6E 7E 12 00 FF 45 A8 00 FF 00 44 7E F9 00 FF 00 6C 00 63 00 20 7E F9 00 00-65 73-00 00-65 32-54 50-2E 79-00 FF-FF 44-20 63-3C 74-00 FF-FF 20-00 00-6F 31-54 56-57 2E-00 FF-FF 6F-00 00-65 6C-00 00-68 73-00 00-6E 31-54 56-57 74-00 00 69 00 58 33 63 FF 20 33 2E FF 54 00 58 33 74 FF 6E 00 65 00 20 00 58 33 2E 00 00 00 54 00 00 00 20 08 00 00 00 00 54 00 00 00 00 00 00 00 00 00 54 00 00 00 0F 00 20 00 0F 00 16 00 0F 00 0F 00 20 00 0F 00 0F 00 0F 00 0F 00 20 00 0F 63 00 77 00 00 00 FF 00 00 00 FF 00 63 00 00 00 FF 00 20 00 65 00 65 00 00 00 00 A4 00 9D 00 21 FF 86 00 9F FF 9F 00 8C 00 43 FF 43 00 43 00 43 00 8C 00 9F 6B 73 20 11 00 6C FF A7 00 74 FF 65 75 F8 00 78 FF 67 6E 20 63 69 77 F8 00 74 00 00 00 50 00 00 FF 63 00 00 FF 00 00 56 00 00 FF 00 00 00 00 00 00 56 00 00 o. .C.8.>...C.`. .".8.:.&.:....&. .5. .n.>...0. . .D!M!M(2OKO ...P .3.3...P.3...... AU.>.C.@.C...*9. >.;............. UECGCNED ....C $3$3...C$3...... .A.>.n."......". T."............. .%.>.0. .O....>. T.". .D.o...C. . .EWOEK(1OKO ...) W3W3...)W3...... .5.A.>..."...CT. "............... .`. .9.o.n...C?. .f.:.9.>... .n. . .f.:.9.>...C . ".o. .C.8...>.C. .".8.:.&. ...C:. &. .5. .n...>.0. .D!M!M(1OKO ...) W3W3...)W3...... .A.>.n."......".
Contc
0AFC:1310 0AFC:1320 0AFC:1330 0AFC:1340 0AFC:1350 0AFC:1360 0AFC:1370 0AFC:1380 0AFC:1390 0AFC:13A0 0AFC:13B0 0AFC:13C0 0AFC:13D0 0AFC:13E0 0AFC:13F0 0AFC:1400 0AFC:1410 0AFC:1420 0AFC:1430 0AFC:1440 0AFC:1450 0AFC:1460 0AFC:1470 78 E5 78 E5 57 44 78 03 20 02 70 01 65 49 57 52 57 00 00 00 00 00 00 00 4E 00 45 33 61 00 74 00 20 00 49 00 41 33 4F 33 00 00 00 00 00 00 74 00 74 57 57 00 74 00 66 00 65 00 77 4D 57 4F 57 00 00 00 00 00 00 00 65 00 54 33 6D 00 20 00 74 00 20 00 4E 33 54 33 00 00 00 00 00 00 00 00 20 45 00 00 00 00 69 00 72 00 20 45 00 48 00 00 00 00 00 00 00 00 77 00 58 00 65 00 6C 00 6F 00 61 00 57 00 20 00 00 00 00 00 00 00 FF 00 44 7E 86 00 FF 00 6C 00 69 00 66 7E 86 20 96 00 00 00 00 00 00 FF-FF 20-00 00-6F 31-54 5A-57 73-00 FF-FF 6F-00 00-65 20-00 00-6D 6D-00 00-69 31-54 5A-57 20-54 5C-57 00-00 00-00 00-00 00-00 00-00 00-00 FF 54 00 58 33 2E FF 6E 00 65 00 20 00 58 33 58 33 00 00 00 00 00 00 00 00 00 54 00 00 00 00 00 00 00 00 00 54 00 54 0E 00 00 00 00 00 00 00 0F 00 20 00 0F 00 0F 00 0F 00 0F 00 20 00 20 00 00 00 00 00 00 00 FF 00 63 00 00 00 FF 00 20 00 65 00 6C 00 00 18 13 00 00 00 00 00 00 FF 9F 00 26 00 0A FF 0A 00 0A 00 0A 00 26 00 0F 00 00 00 00 00 00 00 FF 65 75 85 00 74 FF 67 6E 78 6E 6E 65 85 00 95 00 00 00 00 00 00 00 FF 00 00 5A 00 00 FF 00 00 00 00 00 00 5A 00 5C 00 00 00 00 00 00 00 T."............. .%.>.0. .O....>. T.". .D.o...C. . .EWOEK(1OKO .W.H W3W3...HW3...... D5.A.>.&......". T."............. .". .9.o.n....?. .f.:.9.>... .n. . .".o. .>....T. <.>.,.:.A...>.n. .!. .5.A. ....n. >.0. .f.:...9.>. !AB%EW(1OKO .W.H W3W3...HW3...... U22OD OKO ...\ W3W3...\W3...... ................ ................ ................ ................ ................ ................
" n the a ove sli#e it $an e noti$e# that the long file name is also store# 7ith the .C<s) 8lso the fragments of Uni$o#e strings in the long file name forms a $hain) The first yte in the $hain 7ill e 0:0!% the first yte of the ne:t fragment 7ill e 0:02 an# so on till the last fragment) "f the last fragment is the nth fragment starting from 0 su$h that n is et7een 0 an# 2* the first yte of the last fragment 7ill e given as 8SC"" of Q8M plus n)
;o7 lets move our #is$ussion to .8T+2) "n theory the ma?or #ifferen$e et7een .8T !6 an# .8T +2 is of $ourse the .8T si=e) .8T+2 evi#ently 7ill $ontain more entries an# $an hen$e manage a very large #isk 7hereas .8T!6 $an manage a spa$e of 2 F< ma:imum pra$ti$ally) .ollo7ing sli#e sho7s the stru$ture of the <P< for .8T+2) Clearly there 7oul# e some a##itional information rePuire# in .8T+2 so the stru$ture for <P< use# in .8T+2 is #ifferent)
There $an e #ifferent volumes 7ith #ifferent volume si=es) The #evi$e #river for file han#ling 7oul# rePuire kno7ing the .8T si=e) The follo7ing sli#e illustrates an algorithm that $an e use# to #etermine the .8T si=e in use after rea#ing the <P<)
0ile #rganization
86 ] bit ; . . 5 6 8 C A B ; 7 55 C O
0C$
Start +"uster D
Contc
? O 5; 55 7 3#0
6`6?
0at86 3ntry
W 9a$h entry is of +2- its si=e ut only lo7er 20- its are use#) W 6igher /- its are not tempere#) W >hile rea#ing higher /- its are ignore#) W >hile 7riting higher /- its are not $hange#)
.C< in .8T+2 system has an enhan$e# meaning as sho7n y the sli#e elo7)
8natomy of .8T+2 ase# system #iffers from .8T!6 ase# systems signifi$antly as e:plaine# y the sli#e elo7)
*eser&ed 9"oc3s
W ;o fi:e# spa$e reserve# for root #ire$tory) W .C< of root #ire$tory are save# in a $luster an# the $luster H for root #ire$tory is save# in <P< as #is$usse# earlier)
"n refle$tion of the anatomy of .8T+2 ase# system the metho# use# to translate the $luster H into -S; also varies) The follo7ing formula is use# for this purpose)
;o7 7e #etermine all the parameters in the a ove sli#e for a $ertain volume to translate a $luster num er into -S;)
0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068 0070 0078 0080 0088 0090 0098
EB 34 02 3F 41 00 01 00 80 4F 20 20 7B 88 CD F1 B6 CD C9 83
58 2E 00 00 29 00 00 00 01 20 20 20 8E 4E 13 66 D1 C0 66 7E
90 31 00 F0 54 00 06 00 29 4E 46 33 C1 02 73 0F 80 ED F7 16
4D 00 00 00 02 00 00 00 F1 41 41 C9 8E 8A 05 B6 E2 06 E1 00
53 02 00 3F 3E 02 00 00 17 4D 54 8E D9 56 B9 C6 3F 41 66 75
.eserved $loc's
57 20 F8 00 25 00 00 00 79 45 33 D1 BD 40 FF 40 F7 66 89 38 49 24 00 00 00 00 00 00 2D 20 32 BC 00 B4 FF 66 E2 0F 46 83 4E 00 00 00 00 00 00 00 4E 20 20 F4 7C 08 8A 0F 86 B7 F8 7E . 4 . / A . . . . 2 K . . . P . . . . . 1 . . O . . . P % F 3 . . & . . . . . B . . . . . . . . A A . . . . . . . . . M . . / > . . . . B O . . ) . . / A f . . X . . . @ E 3 . . _ . _ . f . 8 W ! . . . . . . . 2 . . . . f . . F . % . . . . . . . % 235 52 2 63 65 0 1 0 128 79 32 32 123 136 205 241 182 205 201 131 88 46 0 0 41 0 0 0 1 32 32 32 142 78 19 102 209 192 102 126 144 49 0 240 84 0 6 0 41 78 70 51 193 2 115 15 128 237 247 22
^ . . . . . . .
. % . f . . f (
. | . . . . . . (
0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068 0070 0078 0080 0088 0090 0098
EB 34 02 3F 41 00 01 00 80 4F 20 20 7B 88 CD F1 B6 CD C9 83
58 2E 00 00 29 00 00 00 01 20 20 20 8E 4E 13 66 D1 C0 66 7E
90 31 00 F0 54 00 06 00 29 4E 46 33 C1 02 73 0F 80 ED F7 16
4D 00 00 00 02 00 00 00 F1 41 41 C9 8E 8A 05 B6 E2 06 E1 00
53 02 00 3F 3E 02 00 00 17 4D 54 8E D9 56 B9 C6 3F 41 66 75
57 20 F8 00 25 00 00 00 79 45 33 D1 BD 40 FF 40 F7 66 89 38
Copies of 0AT
49 24 00 00 00 00 00 00 2D 20 32 BC 00 B4 FF 66 E2 0F 46 83 4E 00 00 00 00 00 00 00 4E 20 20 F4 7C 08 8A 0F 86 B7 F8 7E . 4 . / A . . . . 2 K . . . P . . . . . 1 . . O . . . P % F 3 . . & . . . . . B . . . . . . . . A A . . . . . . . . . M . . / > . . . . B O . . ) . . / A f . . X . . . @ E 3 . . _ . _ . f . 8 W ! . . . . . . . 2 . . . . f . . F . % . . . . . . . % 235 52 2 63 65 0 1 0 128 79 32 32 123 136 205 241 182 205 201 131 88 46 0 0 41 0 0 0 1 32 32 32 142 78 19 102 209 192 102 126
^ . . . . . . .
. % . f . . f (
. | . . . . . . (
0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068 0070 0078 0080 0088 0090 0098
EB 34 02 3F 41 00 01 00 80 4F 20 20 7B 88 CD F1 B6 CD C9 83
58 2E 00 00 29 00 00 00 01 20 20 20 8E 4E 13 66 D1 C0 66 7E
90 31 00 F0 54 00 06 00 29 4E 46 33 C1 02 73 0F 80 ED F7 16
4D 00 00 00 02 00 00 00 F1 41 41 C9 8E 8A 05 B6 E2 06 E1 00
53 02 00 3F 3E 02 00 00 17 4D 54 8E D9 56 B9 C6 3F 41 66 75
^ . . . . . . .
. % . f . . f (
. | . . . . . . (
0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068 0070 0078 0080 0088 0090 0098
^ . . . . . . .
. % . f . . f (
. | . . . . . . (
0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068 0070 0078 0080 0088 0090 0098
EB 34 02 3F 41 00 01 00 80 4F 20 20 7B 88 CD F1 B6 CD C9 83
58 2E 00 00 29 00 00 00 01 20 20 20 8E 4E 13 66 D1 C0 66 7E
90 31 00 F0 54 00 06 00 29 4E 46 33 C1 02 73 0F 80 ED F7 16
^ . . . . . . .
. % . f . . f (
. | . . . . . . (
So using all this information 7e $al$ulate the -S; for $luster num er 2 as sho7n the sli#e elo7 for this parti$ular volume)
To e:amine the $ontents of a file first a file is $reate# 7hose $ontents are also sho7n in the sli#e)
;o7 7e e:amine the $ontents of $luster num er 2 7hi$h $ontains the root #ire$tory as alrea#y seen in the previous sli#es)
Cluster H 6
000000000000 000000000010 000000000020 000000000030 000000000040 000000000050 000000000060 000000000070 000000000080 000000000090 0000000000A0 0000000000B0 0000000000C0 0000 0010 0020 0030 0040 0050 0060 0070 0080 0090 00A0 00B0 00C0 E5 A8 57 A8 4E 03 4E 03 42 A8 42 6E 01 41 32 49 32 54 31 54 31 4F 32 20 00 44 47 84 4E 21 4C A8 44 A8 4F 21 00 67 00 45 33 44 34 44 32 45 32 54 34 53 00 6F 46 00 4F 00 52 00 54 00 20 0E 00 73 00 49 00 57 00 20 00 45 00 20 00 65 00 63 4C 53 53 A3 20 71 43 D1 20 5C 00 00 00 45 4E 20 31 20 A7 54 A4 20 33 74 00 75 53 84 20 A8 20 03 43 03 49 A8 00 FF 00 59 33 20 32 20 31 4F 31 4E 32 74 FF 6D 53 03 20 03 20 85 4D 9E 49 F0 00 00 00 26 00 10 0A 27 8E 27 8F 06 AD 0F 00 0F 00 00 00 00 08 B0 00 CC 18 D3 00 FF 00 3B 60 4C 00 00 D0 00 B9 30 00 4A FF 4A A2 01 A2 00 71 03 D1 00 25 00 69 FF 65 31 00 31 00 A7 00 A4 00 32 00 00 FF 00 .AGEF!NEMGMW.F.1 .2.3..M%.3...3.. W!%D2WM ..N.1 .2*4...1.2...... %ONDU ]..q. .1.2..q..1...... %ODEOECOC2B].... .1.2.....1...... B22O !%!..0X2 .2*4..\3.2...... B .M.>."."...E:. n.?.&........... .D.o.C. .A...E>.
E5 21 4D 21 00 00
59 34 59 34 00 00
46 21 46 21 00 00
49 34 49 34 00 00
4C 00 4C 09 00 00
45 00 45 00 00 00
20 CD 20 CD 00 00
20 16 20 16 00 00
54 21 54 21 00 00
58 34 58 34 00 00
54 00 54 C9 00 00
20 00 20 29 00 00
18 00 18 29 00 00
67 00 67 00 00 00
CC 00 CC 00 00 00
16 00 16 00 00 00
.GF!NE OKO .?.. *4*4....*4...... BGF!NE OKO .?.. *4*4....*4.PP... ................ ................
+5 - .8T+2 .ile System .rom the information from a ove sli#es the lo7 an# high 7or#s of the first $luster num er is o taine# an# is sho7n in the sli#e elo7) The higher / its of the $luster num er shoul# e ignore# as #is$usse# earlier)
Using the $luster num er a ove the -S; for this $luster is #etermine# as sho7n in the sli#e elo7)
+5 - .8T+2 .ile System The lo$ks 7ithin the $luster are rea# an# their $ontents $an e seen in the sli#e elo7)
0ile (ata
D A< of NM% 19235712 0000 0008 0010 0018 0020 0028 0030 0038 0040 0048 0050 0058 0060 0068
00 7 0 00 7 8 00 8 0 00 8 8 00 9 0 00 9 8 00 A 0 00 A 8 00 B 0 00 B 8 00 C 0 00 C 8 00 D 0 00 D 8 00 E 0 00 E 8 00 F 0 00 F 8 01 0 0 01 0 8 01 1 0 01 1 8 01 2 0 01 2 8 01 3 0 01 3 8 01 4 0 01 4 8 01 5 0 01 5 8 01 6 0 01 6 8 01 7 0 01 7 8 01 8 0 01 8 8 01 9 0 01 9 8 01 A 0 01 A 8 01 B 0 01 B 8 01 C 0 01 C 8 01 D 0 01 D 8 01 E 0 01 E 8 01 F 0 01 F 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74 66 74 33 73 65 00 00 00 00 00 00 00 00
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
68 69 65 32 74 00 00 00 00 00 00 00 00 00
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
69 6C 73 20 72 00 00 00 00 00 00 00 00 00
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
73 65 74 66 75 00 00 00 00 00 00 00 00 00
20 20 20 69 63 00 00 00 00 00 00 00 00 00
69 74 46 6C 74 00 00 00 00 00 00 00 00 00
73 6F 41 65 75 00 00 00 00 00 00 00 00 00
20 20 54 20 72 00 00 00 00 00 00 00 00 00
8 : > 2 " . . . . . . . . .
: C . . . . . . . . .
: " F 9 " . . . . . . . . .
& o A O > , . . . . . . . . . . . . . . . . . .
115 32 105 101 32 116 116 32 70 102 105 108 117 99 116 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
"n the .8T+2 there is another spe$ial reserve# lo$k $alle# .S"nfo se$tor) The lo$k $ontains some information rePuire# y the operating system 7hile $luster allo$ation'#eallo$ation to files) This information is also $riti$al for .8T!6 ase# systems) <ut in .8T!2 an# !6 this information is $al$ulate# 7hen ever rePuire#) This $al$ulation at the time of allo$ation is not feasi le in .8T+2 as the si=e of .8T+2 is very large an# su$h $al$ulations 7ill $onsume a lots of time% so to save time this information is store# in the .S"nfo lo$k an# is up#ate# at the time of allo$ation'#eallo$ation)
)0T
)0T %)irror&
+ser (ata
+ser (ata
9oot 9"oc3
The follo7ing sli#es sho7 the <oot se$tor stru$ture for a ;T.S ase# system)
Field Length
5 b)tes 0O1C0O1C .- b)tes 87 b)tes 8.4 b)tes OR!
Field Name
Dum' Instruction O$/ I! BPB $#tended BPB Bootstra' %ode $nd of Sector /ar(er
+9 - ;e7 Te$hnology .ile System 1;T.S3 The follo7ing sli#e sho7s a sample of the oot lo$k #ump) The follo7ing sli#es #epi$t various parameters pla$e# in the <oot lo$k)
20 FF 7F 07
00 00 00 00
02 3F 00 00
08 00 00 00
00 00 00 00
00 00 00 00
00000160:C3 00000170:B4 00000180:EB 00000190:20 000001A0:0D 000001B0:6E 000001C0:6D 000001D0:20 000001E0:20 000001F0:00
A0 01 F2 65 0A 67 70 43 72 00
F8 8B C3 72 4E 00 72 74 65 00
01 F0 0D 72 54 0D 65 72 73 00
E8 AC 0A 6F 4C 0A 73 6C 74 00
09 3C 41 72 44 4E 73 2B 61 00
00 00 20 20 52 54 65 41 72 00
A0 74 64 6F 20 4C 64 6C 74 00
-FB -09 -69 -63 -69 -44 -00 -74 -0D -83
01 B4 73 63 73 52 0D 2B 0A A0
E8 0E 6B 75 20 20 0A 44 00 B3
03 BB 20 72 6D 69 50 65 00 C9
00 07 72 72 69 73 72 6C 00 00
FB 00 65 65 73 20 65 20 00 00
EB CD 61 64 73 63 73 74 00 55
FE 10 64 00 69 6F 73 6F 00 AA
................ .....$."........ .....A ;:&` ,>5; >,,o, oCC ,,>;. ..%ONDU :& A:&&: n?...%ONDU :& Co A<,>&&>;...P,>&& C",94A9"4D>9 "o ,>&"5,"........ ..............U.
P8@&:C59 M>C"o,:C@9 0# M:;> 1# M>C"o, 1 00000000:EB 52 90 4E 54 46 53 20 -20 20 00000010:00 00 00 00 00 F8 00 00 -3F 00 00000020:00 00 00 00 80 00 80 00 -4A F5 00000030:04 00 00 00 00 00 00 00 -54 FF
000 00 040 :F 6 0 0 00 00 0 1 0 0 00 00 - 14 A5 1 B 7 4 C9 1B 7 4 1 C ... .. .. ... ." .." . 0 000 00 50 :00 0 0 0 0 00 FA 3 3 C 0 8E -D 0 BC 00 7 C F B B8 C0 0 7 . .. ..3 .. .. .|. .. . 00 00 006 0: 8E D8 E 8 1 6 00 B8 00 0D - 8E C0 3 3 D B C6 06 0 E 0 0 ... .. .. ... 3. ... . 0 000 00 70 :10 E 8 5 3 00 68 0 0 0 D 68 -6 A 02 CB 8 A 1 6 24 00 B 4 . .M .8. .8 6. ... .. . 00 00 008 0: 08 CD 1 3 7 3 05 B9 F F F F -8 A F 1 66 0F B6 C6 40 6 6 . .. &. ... .. f.. ._ f 00 00 00 90: 0F B6 D 1 80 E2 3F F 7 E2 -8 6 C D C0 ED 0 6 4 1 66 0F . ... ./ .. ... .. Af. 00 000 0A 0: B7 C9 66 F 7 E1 66 A3 2 0 -00 C 3 B 4 41 BB A A 5 5 8A ..f .. f.. .. A.. U. 000 00 0B 0:1 6 24 00 C D 1 3 72 0F 8 1 - FB 55 A A 75 09 F6 C 1 01 .. ... ,. .. U. .. .. 0 00 000 C0 :7 4 0 4 FE 06 1 4 0 0 C3 66 - 60 1E 06 6 6 A1 10 00 6 6 ".. .. ..f 3. .f ... f 000 00 0D0 :0 3 0 6 1C 00 6 6 3 B 06 20 - 00 0F 8 2 3 A 00 1E 6 6 6 A ... .f F. ... :. .f6 00 000 0E 0: 00 66 50 0 6 53 66 68 1 0 -00 0 1 0 0 80 3E 1 4 0 0 00 .f P. Mf8 .. .. .>. .. 000 00 0F0 :0 F 85 0C 00 E 8 B3 FF 80 - 3E 14 0 0 0 0 0F 84 6 1 0 0 ... .. .. .>. .. ..5 . 0 000 01 00 :B4 4 2 8 A 16 24 0 0 1 6 1F -8 B F4 CD 1 3 6 6 58 5B 0 7 . B. ... .. .. .fK I .. 0 00 001 10 :6 6 5 8 66 58 1 F E B 2D 66 - 33 D2 66 0 F B7 0E 18 0 0 f Kf K. -f3 .f ... .. . 00 00 01 20: 66 F7 F 1 FE C2 8A C A 66 -8 B D 0 66 C1 E A 1 0 F7 36 f ... .. .f ..f .. ..6 0 00 001 30 :1 A 0 0 86 D6 8 A 1 6 24 00 - 8A E8 C0 E 4 06 0A CC B 8 ... .. ... .. ... .. . 00 00 01 40: 01 02 C D 13 0F 82 1 9 00 -8 C C 0 05 20 0 0 8 E C0 66 . ... .. .. ... .. .f 0 00 001 50 :F F 0 6 10 00 F F 0 E 0E 00 - 0F 85 6F F F 07 1F 66 6 1 ... .. ... .. o. ..f 5
00000160:C3 00000170:B4 00000180:EB 00000190:20 000001A0:0D 000001B0:6E 000001C0:6D 000001D0:20 000001E0:20 000001F0:00
A0 01 F2 65 0A 67 70 43 72 00
F8 8B C3 72 4E 00 72 74 65 00
01 F0 0D 72 54 0D 65 72 73 00
E8 AC 0A 6F 4C 0A 73 6C 74 00
09 3C 41 72 44 4E 73 2B 61 00
00 00 20 20 52 54 65 41 72 00
A0 74 64 6F 20 4C 64 6C 74 00
-FB -09 -69 -63 -69 -44 -00 -74 -0D -83
01 B4 73 63 73 52 0D 2B 0A A0
E8 0E 6B 75 20 20 0A 44 00 B3
03 BB 20 72 6D 69 50 65 00 C9
00 07 72 72 69 73 72 6C 00 00
FB 00 65 65 73 20 65 20 00 00
EB CD 61 64 73 63 73 74 00 55
FE 10 64 00 69 6F 73 6F 00 AA
................ .....$."........ .....A ;:&` ,>5; >,,o, oCC ,,>;. ..%ONDU :& A:&&: n?...%ONDU :& Co A<,>&&>;...P,>&& C",94A9"4D>9 "o ,>&"5,"........ ..............U.
The first !6 entries of the &.T are reserve#) ,ests of the entries are use# for user files) There is an entry for ea$h file in the &.T) There $an e #ifferen$e in the 7ay a file is manage# #epen#ing upon the si=e of the file)
.ollo7ing sli#e sho7s the #etail a out the first !6 system entries 7ithin the &.T)
The first logi$al lo$k is rea# to rea# the $ontents of the <P< in ;T.S) .ollo7ing sho7s the $ontents of oot lo$k for this volume)
EB 20 00 3F 00 44 00 24 F6
O . . / . . . . .
F . . . . . . . .
. . . . . . . . _ . f . U . . . . . f 8 . . 5 . I . . . . . . . . f . . . .
M . . . . . . . .
. . . . . . . .
235 82 144 78 84 70 83 32 32 32 0 2 8 0 0 0 0 0 0 248 0 63 0 255 0 63 0 0 0 0 0 0 128 0 128 68 162 215 1 0 0 0 0 0 12 0 0 0 0 36 122 29 0 0 0 0 246 0 0 0 1 0 0
32 0 0 0 0 0 0 0 0
0 1F8
004 8 6A 005 0 00 005 8 D0 006 0 8E 006 8 8E 007 0 10 007 8 6A 008 0 08 008 8 8A 009 0 0F 009 8 86 00A 0 B7 00A 8 00 00B 0 16 00B 8 FB 00C 0 74 00C 8 60 00D 0 03 00D 8 00 00E 0 00 00E 8 00 00F 0 0F 00F 8 3E 010 0 B4 010 8 8B 011 0 66 011 8 33 012 0 66 012 8 8B 013 0 1A 013 8 8A 014 0 01 014 8 8C 015 0 FF 015 8 0F 016 0 C3 016 8 FB 017 0 B4 017 8 09 018 0 EB 018 8 69 019 0 20 019 8 63 01A 0 0D 01A 8 69 01B 0 6E 01B 8 44 01C 0 6D 01C 8 00 01D 0 20 01D 8 74 01E 0 20 01E 8 0D 01F 0 00 83 A0 B3 C9 00 0 0 55 AA . .
94 00 BC D8 C0 E8 02 CD F1 B6 CD C9 C3 24 55 04 1E 06 0F 66 01 85 14 42 F4 58 D2 F7 D0 00 E8 02 C0 06 85 A0 01 01 B4 F2 73 65 63 0A 73 67 52 70 0D 43 2B 72 0A 00 . .
9C 00 00 E8 33 53 CB 13 66 D1 C0 66 B4 00 AA FE 06 1C 82 50 00 0C 00 8A CD 66 66 F1 66 86 C0 CD 05 10 6F F8 E8 8B 0E C3 6B 72 75 4E 20 00 20 72 0A 74 44 65 00 00 .
86 00 7C 16 DB 00 8A 73 0F 80 ED F7 41 CD 75 06 66 00 3A 06 80 00 00 16 13 58 0F FE C1 D6 E4 13 20 00 FF 01 03 F0 BB 0D 20 72 72 54 6D 0D 69 65 50 72 65 73 00 00 . U
. . . .. . . . | . . . . 3 . . M . . . . . . & . f . . . . . . . . f . . . A . . . U . . . . . . f . . . . . : f P . . . . . . . . . . B . . . . . K f K . f . . . . . f . . . . . . . . . . . . . . . . o . . . . . . . . . . . . . . . . & ` > , , C , . % O & A ? . . U : < , > . . P C " , 4 D > , > & . . . . . . 201
T . . . . 8 . . f . . . . . f f
10 6 148 15 6 1 34 212 156 134 1 20 0 0 0 0 250 5 1 192 142 20 8 188 0 1 24 251 184 192 7 14 2 216 23 2 22 0 184 0 13 14 2 192 5 1 2 19 198 6 14 0 1 6 232 8 3 0 104 0 13 1 04 10 6 2 20 3 1 38 22 36 0 1 80 8 205 1 9 115 5 185 255 25 5 13 8 241 10 2 15 182 198 64 1 02 1 5 182 20 9 1 28 226 63 247 2 26 13 4 205 19 2 2 37 6 65 102 15 18 3 201 10 2 2 47 225 102 163 32 0 195 18 0 65 187 170 85 1 38 2 2 36 0 2 05 19 114 15 1 29 25 1 85 17 0 1 17 9 246 193 1 11 6 4 25 4 6 20 0 195 1 02 9 6 30 6 1 02 161 16 0 1 02 3 6 2 8 0 102 59 6 32 0 15 13 0 58 0 30 102 1 06 0 102 8 0 6 83 102 104 16 0 1 0 1 28 62 20 0 0 1 5 133 1 2 0 232 179 255 1 28 6 2 20 0 0 15 132 97 0 18 0 66 13 8 22 36 0 22 31 13 9 244 20 5 1 9 102 88 91 7 1 02 8 8 10 2 88 31 235 45 102 5 1 210 10 2 15 183 14 24 0 10 2 247 24 1 2 54 194 138 202 1 02 13 9 208 10 2 1 93 234 16 247 54 26 0 13 4 2 14 138 22 36 0 13 8 232 19 2 2 28 6 10 204 1 84 1 2 20 5 19 15 130 25 0 14 0 192 5 32 0 142 192 1 02 25 5 6 1 6 0 255 14 14 0 1 5 133 11 1 2 55 7 31 102 97 19 5 160 24 8 1 232 9 0 16 0 25 1 1 23 2 3 0 251 235 2 54 18 0 1 13 9 2 40 172 60 0 1 16 9 180 1 4 1 87 7 0 205 16 23 5 242 19 5 13 10 65 32 1 00 10 5 115 10 7 32 114 101 97 1 00 3 2 101 11 4 1 14 111 114 32 1 11 9 9 99 11 7 1 14 114 101 100 0 1 3 10 7 8 84 76 68 82 32 10 5 115 3 2 1 09 105 115 115 1 05 11 0 103 0 13 10 78 84 76 6 8 82 3 2 1 05 115 32 99 1 11 10 9 112 11 4 1 01 115 115 101 1 00 0 13 1 0 80 114 101 115 1 15 3 2 67 11 6 1 14 108 43 65 1 08 11 6 43 6 8 1 01 108 32 116 1 11 3 2 114 10 1 1 15 116 97 114 1 16 13 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 85 170333 333333 33333333333 333333 3 3333 333333 33333333333 333 33 333
011 8 012 0 012 8 013 0 013 8 014 0 014 8 015 0 015 8 016 0 016 8 017 0 017 8 018 0
D2 F7 D0 00 E8 02 C0 06 85 A0 01 01 B4 F2
80 00 1F 07 66
66 F1 66 86 C0 CD 05 10 6F F8 E8 8B 0E C3
0F FE C1 D6 E4 13 20 00 FF 01 03 F0 BB 0D
B7 C2 EA 8A 06 0F 00 FF 07 E8 00 AC 07 0A
0E 8A 10 16 0A 82 8E 0E 1F 09 FB 3C 00 41
. > . . f
18 CA F7 24 CC 19 C0 0E 66 00 EB 00 CD 20
. . B . K
00 66 36 00 B8 00 66 00 61 A0 FE 74 10 64
. . . . f
3 f . . . . . . . . . . . .
. . . . . . . . . . . . . .
. . . . K
f . f . . . . . o . . . . .
. . . . . . . . . . . . .
. . . f .
. . . . . . . . . . . . . .
. . . . . . . . . . . $ . A
. . . K .
. . . . . . . . f . . . .
. f 6 . . . f . 5 . . " . ;
. 5 . I -
51 1 02 1 39 26 1 38 1 1 40 2 55 15 1 95 2 51 1 80 9 2 35
. . . . f
21 0 24 7 20 8 0 23 2 2 19 2 6 13 3 16 0 1 1 18 0 24 2
102 241 102 134 192 205 5 16 111 248 232 139 14 195
133 20 66 244 88
0188 0190 0198 01A0 01A8 01B0 01B8 01C0 01C8 01D0 01D8 01E0 01E8 01F0 01F8
69 20 63 0D 69 6E 44 6D 00 20 74 20 0D 00 83
73 65 63 0A 73 67 52 70 0D 43 2B 72 0A 00 A0
6B 72 75 4E 20 00 20 72 0A 74 44 65 00 00 B3
20 72 72 54 6D 0D 69 65 50 72 65 73 00 00 C9
72 6F 72 4C 69 0A 73 73 72 6C 6C 74 00 00 00
65 72 65 44 73 4E 20 73 65 2B 20 61 00 00 00
61 20 64 52 73 54 63 65 73 41 74 72 00 00 55
64 6F 00 20 69 4C 6F 64 73 6C 6F 74 00 00 AA
114 111 114 76 105 10 115 115 114 108 108 116 0 0 0
100 111 0 32 105 76 111 100 115 108 111 116 0 0 170
.or ;T.S simply the follo7ing formula 7ill e use# to translate the se$tor num er into $luster num er)
.ollo7ing sli#e sho7s ho7 the se$tor num er for the &.T on this volume 7as $al$ulate#) The first lo$k of &.T no this volume is 629!/*6)
76O5B6;
/0 - 4isassem ling the ;T.S ase# file .rom the lo$k num er 629!/*6 entries 7ere sear$he# for T9ST)TNT an# this file entry 7as foun# at the lo$k num er 629!*20)
0000 0008
46 49 4C 45 30 00 03 00 55 55 12 04 00 00 00 00
F ! N E 0 . . . U U . . . . . .
0 0 1 0 0 0 1 8 0 0 2 0 0 0 2 8 0 0 3 0 0 0 3 8 0 0 4 0 0 0 4 8 0 0 5 0 0 0 5 8 0 0 6 0 0 0 6 8 0 0 7 0 0 0 7 8 0 0 8 0 0 0 8 8 0 0 9 0 0 0 9 8 0 0 A 0 0 0 A 8 0 0 B 0 0 0 B 8 0 0 C 0 0 0 C 8 0 0 D 0 0 0 D 8 0 0 E 0 0 0 E 8 0 3 0 0 7 0 0 1 0 0 0 0 0 6 0 0 0 A 0 0 1 0 0 0 0 0 0 0 4 8 0 0 E 1 3 E 0 3 8 6 0 3 8 6 0 B B 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 5 2 0 0 0 5 0 0 E 1 3 E E 1 3 E E 1 3 E E 1 3 E 0 0 0 0 0 0 0 0 2 0 0 0 0 1 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 2 9 2B 7 D 3F 7 D 3F 8 2 6D 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 2 9 2B 2 9 2B 2 9 2B 2 9 2B 0 0 00 0 0 00 0 0 00 3 80 0 0 00 4 0 00 0 2 00 0 0 00 0 6 00 0 0 00 0 1 80 0 A D1 2 A D1 2 A D1 2 B 71 2 0 00 0 0 00 0 0 B0 1 0 00 0 0 00 0 7 00 0 0 00 0 1 80 0 0 00 0 A D1 2 A D1 2 A D1 2 A D1 2 0 00 0 0 00 0 0 00 0 01 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 C6 0 1 C6 0 1 C6 0 1 C6 0 1 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 04 0 0 01 0 0 05 0 0 C6 0 1 C6 0 1 C6 0 1 C6 0 1 00 0 0 00 0 0 00 0 0 . . < . . . . . . . . . . . D . . > . . . . . . . . . . . . . . . 0 . . . U . . . . > . > . > . > . . . . . . . . . . . . . P + + . . . . . . . . . . P P P P . . . .8 .. .. . .. .3 .. .. 4. /. /. A. .. .. .. .. .. .< .. .. .. 4. 4. 4. 4 . .. .. .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 2 0 6 1 0 1 6 0 7 2 2 5 3 3 1 1 3 2 0 0 0 0 4 8 0 8 2 5 2 5 2 5 2 5 25 0 0 3 2 0 1 0 0 0 0 0 0 6 2 1 0 0 0 0 0 0 0 4 1 0 0 0 0 0 0 0 0 4 3 6 3 6 3 0 9 1 0 0 0 0 0 0 0 0 0 4 3 4 3 4 3 4 3 0 0 0 5 6 0 0 3 2 0 9 6 0 2 4 1 7 3 1 7 3 1 7 3 1 8 3 0 0 1 1 0 0 1 1 2 0 2 4 0 1 7 3 1 7 3 1 7 3 1 7 3 0 0 0 0 4 0 0 0 0 0 0 1 8 1 8 1 8 1 8 0 0 1 0 0 0 0 0 0 1 8 1 8 1 8 1 8 0 0 0 1 0 0 0 0 0 0 0 9 8 1 9 8 1 9 8 1 9 8 1 0 0 0 0 0 0 4 1 5 9 8 1 9 8 1 9 8 1 1 8 9 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 3 4 12 5 1 3 4 12 5 1 7 6 13 0 0 0 0 0 0 0 0 0 0 0 6 2 6 2 6 2 62 0 0 0 0 0 0 0 0 0 0 0 4 1 4 1 4 1 4 1 0 0 0
70 85
73 85
76 18
69 4
48 0
0 0
3 0
0 0
00F0 00F8 0100 0108 0110 0118 0120 0128 0130 0138 0140 0148 0150 0158 0160 0168 0178 0180 0188
08 74 74 40 00 10 06 A9 80 00 1E 68 69 4E 74 FF
03 00 00 00 00 00 B0 46 00 00 00 65 73 54 20 FF
74 2E 2E 00 00 00 B6 00 00 18 00 6C 20 46 66 FF
00 00 00 00 00 00 4A 50 00 00 00 6C 69 53 69 FF
65 74 54 28 00 18 9B 8D 38 00 18 6F 73 20 6C 82
00 00 00 00 00 00 7E 39 00 00 00 20 20 74 65 79
73 78 58 00 05 00 DA 66 00 01 00 74 61 65 00 47
00 00 00 00 00 00 11 58 00 00 00 68 20 73 00 11
0 17 0
20 0 0 5 4 00 65 0 0 7 8 00
. . . . . . . F . . . > & O
. . . . . . E P . . . 9 : F M f : . . .
" . . . . . . . . . . 9
. O. >.T.
. . . . . . ( 9 . . .
. . . . . . . K . . . 8 & . .
84
0 10 1
01 20
74 00 20 00 44 00 6F 00 63 00 75 00 6D 00 65 00 6E 00 74 00 2E 00 74 00
116 99 110
0 32 0 117 0 116
0 68 0 109 0 46
The a ove #ump sho7s the file name as 7ell as the $ontents of the file are store# in this entry) 6as the file een larger it 7oul# not have een possi le to store the $ontent of the file in this entry so other $lusters 7oul# have een use# an# there 7oul# in#e:es 7oul# have een kept in the entry) 8s an e:er$ise one $an try to fin# out the su fol#ers an# the $ontents of the files store# in it)
/0 - 4isassem ling the ;T.S ase# file The follo7ing sli#es e:plain ho7 the ;T.S volume $an e a$$esse# in 4(S) ;ormally it $an not e a$$esse# if the system has oote# in 4(S as the 4(S #evi$e #rivers #o not un#erstan# ;T.S)5
Translating 9 / to 9$A
5idden 9"oc3s
-<8 @ ;o) of Physi$al <lo$ks in other Partition K 6i##en <lo$ks K -S; W 8ll this information $an e retrieve# from the Partition Ta le K <oot <lo$k
-1 - %is3 )ti"ities
Dinc"ude Vstdio=hQ Dinc"ude Vdos=hQ Dinc"ude V,ios=hQ Dinc"ude Va""oc=hQ
ty!edef struct tagfc, I unsigned char fi"ename T7UJ unsigned char e>tT(UJ unsigned char attri,J unsigned char reser&ed T10UJ unsigned int time,dateJ unsigned int firstc"usterJ unsigned "ong int siWeJ N#+9J ty!edef struct tag9P 9 I unsigned int ,yte s!ersecJ unsigned char sec!erc"ustJ unsigned int reser&edsecsJ unsigned char fatsJ unsigned int rootdirentsJ unsigned int sma""secsJ unsigned char mediaJ
unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned N9P9J
int fatsecsJ int secs!ertrac3J int headsJ "ong int hiddensecsJ "ong int hugesecsJ char dri&enoJ char reser&edJ char ,ootsignatureJ "ong int &o"umeidJ char &o"ume"a,e"T11UJ char fi"esystemT7UJ
struct ,oot,"oc3 I unsigned char Sum!instT(UJ unsigned char osnameT7UJ 9P9 ,!,J unsigned char codeT--7UJ NJ
%P9 far H getd!,/int dri&e1 I %P9 far Hd!,;/%P 9 far H10J Rasm !ush dsJ Rasm mo& ah,0>(' Rasm mo& d",,yte !tr dri&eJ Rasm mo& d>,dsJ Rasm int 0>'1J Rasm !o! ds Rasm cm! a",0>ff Rasm Se finish Rasm mo& 6ord !tr d!,B',d> Rasm mo& 6ord !tr d!,,,> return d!,J finishC return //%P9 far H1/011J N
&oid main /&oid1 I unsigned char fi"enameT8UJ struct ,oot,"oc3 ,,J unsigned char e>tT-UJ #+9 H dir,ufferJ unsigned int H # TJ %P9 dJ %P9 far H d!,!trJ int i,f"agJ unsigned int c"usterJ !uts/L:nter fi"enameCL1J gets /fi"ename1J !uts/L:nter :>tensionL1J gets/e>t1J if //a,sread/0>0.,1,0,O,,11;;01 !uts /LSuccessL1J e"seI !uts/L#ai"ureL1J e>it/01J N
# T ;ma""oc/.1'1J dir,uffer;ma""oc//,,=,!,=rootdirents1 H ('1J a,sread/0>0.,,,=,!,=fatsecs,,,=,!,=reser&ed secsB1,# T1J a,sread/0>0.,/,,=,!,=rootdirentsH ('1/,,=,!,=, yt es!ersec ,,,=,!,=fatsecsH,,=,!,=fatsB,,=,!,=reser&edsecs ,dir,uffer1J i ; 0J f"ag;0J 6hi "e/iV,,=,!,=rootdirents1 I if//strncm!i/fi"en ame,d ir,ufferTiU=fi"enam e,str"en/fi"ename111;;01 I if //strncm!i/e>t,dir,ufferTiU=e>t,str"en/e>t111;;01 I f"ag;1J c"uster ; d ir,ufferTiU=firstc"usterJ !rintf/LMn#irst c"u ster ; P> L,c"uster1J 6hi"e /c"uster V 0>###01 I a,sread/0>0.,1,,,=,!,=reser&edsecsB/c"uster/'.21,# T1J c"uster ; # TTc"usterP'.2UJ !rintf/LMn@e>t +"uster is CP>L,c"uster1J N
The a ove program uses the 4P< to rea$h the $lusters of a file) The get4P<13 fun$tion gets the far a##ress of the 4P<) Using this a##ress the #rive parameters are use# to #etermine the lo$ation of .8T an# root #ire$tory) The file is firstly sear$he# in the root #ire$tory through sePuential sear$h) "f the file name an# e:tension is foun# the first $luster num er is use# to look up into the .8T for su sePuent $lusters) The parti$ular lo$k $ontaining the ne:t $luster 7ithin the .8T is loa#e# an# the entry is rea#% similarly the 7hole $hain is traverse# till the en# of file is en$ountere#)
.ormat W -o7 -evel .ormat -- sets the lo$k si=e) -- sets the "nitial values in the lo$k) -- in#e:es the lo$k for optimal usage) -- $an e a$$omplishe# using <"(S routines for small #isks or e:ten#e# <"(S servi$es for larger #isks)
(is' +tilities
W Tui$k .ormat -- initiali=es the #ata stru$tures for file management) -- initiali=es an# sets the si=e of .8T% root #ire$tory et$% a$$or#ing to the #rive si=e) -- initiali=es the #ata in oot lo$k an# pla$es appropriate oot strap $o#e for the oot lo$k)
W After -rite it rea*s )ack the ) ock contents2 W Performs the CRC test on *ata rea* )ack2 W If there is an error then the *ata on that ) ock is not sta) e the c "ster of that ) ock sho" * )e marke* )a*2 W ,he c "ster is marke* )a* )y p acing the appropriate co*e for )a* c "ster so that they may not )e a ocate* to any fi e2
W The #isk s$anning soft7are may also look for lost $hains) W -ost $hains are $hains in .8T 7hi$h apparently #onMt elong to any file) W They may o$$ur #ue to some error in the system like po7er failure #uring #eletion pro$ess)
9ost Chains
W .or ea$h file entry in the #ire$tory stru$ture its $hain in .8T is traverse#) W 8ll the $luster in the file are marke#) W >hen #one 7ith all the files an# fol#ers% if some non-=ero an# non-reserve# $lusters are left then they elong to some lost $hains) W The lost $hains are firstly #is$retely i#entifie# an# then ea$h $hain $an either e restore# to ne7ly name# files or $an e #elete#)
( B W "f a $luster lie in more than one file $hain% then its sai# to e Cross ,eferen$e#) . C W Cross referen$es $an pose great pro lems) 4 O W Cross referen$es $an e #ete$te# easily y traversing through the $hain of all files an# marking the $luster H #uring traversal) W "f a $luster is referen$e# more than on$e 11 3#0 then it in#i$ates a $ross referen$e) W To solve the pro lem only one referen$e 1( 5A shoul# e maintaine#) C 1-
Cross .eferences
W Disk fragmentation is "n-ante*2 W 9ragmentation means that c "sters of a same fi e are not contig"o"s y p ace*= rather they are far apart= increasing seek time hence access time2 W So its *esira) e that fi es c "sters may )e p ace* contig"o"s y= this can )e *one )y compaction or *efragme ntation2 W Defragmentation Soft-are reser;es space for each fi e in contig"o"s ) ock )y mo;ing the *ata in c "sters an* rea*^"sting2 W As a res" t of *efragmentation the 9A, entries -i change an* *ata -i mo;e from one c "ster to other oca iBe* c "ster to re*"ce seek time2 W Defragmentation has high comp"tation cost an* th"s cannot )e performe * freZ"ent y2
(efragmenter
W 9A, str"ct"re pro;i*es the possi)i ity of reco;ering a fi e after *e etion= if its c "sters -ere contig"o"s an* ha;e not )een o;er?-ritten2 W DOS perform fi e *e etion )y p acing $<>: at the first )yte of it 9C. entry an* p acing $_s 6meaning a;ai a) e7 in the entries for the fi e c "sters in the 9A,2 W ,-o task sho" * )e performe* s"ccessf" y to "n*e ete a fi e ?? Rep acing the $<>: entry in 9C. )y a ;a i* fi e name character2 ?? p acing the appropriate ;a "es in 9A, for representation of fi e c "ster chain2 W If any one of the a)o;e cannot )e *one then the fi e cannot )e f" y reco;ere*2
0ile .estoration
W Un#erstan#ing of the #ata stru$tures an# te$hniPues use# for memory management) W Stu#y of the overall memory areas use# y operating system an# appli$ations)
)emory )anagement
The follo7ing sli#e sho7s the memory map of the first !&< of ,8&) The first 6/02< is $alle# $onventional ,8& an# the higher +0/2< is $alle# system memory) Some of the memory areas are reserve# for spe$ial purposes as #es$ri e# y the sli#e rest is user area 7here user appli$ation $an resi#e)
)emory )ap
3arlier *Cs % 6;Wbit Address $us I$T ;;;; @ ;;;;>
9IOS %ata rea %OS %ata rea
IO=Sys MS%OS=Sys Other %e&ice %ri&ers +ommand=+om /*esident Part1 )ser !!"ications +ommand=+om /Transient Part1 ?ra!hics %is!"ay Te>t %is!"ay )nused Shado6 * M
/0 - 4isassem ling the ;T.S ase# file "n higher pro$essors% the main memory may e greater than !&<) "n this sli#e it sho7s that the memory portion higher than !&< is $alle# e:ten#e# memory an# some unuse# portion in system memory is $alle# the e:pan#e# memory)
)emory )ap
>igher *rocessors with 6AWbit or 86Wbit Address $us Conventional .A) %7A; E$&
W also $alle# 9&S W $an e a$$esse# using a #river $alle# 9&&+06)9N9 W this #river allo7s the use of unuse# memory 7ithin system memory) W also $alle# N&S W $an e a$$esse# y installing the #river 6"&9&)SGS W this #river ena le the e:ten#e# memory y shifting from ,eal to Prote$te# &o#e)
3,panded )emory
3,tended )emory
6igher PCs $an operate in t7o mo#es W ,98- &(49 W P,(T9CT94 &(49
W PCs initially oots up in ,eal &o#e) "t may e shifte# to prote$te# mo#e #uring the ooting pro$ess using #rivers like 6"&9&)SGS W (nly first ! &< of ,8& $an e a$$esse# in ,eal &o#e) W The ,eal &o#e a##ress is a 20- it a##ress% store# an# represente# in the form of Segment D (ffset W (S like 4(S has a memory management system in refle$tion of the ,eal &o#e)
.eal )ode
W PC has to e shifte# to Prote$te# &o#e if originally oots in ,eal &o#e) W "n Prote$te# &o#e 7hole of the ,8& is a$$essi le that in$lu#es the Conventional% 9:pan#e# an# 9:ten#e# &emories) W (S like >in#o7s has a memory management system for Prote$te# &o#e) W 8 privilege level $an e assigne# to a memory area restri$ting its a$$ess)
*rotected )ode
W 4(S uses the $onventional memory first 6/0 2< for its memory management) W 8##itional 6/ 2< $an e utili=e# y installing 9&&+06)9N9 an# a##itional 6/ 2< in the start of e:ten#e# memory y installing 6"&9&)SGS W Smallest allo$ata le unit in 4(S is a Paragraph% not a <yte)
)emory )anagement in (#
W >henever memory is to e allo$ate# 4(S a llo$ates memory in form of Paragraph) W 8 Paragraph $an e un#erstoo# from the follo7ing e:amp le $onsi#er t7o Physi$al 8##resses !2+/ 6 D 0000 6 !2+* 6 D 0000 6 W ;ote there is a #ifferen$e of ! et7een the Segment a##ress) W ;o7 lets $al$ulate the Physi$al a##ress !2+/0 6 !2+*0 6 4ifferen$e @ !0 6 W 8 #ifferen$e of ! 6 in Segment a##ress $ause a #ifferen$e of !0 6 in Physi$al a##ress) W 4(S loa#er assign a segment a##ress 7henever memory area is allo$ate#% hen$e a $hange of ! in Seg ment a##ress 7ill impart a # iffe ren$e of !6 4 _ !0 6 in physi$al a##ress)
*aragraph
W Contains 9nvironment information like 9nvironment varia les an# file paths for that program
3nvironment $loc'
W is situate# efore the start of a pro$ess) W $ontains $ontrol information like 4T8 1 4isk Transfer 8rea3 an# $omman# line parameters)
* *
/0 - 4isassem ling the ;T.S ase# file The follo7ing sli#e sho7s that t7o &C<s are allo$ate# for ea$h program typi$ally) The first &C< $ontrols the 9nvironment <lo$k the ne:t &C< $ontrols the PSP an# the program) "f this is the last program in memory then the &C< after the program has QIM in its first yte in#i$ating that it is the last &C< in the $hain)
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$ Q L into the segment address of the )C$. ame is true for all )C$s and hence the whole chain can be traversed.
W 8n #o$umente# servi$e $an e use# to o tain the a##ress of the first &C<) W Servi$e 2!6'*26 is use# for this purpose) W This servi$e returns The a##ress of 4(S internal #ata stru$tures in 9S D <N W /- ytes ehin# the a##ress returne# lies the far a##ress of the first &C< in memory) W Using this a##ress an# hen$e traversing through the $hain of &C<s using the information 7ithin &C<s)
-5 13B0:0100 Ao7 58#52 13B0:0102 :n" 21 13B0:0104 -< AKL5200 BKL0000 DML13B0 EML13B0 13B0:0102 CD21 -< AKL5200 BKL0026 DML13B0 EML00A7 13B0:0104 0000 DM:0026LFF -; 57:22 00A7:0020 00A7:0030 00A7:0040 00A7:0050 00A7:0060 00A7:0070 00A7:0080 00A7:0090 00A7:00A0 -q
CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000 MML13B0 CML13B0 !PL0104 %) UP E! PN %H %A P2 %C ADD IBK4M!Q#AN
70 00 CC 00 00 00 82 2E
00 00 0D AB 00 FF 14 FE
00 24 72 4E 73 00 FF D3
00 00 03 55 03 00 00 28
08 70 00 4C 0E 00 00 2E
02 00 00 20 00 00 00 FE
EA 80 04 20 00 00 00 D7
00 00 00 20 03 00 00 FE
CE 00 D9 00 01 00 00 D7
00 00 02 00 00 00 05 28
A7 00 04 00 04 00 FF 2E
00 00 80 00 00 00 9F FE
5A 7C C6 00 00 00 08 D3
00 03 0D 00 00 00 02 28
The a ove sli#e sho7s ho7 servi$e 2!6'*26 is use# to get the a##ress of first &C< in memory) "n the follo7ing sli#e the #ump of the first &C< is taken) Q&M in the first yte at the lo$ation rea# in#i$ates the pla$ement of &C< at this lo$ation) The a##ress of ne:t &C< $an e $al$ulate# y a##ing the num er of paragraphs $ontrolle# y &C< K ! into the segment a##ress) Using this metho# all the &C<s in memory are traverse# till the last &C< 7ith first yte QIM is en$ountere#)
-; 208:0 0208:0000 0208:0010 -D 40C:0 040C:0000 040C:0010 -D 4AF:0 04AF:0000 04AF:0010 -D 4B7:0 04B7:0000 04B7:0010 -D 525:0 0525:0000 -D DA0:0 0DA0:0000 0DA0:0010 -D E02:0 0E02:0000
0E02:001 0E02:002 0E02:003 0E02:004 0E02:005 0E02:006 0E02:007 -1 0 0 0 0 0 0 0 CD 20 FF 9F 00 0D 04 56 01 0D FF FF FF FF FF 14 0E 14 00 18 05 00 00 00 00 CD 21 CB 00 00 20 20 20 20 20 9A F0 04 0D FF FF 00 03 00 00 00 00 20 20 FE-1D 04-01 FF-FF 0E-FF 00-00 00-00 20-00 F0 03 FF FF 00 00 00 DE 01 FF FF 00 00 00
0208:002 0 28 18 10 00 08 08 03 00-02 67 2D 27 28 90 2B A0 0208:003 0 BF 1F 00 4F 0D 0E 00 00-00 00 9C AE 8F 14 1F 96 0208:004 0 B9 A3 FF 00 01 02 03 04-05 14 07 38 39 3A 3B 3C 0208:005 0 3D 3E 3F 0C 00 0F 08 00-00 00 00 00 10 0E 00 FF 0208:006 0 50 18 10 00 10 00 03 00-02 67 5F 4F 50 82 55 81 0208:007 0 BF 1F 00 4F 0D 0E 00 00-00 00 9C 8E 8F 28 1F 96
4D 08 00 03 02 09 0E 1F-53 44 00 CD 21 EB FE 26 51 0A 02 CE 00 9A F0 FE-4B 42 44 00 08 02 53 25
S ...... ..?-]S .4. . ..2... ...... ... . ...... ....89 :F$ L >/.... ...... ... P ...... .. ?R2P .U. . ..2... ...... S..
B.......MD..*..W 1.......JBD...MX
040C:002 0 0D 04 56 01 0D 04 0D 04-01 03 01 00 02 FF FF FF 040C:003 0 FF FF FF FF FF FF FF FF-FF FF FF FF B8 04 FA 05 040C:004 0 0D 04 14 00 18 00 0D 04-FF FF FF FF 00 00 00 00 040C:005 0 05 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 040C:006 0 CD 21 CB 00 00 00 00 00-00 00 00 00 00 20 20 20 040C:007 0 20 20 20 20 20 20 20 20-00 00 00 00 00 20 20 20
4D 0D 04 A2 00 00 06 00-43 4F 4D 4D 41 4E 44 00 CD 20 FF 9F 00 9A F0 FE-1D F0 7F 01 0D 04 4B 01
. .).... ...... ... . ...... ...... ... . ...... ...... ... . ...... ...... ... . *..... ...... .....
B.......C2BBA%D. . ............J.
04AF:002 0 FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF 04AF:003 0 43 3A 5C 57 49 4E 44 4F-57 53 5C 54 45 4D 50 5C 04AF:004 0 73 63 73 35 2E 74 6D 70-00 00 00 00 00 00 00 00 04AF:005 0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 04AF:006 0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 04AF:007 0 00 20 76 61 6C 75 65 20-6E 6F 74 20 61 6C 6C 6F
4D 00 00 07 00 73 1A 52-65 71 75 69 72 65 64 20 00 01 00 00 00 00 00 00-87 06 00 00 FF FF FF FF
. ...... ...... ... C :\W!%D 2WM\OE BP\ & C&5."A <..... ... . ...... ...... ... . ...... ...... ... . 759 > no" 5 99o
04B7:002 0 57 53 5C 53 59 53 54 45-4D 33 32 5C 43 4F 4D 4D 04B7:003 0 41 4E 44 2E 43 4F 4D 00-41 4C 4C 55 53 45 52 53 04B7:004 0 50 52 4F 46 49 4C 45 3D-43 3A 5C 44 4F 43 55 4D 04B7:005 0 45 7E 31 5C 41 4C 4C 55-53 45 7E 31 00 41 50 50 04B7:006 0 44 41 54 41 3D 43 3A 5C-44 4F 43 55 4D 45 7E 31 04B7:007 0 5C 79 64 6B 5C 41 50 50-4C 49 43 7E 31 00 43 4F
4D 0D 04 6D 00 61 72 61-6D 65 74 65 72 20 76 61 43 4F 4D 53 50 45 43 3D-43 3A 5C 57 49 4E 44 4F
W M\MGMO EB32\C 2BB A %D.C2B .ANNUM EUM P U2F!NE LC:\D2 CUB E (1\ANN UME(1. APP D AOALC: \D2CUB E(1 \ @;`\AP PN!C(1 .C2
B..A.5,5A>">, 75 C2BMPECLC:\W!%D2
0525:001 0 CD 20 A0 0D 00 9A C0 00-00 00 DE 01 0D 04 4B 01 0525:002 0 0D 04 56 01 0D 04 0D 04-01 01 01 00 02 FF FF FF 0525:003 0 FF FF FF FF FF FF FF FF-FF FF FF FF 12 D2 E8 00 0525:004 0 36 05 14 00 18 00 26 05-FF FF FF FF 00 00 00 00 0525:005 0 05 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 0525:006 0 CD 21 CB 00 00 00 00 00-00 00 00 00 03 20 20 20 0525:007 0 20 20 20 20 20 20 20 20-00 00 00 00 00 20 20 20
4D 26 05 7A 08 8E DB C5-44 4F 53 58 00 58 5B 1F
. ..... ...... .J. . .).... ...... ... . ...... ...... ... 6 .....W ...... ... . ...... ...... ... . *..... ...... .....
BW.\....D2MK.KI.
4D 03 0E 61 00 61 6E 6E-6F 74 20 72 75 6E 20 74 43 4F 4D 53 50 45 43 3D-43 3A 5C 57 49 4E 44 4F
W M\MGMO EB32\C 2BB A %D.C2B .ANNUM EUM P U2F!NE LC:\D2 CUB E (1\ANN UME(1. APP D AOALC: \D2CUB E(1 \ @;`\AP PN!C(1 .C2
0DA0:002 0 57 53 5C 53 59 53 54 45-4D 33 32 5C 43 4F 4D 4D 0DA0:003 0 41 4E 44 2E 43 4F 4D 00-41 4C 4C 55 53 45 52 53 0DA0:004 0 50 52 4F 46 49 4C 45 3D-43 3A 5C 44 4F 43 55 4D 0DA0:005 0 45 7E 31 5C 41 4C 4C 55-53 45 7E 31 00 41 50 50 0DA0:006 0 44 41 54 41 3D 43 3A 5C-44 4F 43 55 4D 45 7E 31 0DA0:007 0 5C 79 64 6B 5C 41 50 50-4C 49 43 7E 31 00 43 4F
01 00 FF FF 00 00 00
0D 02 A1 00 00 00 00
04 4B FF FF 0D B9 00 00 00 00 20 20 20 20
5A 03 0E FC 91 27 8A 05-44 45 42 55 47 00 9D 00
01 FF 49 00 00 20 20 . ..... ...... .J. . .).... ...... ... . ...... ...... ..! . ...... ...... ... . ...... ...... ... . *..... ...... .....
H....]..DEBUG...
seg M Y3 ; off M Y$D; off M offW A; temp M %unsigned int far K& )EY0*%seg,off&; seg M K%tempQ5&; pmcb M %)C$ far K&)EY0*%seg,Ktemp&; while %pmcbWJsig MM _)_& N printf%abn egment Address of * * is U,a,pmcbWJpspseg&; printf%abn/o of *aras controlled by )C$ M U ,bna,pmcbWJparas&; seg M seg Q pmcbWJparas Q 5; pm cb M %)C$ far K&)EY0*%seg,Ktemp&; P if %pmcbWJsig MM _^_& N printf%abn9ast )C$ founda&; printf%abn/o of free *aras M U,a,pmcbWJparas&; i M %pm cbWJparas&K579; ltoa%i,st,5;&; printf%abn9argest contigous bloc' M a &; puts %st&; P P
This program use# the same metho# as #is$usse# in previous le$ture to get the a##ress of first &C<% $al$ulate the a##resses of su sePuent &C<s an# traverse the &C<s to rea$h the last &C<)
W 9arlier (perating System like 4(S has $ontiguous memory management system i)e) a program $annot e loa#e# in memory if a $ontiguous lo$k of memory is not availa le to a$$ommo#ate it) W 00206 an# higher pro$essors support non-$ontiguous allo$ation) W 00206 support Segmentation in Prote$te# &o#e% i)e) a pro$ess is su #ivi#e# into segment of varia le si=e an# ea$h segment or fe7 segments of the pro$ess $an e pla$e# any7here in memory W 00+06 an# higher pro$essors also support Paging% i)e) a Pro$ess may e #ivi#e# into fi:e# si=e Pages an# then only fe7 pages may e loa#e# any 7here in memory for Pro$ess 9:e$ution) W The key to su$h non-$ontiguous allo$ation systems is the a##ressing te$hniPue)
/onWContiguous Allocation
W "n Prote$te# &o#e the #ire$t metho# of seg E !06 K offset for -ogi$al to Physi$al a##ress translation is #is$ar#e# an# an in#ire$t metho# is a#opte#)
Address Translation
W "n Prote$te# &o#e the Segment ,egisters are use# as Sele$tor) W 8s the name suggest they are use# to sele$t a #es$riptor entry from some 4es$riptor Ta le)
electors
(escriptor
W 8 4es$riptor #es$ri es a &emory Segment y storing attri utes relate# to a &emory Segment) W Signifi$ant attri utes of a &emory Segment $an e its ase 1starting3 a##ress% it length or limit an# its a$$ess rights)
The follo7ing sli#e sho7s the stru$ture of #es$riptors of 00206 an# 00+06 pro$essors
?;6?7 (escriptor
C B 8 Access $57& .ights .eserved $ase%$68W 7 A 6
9ase
?;8?7 (escriptor
Limit ? % 0 $ L
/L12 <L 181
C B 8
7 A 6
Access .ights
W <ase 1<+! U <03 $ontains the ase a##ress of Segment 7ithin the /F< Physi$al spa$e) W -imit 1-!9 U -03 #efine the length of segment in units of ytes if F @ 0 an# in units of /2 1pages3 if F@ !) This allo7 the Segment to e of !& if F @ 0 an# of /F if F @ !)
(escriptor
W 8$$ess ,ightD $ontains the privilege level an# other information #epen#ing upon the type of #es$riptor) W FD the granularity it sele$ts the multiplier of ! or /2 times the limit fiel#) "f F @ 0 multiplier is !A if F @ ! multiplier is /2) W 4D sele$ts the #efault registers si=e) "f 4 @ 0 the #efault register si=e is !6- it% if 4 @ ! the si=e is +2- it) W 8V-D the (perating System often uses this it to in#i$ate that the segment #es$ri e# y the 4es$riptor is availa le in memory
egment (escriptor
W "f the 4es$riptor #es$ri es a memory segment then the 8$$ess ,ights <yte 7ill have the follo7ing meaning) * W PD (* 9 3 D .W A
Present it% if P @ ! Seg ment is Present% if P @ 0 Segment is not Present) W 4P-D 4es$riptor Privilege level 00 for highest an# !! for lo7est) -o7 privilege level memory area $annot a$$ess a memory area 7ith high privilege 7hereas vi$e versa is T,U9) W SD "n#i$ates #ata or $o#e segment if S @ ! or a System 4es$riptor if S @ 0) W 9D 9:e$uta le% if 9 @ 0 Then itMs a 4ata'Sta$k Segment% if 9 @ ! Then itMs a Co#e Segment) W ND "f 9 @ 0 then N in#i$ates the #ire$tion of e:pansion of the Segment) "f N @ 0 Seg ment e:pan#s up7ar#s 1i)e) 4ata Seg ment3 "f N @ ! Seg ment e:pan#s #o7n7ar#s 1i)e) Sta$k Seg ment3 "f 9 @! then N in#i$ates if the privilege level of Co#e Segment is ignore# 1N @ 03 or o serve# 1N @ !3) W8 8$$esse# is set 7henever the Segment is set)
Limit ? 0 0 0
/L12 <L181
C B 8 5
7 A 6 ;
9ase/9'(-9121
%PL 0
TKP:
(escriptor Table
W F4TD Flo al 4es$riptor Ta le W -4TD -o$al 4es$riptor Ta le W "4TD "nterrupt 4es$riptor Ta le W F4T an# -4T $an have up to 0!92 entries% ea$h of 0ytes 7i#th) W "4T $an have up to 2*6 entries)
T!
elector !nde, elects a (escriptor Table entry 0rom 9(T or 2(T T! M ; 2lobal T! M 5 9ocal
.*9
.equested *rivilege 9evel ;; %>ighest& 55 %9owest&
The hi##en $a$he is illustrate# in the sli#e elo7) The registers in #otte# lines are hi##en i)e) are not a$$essi le to any appli$ation #ire$tly)
+S %S :S SS #S ?S
9ase dd ress
Limit
ccess *ights
T* L%T*
9a se
Limit
GDTR IDTR
Control .egister
W 00+06 an# a ove have / Control ,egisters C,0 X C,+) W These Control ,egisters are use# for $onveying $ertain $ontrol information for Prote$te# &o#e 8##ressing an# Co-Pro$essors) W 6ere 7e 7ill illustrate only the least signifi$ant it of C,0) *3 C.; W The least signifi$ant it of C,0 is P9- it 7hi$h $an e set to ena le Prote$te# &o#e 8##ressing an# $an e $leare# to enter ,eal &o#e)
!)
2) +) /) *) 6)
1iruses
W Viruses are spe$ial program having a ility to em e# themselves in a system resour$es an# there on propagate themselves)
State of Viruses
W 4ormant StateD 8 Virus in #ormant state has em e##e# itself 7ithin an# is o serving system a$tivities) W 8$tivation StateD 8 Virus 7hen a$tivate# 7oul# typi$ally perform some un7ante# tasks $ausing #ata loss) This state may triggere# as result of some event) W "nfe$tion StateD 8 Virus is triggere# into this state typi$ally as a result of some #isk operation) "n this state% the Virus 7ill infe$t some me#ia or file in or#er to propagate itself)
-. - $iruses
Types of 1iruses
W Partition Ta le Virus W <oot Se$tor Virus W .ile Viruses
0ile 1iruses
W Various Viruses em e#s themselves in #ifferent e:e$uta le files) W Theoreti$ally any file that $an $ontain any e:e$uta le $o#e% a Virus $an e em e##e# into it) i)e) )C(&% )9N9 are e:e$uta le files so Viruses $an e em e##e# into them% Plain Te:t .iles% Plain <itmap .iles are pure #ata an# $annot e e:e$ute# so Viruses $annot e a$tively em e##e# into them% an# even if they are someho7 em e##e# they 7ill never get a $han$e to e:e$ute itself)
C#) 0ile
W C(& .ile is a mirror image of the program $o#e) "ts image on #isk is as it is loa#e# into the memory) W C(& .iles are single segment files in 7hi$h oth Co#e an# 4ata resi#es) W C(& .ile 7ill typi$ally have a Three <ytes ;ear cump "nstru$tion as the first instru$tion in program 7hi$h 7ill transfer the e:e$ution to the Co#e Part of the Program) ?mp $o#e @@@@ @@@@ A4ata Part @@@@ $o#eD @@@@ @@@@ ACo#e Part
// - 8##ress translation in Prote$te# mo#e The follo7ing sli#e illustrates ho7 a C(& file virus relo$ates itself to make itself in#epen#ent in memory)
*rogram
) * *
*aras
1irus
(etection
W Viruses $an e #ete$te# y sear$hing for their Signature in &emory or 9:e$uta le .iles) W Signature is a inary su set of Virus Co#e) "t is a part of Virus Co#e that is uniPue for that parti$ular Virus only an# hen$e $an e use# to i#entify the Virus W Signature for a Virus is sele$te# y $hoosing a uniPue part of its Co#e) To fin# a Virus this Co#e shoul# e sear$he# in memory an# in files) "f a mat$h is foun# then the system is infe$te#)
.emoval
Partition Ta le S <oot Se$tor Viruses
W Partition Ta le an# <oot Se$tor Viruses $an e remove# y re-7riting the Partition Ta le or <oot Se$tor Co#e) W "f the Virus is resi#ent it may e:hi it stealth i)e) prevent other programs from 7riting on Partition Ta le or <oot Se$tor y inter$epting int !+6 W "n $ase itMs a stealth Virus the system shoul# e oote# from a $lean #isk 7ill not give the Virus any $han$e to e:e$ute or loa# itself)
W If the Vir"s siBe is kno-n Vir"ses can )e remo;e* easi y from fi e2 W 9irst y= the origina ;a "e of first 5?)ytes in case of COM 9i e or the entry point in case of >3> sho" * )e restore*2 W ,he appen*e* portion of Vir"s can )e remo;e* )y coping the contents of origina fi e into a temporary fi e2
0ile 1iruses
#riginal
temp
W,he Vir"s Co*e is not copie*2 W ,he origina fi e is then *e ete* an* the temporary fi e is rename* as the origina fi e2