System Programming - CS609 Handouts[1]

341
 ystem Programming C 609 Virtual University of Pakistan  Knowledge beyond the boundaries

Transcript of System Programming - CS609 Handouts[1]

Page 1: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 1/340

  ystem ProgrammingC 609

Virtual University of Pakistan  Knowledge beyond

the boundaries

Page 2: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 2/340

CS609-System Programming VU

© Copyright Virtual University of Pakistan 2

Page 3: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 3/340

CS609-System Programming VU

Tale of Contents

0! - "ntro#u$tion% &eans of "'( )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))*02 - "nterrupt &e$hanism)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!+0+ - Use of "S,s for C irary .un$tions))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2!

0/ - TS, programs an# "nterrupts))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))20* - TS, programs an# "nterrupts 1eyoar# interrupt3 )))))))))))))))))))))))))))))))))))))))))))))))))))+*06 - TS, programs an# "nterrupts 14isk interrupt% eyoar# hook3)))))))))))))))))))))))))))))))))/205 - ar#7are "nterrupts))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/0 - ar#7are "nterrupts an# TS, programs)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))*609 - The interval Timer))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))5!!0 - Peripheral Programmale "nterfa$e 1PP"3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))59!! - Peripheral Programmale "nterfa$e 1PP"3 "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))6!2 - Parallel Port Programming))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))9!+ - Serial Communi$ation)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!06!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3))))))))))))))))!!+

!* - C(& Ports))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!20!6 - C(& Ports "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!2!5 - ,eal Time Clo$k 1,TC3))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!+6! - ,eal Time Clo$k 1,TC3 ""))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!/9!9 - ,eal Time Clo$k 1,TC3 """)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!*20 - 4etermining system information))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!662! - eyoar# "nterfa$e))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!5*22 - eyoar# "nterfa$e% 4&8 Controller)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!+2+ - 4ire$t &emory 8$$ess 14&83)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!92/ - 4ire$t &emory 8$$ess 14&83 "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))!9*2* - .ile Systems))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))20226 - ar# 4isk))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2!!25 - ar# 4isk% Partition Tale))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2202 - Partition Tale "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))22529 - ,ea#ing :ten#e# Partition))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2+++0 - .ile System 4ata Stru$tures 1S;% <P<3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2/0+! - .ile System 4ata Stru$tures "" 1<oot lo$k3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))2/+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)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))25+5 - .8T+2 .ile System)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))25+ - .8T+2 .ile System "")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))29*+9 - ;e7 Te$hnology .ile System 1;T.S3)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+0*/0 - 4isassemling the ;T.S ase# file))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+!0/! - 4isk Utilities)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+!6/2 - &emory &anagement)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+2!/+ - ;on-Contiguous memory allo$ation)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+2// - 8##ress translation in Prote$te# mo#e))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))+++/* - Viruses))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))++5

© Copyright Virtual University of Pakistan +

Page 4: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 4/340

CS609-System Programming VU

© Copyright Virtual University of Pakistan /

Page 5: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 5/340

01 - Introduction, Means of I/O

What is Systems Programming?

Computer programming can be categorized into two categories .i.e.

Input OutputInput OutputProcess

While designing software the programmer may determine the required inputs forthat program, the wanted outputs and the processing the software would perform

in order to give those wanted outputs. The implementation of the processing partis associated with application programming. Application programming facilitatesthe implementation of the required processing that software is supposed toperform; everything that is left now is facilitated by system programming.

ystems programming is the study of techniques that facilitate the acquisition ofdata from input devices, these techniques also facilitates the output of data whichmay be the result of processing performed by an application.

Three Layered !!roach

 A system programmer may use a three layered approach for systemsprogramming. As you can see in the figure the user may directly access theprogrammable hardware in order to perform !"# operations. The user may usethe trivial $!# %$asic !nput #utput ystem& routines in order to perform !"# inwhich case the programmer need not 'now the internal wor'ing of the hardwareand need only the 'nowledge $!# routines and their parameters.

'>

4(S

<"(S

!n this case the $!# programs the hardware for required !"# operation which ishidden to the user. !n the third case the programmer may invo'e operating

systems %(# or whatever& routines in order to perform !"# operations. The

Page 6: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 6/340

0! - "ntro#u$tion% &eans of "'(

operating system in turn will use $!# routines or may program the hardwaredirectly 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 threeways 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 theC*+ performs the computations required to complete the !"# operation and thenagain starts waiting for the !"# device to be able to perform net !"# operation. !n

this way the C*+ remains tied up and is not doing anything else besides waitingfor 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. Theprocessor 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 eecution of C*+ is interrupted and an !nterruptervice outine %!& is invo'ed which performs the computations required for!"# operation. After the eecution of ! the C*+ continues with whatever it wasdoing 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 orvice versa if this is done via some processor register. This transfer time can bereduced bypassing the C*+ as ports and memory device are also interconnectedby system bus. This is done with the support of ()A controller. The ()A %directmemory access& controller can controller the buses and hence the C*+ can bebypassed data item can be transferred from memory to ports or vice versa in asingle bus cycle.

© Copyright Virtual University of Pakistan 6

Page 7: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 7/340

0! - "ntro#u$tion% &eans of "'(

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 eample the monitor is not directly collected to the C*+rather the monitor is connected to a 12A card and this 12A card is in turnconnected to the C*+ through busses. The 'eyboard is not directly connected toC*+ rather its connected to a 'eyboard controller and the 'eyboard controller isconnected 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 thetechniques 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 systemsystems programming is not 4ust the study of programmable hardware devices.To develop effective system software one needs to the internals of the operatingsystem as well. #perating systems ma'e use of some data structures or tablesfor 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 datastructures used for these operations be accessed.

© Copyright Virtual University of Pakistan 5

Page 8: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 8/340

0! - "ntro#u$tion% &eans of "'(

#i"e Management0ile 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 canbe directly accessed. The various data structures are popularly 'nown as 0ATwhich 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 structurethe basic requirement is the understanding of the dis' architecture, the dis'formatting process and how this process divides the dis' into sectors andclusters.

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 thememory within this range the (# operating system ma'es use of some datastructures called

• 0C$ %0ile control bloc' &

• ** %*rogram segment prefi&

We shall discuss how these data structures can be directly accessed, what is thesignificance of data in these data structures. This information can be used totraverse through the memory occupied by the processes and also calculate thetotal amount of free memory available.Certain operating systems operate in protected mode. !n protected mode all ofthe memory interfaced with the processor can be accessed. #perating systems inthis mode ma'e use of various data structures for memory management whichare

• 9ocal (escriptor Table

• 2lobal (escriptor Table

!nterrupt (escriptor Table

We will discuss the significance these data structures and the information storedin them. Also we will see how the logical addresses can be translated intophysical addresses using the information these tables 

$iruses and $accines

#nce an understanding of the file system and the memory )anagement isdeveloped it is possible to understand the wor'ing of viruses. 1irus is a simple

program which can embed itself within the computer resources and propagateitself. )ostly viruses when activated would perform something hazardous.

© Copyright Virtual University of Pakistan

Page 9: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 9/340

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 mostlyimportantly prevented to perform any infections.There are various types of viruses but we will discuss those which embedthemselves within the program or eecutable code which are

3ecutable 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 driversare not installed. This is so important because a device driver contains theroutines which perform !"# operations on the device. +nless these routines areprovided no !"# operation on the !"# device can be performed by any application.We will discuss the integrated environment for the development of device driversfor (# and Windows.

We shall begin our discussion from means of !"#. #n a well designed device it ispossible to perform !"# operations from three different methods

• *rogrammed !"#

• !nterrupt driven !"#

• ()A driven !"#

(utput

40

"'(

Controller 

"nput

45

4, 

CPU

40

"'(

Controller 

"nput

45

4, 

CPU

40

45

Stroe

<usy

40

45

Stroe

<usy

CPU

!n case of programmed !"# the C*+ is in a constant loop chec'ing for an !"#

opportunity and when its available it performs the computations operationsrequired for the !"# operations. As the !"# devices are generally slower than theC*+, C*+ has to wait for !"# operation to complete so that net data item can besent to the device. The C*+ sends data on the data lines. The device need to besignaled 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. Thedevice on getting the strobe signal receives the data and starts its output. Whilethe device is performing the output it-s busy and cannot accept any further dataon the other and C*+ is a lot faster device and can process lot more bytes duringthe 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

Page 10: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 10/340

0! - "ntro#u$tion% &eans of "'(

device to get idle by chec'ing the $+< signal as long as the device is busy andwhen the device gets idle the C*+ will compute the net data item and send it tothe device for !"# operation.imilar is the case of input, the C*+ has to chec' the ( %data eady& signal tosee 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 ofprogrammed !"# as can benoticed is that the C*+ isbusy waiting for an !"#opportunity and as a resultremain tied up for that !"#operation. This disadvantage

can be overcome by meansof interrupt driven !"#. !n*rogrammed !"# C*+ itselfchec's for an !"# opportunitybut in case of interruptdriven !"# the !"# controller

interrupts the eecution of C*+ when ever and !"# operation is required for thecomputation of the required !"# operation. This way the C*+ can perform othercomputation and interrupted to perform and interrupt service routine only whenan !"# operation is required, which is quite an optimal technique.

© Copyright Virtual University of Pakistan

Interrupt Driven input / output

Stroe

(utput

40

"'(

Controller 

"<.

"nput

45

";T

CPU

40

45

";T 8C 

<usy

"'(

Controller 

CPU

!0

Page 11: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 11/340

0! - "ntro#u$tion% &eans of "'(

%M dri&en I/O

!n case data is needed to

transferred from mainmemory to !"# port this canbe done using C*+ whichwill consume 6 bus cyclesfor a single word, one buscycle from memory to C*+and other from C*+ to !"#port in case of output andthe vice versa in case of

input. !n case no computation on data is required C*+ can be bypassed andanother device ()A %direct memory access& controller can be used. !ts possible

to transfer a data word directly from memory to C*+ and vice versa in a singlebus cycle using the ()A, this technique is definitely faster.

We shall start our discussion with the study of interrupt and the techniques usedto program them. We will discuss other methods of !"# as required.

What are interrupts=

ISR Performing An I/O

!2

+

9iterally to interrupt means to brea' the continuity of some on going tas'. Whenwe tal' of computer interrupt we mean eactly the same in terms of theprocessor. When an interrupt occurs the continuity of the processor is bro'en andthe eecution branches to an interrupt service routine. This interrupt serviceroutine is a set of instruction carried out by the C*+ to perform or initiate an !"#operation generally. When the routine is over the eecution of the C*+ returns tothe point of interruption and continues with the on going process.

© Copyright Virtual University of Pakistan

DMA Driven I/O

I/O

DMA

CPU

Register

Main Memory

!!

Page 12: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 12/340

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. oftwareinterrupts 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 anotherform temporary eecution transfer, but there some differences as well. /ote thatwhen procedures are invo'ed by there names which represents their addressesis specified whereas in case of interrupts their number is specified. This numbercan be any ? bit value which certainly is not its address. o the first question iswhat is the significance of this number= Another thing should also be noticed thatprocedures are part of the program but the interrupts invo'ed in the program areno where declared in the program. o the net question is where do theseinterrupts reside in memory and if they reside in memory then what would be theaddress of the interrupt=

0irstly lets see where do interrupts reside. !nterrupts certainly reside somewherein memory, the interrupts supported by the operating system resides in 'ernelwhich 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 windowsthe 'ernel is 'ernel86.dll or 'ernel.dll. these files contain most of the !"# routinesand are loaded as required. The interrupts supported by the #) $!# areloaded in #) part of the main memory which usually starts at the address

0@>. )oreover it is possible that some device drivers have been installedthese device drivers may provide some !"# routines so when the system bootsthese !"# routines get memory resident at interrupt service routines. o these arethe three possibilities.

econdly a program at compile time does not 'now the eact address where theinterrupt service routine will be residing in memory so the loader cannot assignaddresses for interrupt invocations. When a device driver loads in memory itplaces the address of the services provided by itself in the interrupt vector table.!nterrupt 1ector Table %!1T& in short is a 56 bytes sized table which can hold6B7 far addresses as each far address occupies bytes. o its possible to store

the addresses of 6B7 interrupts hence there are a maimum of 6B7 interrupt in astandard *C. The interrupt number is used as an inde into the table to get theaddress of the interrupt service routine.

© Copyright Virtual University of Pakistan !2

Page 13: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 13/340

0! - "ntro#u$tion% &eans of "'(

0' - Interru!t Mechanism

"nterrupt &e$hanism"nterrupt follo7 a follo7 a $ertain me$hanism for their invo$ation ?ust like near or far

 pro$e#ures) To un#erstan# this me$hanism 7e nee# to un#erstan# its #ifferen$es 7ith pro$e#ure $alls)

4ifferen$e et7een interrupt an# pro$e#ure $allsPro$e#ures or fun$tions of su-routines in various #ifferent languages are $alle# y#ifferent metho#s as $an e seen in the e:amples)

• Call &yPro$

• 8@ 8##ition1/%*3A

•  Printf1Bhello 7orl#3A

The general $on$ept for pro$e#ure $all in most of the programming languages is that on

invo$ation of the pro$e#ure the parameter list an# the return a##ress 17hi$h is the value if"P register in $ase of near or the value of CS an# "P registers in $ase of far pro$e#ure3 is

 pushe# &oreover in various programming languages 7henever a pro$e#ure is $alle# itsa##ress nee# to e spe$ifie# y some notation i)e) in C language the name of the

 pro$e#ure is spe$ifie# to $all a pro$e#ure 7hi$h effe$tively $an e use# as its a##ress)

o7ever in $ase of interrupts the a numer is use# to spe$ify the interrupt numer in the$all

• "nt 2!h

• "nt !0h

• "nt+

.ig ! 1Call to interrupt servi$e routine an# pro$e#ures'fun$tions3

&ain

Call pro$!13

Call pro$!13

Pro$!13

Pro$213

"nt 2!h

"nt !0h

&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$rie# or#er 7hi$h are restore# on return) 8lso

© Copyright Virtual University of Pakistan !+

Page 14: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 14/340

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 taleThe interrupt numer spe$ifie# in the interrupt $all is use# as an in#e: into the interrupt

ve$tor tale) "nterrupt ve$tor tale is a gloal tale situate# at the a##ress 0000D0000)The si=e of interrupt ve$tor tale is !02/ ytes or ! <) a$h entry in the "VT is si=e# /

 ytes hen$e 2*6 interrupt ve$tors are possile numere# 10-..3) a$h entry in the tale$ontains a far a##ress of an interrupt han#lers hen$e there is a ma:imum of 2*6 han#lersho7ever ea$h han#lers $an have a numer of servi$es 7ithin itself) So the numeroperations 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) a$h ve$tor $ontains a far a##ress ofan 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 numer is kno7n) The segment a##ress of the 7hole"VT is 0000 the offset a##ress for a parti$ular interrupt han#ler $an e #etermine# ymultiplying its numer 7ith / eg) The offset a##ress of the ve$tor of

";T 2! 7ill e 2! E / @ / an# the segment for all ve$tors is 0 hen$e its far a##ressis 0000D00/%1 this is the far a##ress of the interrupt ve$tor an# not the interrupt servi$eroutine or interrupt han#ler3) The ve$tor in turn $ontains the a##ress of the interruptservi$e routine 7hi$h is an aritrary value #epen#ing upon the lo$ation of the "S,resi#ing in memory)

.ig 2 1"nterrupt Ve$tor Tale3

!nterrupt 1ector Table

";T0";T!

";T..

0000D0000

0000D0+..

0000D000/

&oreover it is important to un#erstan# the meaning of the four ytes 7ithin the interruptve$tor) a$h entry 7ithin the "VT $ontains a far a##ress the first t7o ytes 1lo7er 7or#3of 7hi$h is the offset an# the ne:t t7o ytes 1higher 7or#3 is the segment a##ress)

© Copyright Virtual University of Pakistan !/

Page 15: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 15/340

0! - "ntro#u$tion% &eans of "'(

>!%5&

>!%&

9#%5&

9#%&

>!%5&

>!%&

9#%5&

9#%&";T 0 0000D000!

0000D000+

0000D000/

0000D0005

";T !

.ig + 1.ar a##ress 7ithin "nterrupt ve$tor3

o$ation of "S,s 1"nterrupt servi$e routines3Fenerally there are three kin# of "S, 7ithin a system #epen#ing upon the entity 7hi$himplements 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,smaye provi#e# y the system) Those provi#e# y the ,(&-<"(S 7oul# e typi$allyresi#ent at any lo$ation after the a##ress .000D0000 e$ause this the a##ress 7ithinmemory from 7here the ,(&-<"(S starts% the "S,s provi#e# y 4(S 7oul# e resi#entin 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

"()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 assho7n in the te:t elo7) The information given y this $omman# in#i$ates the a##ress

© Copyright Virtual University of Pakistan !*

Page 16: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 16/340

0! - "ntro#u$tion% &eans of "'(

7here "()SGS an# other #evi$e #rivers have een loa#e# ut the lo$ation of ,(& <"(Sis not sho7n y this $omman#)

C:\>mem /dAddress Name Size Type------- -------- ------ ------

  000000 000400 Interrupt Vector  000400 000100 !" Communication Area  000#00 000$00 %!S Communication Area

  000&00 I! 000'&0 System %ata  C!N System %e(ice %ri(er

A)* System %e(ice %ri(er+N System %e(ice %ri(erC,!C. System %e(ice %ri(erC!"1 System %e(ice %ri(er,+T1 System %e(ice %ri(er,+T$ System %e(ice %ri(er,+T' System %e(ice %ri(erC!"$ System %e(ice %ri(erC!"' System %e(ice %ri(erC!"4 System %e(ice %ri(er

000A&0 "S%!S 00110 System %ata

  00$00 I! 00$0'0 System %ata  % 000C20 System +ro3ram

I"2" 000420 %2VIC25*"S****0 Insta66ed %e(ice %ri(er

000470 8I,2S5000070 8CS50001$0 ,AST%IV25000&%0 STACS5

0040C0 C!""AN% 000A$0 +ro3ram004A80 "S%!S 0000&0 -- 8ree --

  004&0 C!""AN% 000%0 2n(ironment  00#$#0 %!S* 00&A0 +ro3ram00%A00 "2" 00010 2n(ironment

  0020$0 "2" 01&420 +ro3ram

0$##10 "S%!S 0&AA%0 -- 8ree --  078880 S9ST2" 0$8000 System +ro3ram

  0C8000 I! 00'100 System %ata  "!)S2 00'080 System +ro3ram0%$110 "S%!S 00000 -- 8ree --

  0%$&$0 "SC%2*NT 0001%0 +ro3ram0%$700 2%I 000A&0 +ro3ram0%''0 %!S* 00000 %ata0%'410 "S%!S 00C20 -- 8ree --

  ##'0 ytes tota6 con(entiona6 memory  ##'0 ytes a(ai6a6e to "S-%!S  #7&7#$ 6ar3est e;ecuta6e pro3ram size

  104#& ytes tota6 conti3uous e;tended memory  0 ytes a(ai6a6e conti3uous e;tended memory  7410# ytes a(ai6a6e *"S memory  "S-%!S resident in i3< "emory Area

"nterrupt "nvo$ation8lthough har#7are an# soft7are interrupts are invoke# #ifferently i)e har#7are interruptsare invoke# y means of some har#7are 7hereas soft7are interrupts are invoke# ymeans of soft7are instru$tion or statement ut no matter ho7 an interrupt has eeninvoke# pro$essor follo7s a $ertain set steps after invo$ation of interrupts in e:a$tly same7ay 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

Page 17: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 17/340

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 #eug program% use# to #eug assemlylanguage $o#e% y assemling an# #eugging ";T instru$tions

C:\>deu3-d 0:40000:000 &C 10 A& 00-48 0' ## 0# A 0' ## 0# =!))0000:0070 1& 0' ## 0# 10 A& 00-70 10 A& 00 7A 10 A& 00 )0000:00A0 10 A& 00 #4 0$ &0 00-8$ 04 &4 CC 10 A& 00 Tpt0000:000 10 A& 00 10 A& 00-40 01 $1 04 #0 07 A %4 ?@+0000:00C0 2A A2 10 A& 00 2 00 80- 10 A& 00 C4 $' 0$ C7 0000:00%0 10 A& 00 10 A& 00- 10 A& 00 10 A& 00 &0000:0020 10 A& 00 10 A& 00- 10 A& 00 10 A& 00

0000:0080 10 A& 00 10 A& 00- 10 A& 00 10 A& 00 0000:0100 A 04 10 0$

-a0A81:0100 int $10A81:010$-rA*50000 *50000 C*50000 %*50000 S+58822 +50000 SI50000 %I50000%S50A81 2S50A81 SS50A81 CS50A81 I+50100 NV )+ 2I +, NB NA +! NC0A81:0100 C%$1 INT $1-tA*50000 *50000 C*50000 %*50000 S+5882 +50000 SI50000 %I50000%S50A81 2S50A81 SS50A81 CS500A& I+510&C NV )+ %I +, NB NA +! NC00A&:10&C 70 N!+-d ss:e0A81:8820 0$ 01 81 0A 0$ 8$ 00 00

0A81:8880 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

The #ump at the a##ress 0000D00/ sho7s the value of the ve$tor of the interrupt H2! i)e) 2! E / @ /) This a##ress hol#s the value !05C in lo7er 7or# an# 0085in the higher 7or# 7hi$h in#i$ates that the segment a##ress of interrupt H 2! is 0085an# the offset a##ress of this "S, is !05C)

&oreover the instru$tion ";T 2! $an e assemle# an# e:e$ute# in the #eug program%on #oing e:a$tly so the instru$tion is tra$e# through an# the result is monitore#) "t $an eseen that on e:e$ution of this instru$tion the value of "P is $hange# to !05C an# thevalue of CS is $hange# to 0085 7hi$h $ause the e:e$ution to ran$h to the "nterrupt H2! in memory an# the previous values of flags% CS an# "P registers are temporarilysave# onto the sta$k as the value of SP is re#u$e# y 6 an# the #ump at the lo$ationSSDSP 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 operatingsystem ut they #o not a$$ept parameters y sta$k rather they nee# to passe# parametersthrough 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

Page 18: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 18/340

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 variales) 8 variale $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 variale a$ts very mu$h like avariale as its value $an e $hange# any7here in the program ut is not a true variale asit is not store# in memory) C programming language provi#es the use of pseu#o variales

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 variale y ?ust atta$hinga BO 1un#ers$ore3 efore the registerMs name eg DA* 5 #E A 5 D* )

8fter passing the appropriate parameters the interrupt $an e #ire$tly invoke# y $allingthe 3eninterrupt 13 fun$tion) The interrupt numer nee#s to e passe# as parameter

into the 3eninterrupt13 fun$tion)

"nterrupt H 2!% Servi$e H 09 #es$ription ;o7 lets learn y means of an e:ample ho7 this $an e a$$omplishe#) <efore invokingthe interrupt the programmer nee#s to kno7 ho7 the interrupt ehaves an# 7hat

 parameters it reuires) ets take the e:ample of interrupt H 2! an# servi$e H 09 7rittenas 2!'09 in short) "t is use# to print a string en#ing y a QRM $hara$ter an# other

 parameters #es$riing the string are as elo7"nputs

8 @ 0:094S @ Segment 8##ress of string4N @ (ffset 8##ress of string

(utputThe QRM terminate# string at the a##ress 4SD4N is #isplaye#(ne thing is note 7orthy that the servi$e H is pla$e# in 8 7hi$h is $ommon 7ith almost

all the interrupts an# its servi$e) 8lso this servi$e is not returning any siginifi$ant #ata% ifsome servi$e nee#s to return some #ata it too is re$eive# in registers #epen#ing upon the parti$ular interrupt)

:ampleD

inc6udeFstdio<>inc6udeFI!S>inc6udeF%!S>inc6udeFconio<>

c<ar stG0H 5Je66o Kor6d.JLE

(oid mainM

c6rscrME //to c6ear t<e screen contentsD%* 5 Munsi3ned int stEDA 5 0;07E3eninterruptM0;$1E3etc<ME //Oaits or t<e user to press any Pey

L

this is a simple e:ample in 7hi$h the parameters of int 2!'09 are loa#e# an# then int2! is invoke#) 4N an# 8 registers are a$$esse# through pseu#o variales an# then

© Copyright Virtual University of Pakistan !

Page 19: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 19/340

0! - "ntro#u$tion% &eans of "'(

3eninterruptMis $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 gloal s$ope an# the C language $ompilerautomati$ally loa#s the segment a##ress of the gloal #ata into the 4S register)

8nother &etho# 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 register8% 8% <% <% C% C% 4% 4) These stru$tures are $omine# su$h that through thisstru$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 thisunion is to e use# a programmer nee# not #e$lare the follo7ing #e$laration rather#e$laration alrea#y availale through its hea#er file B#os)h

struct u66

unsi3ned int a;E

unsi3ned int ;Eunsi3ned int c;Eunsi3ned int d;E

LEstruct <a6  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<ELEtypede union ta32QS

struct u66 ;Estruct <a6 <E

L2QSE

This union $an e use# to signify any of the full or half general purpose register sho7s ifthe fiel# a: in : stru$t is to e a$$esse# then a$$essing the fiel#s al an# ah in h 7ill alsohave the same effe$t as sho7 in the e:ample elo7):ampleD

inc6udeF%!S>union 2QS re3sE(oid main M(oid

re3s<a6 5 0;##Ere3s<a< 5 0;77Eprint MR;Ure3s;a;EL

© Copyright Virtual University of Pakistan !9

Page 20: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 20/340

0! - "ntro#u$tion% &eans of "'(

output:77##

The intM  fun$tion

The signifi$an$e of this ,FS union $an only e un#erstoo# after un#erstan#ing the

int613 fun$tion) The int613 has three parameters) The first parameter is the interruptnumer to e invoke#% the se$on# parameter is the referen$e to a ,FS type union 7hi$h$ontains the value of parameters that shoul# e passe# as inputs% an# thir# parameter is areferen$e to a ,FS union 7hi$h 7ill $ontain the value of registers returne# y thisfun$tion) 8ll the reuire# parameters for an "S, are pla$e# in ,FS type of union an# itsreferen$e is passe# to an int613 fun$tion) This fun$tion 7ill put the value in this unioninto the respe$tive register an# then invoke the interrupt) 8s the "S, returns it might leavesome meaningful value in the register 1"S, 7ill return values3% these values $an eretrieve# from the ,FS union 7hose referen$e 7as passe# into the fun$tion as the thir#

 parameter)

:ample using interrupt H 2! servi$e H /2To make it more meaningful 7e $an again elaorate it y means of an e:ample) ere 7emake use of "S, 2!'/2 7hi$h is use# to move the file pointer) "ts #etail is as follo7s

"nt H 2! Servi$e H /2"nputs

8 @ &ove Te$hniue<N @ .ile an#le

  CN-4N @ ;o of <ytes .ile to e move#8 @ Servi$e H @ /2

(utput  4N-8N @ ;o of <ytes .ile pointer a$tually move#)

BOF cp EOFBOF cp 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 thevalue of 8 @ 0 then file pointer is move# relative to the <(. 1egin of .ile3 if 8@!then its move# relative to $urrent position an# if 8 @ 2 then its move# relative to the(. 1en# of file3)CN-4N spe$ify the numer of ytes to move a #oule 7or# is nee#e# to spe$ify thisvalue 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 numer of ytes the file pointer isa$tually move# eg) "f the file pointer is move# relative to the (. =ero ytes the 4N-8Non return 7ill $ontain the si=e of file if the file pointer 7as at <(. efore $alling theservi$e)

© Copyright Virtual University of Pakistan 20

Page 21: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 21/340

0! - "ntro#u$tion% &eans of "'(

0( - )se of IS*s for + Lirary #unctions

The aove #es$rie# servi$e $an e use# to get the si=e of a file in the #es$rie# manner)The follo7ing C language program tries to a$$omplish ?ust that) This program has een

save# as )C file an# not as )CPP file an# then $ompile#)

:ample 2!'/2Dinc6udeFstdio<>inc6udeFcnt6<>inc6udeFio<>inc6udeFI!S>inc6udeF%!S>

unsi3ned int <and6eE(oid mainM

union 2QS re3sEunsi3ned 6on3 int sizeE<and6e 5 openMJc:\\act;tJU!D%!N,9Ere3s;; 5 <and6eEre3s<a< 5 0;4$Ere3s<a6 5 0;0$E //correctionre3s;c; 5 0Ere3s;d; 5 0EintM0;$1Ure3sUre3sEWMMintWMsize 5 re3s;a;E

WMMMintWMsizeX1 5re3s;d;Eprint MJSize is dR UsizeEL

This program opens a file an# saves its han#le in the <and6e variale) This han#le is

 passe# to the "S, 2!'/2 along 7ith the move te$hniue 7hose value is 2 signifingmovement relative to the (. an# the numer of ytes to move are spe$ifie# to e =eroin#i$ating that the pointer shoul# move to the (.) 8s the file 7as ?ust opene# the

 previous lo$ation of the file pointer 7ill e <(.) (n return of this servi$e 4N-8N 7ill$ontain the si=e of the file) The lo7 7or# of this si=e in a: is pla$e# in the lo7 7or# ofsize variale an# the high 7or# in #: is pla$e# in the high 7or# of size variale)

8nother :ampleDets no7 illustrate ho7 "S, $an e invoke# y means of another e:ample of <"(Sservi$e) ere 7e are $hoosing the "S, !0h'0!h) This interrupt is use# to perform "'( onthe monitor) &oreover this servi$e is use# to $hange the si=e of $ursor in te:t mo#e) The#es$ription of this servi$e is given as un#er)

© Copyright Virtual University of Pakistan 2!

Page 22: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 22/340

0! - "ntro#u$tion% &eans of "'(

"nt H !0 Servi$e H 0!

ntry8 @ 0!C @ <eginning S$an ine

  C @ n#ing S$an ine(n :it  Un$hange#

The si=e of the $ursor #epen#s upon the numer 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 mainM

c<ar stG0HE

union 2QS re3sEre3s<a< 5 0;01Ere3s<c< 5 0;01Ere3s<c6 5 0;00EintM0;10Ure3sUre3sE //corrected3etsMstE

L

The program is uite self e:planatory as it puts the starting s$an line to e ! an# theen#ing s$an line to e 0) en$eforth 7hen the servi$e e:e$ute the $ursor 7ill #isappear)

Use of "S,s for C irary fun$tionsThere are various lirary fun$tion that a programmer 7oul# typi$ally use in a program to

 perform input output operations) These lirary fun$tions perform trivial "'( operationslike $hara$ter input 1putc<M3 an# $hara$ter output 13etc<MU 3etcM et$3) 8ll

these fun$tion $all various "S,s to perform this "'() "n <"(S an# 4(S #o$umentationnumer of servi$es $an e foun# that lie in $orrespon#en$e 7ith some C lirary fun$tionin terms of its fun$tionality)

>riting S'> "S,sets 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:hiit this 7e 7ill make use of an interrupt7hi$h is not use# y 4(S or <"(S so that our e:periment #oes not put any interferen$eto the normal fun$tions of 4(S an# <"(S) (ne su$h interrupt is interrupt H 6*) Theve$tor of int 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 tale $ontaining / yte entries ea$h of 7hi$h is afar a##ress of an interrupt servi$e routine) 8ll the ve$tors are arrange# serially su$h thatthe interrupt numer $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##ressstore# 7ithin the ve$tor) The ve$tor is #oule 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 ave$tor $an e use# as a fun$tion pointer) The C lirary fun$tion use# to #o the e:a$tly

© Copyright Virtual University of Pakistan 22

Page 23: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 23/340

0! - "ntro#u$tion% &eans of "'(

same is 3et(ectMint 7hi$h reuires the interrupt numer a parameter an# returns

the value of its ve$tor)

.ig ! 1Ve$tor eing rea# from "VT 3

egment

egment

#ffset

#ffset

egment

egment

#ffset

#ffset";T H

Intproc

far

.un$tion pointers8nother thing reuire# to e un#erstoo# are the fun$tion pointers) C language is a veryfle:ile language ?ust like there are pointers for integers% $hara$ters an# other #ata typesthere are pointers for fun$tions as 7ell as illustrate# y the follo7ing e:ample

(oid myuncM

L

(oid MWuncptr M

uncptr 5 myuncEMWuncptr M EmyuncME

There are three fragments of $o#e in this e:ample) The first fragment sho7s the#e$laration of a fun$tion myuncM

The se$on# fragment sho7 #e$laration of a pointer to fun$tion name# uncptr 7hi$h is

a pointer to a fun$tion that returns voi#)"n the thir# fragment uncptr is assigne# the a##ress of myunc 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 uncptr y the statement MWuncptrME is $alle# an# then the original

myuncM is $alle#) The user 7ill oserve in oth the $ases same fun$tion myprocM 

7ill e invoke#)

© Copyright Virtual University of Pakistan 2+

Page 24: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 24/340

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

L

Similarly a pointer to su$h interrupt type fun$tion $an also e #e$lare# as follo7ing(oid interrupt MWintptr M E

7here intptr is the interrupt pointer an# it $an e assigne# an a##ress using the

3et(ectM fun$tion

intptr 5 3et(ectM0;0E

 ;o7 interrupt numer $an e invoke# using the interrupt ve$tor as follo7ing

MWintptr M E

Setting "nterrupt Ve$tor Setting interrupt ve$tor is ?ust the reverse pro$ess of getting interrupt ve$tor) To set theinterrupt ve$tor means is to $hange the #oule 7or# si=e# interrupt ve$tor 7ithin the "VT)This task $an e a$$omplishe# using the fun$tion set(ectMint U neOint 7hi$h

reuires the numer of interrupt 7hose ve$tor is to e $hange# an# the ne7 value of theve$tor)

egment

egment

#ffset

#ffset

egment

egment

#ffset

#ffset";T H

far

© Copyright Virtual University of Pakistan 2/

Page 25: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 25/340

0! - "ntro#u$tion% &eans of "'(

"n the follo7ing e:ample a $ertain interrupt type fun$tion has een #e$lare#) The a##ressof this fun$tion $an e pla$e# on to the ve$tor of any interrupt using set(ectM 

fun$tion as follo7ing) The follo7ing $o#e pla$es the a##ress of neOint fun$tion at the

ve$tor of int

(oid interrupt neOint M YYL

set(ectM0;0U neOintE

C program making use of "nt 6*

ere is a listing of a program that makes use of int 6* to e:hiit ho7 soft7are interrupts

nee#s to e programme#)

(oid interrupt MWo6dint#M Ec<ar stG0H 5 Re66o Kor6d.LE(oid interrupt neOint#M(oidE(oid mainM

o6dint# 5 3et(ectM0;#Eset(ectM0;#U neOint#E3eninterrupt M0;#E3eninterrupt M0;#E3eninterrupt M0;#Eset(ectM0;#U o6dint#E

L(oid interrupt neOint#M   DA 5 0;07E  D%*5Munsi3ned intstE  3eninterrupt M0;$1EL

The aove listing saves the a##ress of original int 6* in the pointer o6dint#) "t then

 pla$es the a##ress of its o7n fun$tionneOint#

 at the ve$tor of interrupt numer 6*)

.rom this point on7ar#s 7henever int 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 eep fun$tion(ne #efi$ien$y in the aove 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*

Page 26: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 26/340

0! - "ntro#u$tion% &eans of "'(

 pointer 1pointing to a pla$e 7here there is garage or 7here there is no meaningfulfun$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 uite 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 o parasE

the Peep13 fun$tion reuires the return $o#e 7hi$h is usually =ero for normal termination

an# the numer of paragraphs reuire# to e allo$ate#) a$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 numer 6* ut in this $ase the ne7 interrupt 6* fun$tion remains inmemory even after the termination of the program an# hen$e the ve$tor of int 6*h #oesnot e$ome a #angling pointer)

inc6udeFI!S>inc6udeF%!S>

c<ar stG0H 5Je66o Kor6d.JLE(oid interrupt MWo6dint#M E(oid interrupt neOint#M E(oid mainM

  o6dint# 5 3et(ectM0;#E  set(ectM0;#U neOint#E  PeepM0U 1000EL(oid interrupt neOint#M   DA 5 0;07E  D%*5Munsi3ned intstE  3eninterrupt M0;$1EL

The mainMfun$tion gets an# sets the ve$tor of int 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 1theamount 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* the string st 7hi$h is alsono7 memory resi#ent 7ill e #isplaye#)

© Copyright Virtual University of Pakistan 26

Page 27: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 27/340

0! - "ntro#u$tion% &eans of "'(

inc6udeFI!S>inc6udeF%!S>

(oid mainM

3eninterrupt M0;#E3eninterrupt M0;#E

L

This program invokes the interrupt 6* t7i$e 7hi$h has een ma#e resi#ent)

© Copyright Virtual University of Pakistan 25

Page 28: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 28/340

0 - TS* !rograms and Interru!ts

8nother :ampleD

inc6udeFI!S>inc6udeF%!S>c<ar stG0H 5Je66o Kor6d.JLEc<ar st1G0H 5Je66o [email protected](oid interrupt MWo6dint#M E(oid interrupt neOint#M E(oid mainM  o6dint# 5 3et(ectM0;#E  set(ectM0;#U neOint#E  PeepM0U 1000EL(oid interrupt neOint#M

i MM DA 55 0 //corrected

DA 5 0;07ED%* 5 Munsi3ned int stE3eninterrupt M0;$1E

L

e6sei MM DA 55 1 //corrected

DA 5 0;07ED%* 5 Munsi3ned int st1E3eninterrupt M0;$1E

LL

L

Various interrupts provi#e a numer of servi$es) The servi$e numer is usually pla$e# inthe 8 register efore invoking the interrupt) The "S, shoul# in turn $he$k the value in8 register an# then perform the fun$tion a$$or#ingly) The aove e:ample e:emplifies

 ?ust that) "n this e:ample int 6* is assigne# t7o servi$es 0 an# !) Servi$e 0 prints thestring st an# servi$e ! prints the string st1) These servi$es $an e invoke# in the

follo7ing manner)

inc6udeFI!S>inc6udeF%!S>(oid mainM

DA 5 1E

Page 29: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 29/340

0/ - TS, programs an# "nterrupts

3eninterrupt M0;#E

DA 5 0E3eninterrupt M0;#E

L

"nterrupt stealing or interrupt hooksPreviously 7e have #is$usse# ho7 a ne7 interrupt $an e 7ritten an# implemente#)"nterrupt stealing is a te$hniue y 7hi$h alrea#y implemente# servi$es $an e altere# ythe programmer)

This te$hniue 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 variale% after this the ve$tor is$hange# to point to one of the interrupt fun$tion 1ne7 routine3 7ithin the program) "f theinterrupt 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 performingan important task so it also nee#s to invoke#% it $an either e invoke# in the start of thene7 routine or at the en# of the ne7 routine using its pointer as sho7n in the follo7inge:e$ution $harts elo7

.ig ! 1;ormal :e$ution of an "S,3

:e$ution "nterrupte#

"S, Perform "'(

 ;ormal :e$ution of "nterrupt

Page 30: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 30/340

0/ - TS, programs an# "nterrupts

.ig 2 1The original "S, eing $alle# at he en# of ne7 routine3

"nterrupt "nter$eption

 ;e7 ,outine

(riginal ,outine

.ig + 1The original "S, invoke# at the start of ne7 "S,3

(ther form of "nterrupt "nter$eption

 ;e7 ,outine

(riginal ,outine

Care must e taken 7hile invoking the original interrupt) Fenerally in $ase har#7areinterrupts are inter$epte# invoking the original interrupt at the start of ne7 routine might$ause some prolems 7hereas in $ase of soft7are interrupts the original interrupt $an einvoke# any7here)

Sample Program for interrupt "nter$eption

(oid interrupt neOintME

(oid interrupt MWo6dME(oid mainMo6d53et(ectM0;0Eset(ectM0;0UneOintEPeepM0U1000EL(oid interrupt neOint MYY

MWo6dMEL

Page 31: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 31/340

0/ - TS, programs an# "nterrupts

The aove program gets the a##ress store# at the ve$tor of interrupt 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 ofint an# the program is ma#e memory resi#ent) .rom this point on7ar#s 7heneverinterrupt o$$urs the interrupt fun$tion ne7int is invoke#) This fun$tion after performing

its operation $alls the original interrupt 7hose a##ress has een store# in ol#int pointer)

Timer "nterrupt"n the $oming fe7 e:amples 7e 7ill inter$ept interrupt ) This is the timer interrupt) Thetimer interrupt has follo7ing properties)

"ts an ar#7are "nterrupts

"t is "nvoke# y &eans of ar#7are

"t appro:imately o$$urs !)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$ean# is interfa$e# 7ith the pro$essor as a part of main memory) o7ever the <"(Sroutines 7oul# reuire a fe7 variales% these variales are store# in the <"(S #ata arera atthe lo$ation 00/0D0000 in the main memory)(ne su$h yte store# in the <"(S #ata area is the keyoar# status yte at the lo$ation/0D!5) This $ontains the status of various keys like alt% shift% $aps lo$k et$) This yte $an

 e #es$rie# y the #iagram elo7

.ig / 1eyoar# status yte3

568B7 568B7

Right Shift key

Left Shift Key

Ctr Key

At Key

Right Shift key

Left Shift Key

Ctr Key

At Key

Insert key

Caps Lock Key

!"m Lock key

Scro ock key

Insert key

Caps Lock Key

!"m Lock key

Scro ock key

#$%&'(

Key)oar* Stat"s +or*

8nother :ample

inc6ude Fdos<>(oid interrupt MWo6dME(oid interrupt neOMEc<ar ar Wscr5Mc<ar arW 0;0040001&E(oid mainMo6d53et(ectM0;0E

set(ectM0;0UneOEPeepM0U1000E

Page 32: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 32/340

0/ - TS, programs an# "nterrupts

L(oid interrupt neO MWscr54EMWo6dMEL

This fairly simple e:ample inter$epts the timer interrupt su$h that 7henever the timerinterrupt o$$urs the fun$tion ne713 is invoke#) ,ememer 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$eof interrupt the fun$tion ne7 sets the $aps lo$k it in key oar# status y pla$ing 6/ atthis position through its far pointer) So even if the user turns of the $aps lo$k on the ne:to$$urren$e of int 1 almost imme#iately3 the $aps lo$k 7ill e turne# on again 1turing onthe $aps lo$k on like this 7ill not effe$t its 4 in the keyoar# 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 #atato'from the "'( #evi$e) "f the similar fun$tion is performe# using a #e#i$ate# part of mainmemory then the "'( operation is memory mappe#)

.ig * 1"solate# "'(3

Isoate* I/O

&P

"'(

I!

OU,

&P

"'(

I!

OU,

.ig 6 1&emory mappe# "'(3

Memory Mappe* I/O

&P

"'(

MOV

MOV

Page 33: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 33/340

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 themonitor is that a large amount of #ata is nee#e# to e $onveye# to the vi#eo $ontroller in

or#er to #es$rie 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 feasile i#ea as the numer of

 port in PCs is limite# to 6**+6)

The memory area starting from the a##ress 00D0000) 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#eof the $hara$ter to e #isplaye# an# the high yte $ontains the attriute of the $hara$ter to

 e #isplaye#) The a##ress 00D0000h $orrespon#s to the $hara$ter #isplaye# at the topleft $orner of the s$reen% the ne:t 7or# 00D0002 $orrespon#s to the ne:t $hara$ter onthe same ro7 of the te:t s$reen an# so on as #es$rie# in the #iagram elo7)

.ig 5 1&emory mappe# "'( on monitor3

Memory Mappe* I/O O! Monitor

<((D0000<((D000!

<((D0002<((D000+

-o7 <yte @ 8SC"" C(49

igh <yte @8ttriute <yte

The attriute yte 1higher yte3 #es$ries the fore$olor an# the a$k$olor in 7hi$h the$hara$ter 7ill e #isplaye#) The 4(S s$reen $arries la$k as the a$k$olor an# 7hite asthe fore $olor y #efault) The lo7er / its 1lo7er nile3 represents the fore$olor an# thehigher / its 1higher nile3 represents the a$k $olor as #es$rie# y the #iagram elo7

.ig 18ttriute <yte3

Page 34: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 34/340

0/ - TS, programs an# "nterrupts

Memory Mappe* I/O O! Monitor

DDDDDDDD DDDDDDDD

<a$k Color  Color <ol#

<link 

Lo- .yte Ascii Co*e

(igh .yte Attri)"te .yte

White555

$lue5

2reen5

ed5

$lac'

White555

$lue5

2reen5

ed5

$lac'

fore $olor 

To un#erstan# all #es$rie aove lets take a look at this e:ample)

unsi3ned int ar Wscr50;000000E

(oid mainMMWscr50;0&#EMWMscrX150;&0##EL

This e:ample 7ill generate the output V) 

The far pointer s$r is assigne# the value 0:00 in the high 7or# 7hi$h is the segmenta##ress an# value 0:0000 in the lo7 7or# 7hi$h is the offset a##ress) The 7or# at thisa##ress is loa#e# 7ith the value 0:05*6 an# the ne:t 7or# is loa#e# y the value0:50**% 0:05 is the attriute 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 the8SC"" value of BV an# BU respe$tively)

Page 35: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 35/340

0/ - TS, programs an# "nterrupts

0. - TS* !rograms and Interru!ts eyoard interru!t

This same task $an e performe# y the follo7ing program as 7ell) "n this $ase the vi#eote:t memory is a$$esse# yte y yte)

unsi3ned c<ar ar Wscr5Munsi3ned c<ar arW0;000000E(oid mainMWscr50;#E

WMscrX150;0&EWMscrX$50;##EWMscrX'50;&0EL

The ne:t e:ample fills 7hole of the s$reen 7ith spa$es) This 7ill $lear the $ontents of thes$reen)

unsi3ned c<ar ar Wscr5Munsi3ned c<ar arW0;000000E//corrected(oid mainM

int iE //instruction added

Page 36: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 36/340

0/ - TS, programs an# "nterrupts

or Mi50EiF$000EiXX //corrected

Wscr50;$0E //correctedWMscrX150;0&E //correctedscr5scrX$E

LL

Usually the in te:t mo#e there are 0 $olumns an# 2* ro7s making a total of 2000$hara$ters that $an e sho7n simultaneously on the s$reen) This program runs a loop2000 times pla$ing 0:20 8SC"" $o#e of spa$e $hara$ter in 7hole of the te:t memory inthis te:t mo#e) 8lso the attriute is set to 7hite fore$olor an# la$k a$k$olor)

8nother :ample"n the follo7ing e:ample memory mappe# "'( is use# in $omination 7ith interruptinter$eption to perform an interesting task)

inc6ude Fdos<>(oid interrupt MWo6dME(oid interrupt neOuncMEc<ar ar Wscr5Mc<ar arW 0;000000E(oid mainM

o6d53et(ectM0;0Eset(ectM0;0UneOuncEPeepM0U1000E

L

(oid interrupt neOunc M

Wscr50;41E //correctedWMscrX150;0&E //correctedMWo6dME

L

"n the aove e:ample the timer interrupt is inter$epte# su$h that 7henever the timerinterrupt is invoke# 1y means of har#7are3 the memory resi#ent neOunc13 is invoke#)

This fun$tion simply #isplays the 8SC"" $hara$ter 0:/! or Q8M in the top left $orner of thete:t s$reen)

ere is another e:ample)inc6ude Fstdio<>(oid interrupt MWo6dME(oid interrupt neOuncMEc<ar ar Wscr5Mc<ar arW 0;000000Eint ZE(oid mainM

o6d53et(ectM0;0Eset(ectM0;0UneOuncE //corrected

Page 37: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 37/340

0/ - TS, programs an# "nterrupts

PeepM0U1000E //correctedL

(oid interrupt neOunc M

 or M Z50EZF4000EZX5$ //corrected  iMWMscrXZ55[1

WMscrXZ5[7E L  LMWo6dMEL

This program s$ans through all the ytes of te:t #isplay memory 7hen int o$$urs) "ton$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 7hi$ho$$urs !)2 times every se$on#)

The keyoar# "nterrupteyoar# is a har#7are #evi$e an# it makes use of interrupt numer 9 for its inputoperations) >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#sthe s$an $o#e from the keyoar# port an# $onverts it into the appropriate 8SC"" $o#e an#

 pla$es the 8SC"" $o#e in the keyoar# uffer in <"(S #ata area as #es$rie# " nthe#iagram elo7

Any Process

I!, 0

K)*

1$(,ea#s S$an

Co#e $onverts to

8SC"" pla$e it

in eyoar#

<uffer returns

eyoar#

Controller 

2

"nterrupt

";T

ets no7 e:periment on the keyoar# interrupt to un#erstan# its ehavior 

:ample

inc6ude Fdos<>(oid interrupt MWo6dM E(oid interrupt neOuncM E

(oid mainM

o6d 5 3et(ectM0;07E

Page 38: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 38/340

0/ - TS, programs an# "nterrupts

set(ectM0;07UneOuncEPeepM0U1000E

L(oid interrupt neOunc M

MWo6dM EMWo6dM EMWo6dM E

L

This program simply inter$epts the keyoar# 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 keyoar# uffer thri$e i)e three $hara$ters 7ill e re$eive# for ea$h $hara$ter input)

:ample

inc6ude Fdos<>(oid interrupt MWo6dM E(oid interrupt neOuncM Ec<ar ar Wscr 5 Mc<ar arW 0;0040001&E

(oid mainM

o6d 5 3et(ectM0;07E

set(ectM0;07UneOuncEPeepM0U1000E

L(oid interrupt neOunc M

Wscr 5 4EMWo6dM E

L

The aove program is uite familiar it 7ill ?ust set the $aps lo$k status 7henever a key is presse#) "n this $ase the keyoar# interrupt is inter$epte#)

:ample

(oid interrupt MWo6dM E(oid interrupt neOuncM Ec<ar ar Wscr 5 Mc<ar arW 0;000000Eint ZE(oid mainM

o6d 5 3et(ectM0;07E

set(ectM0;07UneOuncEPeepM0U1000E

Page 39: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 39/340

0/ - TS, programs an# "nterrupts

L(oid interrupt neOunc M orM Z 5 0EZ F 4000E Z X5 $

i MWMscr XZ 55 [1

WMscr X Z 5 [7EL

 MWo6dM E L

This too is a familiar e:ample) >henever a key is presse# from the keyoar# the ne7fun$fun$tions runs through 7hole of the test #isplay memory an# repla$es the 8SC"" Q!M#isplaye# y 8SC"" Q9M)

Timer eyoar# "nterrupt Program

inc6ude Fdos<>

(oid interrupt MWo6dTimerM E //corrected(oid interrupt MWo6deyM E //corrected(oid interrupt neOTimer M E(oid interrupt neOey M Ec<ar ar Wscr 5 Mc<ar arW 0;000000Eint iU t 5 0U m 5 0Ec<ar c<arscr G4000HE(oid mainM

o6dTimer 5 3et(ectMEo6dey 5 3et(ect M7Eset(ect MUneOTimerE

set(ect M7UneOeyE3etc<ME3etc<ME3etc<ME3etc<ME

L

(oid interrupt neOTimer M

tXXEi MMt >5 1$ Mm 55 0

  or Mi 50E i F 4000E i XXc<arscr GiH 5 WMscr X iE

Page 40: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 40/340

0/ - TS, programs an# "nterrupts

  or Mi 50E i F54000E i X5$ 

WMscr X i 5 0;$0EWMscr X i X 1 5 0;0&E

  L  t 5 0E m 5 1E

L  MWo6dTimer M EL(oid interrupt neOey M  int OE i Mm 55 1   or MO 50E O F 4000E O XX  WMscr X O 5 c<arscr GOHE

m 5 0E  L  MWo6dey M EL

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 !2 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 7ithspa$es an# sets a flag m) The neOey 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 "nterrupt "f on return of a fun$tion the values 7ithin the registers are un$hange# as $ompare# tothe values 7hi$h 7ere store# in registers on entry into the pro$e#ures then the pro$e#ureis $alle# reentrant pro$e#ure) Usually interrupt pro$e#ures are reentrant pro$e#uresespe$ially those interrupt pro$e#ure $ompile# using C language $ompiler are reentrant)This $an e un#erstoo# y the follo7ing e:ample

A3 &45#(

Proc& 6 7

A3 8

A3 99::(

Page 41: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 41/340

0/ - TS, programs an# "nterrupts

"n the aove e:ample the fun$tion Pro$!13 is invoke#) (n invo$ation the register 8N$ontaine# the value !2+/% the $o#e 7ithin the fun$tion Pro$!13 $hanges the value in 8Nto ..**) (n return 8N 7ill $ontain the value !2+/ if the fun$tion have eenimplemente# as a reentrant pro$e#ure i)e a reentrant pro$e#ure 7oul# restore the values inregisters 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% S% 4S% S"% 4"% <P on invo$ation an# restores in reverse or#er efore return)

This fa$t aout reentrant pro$e#ures $an e analyse# through follo7ing e:ample)

inc6ude Fstdio<>(oid interrupt Wo6dME(oid interrupt neOintM(oid main Mo6d 5 3et(ectM0;#E

set(ectM0;#UneOintEDA*50;00E3eninterruptM0;#Ea 5 DA*printMR;UaEL

(oid interrupt neOintMDA*50;1$'4EL

.irstly its important to compie this a)o;e an* a the rest of the e<ampes as 2C fies

an* not as 2CPP fie) "t these $o#es are $ompile# using )CPP e:tension then there is nosurety that this program $oul# e $ompile#)8gain int 6* is use# for this e:periment) The int 6* ve$tor is ma#e to point at thefun$tion neOint13) <efore $alling the interrupt 6* value 0:.00. is pla$e# in the 8N

register) 8fter invo$ation of int 6* the value of 8N register is $hange# to 0:!2+/) <utafter 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 returnan# also that the interrupt type pro$e#ures are reentrant)

Page 42: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 42/340

0/ - TS, programs an# "nterrupts

02 - TS* !rograms and Interru!ts %is3 interru!t,eyoard hoo3

The typi$al seuen$e in 7hi$h registers 7ill e pushe# an# pope# into the sta$k oninvo$ation an# on return $an e est #es$rie# y the follo7ing #iagrams

Push flags% CS% "P

Pop IP=CS=fags

P"sh

A3=.3=C3=D3=>S=DS=SI=DI=.P

POP.P=DI=SI=DS=>S=D3=C3=.3=A3

Page 43: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 43/340

0/ - TS, programs an# "nterrupts

----

----

----

----

----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% S% 4S% S"% 4"% <P in this or#er) The interrupt pro$e#ure then e:e$utes% eforereturning it pops all the registers in the reverse or#er as <P% 4"% S"% 4S% S% 4N% CN% <Nan# 8N) "P% CS an# flags are pope# on e:e$ution of the ",T instru$tion)

 ;e:t #iagram sho7s the status of the sta$k after invo$ation of the interrupt pro$e#ure)

9agsCSIP

A3

.3

>S

D3

DS

C3

SI

DI

.P

9agsCSIP

A3

.3

>S

D3

DS

C3

SI

DI

.P

The arguments in simple pro$e#ure or fun$tions are save# in the sta$k for the s$ope of thefun$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)

Page 44: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 44/340

0/ - TS, programs an# "nterrupts

8$$essing Sta$k :ample(oid interrupt neOint M unsi3ned int +Uunsi3ned int %IU

unsi3ned int SIUunsi3ned int %SU unsi3ned int2SUunsi3ned int %*U unsi3ned int C*Uunsi3nedint *U unsi3ned int A*Uunsi3ned int I+U

unsi3ned int CSUunsi3ned int 6a3s//corrected

a 5 A*E 5 *Ed 5 2SE

L

8lthough interrupt #o not take parameters through sta$k ut an interrupt pro$e#ure $anstill 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 aove e:ample value of 8Nin sta$k is move# in a% the value of <N is move# into an# the value of S is move# into#)

:ampleD

(oid interrupt neOint M unsi3ned int+Uunsi3ned int %IU unsi3ned int SIUunsi3nedint %SU unsi3ned int 2SUunsi3ned int %*U

unsi3ned int C*Uunsi3ned int *U unsi3ned intA*Uunsi3ned int I+U unsi3ned int CSUunsi3nedint 6a3s //corrected

A* 5 0;8008EL(oid main M set(ectM0;#UneOintEDA* 5 0;1$'4E3eninterrupt M0;#E

a 5 DA*Eprint MR;U aEL

"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 variales rather it $hanges the$orrespon#ing of 8N in sta$k 7hi$h 7ill e restore# in 8N efore return)

4isk "nterruptThe follo7ing e:ample makes use of #isk interrupt !+ an# its servi$e +) The #etails ofthis servi$e are as un#er)(n ntry

Page 45: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 45/340

0/ - TS, programs an# "nterrupts

8 @ Servi$e H @ 0+8 @ ;o of <lo$ks to 7rite<N @ (ffset 8##ress of 4ataC @ Tra$k H % C @ Se$tor H4 @ ea# H

4 @ 4rive H1Starts from $<@$ for fi:e# #isk $ for removale #isks3S @ Segment 8##ress of #ata uffer)(n :it8 @ return Co#eCarry flag @ 0 1 ;o rror 8 @ 03Carry flag @ ! 1 rror 8 @ rror Co#e3

<oot lo$k is a spe$ial lo$k on #isk 7hi$h $ontains information aout the operatingsystem to e loa#e#) "f the #ata on oot lo$k is someho7 #estroye# the #isk 7oul# eren#ere# ina$$essile) The a##ress of partition lo$k on har# #isk is hea# H @!% tra$kH @ 0an# 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)

pra3ma in6ineinc6ude Fdos<>inc6ude Fios<>(oid interrupt MWo6dtsr M E(oid interrupt neOtsr Munsi3ned int +U YU 6a3sE

//must pro(ide a66 t<e ar3uments(oid main M

o6dtsr 5 3et(ect M0;1'Eset(ectM0;1'U neOtsrE //correctedPeep M0U 1000E

L(oid interrupt neOtsrMunsi3ned int +U unsi3ned int %IUunsi3ned int SIU unsi3ned int %SU unsi3ned int 2SU unsi3nedint %*U unsi3ned int C*U unsi3ned int *U unsi3ned int A*Uunsi3ned int I+U unsi3ned int CSUunsi3ned int 6a3s //correctedi M DA 55 0;0'iMM D% 55 1 DC 55 0 DC, 55 1 D%, >5 0;0

asm c6cEasm pus<Easm pop 6a3sEreturnE

LD 2S 5 2SE D%* 5 %*EDC* 5 C*E D* 5 *EDA* 5 A*E

Page 46: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 46/340

0/ - TS, programs an# "nterrupts

Wo6dtsrEasm pus<Easm pop 6a3sEA* 5 DA*E * 5 D*EC* 5 DC*E %* 5 D%*E

2S 5 D2SEL

The aove program inter$epts interrupt !+) The ne7 interrupt pro$e#ure first $he$k 8for servi$e numer an# other parameters for the a##ress of oot lo$k) "f the oot lo$k isto 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 thenit 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 registervalues in the sta$k so that they maye up#ate# into the registers on return)

The keyoar# ook The servi$e !*'/. is $alle# the keyoar# hook servi$e) This servi$e #oes not performany useful output% it is there to e inter$epte# y appli$ations 7hi$h nee# to alter thekeyoar# layout) "t $alle# y interrupt 9 after it has a$uire# the s$an $o#e of input$hara$ter from the keyoar# port 7hile the s$an $o#e is in 8 register) >hen this servi$ereturns interrupt 9 translates the s$an $o#e into 8SC"" $o#e an# pla$es it in uffer) Thisservi$e normally #oes nothing an# returns as it is ut a programmer $an inter$ept it inor#er to $hange the s$an $o#e in 8 an# hen$e altering the input or keyoar# layout)

Key Presse*

Mo;e Scan Co*e

from 1$( port to

AL

Con;ert to ASCII

pace it in key)oar* )"ffer

Int &:(

Ser;ice #9(

The follo7ing appli$ation sho7 ho7 this $an e #one)

inc6ude Fdos<>inc6ude Fios<>inc6ude Fstdio<>(oid interrupt MWo6dint1# M E

(oid interrupt neOint1#Munsi3ned int +U YU 6a3sE(oid main M

Page 47: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 47/340

0/ - TS, programs an# "nterrupts

o6dint1# 5 3et(ect M0;1#Eset(ect M0;1#U neOint1#EPeep M0U 1000E

L

(oid interrupt neOint1#Munsi3ned int +U unsi3ned int %IUunsi3ned int SIU unsi3ned int %SU unsi3ned int 2SU unsi3nedint %*U unsi3ned int C*U unsi3ned int *U unsi3ned int A*Uunsi3ned int I+U unsi3ned int CSUunsi3ned int 6a3s

i MWMMMc<arWA* X 1 55 0;48

i MWMMc<arWA* 55 0;$CWMMMc<arWA* 5 0;12E

e6se i MWMMc<arWA* 55 0;12

WMMc<arWA* 5 0;$CE //correctedLe6se

MWo6dint1#MEL 

The appli$ation inter$epts interrupt !*) 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 thes$an $o#e) ere a simple sustitution have een performe# 0:! is the s$an $o#e of Q8Man# 0:2C is the s$an $o#e of QIM) "f the s$an $o#e is 8 is that of Q8M it is sustitute# 7iththe s$an $o#e of QIM an# vi$e versa) "f some other servi$e of !* is invoke# the originalinterrupt fun$tion is invoke#)

Page 48: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 48/340

0/ - TS, programs an# "nterrupts

04 - 5ard6are Interru!ts

The mi$ropro$essor pa$kage has many signals for #ata% $ontrol an# a##resses) Some ofthese signals may e input signals an# some might e output) ar#7are interrupts make

use of t7o of su$h input signals namely ;&" 1;on maskale "nterrupt3 ";T,1"nterrupt,euest3)

&i$ropro$essor 

Reset

ol#

 ;&"

I!,R 

 ;&" is a higher priority signal than ";T,% (4 has even higher priority an# ,SThas the highest priority) "f any of the ;&" or ";T, pins are a$tivate# the mi$ropro$essoris interrupte# on the asis of priority% if no higher priority signals are present) This is ho7mi$ropro$essor $an e interrupte# 7ithout the use of any soft7are instru$tion hen$e thename har#7are interrupts)

ar#7are "nterrupt an# 8ritration

Page 49: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 49/340

0/ - TS, programs an# "nterrupts

&ost of the #evi$es use the ";T, line) ;&" signal is use# y #evi$es 7hi$h performoperations of the utmost nee# like the #ivision y =ero interrupt 7hi$h is generate# y8U $ir$uitry 7hi$h performs #ivision) 4efinitely this operation is not possile 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% keyoar#% timer et$) Sin$e only

one signal is availale for mi$ropro$essor interruption% this signal is aritrate# amongvarious #evi$es) This aritration $an e performe# y a spe$ial har#7are $alle# theProgrammale "nterrupt Controller 1P"C3)

"nterrupt Controller8 single interrupt $ontroller $an aritrate among #ifferent #evi$es)

P"C

",0

",5

40

45

";T

8s it $an e seen from the #iagram aove the P"C #evi$e has inputs ",0-",5) ",0has the highest priority an# ",5 has the lo7est) a$h ", input is atta$he# to an "'(#evi$e 7henever the #evi$e reuires an "'( operation it sen#s a signal to the P"C) TheP"C on the asis of its priority an# presen$e of other reuests #e$i#es 7hi$h reuest toserve) >henever a reuest is to e serve# y P"C it interrupt the pro$essor 7ith the ";Toutput $onne$te# to the ";T, input of the pro$essor an# sen# the interrupt H to egenerate# the #ata lines $onne$te# to the lo7er #atelines of the #ata us to inform the

 pro$essor aout the interrupt numer) "n $ase no higher priority signal is availale 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#)

Page 50: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 50/340

0/ - TS, programs an# "nterrupts

The follo7ing #iagram also sho7s the typi$al $onne$tivity of the ", lines 7ith various#evi$es

&"C,(

P,(C9SS(, P"C

4(

45

";T8

";T ";T,  

0!

2

+

/

*

6

5

",!

",5

"nterval Timer 

<4 Controller 

C(&2

C(&!

(ther

ControllersPrinter Controller 

&"C,(

P,(C9SS(, P"C

4(

45

";T8

";T ";T,  

0!

2

+

/

*

6

5

",!

",5

"nterval Timer 

<4 Controller 

C(&2

C(&!

(ther

ControllersPrinter Controller 

"n stan#ar# PCs there maye more than #evi$es so generally t7o P"C are use# for ";T,line aritration) These 2 P"Cs are $as$a#e# su$h that they $olle$tively are ale to aritrateamong !6 #evi$es in all as sho7n in the follo7ing #iagram)

P"C

P"C

&8ST, 

S8V

",(

",5

",

",!*

$as!$as2$as+

$as2$as+

$as!

";T8

";T8

4(

45

4(

45 P"C

P"C

&8ST, 

S8V

",(

",5

",

",!*

$as!$as2$as+

$as2$as+

$as!

";T8

";T8

4(

45

4(

45

The P"Cs are $as$a#e# su$h that a total of !6 ", levels $an e provi#e# numer ",0-",!*) The ", 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 numer is issue# y the $on$erne# P"C) The ", 2input of the &aster P"C is $onne$te# to the ";T output of the Slave P"C) "f the slave P"C

Page 51: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 51/340

0/ - TS, programs an# "nterrupts

is interrupte# y a #evi$e its reuest ins propagate# to the master P"C an# the master P"Cultimately 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# theinterrupt numer -!* for ",0 ",5 respe$tively an# the slave P"C generates interruptnumer 50-55 for ",-",!*

ar#7are "nterrupts are ;on-Preemptive8s #es$rie# earlier ", 0 has the highest priority an# ", !* has the lo7est priority) "f anumer of reuests are availale instantaneously the reuest 7ith higher priority 7ill esent 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 reuest o$$urs% 7ill the lo7er priorityinterrupt e preempte# 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 thee: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 '> 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# anotherinstan$e for the '> 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 seuen$e of input 7ill $hange to C<8 7hile the $orre$tseuen$e 7oul# e 8<C)

8 P,9SS94

< P,9SS94

C P,9SS94

"nput re$eive# C < 8 -ogi$ally "n$orre$t

-ogi$ally Corre$t 8 < C

The input 7ill e re$eive# in $orre$t seuen$e only if the '> interrupts are non- preemptive as illustrate# in the #iagram elo7)

Page 52: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 52/340

0/ - TS, programs an# "nterrupts

"nput re$eive# 8 < C ogi$ally Corre$t

8 P,SS4

< P,SS4

C P,SS4

ar#7are interrupts reuires something more to e programme# into them as $ompare#7ith soft7are interrupts) The ma?or #ifferen$e is e$ause of the reason given aove thatthe '> 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#inginterrupt unless it is notifie# that the previous interrupt has returne#)

>ho ;otifies (" 1n# of interrupt3The P"C has to e notifie# aout the return of the previous interrupt y the "S, routine).rom programmer point of vie7 this is the ma?or #ifferen$e et7een '> an# soft7areinterrupt) 8 soft7are interrupt 7ill not reuire any su$h notifi$ation) 8s the #iagram

 elo7 illustrates that every interrupt returns 7ith an ",T instru$tion) This instru$tion ise: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 aout the n# of interrupt)

Pen#ing ar#7are interrupts)>hile a har#7are interrupt is eing pro$esse# a numer of various other interrupt maye

 pen#ing) .or the sutle 7orking of the system it is ne$essary for the "n-servi$e har#7areinterrupt to return early an# notify the P"C on return) "f this operation takes long an# the

 pen#ing interrupt reuests o$$ur repeate# there is a $han$e of loosing #ata)

Programming the P"CTo un#erstan# ho7 the P"C is notifie# aout the en# of interrupt lets take a look into theinternal registers of P"C an# their signifi$an$e) 8 P"C has a numer 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 upW "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 0X 0. or50-55 on ", reuest)

W (C> are use# at run-time)W (C> is use# signal P"C ("

W (C> are also use# to rea#'7rite the value of "S,1"n-servi$e register3%"&,1interrupt mask register3% ",,1interrupt reuest register3)

Page 53: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 53/340

0/ - TS, programs an# "nterrupts

To un#erstan# the "S,% "&, an# ",, lets take a look at the follo7ing #iagram illustratingan e:ample)

5 5

5 5

5555 5555

"S, 

"&, 

",, 

5 6 * / + 2 ! 0

5 6 * / + 2 ! 0

5 6 * / + 2 ! 0

The values sho7n in the various registers illustrate that the $urrently in-servi$e interrupt

is that generate# through ",/ of the P"C 1int 0C in $ase of mater P"C3% also theinterrupt through ",! has een maske# 1int 9h 1keyoar# interrupt3 in $ase of masterP"C3 7hi$h means that even though a reuest for this interrupt is re$eive# y the P"C utthis reuest is ignore# y the P"C until this it is $leare#) 8n# the reuests through ",5%",6% ",2 an# ",0 are pen#ing an# 7aiting for the previously issue# interrupt toreturn)

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 ports20@(C> for ("2!@(C> for "&, 

W Slave P"C has t7o ports as 7ell80@(C> for (" $o#e8!@(C> for "&, 

etMs no7 #is$uss an e:ample that a$$esses these ports to $ontrol the P"C

inc6ude Fstdio<>inc6ude Fios<>(oid mainM

outportM0;$1U0;0$E

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 keyoar# interrupt) 8s a result no input $oul# e re$eive# from the

keyoar# after running this program)

Page 54: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 54/340

0/ - TS, programs an# "nterrupts

etMs no7 look at another e:ample

inc6ude Fdos<>inc6ude Fstdio<>inc6ude Fios<>

(oid interruptMWo6dintsME(oid interrupt neOintMEint t50E //corrected(oid mainMo6dints53et(ectM0;0E

set(ectM0;0UneOintEPeepM0U1000EL(oid interrupt neOintM

tXX:

i Mt551$ 

outportM0;$1U$E  L

  e6se  i Mt55'4

outportM0;$1U0Et50E

LL

MWo6dintsMEL

The e:ample aove is also an interesting e:ample) This program inter$epts the timerinterrupt) The timer interrupt makes use of a variale to keep tra$k of ho7 mu$h time has

 passe#A t is in$remente# ea$h time int o$$urs) "t the rea$hes the !2 after !0 se$on#% at

this point the keyoar# interrupt is maske# an# remains maske# for suseuent !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#)

inc6ude Fdos<>(oid interruptMWo6dME(oid interrupt neOint7MEc<ar ar Wscr5Mc<ar ar W 0;0040001&E

(oid mainMo6d53et(ectM0;07Eset(ectM0;07UneOint7EPeepM0U1000EL(oid interrupt neOint7Mi MinportM0;055'

Page 55: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 55/340

0/ - TS, programs an# "nterrupts

  MMMWscr1$551$ //corrected    outportM0*$0U0;$0E  returnE  L

MWo6dMEL

The aove program #isales the CT,K8TK4 $omination in the 4(S environment1if 7in#o7s (S is also running this $omination 7ill not e #isale# for its environment3)The keyoar# interrupt has een inter$epte#% 7henever the keyoar# interrupt o$$urs thene7int9 fun$tion re$eives the s$an key $o#e from the keyoar# port 0:60% + is the s$ankey $o#e of 4 key) 8lso the program $he$ks if the 8T an# CT, utton has een

 presse# as 7ell from the status of the /0D!5 keyoar# status yte) "f it $onfirms that the$omination presse# is CT,K8TK4 then it #oes not invoke the real int 9 1 Eol#int137hi$h 7ill make the $omputer reoot 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 thatthe interrupt has en#e#) The (" $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 interruptthis 7oul# have not een reuire#)

inc6ude Fdos<>

(oid interruptMWo6dME

(oid interrupt neOint7ME

(oid mainM

o6d53et(ectM0;07Eset(ectM0;07UneOint7EPeepM0U1000E

L(oid interrupt neOint7M

i MinportM0;0550;18 //corrected 

 

outportM0*$0U0;$0E

Page 56: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 56/340

0/ - TS, programs an# "nterrupts

  returnE  LMWo6dME

L

The aove C language program suppresses the QsM input from the keyoar#) The keyoar#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 keyoar# port numere# 0:60) "f hes$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 aout the en# of interrupt)

07 - 5ard6are Interru!ts and TS* !rograms

The keyoar# uffer

Eeyboard $uffer

F Eeyboard $uffer is located in $!# (ata Area.

F tarts at @ !3>

F 3nds at @ 8(>

F >as 86 byes of memory 6 bytes for eachcharacter.

F >ead pointer is located at address @ 5A to@!$>

F Tail pointer located at address @ !C to @!(>

Page 57: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 57/340

0/ - TS, programs an# "nterrupts

The keyoar# 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 keyoar#) "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)

Page 58: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 58/340

Cir$ular uffer 

/0D!8

/0D!C

/0D!ea# Tail

/0D+4

The $ir$ular keyoar# uffer starts at the a##ress /0D! an# $ontains +2 ytes) The

a##ress /0D!8 stores the hea# of this $ir$ular uffer 7hile the a##ress /0D!C 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 aove)

Storing $hara$ters in the keyoar# uffer

?8

G$-

-

GA-

0:20

0:2!

0:22

0:2+

ea# @ 0:2/

0:!Tail

Page 59: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 59/340

0 - ar#7are "nterrupts an# TS, programs

The aove 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 4 is to e store# the first yte 7ill store 0 an# the se$on# yte 7ill

store its s$an $o#e i)e) +) 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 /0D00 an# not from a##ress /0D!) 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 keyoar#

 uffer)

Position of tail

?8

G$-Tail@0:20

0:"

ea# @ 2/

8s #is$usse# earlier the keyoar# 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#)

Page 60: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 60/340

0 - ar#7are "nterrupts an# TS, programs

F o E$( buffer acts as a circular buffer.

F The tail value should be eamined to get

to the start of the buffer.

:ample

Hinclude Idos.hJ

void interrupt %Kold&%&;

void interrupt new5%&L

unsigned char far Kscr M %unsigned char farK& A5C

void main%&

N

oldMgetvect%O&;

setvect%O,new5&;

'eep%,5&;

P

Page 61: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 61/340

0 - ar#7are "nterrupts an# TS, programs

void interrupt new5 %&Nif%inportb%7&MM?8&N

K%%unsigned char farK&QKscr&M6B;if%%Kscr&MM7&

KscrM8;else

KscrQM6;outportb%6,6&;return;

PP

The program liste# in the sli#es aove inter$epts interrupt 9) >henever the interrupt 9

o$$urs it rea#s the keyoar# port 0:60) "f the port $ontains + then it means 4 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 + represents the $ominations CT,KG) The

 program 7hen resi#ent 7ill $ause the program to re$eive CT,KG $omination

7henever 4 is presse# y the user) i)e in <orlan# C environment CT,KG

$omination is use# to #elete a line% if this program is resi#ent then in <orlan# C

environment a line 7ill e #elete# 7henever 4 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 ("

$o#e 7hi$h in$i#entally is also 0:20)

Page 62: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 62/340

0 - ar#7are "nterrupts an# TS, programs

3#! Code for lave !R

0or )aster 

outportb%6,6&;

0or lave

outportb%6,6&;outportb%A,6&;

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 ("

$o#e to the master P"C ut if the interrupt reuest 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)

Page 63: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 63/340

0 - ar#7are "nterrupts an# TS, programs

,ea#ing (C>

#CW6S #CW8

DDD

568B7

00! .(, ;on Spe$ifi$ ("

0! "f other ,egisters are to e a$$esse#

00 "f (" is to e sent

The same port i)e 0:20 is use# to a$$ess the (C>s) 00 is pla$e# in its numer / an# + to

in#i$ate an (" is eing re$eive# an# 0! is pla$e# to in#i$ate that a internal register is to

 e a$$esse#)

568B7

(! To rea# ",, or "S, 

!0 @ ",, 

!!@ "n-Servi$e ,egister 

The value in its numer ! an# 0 in#i$ate 7hi$h ,egister is to a$$esse#) !0 is for ",, an#

!! is for "S,)

Page 64: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 64/340

0 - ar#7are "nterrupts an# TS, programs

8$$essing the "S, an# ",,)

5

568B7

 ;o (" relevant

(ther ,egister to e 8$$esse#

4onMt Care

8 value is pla$e# in the port 0:20 as sho7n in the aove sli#e to in#i$ate that a register is

to e a$$esse#)

55

568B7

0! P"C ;otifie# aout rea#ing operation

",, 8$$esse#

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 aove sli#e ",, is to e a$$esse#)

Page 65: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 65/340

Page 66: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 66/340

0 - ar#7are "nterrupts an# TS, programs

)ore about T *rograms

F A T need to be loaded once in memory

F )ultiple loading will leave redundantcopies in memory

F o we need to have some chec' which

will load the program only once

(ne of the solution to the prolem $an e

Page 67: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 67/340

0 - ar#7are "nterrupts an# TS, programs

+sing a 2lobal 1ariable as aflag

as sho7n in the sli#e elo7

int flag;

flag M5;'eep%,5&;

if %flagMM5&)a'e T

elseeit *rogram

This 7ill not 7ork as this gloal variale is only gloal for this instan$e of the program)

(ther instan$es in memory 7ill have their o7n memory spa$e) So the

Page 68: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 68/340

0 - ar#7are "nterrupts an# TS, programs

 Answers is to use a memory area asflag that is global to all programs.

i.e. !1T

int 6* is empty% 7e $an use

its ve$tor as a flag)

8##ress of ve$tor 

seg @ 0

offset @ 6* E /

3ample@Hin$lu#eYst#io)hZ

Hin$lu#eY<"(S)Z

Hin$lu#eY4(S)Zunsigne# int far E int6*ve$ @

1unsigne# far E3

&O.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 @ etve$t 0:0

setve$t10:0% ne7int3A

1Eint6*ve$3 @ 0:.00.A

keep 10%!0003A]else

[

 puts 1BProgram 8lrea#y

,esi#ent3A

]]

voi# interrupt ne7fun$ 13

[ DDDDDDD

DDDDDDD

1Eol#int3 1 3A

]

Page 69: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 69/340

0 - ar#7are "nterrupts an# TS, programs

The aove 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)

$ut what if another program isresident or using this vector.

 Another )ethodervice H 00 usually does noteist for !-s.

Eey is to create another service H00 for the ! interrupt besides

other processing.

3ample@Hin$lu#eYst#io)hZ

Hin$lu#eY<"(S)Z

Hin$lu#eY4(S)Z

voi# interrupt 1Eol#int3 1 3A

voi# interrupt ne7fun$ 1 unsigne# int <P%))^%flags3Avoi# main13

[

 O4" @ 0A

 O8 @ 0:..A

geninterrupt 10:!+3A

if 1O4" @ @ 0:.00.3 [

 puts 1BProgram 8lrea#y ,esi#ent3A

e:it 103A

]

Page 70: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 70/340

0 - ar#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)

3ample@lse

[

ol#int @ getve$t 10:!+3A

setve$t 10:!+% ne7int3A

keep 10% !0003A

]]

voi# interrupt ne7int 1 3

[if 1O8 @@ 0:..3

[

4" @ 0:.00.A

returnA

]

else

[ DDDDDDD

DDDDDDD

DDDDDDD

]

1Eol#int3 1 3A

]

Page 71: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 71/340

0 - ar#7are "nterrupts an# TS, programs

08 - The inter&a" Timer The interval timer 

ynchronous (evices require a

timing signal.

Clo$k

generate#

"nterval

Timer 

&i$ropro$essor 

!nterval Timer 

Ck 

Ck 

PCLK &2&05&@ M(B

PCLK 6for peripheraSynchrono"s De;ices7

Ck Ch0 to ",0

C! T( 4,8& $ontroller 

Ch2 to PC Speaker 

The interval timer is use# to #ivi#e an input freuen$y) The input freuen$y use# y the

interval timer is the PC 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)

Page 72: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 72/340

4ivi#ing Clo$k signal

Counter egisters@

F Counter registers can be used to divide frequency.

/&1 /@ /# /4

co"nt

5 6 * / + 2 ! 0

8 $ounter register $an e use# to #ivi#e the $lo$k signal) 8s sho7n in the sli#e aove% 0

of the $lo$k register is use# to #ivi#e the $lo$k freuen$y y 2 suseuently it ! is use#

to #ivi#e it y / an# so on)

The 4ivision me$hanism

5

5

55

5 55

55

555

5

55

55

555

55 555

555

5555

The aove sli#e sho7s a seuen$e of output that a it $lo$k register 7ill generate in

seuen$e 7henever it re$eives the $lo$k signal) (serve it H!% its value $hanges et7een

Page 73: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 73/340

09 - The interval Timer 

0 an# ! et7een t7o $lo$k $y$les so it $an e use# to #ivi#e the asi$ freuen$y y 2)

Similarly oserve it H2 its value transits et7een 0 an# ! 7ithin / $lo$k $y$les hen$e it

#ivi#es the freuen$y y / an# so on)

Timing #iagram

Timing (iagram

.it $ 6/47

.it & 6/#7

.it 4 6/@7

.it 5 6/&17

% % % % %

% % % % %

% % % % %

ere is the timing #iagram for aove 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)

Page 74: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 74/340

09 - The interval Timer 

Comman# registers 7ithin the programmale interval timer 

!nterval Timer *rogramming@

Command egistersF ?bit Command port

F /eed to be programmed beforeloading the divisor value for achannel.

F 8 channels, each requires a 57bit divisor value to generate the

output frequency.

Comman# register an# the $hannels nee# to e programme# for the interval timer to

generate a 7ante# freuen$y)

Comman# ,egister 

5555

.inary $

.CD &

Mo*e $ :

$$$ &$&

Ch% $$$

$&&

&$4

$&Lo- .yte

&$(igh .yte

&&Lo- .yte foo-e*

)y (igh .yte

5 6 * / + 2 ! 0

Comman# register is an it register 7hi$h shoul# e programme# as #es$rie# in the

sli#e aove 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)

Page 75: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 75/340

09 - The interval Timer 

&o#e 4es$ription

Di;isor #

Mo*e 5

-----+----- -----+-----

-----/----- -----/-----

---2--- ---2---

-----/----- -----/-----

Di;isor #

Mo*e 4

Di;isor #

Mo*e &

Di;isor #

Mo*e $

The interval timer $an operate in si: mo#es) a$h mo#e has a #ifferent suare 7ave

 pattern a$$or#ing to nee# of the appli$ation) Some mo#es might e suitale to $ontrol a

motor an# some might e suitale to $ontrol the speaker)

<inary $ounter 

555

555

& $ $ & $ $ $ $

& $ $ $ & $ & $

& $ $ $ & $ & &

& $ $ & $ $ $ &

& $ $ & & $ $ &

$ $ $ $ $ $ $ $

$inary Count@$ount

<C4 C(U;T@9

99@

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 seuen$e an# if its use# as a

<C4 $ounter its registers 7ill $ount in <C4 seuen$e as #es$rie# aove)

Page 76: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 76/340

09 - The interval Timer 

Ports an# Channels

*orts S Channels@F 8Channels 57bit wide divisor value

i.e X7BB8B

?bit port for each channel therefore thedivisor word is loaded serially byte by byte.

*ort Addresses8> M Command *ort

> M ?bit port for Channel

5> M ?bit port for Channel 5

6> M ?bit port for Channel 6

The interval timer has + $hannels ea$h $hannel is !6 it 7i#e) The port /+ is an it

 port use# as the $omman# register) Ports /0h% /! an# /2 are asso$iate# 7ith the

$hannels o% ! an# 2 respe$tively) Channels are !6 it 7i#e 7hereas the ports are it

7i#e) 8 !6 it value $an e loa#e# serially through the ports into the register)

Steps for programming the interval timer 

*rogramming Concepts for !ntervalTimer@

F 9oad the Command byte intocommand register required toprogram the specific channel.

F The divisor word is thenerially loaded byte by byte.

Page 77: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 77/340

09 - The interval Timer 

The port 6!

Connect

to inter;a

timer &

,"rn O! Speaker &

,"rn O99 Speaker$

Rest of the )its are "se* )y other

*e;ices an* sho"* not )e change*2

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)

:ample

3ample@''Program loa#s #ivisor value of 0:2!..

''Turns (; the speaker an# $onne$ts it to "nterval

Timer 

Hin$lu#eY<"(S)Z

Hin$lu#eY4(S)Z

voi# main13

[

outport 10:/+%0:</3A

outport 10:/2%0:..3Aoutport 10:/2%0:2!3A

outport 10:6!%inport10:6!3 _ +3A

get$h13A

outport 10:6!%inport10:6!3 0:.C3A

]

The aove 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#%

Page 78: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 78/340

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!ff% 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@/0D6C"n$remente# every !'!)2 se$on#s) >henever ";T

unsigne# long int far Etime @ 1unsigne# long int farE3 0:00/0006C

voi# main13

[

unsigne# long int t:A

t: @ 1Etime3A

t: @ t: K!A

 puts1B<efore3A

7hile11Etime3 Y@ t:3A

 puts1B8fter3A

]

4elay $an e pro#u$e# using #oule 7or# variale in the <"(S 4ata area pla$e# at the

lo$ation 00/0D006C) This value $ontains a timer $ount an# is in$remente# every !'! th of

a se$on#) "n this program the this #oule 7or# is rea#% pla$e# in a program variale an#

in$remente# y !) The value of /0D6$ is $ompare# 7ith this variale in a loop) This

loop iterates until the value of /0D6$ is not greater) "n this 7ay this loop 7ill keep on

iterating for a se$on# appro:imately)

Page 79: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 79/340

09 - The interval Timer 

10 - Peri!hera" Programma"e Interface PPISample Program

unsigne# long int E time @ 1unsigne# long int E3 0:00/0006C

voi# main13

[ unsigne# long int t:A

unsigne# int #ivisor @ 0:2!..A

7hile 1#ivisor Z@ 0:*03 [

outport10:/+%0:</3A

outport10:/2%E11$harE31#ivisor333A

outport10:/2%E111$harE31#ivisor33K!33A

outport10:6!%inport10: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 freuen$y of the interval timer $hanges after every uarter of a se$on#

appro:imately) The speaker 7ill turn on 7ith a lo7 freuen$y pit$h an# this freuen$y

7ill in$rease gra#ually pro#u$ing a spe$trum of various soun# pit$hes)

Page 80: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 80/340

Sample Program

Hin$lu#e Y#os)hZ

Hin$lu#e Yios)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 S%

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 S%

unsigne# int 4N% unsigne# int CN% unsigne# int <N%

unsigne# int 8N% unsigne# int CS% unsigne# int "P%

unsigne# int flags3

[

if 1O8 @ @ 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 aove program is a TS, program that $an e use# to turn the speaker on'off) Theaove program inter$epts the int !*h) >henever this interrupt o$$urs it looks for servi$e H

0:/f 1keyoar# hook3) "f QSM10:!f s$an $o#e3 has een presse# it toggles the speaker)

Page 81: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 81/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

Sample Program

Hin$lu#e Y#os )hZ

Hin$lu#e Yios)hZ

unsigne# int #ivisorsJ/L@[0:2!ff%0:!#/*%0:!a%%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\khit133

[

7hile 1iY/3

[ outport10:/+% 0:</3A

outport10:/2%E11$har E31#ivisorJiL333A

outport10:/2%E111$har E31#ivisorJiL33K!33A

outport10:6!% inport10:6!3_+3A

t:@EtimeA

t:@t:K/A

7hile 1t: Z@ 1Etime33A

iKKA

]i@0A

]

outport10:6!%inport10:6!30:.C3A

This program generates a tune 7ith / #ifferent pit$hes) This program is uite 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 uarter of a se$on# an# this $ontinues until a key is

 presse#)

Page 82: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 82/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

Sample Program

Hin$lu#e Yst#io)hZ

Hin$lu#e Y#os)hZHin$lu#e Yios)hZ

stru$t tagTones

[ unsigne# int #ivisorA

unsigne# int #elayA

]A

stru$t tagTones TonesJ/L@[

[0:2!ff%+]%[0:!#/*%2]%[0:!a%+]%[0:!e/$%/]]A

int i%ti$ks%flag@0 A

voi# interrupt 1Eol#int!*313A

voi# interrupt 1Eol#int313A

voi# interrupt ne7int!*13A

voi# interrupt ne7int13A

unsigne# $har far Es$r @ 1unsigne# $har far E310:00/000!53A

voi# main 13

[

ol#int!*@getve$t10:!*3A

setve$t10:!*%ne7int!*3Aol#int@getve$t10:03A

setve$t10:0%ne7int3A

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)

Page 83: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 83/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

void interrupt newint5B%&

N

if %YA>MMf&

N

if %%YA9MM5f&SS%%%Kscr&S56&MM56&&

N

tic'sM;

iM;

outport%8,b&;outport%6,K%%c har K&%S TonesZi[.di viso r&&&;

outport %6,K%%%char K&%STonesZi[.divisor&&Q5&&;

outport%75,inport%75&\8&;

flagM5;

P

else if %%YA9MM53&SS%%%Kscr&S56&MM56&&

N

outport%75,inport%75&Sfc&;

flagM;

P

return;

P

%Koldint5B&%&;

The speaker turns on 7henever QSM 1s$an $o#e 0:!f3 is presse# an# turns off 7henever

Q8M 1s$an $o#e 0:!3 is presse#)

voi# interrupt ne7int13

[

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 E31TonesJiL)#ivisor333A

outport10:/2%E111$har E31TonesJiL)#ivisor33K!33A

outport10:6!%inport10:6!3_+3A

ti$ks @ 0A

]

]

1Eol#int313A

]

The timer interrupt shift the #ivisor value store# in the tones stru$ture 7henever the

reuire# numere# of ti$ks1 timer $ounts3 have passe# as reuire# 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)

Page 84: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 84/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

Peripheral Programmale interfa$e 1PP"3

*arallel *orts %**!&

*arallel Communication

Parae O"t P"t De;ice

O"tp"t

40

45

Stroe

<usy

CPU

4!

42

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 aove) "tMs $alle# parallel e$ause a numer of its are transferre# from one point ot

another parallel on various lines simultaneously)

Page 85: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 85/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

*arallel Communication

Parae Inp"t De;iceCPU

40

I/O

Controer

Inp"t

45

4, 

CPU

4!

42

8#vantages of Parallel $ommuni$ation

*arallel Communication

.aster(nly $onomi$ally .easile .or

Small 4istan$es

Page 86: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 86/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

11 - Peri!hera" Programma"e Interface PPI II

F (evice +sed as *arallel port !nterface %!"#controller& is **!

*rogrammable *eripheral !nterface%**!&

*rogrammable *eripheral !nterface%**!&

CPU PP"

Parallel

"'( 4evi$e

Printer 

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 reuire a $ontroller to e

 pla$e# et7een the CPU an# "'( #evi$e) (ne su$h $ontroller is the PP") ere 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)

Page 87: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 87/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

 Access ing the *arallel *ortThrough $!# 0unctions

"nt !5

ccessing the Para""e" Port

Through 9IOS #unctions

*ort !nterface /umber 

M9*T5,5M9*T6,6M9*T8

(Dregister 

equest *rinter 6

!nitialize *rinter5

(isplay Characters

ervices

!/T 5>

"nt !5 is use# to $ontrol the printer via the <"(S) The <"(S fun$tions that perform the

 printer "'( are liste# in the sli#e aove 7ith its other parameter i)e 4N 7hi$h $ontains the

PT numer) 8 stan#ar# PC $an have / PP" name# PT!% PT2% PT+ an# PT/)

Page 88: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 88/340

Page 89: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 89/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

Accessing the Parallel Port Through BIOS Functions

F pecify the number of Attempts $!# performbefore giving a time out 3rror 

F This byte 1aries (epending upon the speedof the *C

F $usy M *rinter is $usy

F $usy M5 *rinter is not $usy

"mportan$e of Status <yte

!mportance of the tatus $yte

"f11pstate0:293\@03or

11pstate0:03@@03 or

11pstate0:!03@@03[[email protected]]

else

[printerok@T,UA]

The status of the printer $an e use# in the aove #es$rie# 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)

Page 90: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 90/340

!0 - Peripheral Programmale "nterfa$e 1PP"3

!mportance of the tatus $yte

&'(/$$( +rite

a character on entryA($$

ALASCII co*e

D3Interface

On e<it

A(Stat"s .yte

&'(/$&( InitiaiBe Printer

on entryA($&

D3Interface

On e<it

A(Stat"s .yte

&'(/$4( Eet Printer Stat"s

on entry

A($4= D3Interface On e<it A(Stat"s .yte

*rinting *rograms

Page 91: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 91/340

Sample Program

*rinting *rogram"nion R>ES regsF 9IL> GfptrF

;oi* main6;oi*7

H

fptrfopen6c%JJtempJJa)c2t<t=r)7F

regs2h2ah&F

regs2<2*<$F

int@16$<&'=regs=regs7F

-hie6feof6fptr77

Hregs2h2ah4F

regs2<2*<$F

int@16$<&'=regs=regs7F

if 66regs2h2ah $<@$7$<@$7

H regs2h2ah$F

regs2h2agetc6fptr7F

int@16$<&'=regs=regs7F

The aove program performs programme# "'( on the printer using <"(S servi$es) The

 program firstly initiali=es the printer int !5'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

inc"*e N*os2h

;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

;oi* interr"pt ne- 67

H if 6A($7

H

if 66ALQAQ7 6ALQQ77 //correcte*

ret"rnF

6Go*767F

*rinting *rogram 5

Page 92: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 92/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

The aove program inter$epts int !5) >henever a $ertain program issues int !5 to

 print a $hara$ter the aove 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

inc"*e N*os2h

;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

;oi* interr"pt ne-f"nc6 7

H

if 6A($7

H

if 6 AL T T 7

6Go*767F

*rinting *rogram 6

"n this sample program again int !5 is inter$epte#) The ne7 interrupt fun$tion 7ill

ignore all the spa$es in the print #o$ument)

Page 93: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 93/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

Sample Program

inc"*e N*os2h

;oi* interr"pt 6Go*76 7F

;oi* interr"pt ne-f"nc 6 7F

main67

Ho*get;ect6$<&'7F

set;ect6$<&'=ne-f"nc7F

keep6$=&$$$7F

;oi* interr"pt ne-f"nc 6 7

H if 6 A( $ 7 H

6Go*767F

 A($F

6Go*767F

 A($F

6Go*767F

6Go*767F

*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)

(irect *arallel *ort*rogramming

 ;o7 7e 7ill see ho7 the register 7ithin the PP" $an e a$$esse# #ire$tly to $ontrol the

 printer)

Page 94: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 94/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

(irect *arallel *ort*rogramming

F $!# support up tothree parallel ports

F Address of these 9*Tports is tored in$!# (ata Area

9*Tword@3

9*T8word@C

9*T6word@A

9*T5word@?

8ove sli#e list the a##resses 7ithin the <"(S #ata area 7here the ase a##ress 1starting

 port numer3 of PT #evi$es is store#)

4ump of <"(S #ata area

(irect *arallel *ort *rogramming

(ump 0ile Te,t

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+5% for pt+ it is

0:025) These values nee# not e the same for all the $omputer an# $an vary from

$omputer to $omputer)

Page 95: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 95/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

S7apping PTs

(irect *arallel *ort *rogramming

"nsigne* int far G pt

6"nsigne* int far G7 $<$$#$$$$@ F

"nsigne* int tempF

tempG6pt7F

GptG6pt &7F

G6pt &7tempF

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 aove)

(irect *arallel *ort *rogramming*ort egisters

F @? store the base address for lpt5

F The parallel port interface has 8 portsinternally

F !f the $ase address is D8? then thethree *orts will be 8?,8O 8A

Page 96: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 96/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

PT Ports

(irect *arallel *ort *rogramming*ort egisters

568B7

.ase $Data Port

.ase &Printer Stat"s

:**;0SL;1P:;1+;09usy;0

Printer (nline(ut of Paper 

Printer is rea#y for ;e:t Chara$ter 

Printer is <usy

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$rie# in the sli#e) a$h it

represents the various status of the printer uite similar to the status yte in $ase of <"(S

servi$e)

Printer Control ,egister 

T A90!/!!R

568B7

Printer Control ,egister @<ase K 2

ST,(<

8uto

ine.iel#

initiali=e", ;8<

SCT "nine

Turn Computer on line

(irect *arallel *ort *rogramming*ort egisters

:e$ute "nterrupt>hen 8C@0A

1<ase K23 is the printer $ontrol register it is use# to pass on some $ontrol information to

the printer as #es$rie# in the sli#e)

Page 97: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 97/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

4ire$t Parallel Port Programming

(irect *arallel *ort *rogrammingfie GfptrF

"nsigne* far G)ase6"nsigne* int far G7$<$$#$$$$@

;oi* main 6;oi*7

H

fptrfopen6c%JJa)c2t<t=r)7F

-hie6 feof 6fptr7 7

H if6 6 inport 6G)ase & 7 $<@$7

H o"tport6G)ase=getc6fptr77F

o"tport 66G)ase4=inport66G)ase47 $<$&7F

o"tport66G)ase4=inport66G)ase47 $<9>7F

The aove 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 stroe 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)

Page 98: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 98/340

!! - Peripheral Programmale "nterfa$e 1PP"3 ""

1' - Para""e" Port Programming

Printer "nterfa$e an# ",5

PIC

Printer

Interface

Printer

IR'

I!,

ACK 

*rinter!nterface

The printer interfa$e uses the ", 5 as sho7n in the sli#e aove) Therefore if interrupt

#riven "'( is to e performe# int 0:0f nee# to e programme# as an har#7are interrupt)

!nterrupt (riven *rinter !"#$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 _ /3Aoutport11 Elpt3% inport1 Elpt3 _ 0:!03A

ol#int @getve$t 10:0.3A

setve$t 10:0.% ne7int3A

outport10:2!% inport1 0:2!3 0:5.3A''$orre$te#

keep10%!0003A

]

Page 99: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 99/340

voi# interrupt ne7int 1 3

[

outport1 Elpt% <ufJ iL3A

outport11 Elpt3K2% inport11 Elpt3K23 0:.3Aoutport11 Elpt3K2% inport11 Elpt3K23 _ !3A

iKKA

if1 i@@ !02/3

[

outport10:2!% inport10:2!3_0:03A''$orre$te#

setve$t10:0.%ol#int3A

freemem1Opsp3A

]

]

8ove is a listing of a program that uses int 0:0f to perform interrupt #riven "'() To

enale the interrupt 0:0f three things are reuire# to e #one) The interrupt shoul# e

enale# 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

stroe 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 aove listing might not 7ork) ;ot all of the printer interfa$es are #esigne# as

#es$rie# aove) 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#)

Page 100: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 100/340

!2 - Parallel Port Programming

Printing in the a$kgroun#

Hin$lu#e Yst#io)hZ

Hin$lu#e Y#os )hZ

Hin$lu#e Yios)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/0000A

$har stJ0L@ this is a test print string \\\\\\\\\\\A

int i A

voi# main 13

[

ol#int @ getve$t10:03A

setve$t10:0%ne7int3A

keep10%!0003A

]

voi# interrupt ne7int13

[

if 111 inport11Elpt3 K!33 0:03 @@ 0:03

[

outport 1Elpt%stJiKKL3A

outport 11Elpt3K2% inport11Elpt3K23 0:fe3Aoutport 11Elpt3K2% inport11Elpt3K23 _ !3A

]

if 1i@@+23

[

setve$t 10:0%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 stroe signal) >hen the uffer is

full the program restores the int ve$tor an# the relinuishes the memory o$$upie# y the

 program)

Page 101: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 101/340

!2 - Parallel Port Programming

Printer Cale Conne$tivity

*rinter Cable Connectivity

2/(5?6B

9CT !/5

!/!T57

3#5B

 A+T# 033 (5

9CT58

*356

$+<55

 ACE5

(O

(7?

(B

(7

(8B

(6

(58

(6

T#$5

 ;ot all the its of the internal registers of the PP" are availale 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 availale as pin outs as #es$ries in the sli#e aove)

Page 102: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 102/340

!2 - Parallel Port Programming

Computer to Computer $ommuni$ation

Computer to ComputerConnectivity

"t might e #esirale 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 its of PP" $annot

 e ma#e possile as all the its of the internal ports are not availale as pinouts) So the

ans7er is to $onne$t a nile 1/-its3 at one en# to the nile at the other) "n this 7ay t7o

7ay $ommuni$ation $an e performe#) The niles are $onne$te# as sho7n in the sli#e

aove)

Page 103: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 103/340

!2 - Parallel Port Programming

PP" "nter$onne$tion

P$ 4 &: 5

P& 5 &5 #P4 # &4 :

P5 : &$ 1

P# 1 && '

5 &: 4 P$

# &5 5 P&

: &4 # P4

1 &$ : P5

' && 1 P#

The pins that are inter$onne$te# are sho7n in the sli#e aove) 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 5 th 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)

$$5$6$8Sen#er 

$$5$6$85,e$eiver 

.USW ACK P> SLC >R 

D# D5 D4 D& D$

>' >1 >: ># >5

Sen*er sen*s

LO+ !i))e

an* D# $

recei;e* as

.USW &

Page 104: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 104/340

!2 - Parallel Port Programming

.irst the lo7 nile 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 nile is eing sent) The re$eiver 7ill kno7 the arrival of

the lo7 nile 7hen its $he$ks <USG it 7hi$h shoul# e set 1y the interfa$e3 on

arrival)

$$5$6$85Sen#er 

$$5$6$8,e$eiver 

.USW ACK P> SLC >R 

D# D5 D4 D& D$

Recei;er sen*

)ack LO+

!i))e an* D#$

recei;e* as

.USW & )ySen*er

The re$eiver then sen#s a$k the nile turning its 4/ it to 0 as an a$kno7le#gement of

the re$eipt of the lo7 nile) This 7ill turn the <USG it to ! at the sen#er si#e)

$$B$7$5

Sen#er 

$$B$7$,e$eiver 

.USW ACK P> SLC >R 

D# D5 D4 D& D$

Sen*er sen*s (i

!i))e an* t"rns

D# & recei;e*

as .USW $ )y

Recei;er

Page 105: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 105/340

!2 - Parallel Port Programming

The sen#er then sen# the high nile an# turns its 4/ it to ! in#i$ating the transmission

of high nile) (n the re$eiver si#e the <USG it 7ill turn to 0 in#i$ating the re$eipt of

high nile)

The re$eiver then sen#s a$k the high nile to the sen#er as an a$kno7le#gment)

$$B$7$Sen#er 

$$B$7$5,e$eiver 

.USW ACK P> SLC >R 

D# D5 D4 D& D$

Recei;er sen*

)ack (i !i))e

an* t"rns

D# & recei;e*

as .USW $ )y

Sen*er

Page 106: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 106/340

!2 - Parallel Port Programming

1( - Seria" +ommunication

Program implementing the #es$rie# proto$ol

int i $F char ."fX&$4#YF-hie 6&7

H ch ."f XiYF

if 66inport66Gpt7 &7 $<@$7 $7

H ch ."f XiYF

ch ch $<>9F

-hie66inport66Gpt7 &7 $<@$7 $7F

ese

H ch ."f XiYF

ch ch #F

ch ch $<&$F

o"tport 6Gpt= ch7F

iF

-hie66inport66Gpt7 &7 $<@$7 @$7F

This is the sen#er program) This program if fin# the <USG it $lear sen#s the lo7 nile

 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 nile an# 7aits for a$kno7le#gment until the <USG is

$leare#)

Page 107: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 107/340

!2 - Parallel Port Programming

int iF

-hie 6&7

H if 66inport6Gpt &7 $<@$7 $<@$7

H < inport 66Gpt7 &7F

< < 5F

< < $<$9F

o"tport66Gpt7= <7F

-hie66inport6Gpt &7 $<@$7 $<@$7F

ese

H y inport 66Gpt7 &7F

y y NN &F

temp yF

y y $<9$F //instr"ction a**e*

y y <F

temp temp 5F

temp temp $<&$F

iF

o"tport 6Gpt= temp7F

."f XiY yF

-hie66inport66Gpt7 &7 $<@$7 $7F

This is re$eiver program) "f the <USG it is $lear it re$eives the lo7 nile an# stores it

in :) Similarly if the <USG it is 0 it re$eives the high nile an# $on$atenates the oth

nile to form a yte)

Page 108: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 108/340

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$hniue is that in this $ase the $ost is re#u$e# as only ! or 2 lines

maye reuire# to transfer #ata)

The ma?or #isa#vantage of Serial $ommuni$ation is that the spee# of #ata transfer maye

re#u$e# as #ata is transferre# in serial pattern)

There are t7o kin#s of serial $ommuni$ations)

Syn$hronous Communi$ation

ynchronous CommunicationW Timing signal is use# to i#entify start an# en#

of a it)

LS. MS.& & $ & $ & & $

0 ! ! 0 ! 0 ! !

Page 109: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 109/340

!+ - Serial Communi$ation

"n $ase of syn$hronous $ommuni$ation as sho7n in the sli#e a timing signal is reuire# to

i#entify the start an# en# of a it)

W Sampling may e e#ge triggere#)

W Spe$ial line may e reuire# for

timing signal 1reuires another line3)

W (r the timing signal may e en$o#e#

7ithin the original signal 1reuires

#oule the an#7i#th3)

ynchronous Communication

8syn$hronous Communi$ation

W 4oes not use make use of timing

signal)

W a$h yte 17or#3 nee#s to

en$apsulate# in start an# en# it)

 Asynchronous Communication

"n $ase of asyn$hronous $ommuni$ation no timing signal is reuire# ut ea$h yte nee#s

to e en$apsulate# to kno7 the en# an# start of a yte)

Page 110: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 110/340

Page 111: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 111/340

!+ - Serial Communi$ation

-- <it rate an# other settings shoul# e

the same at oth en#s i)e)

- 4ata its per <yte) 1* 3- Parity $he$k 

- Parity ven'(##

- ;o) of stop its)

ampling ate

ampling ate

Start it

%ata its

1/1(00 sec

Sto! it

Odd !arity

8 @ /! @ 0!00 000! <

Parity @ (##

4ata @

Stop it @!

4ata rate @ +00 its'se$

Page 112: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 112/340

!+ - Serial Communi$ation

] 686C tandardW Stan#ar# for physi$al #imensions of the

$onne$tors)

*C%(T3&

Modem

*S < '('+ +a"e

+onnected &ia

seria" !ort

%+:

,S2+2C is a stan#ar# for physi$al #imension of the $onne$tor inter$onne$ting a

4T14ata terminal euipment3 an# 4C 14ata $ommuni$ation euipment3)

] 686C Connectors and ignals($6B %6B pin connector&

'. !in connector on P+1

'

8

4

7

.

2

10

11

1'

1(

(

'.

'

'(

''

'1

'0

18

17

14

12

1.

1

*I

%T*+%

@%

%S*

+TS

*TS

*%

T A %

The pin outs of the 4<2* $onne$tor use# 7ith ,S2+2C is sho7n in the sli#e aove)

Page 113: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 113/340

!+ - Serial Communi$ation

1 - Seria" +ommunication )ni&ersa" synchronous*ecei&er Transmitter

] 686C tandardW Stan#ar# for physi$al #imensions of the

$onne$tors)

*C

%(T3&Modem

*S < '('+ +a"e

+onnected &iaseria" !ort

%+:

] 686C Connectors and ignals($6B %6B pin connector&

'. !in connector on P+1

'

8

4

7

.

2

10

11

1'

1(

(

'.

'

'(

''

'1

'0

18

17

14

12

1.

1

*I

%T*+%

@%

%S*

+TS

*TS

*%

T A %

Page 114: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 114/340

.lo7 Control using ,S2+2C

*C )#(3)

(T3 (C3(T

(

T

CT

C(

!

%T* S5O)L% *:MI@ 5I5 T5*O)5 O)T T5: S:SSIO@ +TS +@ 9: )S:% #O* #LOW +O@T*OL

( T(

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 ,euest 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

5

6

8

B

7

?

O

+%

* > %

T > %

% T *

@ %

*I

+TS

*TS

%S*

%98 +onnector

The aove sli#e sho7s the pinouts of the 4< 9 $onne$tor)

Page 115: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 115/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

U8,T internals

+AT !nternalseceiver $uffer egister

!nterrupt 3nable egister

9ine tatus egister

!nterrupt !( egister

(ivisor 9atch egister

9ine Control egister

)odem Control egister

)odemtatus egister

Transmitter >olding egister

eceiver hift egister

!nterruptto*arity 9#2!C

(

Transmit hift

egister 

T (

5.CT 6.(8.C(

.!

5.T 6.(T

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

*cratch *ad

7))odem tatus

B99ine tatus

)C)ode Control

89C9ine Control

6!!!nterrupt !(

60C 0!0# Control egister 

5!3!nterrupt 3nable

5(9)$and ate (ivisor %>igh $yte&

(99$and ate (ivisor %9ow $yte&

$eceiver (ata

T> Transmitter >olding egister 

9ase B

The aove tale lists the registers 7ithin the U8,T ans also sho7s their areviation)

8lso it sho7s there offsets 7ith respe$t to the ase register)

Page 116: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 116/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

erved *orts in tandard *C

$!# supports +A T as C#) *ortsC#)5, C#)6, C#)8, C#)

63?>@7C#)

83?>@C#)8

60?>@6C#)6

80?>@C#)5

*ort $ase)emory Address

*orts

<"(S 4ata 8rea

Te,t (ump

Wd 0C0

000C0000 #7 0( #7 0' :7 0( :7 0'-9+ 0( 47 0( 47 0' +0 8# ==========>=>===

000C0010 '( +7 '0 70 0' 7. 00 '0-00 00 ( 00 ( 00 41 10 D= ==== ====E=

000C00'0 0% 1+ 41 10 0% 1+ 2 '0-'0 (8 ( 0. (0 09 ( '4 ==E===d 8=0=CF

000C00(0 (0 09 0% 1+ 00 00 00 00-00 00 00 00 00 00 00 00 0===============

000C000 %7 00 +( 00 00 00 00 00-00 0( .0 00 00 10 00 00 ==========P=====

000C00.0 00 0 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ================

000C0020 0# 0+ 00 % 0( '8 (0 00-00 00 00 00 0' +8 09 00 =====0=========

000C0040 00 00 00 00 00 00 07 00-1 1 1 1 01 01 01 01 ================

-E

The aove #ump of the <"(S #ata area for a $ertain $omputer sho7s that the a##ress of

C(&! is 0+. % the a##ress of C(&2 is 02. an# the a##ress of C(&+ is 0+) These

a##resses may not e same for all the $omputers an# may vary $omputer to $omputer)

Page 117: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 117/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

Setting the <au# rate

etting the $aud ate5.?86 )>^Mfrequency generating by +ATinternally

(ivisor value loaded in (99 % $ase Q &and (9) % $ase Q5 &

9aud rate ;1=7(' M5G / 12H%i&isor

(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 

9ine Control egister

568B7

9oad T>59oad (ivisor 1alue

>or# ength M B $!T5 M 7 $!T

5 M $!T55 M ? $!T

9ength of top $!T M one $!T5 M5.B for B bit Word

*arity Chec' andgeneration on

*arity M odd5 M 3ven.

top Communication M5esume Communication M

Constant *ari ty M/# cons tant *arity5 MConstant *arity if bit M55 if bit M

The line $ontrol register $ontains important information aout 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)

Page 118: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 118/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

9ine tatus egister

568B7

4ata ,ea#y @!

#ver un 3rror M 5

*arity 3rror M5

top Communication ignal from #ther end M5

T is 3mp tyM5T Contain a $yteM

T> entry M5T> contains a $<T3 M

Transfer 3rror %0raming 3rror&

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 nale ,egister 

!nterrupt 3nable egister

568

Trigger "nterrupt

(n 4ata ,ea#y @!

Trigger "nterrupt

(n $hange in &o#em Status @!

Trigger "nterrupt

8s soon as T, is empty @!

Trigger "nterrupt

(n line status $hange @!

"f interrupt #riven output is to e performe# then this register is use# to enale interrupt

for the U8,T) "t $an also use# to sele$t the events for 7hi$h to generate interrupt as

#es$rie# in the sli#e)

Page 119: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 119/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

"nterrupt "4 ,egister 

!nterrupt !( egister

56

Trigger Triggere#

&o#em'ine

00 @Change in &o#em Status

0! @ T, is mpty

!0 @ 4ata is ,ea#y

!! @rror in 4ata

(n$e an interrupt o$$urs it may e reuire# to i#entify the $ase of the interrupt) This

register is use# to i#entify the $ause of the interrupt)

Page 120: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 120/340

!/ - Serial Communi$ation 1Universal 8syn$hronous ,e$eiver Transmitter3

1. - +OM Ports

&o#em Control ,egister 

)odem Controller egister 

58

D,R 

$ Poing Operator

& Interr"pts >na)e*

*TS1 ;Se"f Test0 ;@orma"

"n $ase soft7are oriente# flo7 $ontrol te$hniue is use# the its 0 an# ! nee# to e set in

that $ase) <it H+ nee# to e set to enale interrupts) &oreover if a single $omputer is

availale 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#)

Page 121: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 121/340

&o#em Status ,egister 

)odem tatus egister

568B7

+%+hangein +TS

+hange in *I

+hange in +%+TS

*I

%S*

+hange in %S*

This register in#i$ates the status of the mo#em status line or any $hange in the status of

these lines)

.".( ueue

+AT %57BB& 0!0# R+3+3

567

9I9O )"ffer on&

+"ear send 9uffer ;1

@umer of +haracters *ecei&edTo Trigger an Interru!t

00 ;fter :&ery +haracter 

01 ;fter +haracter 10 ;fter 7 +haracter 11 ;fter 1 +haracter 

Cear Recei;er

."ffer &

This feature is availale in the ne7er version of the U8,T numere# !6*00) 8 ueue 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 ueue $an e $ontrolle# through this register as sho7n

 y the sli#e)

Page 122: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 122/340

!* - C(& Ports

"nterrupt "4 ,egister 

!nterrupt !( egister %evisited&

5687

Interr"pt

,riggere* &

ny one of these 9:I@

Set Indicates #I#O is O@=

Reasons of Interr"pt

$$Change in Mo*em Line Stat"s

01;T5* is :m!ty

10;%ata is ready

11;:rror in %ata Transmit

5M !nterrupt Triggered$ecause $uffer is not full$ut other side hasstop sending data.%Time #+T&

<"(S Support for C(& Ports

I@T D 15

%A ; Port D 0 for +OM1

1 for +OM' etc=

Ser&ice D0 ; Set communication !arameters

Ser&ice D01 ; Out!ut characters

Ser&ice D0' ; *ead in characters

Ser&ice D0( ; et !ort status

The follo7ing sli#e sho7s ho7 int !/ 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)

Page 123: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 123/340

!* - C(& Ports

Data Length

$$ :)its

$& 1)its

&$ ')its

&& @)its of stop )its$ & stop )it

& &2: or 4 stop )it

Parity Check $$ !one

$& O**

&$ Parity

Disa)e

&& >;en

.a"* Rate$$$ &&$ )a"*s

$$& &:$ )a"*s

$&$ 5$$ )a"*s

$&& 1$$ )a"*s

&$$ &4$$ )a"*s

&$& 4#$$ )a"*s

&&$ #@$$ )a"*s

&&& 01$$ )a"*s

Ser;ice $

AL

The Servi$e on return pla$es the line status in 8 register as sho7n in the sli#e elo7)

Data Rea*y

O;er r"n error

Parity error

9raming error

,ime O"t

,SR >mpty

,(R 

.reak Detecte*

A( Line Stat"s

Page 124: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 124/340

!* - C(& Ports

8n# pla$es the mo#em status in the 8 register as sho7n in sli#e elo7)

Change in C,S

Change in DSR 

Change in RI

Change in CD

CD

RI

Rea*y 6DSR7

Rea*y to Recei;e

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 AC!! character to send

#/ 3T+/

 A> M 3rror Code

!f th bit in A> M 5 M +nsuccessful

M uccessful

Ser&ice D 0'

#/ 3T+/

 A9 M AC!! character received

 A> M 3rror Code

Page 125: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 125/340

!* - C(& Ports

Communi$ation through &o#em

)odem

PC&o#em

UAR, Digita Data Anaog

,e Line

UAR,

PC&o#em

Digita DataAnaog

&o#em is generally use# to sen#'re$eive #ata to'from an analog telephone) a# 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 PC

Ca)e UAR,UAR,

Page 126: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 126/340

!* - C(& Ports

 ;U &o#em Configuration

C( 5

( 6

T( 8

(T

2/( B

( 7

T

CT ?

! O

C( 5

( 6

T( 8

(T

2/( B

( 7

T

CT ?

! O

The aove 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

3ample@Hin$lu#eY<"(S)Z

Hin$lu#eY4(S)Z

$har $h!% $h2A

voi# initiali=e 1int pno3

[

 O8@0A

 O8@0:*5A

 O4N@pnoA

geninterrupt10:!/3A

]

Page 127: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 127/340

!* - C(& Ports

char receivechar %int pno&

N

char ch;

 Y(D M pno;

 YA> M 6;

geninterrupt %5&;

ch M YA9;

return ch;

P

voi# sen#$har 1$har $h% int pno3

[

 O4N @ pnoA

 O8 @ !A

 O8 @ $hA

geninterrupt 10:!/3A

]

unsigne# int get$omstatus 1int pno3

[

unsigne# int tempA

 O4N @ pnoA

 O8 @ 0+A

geninterrupt 10:!/3A

E11$harE31temp33 @ O8A

E111$harE31temp33 K !3 @ O8A

return tempA

]

Page 128: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 128/340

!* - C(& Ports

12 - +OM Ports IISample Program using <"(S routines

3ample@Hin$lu#eY<"(S)Z

Hin$lu#eY4(S)Z

$har $h!% $h2A

voi# initiali=e 1int pno3

[

 O8@0A

 O8@0:*5A

 O4N@pnoA

geninterrupt10:!/3A

]

char receivechar %int pno&N

char ch;

 Y(D M pno;

 YA> M 6;

geninterrupt %5&;

ch M YA9;

return ch;

P

The initiali=e 13 fun$tion initiali=es the C(& port 7hose numer is passe# as parameter

using <"(S servi$es) The re$ieve$har13 fun$tion uses the C(& port numer to re$eive a

 yte from the C(& port using <"(S servi$es)

Page 129: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 129/340

!* - C(& Ports

voi# sen#$har 1$har $h% int pno3

[

 O4N @ pnoA

 O8 @ !A

 O8 @ $hA

geninterrupt 10:!/3A

]unsigne# int get$omstatus 1int pno3

[

unsigne# int tempA

 O4N @ pnoA

 O8 @ 0+A

geninterrupt 10:!/3A

E11$harE31temp33 @ O8A

E111$harE31temp33 K !3 @ O8A

return tempA

]

The sen#$har13 fun$tion sen#s a $hara$ter to the C(& port using <"(S servi$e 7hose

numer is passe# as parameter) 8n# the get$omstatus13 fun$tion retrieves the status of the

C(& port 7hose numer 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$harE31i33 K !30:203 @@ 0:203 1khit1333

[

$h! @ get$he13A

sen#$har 1$h!% 03A

]

if 11E111$harE31i33 K!3 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)

Page 130: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 130/340

!* - 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&Q,inport%%Kcom&Q&\5&;

P

The initiali=e13 loa#s the #ivisor value of 0:0!0 high yte in ase K! an# lo7 yte in

 ase K0) "t also programs the line $ontrol register for all the reuire# line parameters)

The SelfTest(n13 fun$tion simply enales the self test fa$ility 7ithin the mo#em $ontrol

register)

Page 131: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 131/340

!* - C(& Ports

void elfTest#ff%unsigned int far K com&N

outportb% %Kcom&Q, inport%%Kcom&Q& S 3f&;Pvoid writechar% char ch, unsigned int far K com&

Nwhile % L%%inportb%%Kcom&QB& S 6& MM 6&&;outport%Kcom,ch&;

Pchar readchar% unsigned int far Kcom&N

while %L%%inportb%%Kcom&QB& S 5&MM5&&;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& ;void main %&N

char ch M ; int i M 5;int 4M 5;

char ch6M_A_;initialize% com&;elfTest#n%com&;clrscr%&;while %chLM6&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#)

Page 132: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 132/340

!* - C(& Ports

if %4MM58& 4M;

gotoy%i,4&;

chMgetche%&;writechar%ch,com&;ch6Mreadchar%com&;gotoy%i,4Q5&;putch%ch6&;iQQ;

PelfTest#ff %com&;

P

8ll the input from the keyoar# 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

hello how r u = whats new about systems programming=

hello how r u = whats new about systems programming=

Page 133: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 133/340

!* - C(& Ports

Sample Program using interrupt #riven "'(

Hinclude Idos.hJ

Hinclude Ibios.hJvoid 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&Q,inport%%Kcom&Q&\5?&;

P

void elfTest#ff%unsigned int far K com&N

outportb% %Kcom&Q, inport%%Kcom&Q& S 3&;Pvoid writechar% char ch, unsigned int far K com&N

""while % L%%inportb%%Kcom&QB& S 6& MM 6&&;

outport%Kcom,ch&;Pchar readchar% unsigned int far Kcom&N

""while %L%%inportb%%Kcom&QB& S 5&MM5&&;

return inportb%Kcom&;P

Page 134: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 134/340

!* - C(& Ports

unsigned int far KcomM%unsigned int farK& ;unsigned char far KscrM%unsigned char farK& $?;int i M,4M;char ch;int ';void interrupt %Koldint&%&;void interrupt newint%&;

void main %&Ninitialize%com&;elfTest#n%com&;oldint M getvect%c&;setvect%c,newint&;

outport%%Kcom&Q5,5&;outport%65,inport%65&S30&;'eep%,5&;

P

This si program is also uite 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

",/) 8lso to use it in this 7ay ",/ must e unmaske# from the "&, register in P"C)

8lso efore returning from the "S, the P"C must e signale# an (" $o#e)

void interrupt newint%&N

chM readchar%com&;if %iMM?&N

 4QQ;iM;

Pif %4MM58&

 4M;' M iK6Q%4Q5&K?K6;K%scrQ'&Mch;iQQ;outport%6,6&;

P

Page 135: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 135/340

!* - C(& Ports

]C:\>DEBUG-o 3f8 41-o 3f8 42

-o 3f8 56-o 3f8 55-q 

C:\> 

Hinclude Ibios.hJHinclude Idos.hJvoid interrupt %Koldint&%&;void interrupt newint%&;unsigned char far KscrM %unsigned char farK&$?;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 main %void&N

oldint M getvect%C&;setvect %C,newint&;initialize %Kcom&;

outport %%Kcom&Q, inport %%Kcom&Q& \ ?&;outport %65,inport %65&S30&;outport %%Kcom& Q 5, 5&;'eep%,5&;

Pvoid interrupt newint %&N

Kscr M inport%Kcom&;outport %6,6&;

P

Page 136: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 136/340

!* - C(& Ports

14 - *ea" Time +"oc3 *T+Sample Program

Hinclude Idos.hJ

Hinclude Ibios.hJchar ch5,ch6;

void initialize %unsigned int com&N

outportb % comQ8, inport %comQ8& \ ?&;outportb % com,?&;outportb% com Q5, 5&;

outportb % comQ8, 5b&;P

void main % &

Ninitialize%8f?&;while %5&

Nif % %%inport%8fd&S6&MM6& SS %'bhit%&&&N ch5Mgetche%&;

outport%8f?,ch5&;Pif %% %inport%8fd&S5&MM5&&N ch6M inport%8f?&;

putch%ch6&;P

if %% ch5MM6& \\ %ch6MM6&&brea';

PP

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)

Page 137: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 137/340

!* - C(& Ports

C( 5

( 6

T( 8(T

2/( B

( 7

T

CT ?

! O

C( 5

( 6

T( 8(T

2/( B

( 7

T

CT ?

! O

/+99 )odem %evisited&

(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)

C( 5

( 6

T( 8

(T

2/( B

( 7

T

CT ?

! O

C( 5

( 6

T( 8

(T

2/( B

( 7

T

CT ?

! O

/+99 )odem %evisited&

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)

Page 138: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 138/340

!* - C(& Ports

)a'es use of Two Control characters. ] D#/ %`&

 ] D#00 %`T&

oftware #riented 0lowControl

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 eadtatus M T+3;

continue;Pif %receivedchar MM D#00&N eadtatus M 0A93;

continue;Pif %eadtatus 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,U an# if N(.. is re$eive# the status is set to .8S) The

$hara$ters 7ill only e re$eive# if the status is T,U other7ise they 7ill e #is$ar#e#)

Page 139: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 139/340

,eal Time Clo$k 

F $attery powered device

F +pdates time even if *C is shutdown

F TC has 7 byte battery powered A)

F !/T 5A> used to get"set time.

Time )!dation Through I@T7

eal Time Cloc' (evice

,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 aove 7hi$h enales 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)

#/ 3/T<

 A> M

#/ 3D!T A9 M )idnight flag

CD M Cloc' count %>i word&

(D M Cloc' count %9ow word&

5B8 Times !ncrement

5B8"5?.67B M ?78OO.O565 sec

Whereas ?7 sec represent 6 hrs.

Cloc' Counter 5A>"

%hoursK7K7 Q minK7 Q sec& K 5?.67B

Page 140: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 140/340

!5 - ,eal Time Clo$k 1,TC3

#/ 3/T<

 A> M 5

CD M Cloc' count %>i word&

(D M Cloc' count %9ow word&

 A9 M 5 if )idnight passed A9 M if )idnight not passed

et Cloc' Counter 5A>"5

#/ 3/T<

 A> M 6

#/ 3D!T

C> M >ours %$C(&

C9 M )inutes %$C(&(> M econds %$C(&

ead Time 5A>"6

Page 141: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 141/340

!5 - ,eal Time Clo$k 1,TC3

#/ 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

et Time 5A>"8

#/ 3/T<

 A> M

#/ 3D!T

C> M Century %$C(&

C9 M <ear %$C(&

(> M )onth %$C(&

(9 M (ay %$C(&

ead (ate 5A>"

Page 142: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 142/340

!5 - ,eal Time Clo$k 1,TC3

#/ 3/T<

 A> M B

C> M Century %$C(&

C9 M <ear %$C(&

(> M )onth %$C(&

(9 M (ay %$C(&

et (ate 5A>"B

#/ 3/T<

 A> M 7

C> M >ours %$C(&

C9 M )inutes %$C(&

(> M econds %$C(&

et Alarm 5A>"7

Page 143: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 143/340

!5 - ,eal Time Clo$k 1,TC3

#/ 3/T<

 A> M

(isable Alarm 5A>"

#/ 3/T<

 A> M O

#/ 3D!T

C> M >ours %$C(&C9 M )inutes %$C(&

(> M econds %$C(&

(9 M Alarm tatus % M /ot 3nable

5 M 3nable&

ead Alarm 5A>"O

Page 144: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 144/340

!5 - ,eal Time Clo$k 1,TC3

,TC internals

eal Time Cloc'

7 $ytes$attery

*owered9ow power

C)#A)

Cloc' and9ogic

circuitry

ControlCircuitry

405

415

4#5

I@T

CCCCCCCCCCCCCCCCCCCCCCCC

CCCCCCCCCCCC

The ,TC internally has an array of registers 7hi$h $an e use# to a$$ess the 6/ yte

 attery po7ere# C&(S ,8&)

] 0> %57 ports&

#nly S 5> are important fromprogramming point of view

!nternal *orts

Page 145: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 145/340

!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)

> M Current econd

5> M Alarm econd

6> M Current )inute

8> M Alarm )inute

> M Current >our 

B> M Alarm >our 

7> M (ay #f the Wee'> M /umber #f (ay

7 $yte $attery *owered A)

?> M )onth

O> M <ear 

A> M Cloc' tatus egister A$> M Cloc' tatus egister $

C> M Cloc' tatus egister C

(> M Cloc' tatus egister (

86> M Century

7 $yte $attery *owered A)

Page 146: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 146/340

!5 - ,eal Time Clo$k 1,TC3

4ay of the 7eek 

5> M unday

6> M )onday

8> M Tuesday

> M Wednesday

B> M Thursday

7> M 0riday

> M aturday

Wee' (ay

The value in the #ays of the 7eek yte in#i$ates the #ay a$$or#ing to sli#e sho7n aove)

Fenerally <C4 values are use# to represent the units of time an# #ate)

/o of Century and <ear are in $C(.<ear

Page 147: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 147/340

!5 - ,eal Time Clo$k 1,TC3

8$$essing the <attery Po7ere# ,8&

$attery *owered A) is accessed intwo steps

F pecify the $yte no. in > port.

F ead"write port 5> to get"set thevalue of specified byte.

 Accessing the $attery *owered A)

.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&)

outport %, &; outport %, &;

sec M inport %5&; outport %5,hrs&;

 Accessing the $attery *owered A)

Page 148: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 148/340

!5 - ,eal Time Clo$k 1,TC3

Clo$k Status ,egisters

tatus egister A

Interr"pt

freZ"ency

,ime

freZ"ency

$ ,ime is not "p*ate*& ,ime is "p*ate*

4 2 . ( ' 1 0

The lo7er / its of this register stores a $o#e in#i$ating the freuen$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 freuen$y i)e) the freuen$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)

Page 149: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 149/340

!5 - ,eal Time Clo$k 1,TC3

17 - *ea" Time +"oc3 *T+ II

Clo$k Status ,egisters

4 2 . ( ' 1 0

tatus egister $

$ Dayight

sa;ing time

4#/&4 [ ho"r co"nter

$ &4 ho"r format

& 4# ho"r format

,ime *ate format

$ .CD

& .inary

Up*ate time

Ca perio*ic

interr"pt

Ca Aarm interr"pt

Ca interr"pt on

time "p*ate

.ock generator

The status register < is the main $ontrol register) "t is use# to spe$ify the #ate time

formats an# is also use# to enale 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 freuen$y

spe$ifie# in the 8 register)

4 2 . ( ' 1 0

tatus egister C

& ,ime "p*ate compete

& Aarm time reache*

& Perio*ic interr"pt ca

Status register is use# to i#entify the reason of interrupt generation as #es$rie# in the

sli#e aove)

Page 150: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 150/340

!5 - ,eal Time Clo$k 1,TC3

4 2 . ( ' 1 0

tatus egister (

$ .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 II;K%%unsigned char K&%S hours&& M

%K%%unsigned char K& %S hours&&& JJ;

hours M hours Q 88;

seconds M seconds II;K%%unsigned char K&%S seconds&& M

%K%%unsigned char K&%S seconds&&& JJ;seconds M seconds Q 88;

Page 151: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 151/340

!5 - ,eal Time Clo$k 1,TC3

minutes M minutes II;K%%unsigned char K&%S minutes&& M

%K%%unsigned char K&%S minutes&&& JJ;minutes M minutes Q 88;clrscr%&;

printf%UcUcUcUcUcUcUcUc,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 aove program uses the servi$e int !8h'02 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)

Page 152: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 152/340

,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.hJHinclude Idos.hJ

void main %&N

int hrs,mins,secs;char temp;do N

outportb%,a&;

tempMinportb%5&;

Pwhile %%temp S ?& MM &;outportb%,&;secsMinport%5&;outportb%,6&;minsMinport%5&;

outportb%,&;hrsMinport%5&;

hrs M hrs II;

K%%unsigned char K&%Shrs&& M%K%%unsigned char K&%Shrs&&& JJ;hrs M hrs Q 88;

mins M mins II;K%%unsigned char K&%Smins&& M

%K%%unsigned char K&%Smins&&& JJ;mins M mins Q 88;

secs M secs II;K%%unsigned char K&%Ssecs&& M

%K%%unsigned char K&%Ssecs&&& JJ;secs M secs Q 88;clrscr%&;

Page 153: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 153/340

! - ,eal Time Clo$k 1,TC3 ""

printf%UcUc@UcUc@UcUc,

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.hJHinclude Idos.hJunsigned char AC!!to$C(%char hi, char lo&N

hi M hi 8;

lo M lo 8;hi M hi II ;hi M hi \ lo;return hi;

P

unsigned long int far Ktm M%unsigned long int far K&7c;

Page 154: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 154/340

! - ,eal Time Clo$k 1,TC3 ""

void main %&N

unsigned char hrs,mins,secs;char ch5, ch6;puts%n3nter the hours to update@ &;ch5Mgetche%&;ch6Mgetch%&;hrs M AC!!to$C(%ch5, ch6&;

puts%n3nter the minutes to update@ &;ch5Mgetche%&;ch6Mgetch%&;mins M AC!!to$C(%ch5, ch6&;

puts%n3nter the seconds to update@ &;ch5Mgetche%&;ch6Mgetch%&;secs M AC!!to$C(%ch5, ch6&;

Ktm M ; YC> M hrs; YC9Mmins; Y(>M secs;

 Y(9M; YA> M8;geninterrupt%5a&;puts%Time +pdated&;

P

The aove 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#)

Page 155: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 155/340

! - ,eal Time Clo$k 1,TC3 ""

Sample Program

Hinclude Ibios.hJ

Hinclude Idos.hJunsigned char AC!!to$C( %unsigned

char hi, unsigned char lo&

Nhi M hi 8;lo M lo 8;hi M hi II ;hi M hi \ lo;return hi;

Pvoid main %&N

unsigned int hrs,mins,secs;char ch5, ch6;int temp;

puts%n3nter the hours to update@ &;ch5Mgetche%&;ch6Mgetche%&;hrs M AC !!to$C(%ch5, ch6&;

puts%n3nter the minutes to update@ &;ch5Mgetche%&;ch6Mgetche%&;mins M AC !!to$C(%ch5, ch6&;

puts%n3nter the seconds to update@ &;

ch5Mgetche%&;ch6Mgetche%&;secs M AC!!to$C(%ch5, ch6&;

outportb%,b&;temp M inport%5&;

Page 156: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 156/340

! - ,eal Time Clo$k 1,TC3 ""

temp M temp \ ?;outportb%,b&;outportb%5,temp&;

outport %,&;outport %5,secs&;outport %,6&;outport %5,mins&;outport %,&;outport %5,hrs&;

outportb%,b&;temp M inport%5&;temp M temp S f;outportb%,b&;outportb%5,temp&;

delay %8&;do N

outportb%,a&;tempMinportb%5&;

Pwhile %%temp S ?& MM &;outportb%,&;secsMinport%5&;

outportb%,6&;minsMinport%5&;

outportb%,&;hrsMinport%5&;hrs M hrs II;K%%unsigned char K &%Shrs&& M

%K%%unsigned c har K&%Shrs&&& JJ;

hrs M hrs Q 88;

To elaorate more on the prolem 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)

Page 157: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 157/340

! - ,eal Time Clo$k 1,TC3 ""

mins M mins II;K%%unsigned char K &%Smins&& M

%K%%unsigned char K&%Smins&&& JJ;mins M mins Q 88;secs M secs II;

K%%unsigned char K &%Ssecs&& M%K%%unsigned char K&%Ssecs&&& JJ;

secs M secs Q 88;printf%n+pdated time is M UcUc@UcUc@UcUc,

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

Page 158: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 158/340

! - ,eal Time Clo$k 1,TC3 ""

18 - *ea" Time +"oc3 *T+ III,ea#ing the 4ate

Hinclude Ibios.hJHinclude Idos.hJvoid main %&N

unsigned int cen,yrs,mons,days; YA> M;geninterrupt%5a&;cenMYC>;yrsMYC9;monsMY(>;daysMY(9;cen M cen II;K%%unsigned char K&%Scen&& M

%K%%unsigned char K&%Scen&&& JJ;cen M cen Q 88;

mons M mons II;K%%unsigned char K&%Smons&& M

%K%%unsigned char K&%Smons&&& JJ;mons M mons Q 88;

yrs M yrs II;K%%unsigned char K&%Syrs&& M

%K%%unsigned char K&%Syrs&&& JJ;

yrs M yrs Q 88;

days M days II;K%%unsigned char K&%Sdays&& M

%K%%unsigned char K&%Sdays&&& JJ;days M days Q 88;

clrscr%&;

Page 159: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 159/340

! - ,eal Time Clo$k 1,TC3 ""

printf%UcUcUcUcUcUcUcUc,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

Setting the 4ate

unsigned char AC!!to$C(%char hi, char lo&N

hi M hi 8;lo M lo 8;hi M hi II ;hi M hi \ lo;return hi;

P

void main %&N

unsigned char yrs,mons,days,cen;char ch5, ch6;puts%n3nter the century to update@ &;ch5Mgetche%&;

ch6Mgetche%&;cen M AC!!to$C(%ch5, c h6&;

puts%n3nter the yrs to update@ &;ch5Mgetche%&;ch6Mgetche%&;

yrs M A C!!to$C( %ch5, ch6&;puts%n3nter the month to update@ &;ch5Mgetche%&;ch6Mgetche%&;mons M AC !!to$C(%ch5, ch6&;puts%n3nter the days to update@ &;ch5Mgetche%&;

ch6Mgetche%&;days M AC!!to$C(%ch5, ch6&;

 YC> M cen;YC9Myrs;Y( >M mons; Y(9Mdays; YA> MB;geninterrupt%5a&;puts%(ate +pdated&;

P

Page 160: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 160/340

! - ,eal Time Clo$k 1,TC3 ""

The aove 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*)

Setting the 8larm

void interrupt %Koldint&%&;void interrupt newint%&;

unsigned int far K scr M %unsigned int far K&b?;void main %&N oldint M getvect% a &;

setvect%a, newint&; YA>M7; YC> M68;

 YC9MB; Y(>M;

geninterrupt%5a&;'eep%,5&;

Pvoid interrupt newint%&

N KscrM5;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 aove 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.hJvoid interrupt newint%&;void interrupt %Koldint&%&;unsigned int far Kscr M

%unsigned int far K&b?;unsigned char AC!!to$C(%char hi, char lo&

Nhi M hi 8;lo M lo 8;hi M hi II ;hi M hi \ lo;return hi;

P

Page 161: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 161/340

! - ,eal Time Clo$k 1,TC3 ""

void main %void&N

int temp;unsigned char hrs,mins,secs;char ch5, ch6;

puts%n3nter the hours to update@ &;ch5Mgetche%&;

ch6Mgetch%&;hrs M AC !!to$C(%ch5, ch6&;

puts%n3nter the minutes to update@ &;ch5Mgetche%&;ch6Mgetch%&;

mins M AC !!to$C(%ch5, ch6&;

puts%n3nter the seconds to update@ &;ch5Mgetche%&;ch6Mgetch%&;secs M AC!!to$C(%ch5, ch6&;

outportb%,5&;outportb%5,secs&;outportb%,8&;

outportb%5,mins&;

outportb%,B&;

outportb%5,hrs&;outportb%,b&;

temp M inport%5&;temp M temp \ ;outportb%,b&;outportb%5,temp&;

oldint M getvect%&;setvect%, newint&;

'eep%,5&;Pvoid interrupt newint%&N

outportb%,c&;if %% inport%5& S 6& MM 6&

sound%65ff&;KscrM5;%Koldint&%&;

P

Page 162: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 162/340

! - ,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 enale the interrupts su$h that

other its are not #isture#) >henever the ,TC generates an interrupt% the reason of the

interrupt nee#s to e estalishe#) 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 estalishe# 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&

Page 163: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 163/340

! - ,eal Time Clo$k 1,TC3 ""

Page 164: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 164/340

4etermining Systems "nformation

!/T 55>

!/T 56>!/T 55>

used to get hardware environment info.

#n 3ntry

call 55>

#n 3it

 AD M ystem !nfo.

(etermining ystems !nformation

"nterrupt !! is use# to #etermine the systems information) (n return this servi$e returnsthe systems info in 8N register) The #etail of the information in 8N register is sho7n in

the sli#e aove)

Page 165: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 165/340

!9 - ,eal Time Clo$k 1,TC3 """

!/T 56>used for memory interfaced.

!/T 5B>"??>

eturns M /o. of E$ above 5)$ mar'.

(etermining ystems !nformation

"nt !2 is use# to #etermine the amount of $onventional memory interfa$e# 7ith the

 pro$essor in kiloytes) The amount of memory aove $onventional memory 1e:ten#e#

memory3 $an e #etermine# using the servi$e !*')

Page 166: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 166/340

!9 - ,eal Time Clo$k 1,TC3 """

'0 - %etermining system information

Types of Pro$essor 

0lags register test to identify 7072

(etermining the *rocessor Type

+nused in ??7

1'1.

*ushing or *oping the flags register will setthese bits in ??7.

mov AD,

push ADpopf 

pushf 

pop AD

Test the bits 5B ] 56 of AD if all set, the

processor is ??7 else higherprocessor.

(etermining the *rocessor Type

The aove sli#es sho7 the test that $an e use# to #etermine if the un#erlying pro$essor is

06 or not) "f its not 06 some test for it to e 026 shoul# e performe#)

Page 167: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 167/340

Page 168: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 168/340

20 - 4etermining system information

 oth +2 it pro$essors ut /6 has alignment $he$k 7hi$h +6 #oes not have) This

 property $an e use# to #istinguish et7een +6 an# /6) "f the previous tests have faile#

then there is a possiility that the pro$essor is not 06 or 26) To eliminate the

 possiility of it eing a +6 7e perform the alignment test) 8s sho7n in the sli#e aove

the !th it of the .8FS register is the alignment it% it sets if a #oule 7or# is move#

onto a o## a##ress or an a##ress 7hi$h #oes not lie on a / yte oun#ary)

pushfd

pop eamov ec, ea

mov dword ptr Z58[, 3(D

pushfd

pop ea

 Alignment Test

"n the aove sli#e a #oule 7or# is move# into a o## a##ress) "f the pro$essor is +6 then

the !th it of the .8FS register 7ill not e set% it 7ill e set if the pro$essor is higher

than +6)

Page 169: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 169/340

20 - 4etermining system information

4istinguishing et7een /6 an# Pentium pro$essors

F ?7 will pass the alignment test.

F To distinguish ?7 with *entiumC*+!( Test is used.

C*+!( Test

8 Pentium an# /6 oth 7ill pass the alignment test) <ut a /6 #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 /6 or a Pentium as Pentium #oes support CPU"4 instru$tion)

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 andstore it.

F Clear bit 65 of 3flags, read the value of 3flags.

F Compare both the value if bit 65 has changed theC*+!( instruction is available.

C*+!( Test'1

3flags

"f the CPU"4 instru$tion is availale the pro$essor is a Pentium pro$essor other7ise itMs a

/6)

Page 170: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 170/340

20 - 4etermining system information

&ore aout CPU"4 "nstru$tion

$efore After  the eecution of !nstruction3AD M 3AD M 5

3$D ] 3(D ] 3CD

3$D M 2enuV

3(D M ine!V

3CD M ntelV

3AD M 5 3AD %bit 8 ] & M tepping !(

3AD %bit ] & M )odel

3AD %bit 55 ] ?& M 0amily

3AD %bit 58 ] 56& M Type3AD %bit 5 ] 85& M eserved

C*+!( !nstruction

The CPU"4 instru$tion% if availale% returns the ven#or name an# information aout the

mo#el as sho7n in the sli#e aove) <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)

Page 171: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 171/340

20 - 4etermining system information

Testing for Copro$essor

Copro$essor $ontrol 7or#

Coprocessor Control Word4

1 1

Interr"pt ena)e fag

&& after initiaiBation

signifies e<ten*e*

precision operation

The $opro$essor $ontrol 7or# $ontains some $ontrol information aout the $opro$essor)

The it numer 5 of $opro$essor $ontrol 7or# is the "nterrupt nale .lag an# it numer

9 shoul# $ontain !! on initiali=ation)

Copro$essor Status >or#

Coprocessor tatus Word10

C8 C6 C

st J operand

5 st I operand

5 st M operand

1 7

+( +0+( +1

8

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)

Page 172: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 172/340

20 - 4etermining system information

.ollo7ing test $an e performe# to test the presen$e of $opro$essor)

F !nitialize

F ead >i ] $yte of Control register.

F !f value in >i ] $yte is 8, thencoprocessor is available, otherwiseits absent.

To Chec' Coprocessor is*resent

(n$e its estalishe# 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 reueste# the 05

$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 05

an# higher pro$essor as sho7n in the sli#e aove) The higher pro$essor 7ill not respon#

to an attempt ma#e to set the "& flag 7hile 05 7ill respon#)

F !3) can be set in ??.F !3) cannot be set in ?6?, ?8?

as they use eception to inform thesoftware about any invalid

instruction.F !f an attempt to set this bit using

0(!! fails then it implies, its not a?? coprocessor .

Chec' for ?? Coprocessor 

Page 173: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 173/340

20 - 4etermining system information

4istinguishing et7een 025 an# 0+5

F ?8? only allows to reverse thesign of infinity.

F *erform a division by zero.

F !f the sign of result can bereversed then the coprocessor is?8?.

(istinguish between ?6? S ?8?

"f the sign of infinity $an e reverse# than the $opro$essor is 0+5 other7ise its 0+5

Page 174: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 174/340

20 - 4etermining system information

,ea#ing the Computer $onfiguration

&oid Print+onfig &oid

union *:S *egisterJ

9KT: TJc"rscrJT ; !ee30>#000, 0>###: ;; 0>#+J

!rintfKour P+ +onfiguration nJ!rintf----------------------------------------------nJ!rintfP+ty!e C Js6itch !ee30>#000, 0>###:

case 0>## C !rintfP+nJ

rea3Jcase 0>#: C !rintfATnJ

rea3Jdefau"t C !rintfT or highernJ

rea3J

N

!rintf+on&entiona" *M C Jint720>1', *egister, *egisterJ

!rintfd n,*egister=>=a>Jif T

*egister=h=ah; 0>77Jint720>1., *egister, *egisterJ

!rintfdditiona" *M Cd o&er 1 megayten, *egister=>=a>J

Nint720>11, *egister, *egisterJ!rintf%efau"t &ideo mode C J

!rintf%is3 dri&es C dn, *egister=>=a> QQ 2 ( B 1J!rintfSeria" interfaces C dn, *egister=>=a> QQ 8 0>0(J

!rintfPara""e" interfaces C dnn, *egister=>=a> QQ 1JN

&oid main

Print+onfigJN

"n this program the general $onfigurations of the $omputer are rea# using interrupt !!%

!2 an# !*) .irst its #etermine# if the Pro$essor is an# 8T 1a#van$e# te$hnology all

 pro$essors aove 063 type $omputer or not) This $an e #one easily y $he$king its

signature yte pla$e# at the lo$ation .000D... 7hi$h 7ill $ontain neither 0:.. nor

0:. if its an 8T $omputer) The program sho7s the si=e of $onventional ,8& using the

interrupt !2% then if the $omputer is an 8T $omputer then the program $he$ks the

e:ten#e# memory si=e using int !*' an# reports its si=e) 8n# ultimately the program

$alls int !! to sho7 the numer an# kin# of "'( interfa$es availale)

Page 175: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 175/340

Page 176: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 176/340

20 - 4etermining system information

The aove sli#e further performs the test for 026 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 0/6)

c"i J@o interru!ts no6

mo&e>,offset array

mo&e>U,ea>

!ushfd

!o! ea>

mo&first,ea>J

mo&e>B1U,ea>

!ushfd

!o! ea>

shr first,17

shr ea>,17

and first,1

and ea>,1cm! first,ea>

inc d"

sti

 ne !ende

The aove $o#e performs the alignment test as #is$usse# efore y test the ! th it after

a##ressing a #oule 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!,'1cm! tem!, ea>inc d"

 e !ende

 m! !ende JTest is ended

the aove $o#e performs a test to see if CPU"4 instru$tion is availale or not for 7hi$h

the it numer 2! of flags is set an# then rea# a$k)

Page 177: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 177/340

20 - 4etermining system information

!ende "ae" near J:nd testing

!o! di JPo! %I off of stac3!o!f JP o! f"ag register off of stac3

>or dh,dh JSet high yte of !roc= code to 0mo& a>,d> JProc= code ; return &a"ue of funct=

ret J*eturn to ca""er

 Rget!roc end! J:nd of !rocedure

8 CPU"4 Program

Dinc"ude stdaf>=hDinc"ude Vstdio=hQ

Dinc"ude Vdos=hQunsigned "ong int id(UJ

unsigned char ch;F0FJunsigned int ste!!ingid Junsigned int mode",fami"y,ty!e1J

unsigned int c!c6Jint mainint argc, charH arg&U

 Rasm >or ea>,ea>

 Rasm c!uid Rasm mo&id0U, e>J Rasm mo&idU, ed>J

 Rasm mo&id7U, ec>J!rintfsn , char H idJ

 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>

Page 178: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 178/340

20 - 4etermining system information

 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!rintfnste!!ing is dn mode" is dn#ami"y is dnTy!e is

dn,ste!!ingid,mode",fami"y,ty!e1JN

The aove 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

aout family% mo#el et$ is also printe#)

Page 179: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 179/340

4ete$ting a Co Pro$essor 

 Rasm finit Rasm mo&yte !tr c!c6B1, 0J

 Rasm fstc6 c!c6if Hchar H c!c6B1;;(

!uts+o!rocessor foundJ

e"se!uts +o!rocessor not foundJ

8fter initiali=ation the $ontrol 7or# is rea# if the higher yte $ontains the value +)

 Rgetco !roc near 

mo& d>,coRnone J#irst assume there is no +P

mo& yte !tr csC6ait1,@OPR+O%: JWIT-instruction on 7074

mo& yte !tr csC6ait',@OPR+O%: J*e!"ace y @OP

6ait1C f init JInitia"ie +o!mo& yte !tr c!B1,0 JMo&e high yte contro" 6ord to 0

6ait'C fstc6 c! JStor e contro" 6ordcm! yte !tr c!B1,( J5igh yte contro" 6ord ; (?

 ne gcende J@o ---Q @o co!rocessor J-- +o!rocessor e>ists= Test for 7074 -----------------------

inc d>and c!,0##4#h JMas3 interru!t ena"e mas3 f"ag

f"dc6c! JLoad in the contr o" 6ordfdisi JSet I:M f"agfstc6 c! JStore contro" 6ord

test c!,70h JI:M f"ag set? ne gcende JK:S ---Q 7074, end test

"n the $o#e aove the "& 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 05 $o pro$essor

other7ise other tests must e performe#)

Page 180: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 180/340

2! - eyoar# "nterfa$e

J-- Test for 70'74/70(74 ------------------------------------inc d>

finit JInitia"ie co!f"d1 J@umer 1 to co! stac3f"d J@umer 0 to co! stac3

fdi& J%i&ide 1 y 0, erg to STf"d st JMo&e ST onto stac3

fchs J*e&erse sign in STfcom!! J+om!are and ! o! S T and ST1fsts6 c! JStore resu"t from status 6ord

mo& ah,yte !tr c!B1 Jin memory and mo&e A register sahf Jto f"ag register  

 e gcende JGero-#"ag ; 1 C 70'74

inc d> J@ot 70'74, must e 70(74 or inte -Jgrated co!rocessor on 7072

gcendeC mo& a>,d> JMo&e function resu"t to Aret J*eturn to ca""er 

 Rgetco end!

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 0+5 $o pro$essor other7ise its

$ertainly 025)

Eey$oard !nterface

25

205

Processor 

I@T*

PI+I*X1

Synchronous %ata

eyoard

The keyoar# interfa$e as #is$usse# earlier uses the ",! an# the port 60 as #ata port% it

also uses another port numer 6/ as a status port) The keyoar# $an perform

syn$hronous serial "'()

Page 181: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 181/340

2! - eyoar# "nterfa$e

4 2 . ( ' 1 0

*ort 7> tatus egister 

& O"tp"t

."ffer f"

& Inp"t ."ffer

f"

& Key)oar* Acti;e

& Parity

>rror

& ,ime O"t >rror

*"ring inp"t

& ,ime O"t >rror

*"ring o"tp"t

The aove sli#e sho7s the #etaile# meaning of its in port 6/)

Typematic ate

,ypematic Rate11111 ; ' char/s11110 ; '=1 char/s

11101 ; '=( char/s11010 ; ( char/s

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

00100 ; '0 char/s00011 ; '1=7 char/s00010 ; ' char/s

00001 ; '2=4 char/s00000 ; (0 char/s

Deay

$$ \ Secon*$& ] Secon*

&$ \ Secon*

&& & Secon*

4 2 . ( ' 1 0

The typemati$ rate of the keyoar# $an e $ontrolle# y a $ontrol 7or# as #epi$te# in the

sli#e aove) 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)

Page 182: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 182/340

2! - eyoar# "nterfa$e

ecieving bytes 0romEeyboard

205

25

In!ut from

eyoard

In!ut uffer fu""

The input $hara$ter s$an $o#e is re$eive# at port 60) 8 $ertain it in the port 6/ or

keyoar# $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 keyoar# on 7hi$h this it 7ill

turn to !)

ending bytes to the Eeyboard205

25

#rom Processor 

Out!ut uffer fu""

Later on

*ecei&es 0># to indicate

succe ssfu" transmission

Similarly some #ata 1as $ontrol information3 $an e sen# to the keyoar#) The pro$essor

7ill 7rite on the port 60) The #evi$e #river 7ill $he$k the (<.1 output uffer full it of

 port 6/ 7hi$h remains set as long as the yte is not re$eive# y the keyoar#) (n

re$eipt of the yte from the port 60 the keyoar# #evi$e 7rite a $o#e 0:.8 on the port

60 to in#i$ate that the yte has een re$eive# properly)

Page 183: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 183/340

2! - eyoar# "nterfa$e

'' - eyoard Interface, %M +ontro""er 

Using the #es$rie# information 7e $an #esign a proto$ol for $orre$tly 7riting on the

keyoar# #evi$e as #es$rie# elo7)

Eeyboard writing *rotocol

W >ait till input uffer is full

W >rite on uffer 

W >ait till output uffer is full

W Che$k the a$kno7le#gement yte

W ,epeat the pro$ess if it 7as previously

unsu$$essful)

eyoar# is a typi$ally an input #evi$e ut some #ata $an also e sen# to the keyoar#

#evi$e) This #ata is use# as some $ontrol information y the keyoar#) (ne su$h

information is the typemati$ rate) This type mati$ rate $an e $onveye# to the keyoar# as

#es$rie# y the sli#e elo7)

Command for writing Typematic rate

0:.+&eans Typemati$ rate 7ill e sent in the

ne:t yte)

(ther su$h $ontrol information is the 4 status) very keyoar# has three 4s for

representing the status of ;um o$k% Caps o$k an# the S$roll o$k) "f the #evi$e #river

Page 184: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 184/340

2! - eyoar# "nterfa$e

nee#s to $hange the status then the 4 status yte shoul# e 7ritten on the keyoar# as

#es$rie# elo7) <ut efore 7riting this yte the keyoar# shoul# e tol# that the $ontrol

 yte is to e 7ritten) This is #one y sen#ing the $o#e 0N4 efore sen#ing the status

 yte using the aove #es$rie# proto$ol)

Eeyboard 93(s

56

Scro Lock 

L>D Stat"s )yte

!"m Lock 

Caps Lock 

L>D Contro )yte $<>D

Changing Typemati$ ,ate

Hinclude Idos.hJHinclude Iconio.hJchar st Z?[;int endEbdate%unsigned char data , int matry&Nunsigned char ch;doN

doNchMinport%7&;

Pwhile %chS6&;outport%7,data&;doN

ch M inport%7&;Pwhile %chS5&;

Page 185: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 185/340

2! - eyoar# "nterfa$e

if %chMMfa&N puts%successn&;

brea';P

matry M matry 5;P while %matry LM &;

if %matryMM&return 5;

elsereturn ;

P

The aove program has fun$tion Sen##,ate13) This fun$tion takes 2 parameters% first

one is value to e sent an# the se$on# one is the ma:imum numer of retries it performs if

the yte $annot e sent) This fun$tion implements the #es$rie# 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 numer of retries en# 1failure3)

void main %&N""clrscr%&;endEbdate%f8,8&;endEbdate%f,8&;gets%st&;endEbdate%f8,8&;endEbdate%,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)

Page 186: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 186/340

2! - eyoar# "nterfa$e

Changing 4s Status

Hinclude Ibios.hJHinclude Idos.hJchar st Z?[;

unsigned char far K'bd M%unsigned char far K& 5;

int endEbdate%unsigned char data , int matry&Nunsigned char ch;doN

doNchMinport%7&;

Pwhile %chS6&;outport%7,data&;

doNch M inport%7&;

Pwhile %chS5&;chMinport%7&;if %chMMfa&N puts%successn&;

brea';

Pmatry M matry 5;P while %matry LM &;if %matryMM&

return 5;else

return ;P

Page 187: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 187/340

2! - eyoar# "nterfa$e

void main %&N""clrscr%&;endEbdate%ed,8&;endEbdate%,8&;puts%3nter a string &;gets%st&;K'bdM%K'bd &\;puts%3nter a string &;gets%st&;P

8gain the same fun$tion is eing use# in this program to turn on the keyoar# 4s)

.irstly 0:4 is sent to in#i$ate the operation an# then 5 is 7ritten to turn on all the 4s)

<ut tuning on the 4s like this 7ill not $hange the keyoar# status in#i$ate# y the yte

at /0D!5) "f the status for the #evi$e #river usage is to $hanges as 7ell then the

$orrespon#ing at /0D!5 $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

Processor 

%M

Main

Memory

Page 188: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 188/340

2! - eyoar# "nterfa$e

4&8 is a #evi$e 7hi$h $an a$uire $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)

Page 189: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 189/340

2! - eyoar# "nterfa$e

'( - %irect Memory ccess %M

The lat$h < of the 4&8 interfa$e is use# to hol# the higher / or its of the 20 or 2/ it

asolute a##ress respe$tively) The lo7er !6its are loa#e# in the ase a##ress register an#

the numer of ytes to e loa#e# are pla$e# in the $ount register) The 4&8 reuests to

a$uire uses through the (4 signal% it re$eives a 48 1ol# 8$kno7le#ge 3 signal

if no higher priority signal is availale) (n a$kno7le#gment the 4&8 a$uires $ontrol of

the uses an# $an issue signals for rea# an# 7rite operations to memory an# "'( ports

simultaneously) The 4, signals are use# y various #evi$es to reuest a 4&8

operation) 8n# if the 4&8 $ontroller is su$$essful in a$uiring the us it sen#s a$k the

48C signal to signify that the reuest is eing servi$e#) .or the reuest to e servi$e# properly the 4&8 $hannel must the programme# a$$urately efore the reuest)

()A Cascading

8 single 4&8 $an transfer it operan#s to an# from memory in a single a us $y$le) "f

!6it values are to e transmitte# then t7o 4&8 $ontrollers are reuire# an# shoul# e

$as$a#e# as sho7n aove)

Page 190: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 190/340

2! - eyoar# "nterfa$e

()A *rogramming )odelW 4&8 has / Channels

W a$h Channel $an e programme# to transfer a

 lo$k of ma:imum si=e of 6/k)

W .or ea$h Channel there is a

W .ase Register

W Co"nt Register

W (igher A**ress !i))e/.yte is pace* in Latch .2

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 reuest to 4&8 is ma#e to start itMs transfer)

!nternal egistersW ;o of !6 it "nternal registers

W Total of 25 internal registers in 4&8

Register !"m)er +i*thStarting ddress 12

+ounter 12

+urrent ddress 12

+urrent +ounter 12

Tem!orary ddress 1 12

Tem!orary +ounter 1 12

Status 1 7

+ommand 1 7

Intermediate Memory 1 7

Mode 7

Mas3 1 7

*eEuest 1 7

The aove 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 numer 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)

Page 191: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 191/340

()A )odes

W <lo$k Transfer 

W Single Transfer 

W 4eman# Transfer 

The 4&8 $an 7ork in aove 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 reuests re$eive# mean7hile)

"n Single transfer mo#e the 4&8 transfers a single yte on ea$h reuest an# up#ates the

$ounter registers on ea$h transfer an# the registers nee# not e programme# again) (n the

ne:t reuest 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, 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, signal the transfer may start from the point it left)

Page 192: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 192/340

2+ - 4ire$t &emory 8$$ess 14&83

Programming the 4&8

The aove tale 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)

Page 193: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 193/340

2+ - 4ire$t &emory 8$$ess 14&83

()A tatus egister 

Terminal $ount if rea$he# signifies that the 7hole of the lo$k as reueste# through some

4&8 $hannel has een transferre#) The aove status register maintains the status of

Terminal $ount 1TC3 an# 4, for ea$h $hannel 7ithin the 4&8)

Page 194: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 194/340

2+ - 4ire$t &emory 8$$ess 14&83

This is the $omman# register) "t is use# to program various $ommon parameters of

transfer for all the $hannels)

Page 195: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 195/340

2+ - 4ire$t &emory 8$$ess 14&83

' - %irect Memory ccess %M II

This register $an e use# to simulate a 4&8 reuest through soft7are 1in $ase of memory

to memory transfer3) The lo7er 2 its $ontains the $hannel numer to e reueste# an#

the it H 2 is set to in#i$ate a reuest)

Page 196: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 196/340

This register $an e use# to mask'unmask reuests from a #evi$e for a $ertain 4&8

$hannel) The lo7er 2 its $ontains the $hannel numer an# the it H2 is set if the $hannel

is to e maske#)

Page 197: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 197/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

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 reuests for that $hannel)

Page 198: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 198/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

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 reuire# mo#e)

Page 199: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 199/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

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 numer as sho7n y the sli#e aove) (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 aove for the

$hannel1s3 involve# in the transfer)

Page 200: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 200/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

>igh Address /ibble"$yte

The aove sli#e sho7s the port numer for ea$h $hannel in 7hi$h the higher / or its of

the asolute a##ress is store# in $ase of 20 or 2/ it a##ress us)

Hinclude Idos.hJHinclude Ibios.hJchar stZ?[;unsigned long int temp;unsigned int i;

unsigned int countM?;

void main %void&N

tempM%unsigned long int&Y(;temp M temp II 9;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 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 3 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

Page 201: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 201/340

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&&;count;outportb%,K%%unsigned char K&%Scount&&&;outportb%,K%%%unsigned charK&%Scount&&Q5&&;

outportb%b,b&;

outportb%?,&;outport%a,8&;getch%&;

P

Page 202: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 202/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

'. - #i"e Systems

This program attempts to perform memory to memory transfer operation) This program

7ill only 7ork for a 06 pro$essor% higher pro$essorsM 4&8 may not support memor to

memory transfer)

Hinclude Idos.hJHinclude Ibios.hJ

char stZ6?[Mhello u whats up=;

char st5Z6?[Myz;unsigned long int temp;unsigned int i;

void main %void&N

tempMY(;temp M tempII;i M K%%unsigned int K&%Stemp&&;temp M temp JJ57;

Page 203: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 203/340

2/ - 4ire$t &emory 8$$ess 14&83 ""

outportb%?,K%%unsigned char K&%Stemp&&&;outportb%,K%%unsigned char K&%Si&&&;outportb%,K%%%unsigned char K&%Si&&Q5&&;outportb%5,ff&;

outportb%5,&;outportb%b,??&;tempMY(;tempM tempQ56?;tempMtempII;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&&;

Page 204: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 204/340

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>ffJ

out!ort(,0>04Jout!ort0>0,0>7.J

out!ort0>07,1Jout!ort0>0f,0>0cJ

out!ort0>08,0>0J

6hi"e Y3hit

!rintf+hanne" 0 ;

>,>n,in!ort0>01,in!ort0>01J!rintf+hanne" 1 ;

>,>n,in!ort0>0(,in!ort0>0(J

!rintfStatus ; >n,in!ort0>07J

N!utsst1J

N

.ile Systems

0ile ystem

W4isk 8r$hite$ture

W4isk Partitioning

W.ile systems

Page 205: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 205/340

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)

#n trac's and sectors

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 aove)

Page 206: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 206/340

2* - .ile Systems

 Addressable unit *arametersW ea#s

WSe$tors

WTra$ks

8n a##ressale 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) a$h a##ressale unit has a uniue $omination 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##ressale unit in memory

W8##ress of lo$k is spe$ifie# as a uniue

$omination of three parameters 1i)e) tra$k% hea#%

se$3

Page 207: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 207/340

2* - .ile Systems

(ensity of )agnetic mediaW 4ensity of magneti$ me#ia is the #eterminant of

the amount of #ata that $an resi#e staly on the

#isk for e:ample floppy #isk $ome 7ith #ifferent

#ensities)W4oule 4ensity

Wigh 4ensity

3ffect of surface area on dis' size

W "n$reasing the surfa$e area $learly in$reases the

amount of #ata that $an resi#e on the #isk as more

magneti$ me#ia no resi#es on #isk ut it might

have some #ra7a$ks like in$rease# seek time in

$ase only one #isk platter is eing use#

>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 thehar# surfa$e of the #isk 

W8lso e$ause the surfa$e area of the #isk is in$rease# y

in$reasing the numer of platters as sho7n in the #iagram

Page 208: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 208/340

2* - .ile Systems

>ard (is' Architecture

W

Cylinders

W "n $ase of har# #isk 7here there are numer 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

reuire# y the #isk to rotate to the spe$ifie#

se$tor is $alle# rotational #elay

Page 209: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 209/340

2* - .ile Systems

ee' Time

W >hile a$$essing a sele$te# lo$k Time reuire#

 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 reuire# to a$$ess

the sele$te# lo$k is $alle# a$$ess time

W8$$ess time in$lu#es the #elay reuire# y #isk

rotation as 7ell as hea# movement)

>ead is li'e 3lectric Coil

W 4isk follo7 the asi$ prin$iple of magnetism of

#ynamo)

W>hen ever a magneti=e# portion of #isk runs

along the $oil like hea# ele$tri$ity is pro#u$e# in

the hea# 7hi$h is interprete# as a logi$ !

W8n# 7henever a #emagneti=e# portion on the

#isk runs through the hea# no ele$tri$ity is

 pro#u$e# in hea# 7hi$h is interprete# as logi$ 0

Page 210: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 210/340

2* - .ile Systems

>ead position and precautionsW The hea# is tou$hing the surfa$e of floppy #isk

7hi$h rotates at a lo7 spee# of +00 ,P&

WThe hea# is not tou$hing the surfa$e of har# #isk

7hi$h run at high spee#s up to 9600 ,P& ut is

at a fe7 mi$rons #istan$e from the surfa$e

W8ll the magneti$ #isk are ma#e out of magneti$

me#ia an# hen$e #ata may e lost y e:posing

them to sunlight% heat% ra#iation% magneti$ or

ele$tri$ fiel#s)

W4ust is harmful an# even fatal in $ase of hea#

#isk y the virtue of its spee# an# its #istan$e of

hea# from the surfa$e

Page 211: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 211/340

2* - .ile Systems

'2 - 5ard %is3

eading"Writing a physical $loc'

W ios#isk1int $m#% int #rive% int hea#% int tra$k%

int se$tor% int nse$ts% voi# E uffer3A

Cm# 0 @ #isk reset

! @ #isk status 1status of last #isk operation3

2 @ #isk rea#

+ @ #isk 7rite

/ @ #isk verify

* @ #isk format

 ;o7 7e estalish 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 numer% hea# numer% tra$k numer% numer 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#)

eading Writing a physical $loc'

W 4rive 0:0 @ first fi:e# #isk 1phys$ial #rive3

0:! @ se$on# fi:e# #isk

0:2 @ thir# fi:e# #isks

^) ^)

0:00 @ first removale #isk

0:0! @ se$on# removale #isk

^) ^)

4rive numer is #es$rie# in the sli#e elo7 it starts from 0 for first removale #isk an#

starts from 0:0 for first fi:e# #isk)

Page 212: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 212/340

2* - .ile Systems

eading Writing a physical $loc'Hinclude Ibios.hJHinclude Idos.hJ0!93 Kfp;

unsigned char bufZB56[;unsigned char stZ7[;unsigned char headnoZ5[;unsigned char secnoZ5[;unsigned char trac'noZ5[;void main %void&N

int i ;for %iM;iIB56;iQQ&

bufZi[M;

Contgets%st&;fpMfopen%st,wb&;printf%>ead &;gets%headno&;puts %headno&;printf%nsector &;gets%secno&;puts%secno&;printf%ntrac' &;gets%trac'no&;puts%trac'no&;

Page 213: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 213/340

2* - .ile Systems

Conti M biosdis'%6,?,atoi%headno&,

atoi%trac'no&,atoi%secno&,5,buf& ;if %K%%%char K&%Si&&Q5&MM&

Nfwrite%buf,5,B56,fp&;fclose%fp&;

Pelse

printf%Cannot ead 3rrorH M U,i&;P

The aove 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 !+'0'!'2'+'/'*W4etails of !+ servi$es use# y <ios#isk13

W(n ntry

8 @ servi$e H

8@;o) of se$tors

<N @ offset a##ress of #ata uffer

C @ tra$k H

C @ se$tor H

4 @ hea#'si#e H

4 @ 4rive H

S @ Segment 8##ress of uffer)

o7ever there are some limitation of this ios#isk13 7hile using large #isks) This

fun$tion uses the int !+ servi$es liste# in the sli#e aove)

Page 214: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 214/340

2* - .ile Systems

9imitation of biosdis'%&

W arge si=e# #isk are availale no7 7ith

thousan#s of tra$ks

W<ut this <"(S routine only is $apale ofa$$essing a ma:) of !02/ tra$ks)

Wen$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

numer of lo$k to e a$$esse#)

3tended $!# functions

W :ten#e# <"(S fun$tions of int !+h $an e use#

for operations on higher tra$ks

W8s #is$usse# later usual <"(S fun$tions $ana$$ess a ma:imum of *0/&< of #isk appro:)

8ove sli#e sho7s for 7hi$h #isks e:ten#e# servi$es are reuire# to a$$ess the lo$k

effi$iently)

Page 215: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 215/340

2* - .ile Systems

3tended $!# functions

567BB8756)aCapacity

57576B7)aheads

786BB78)aec

9imit!(3$!#

>ighest biosdis'%& capacity

W en$e the highest $apa$ity of #isk $an e

a$$esse# using ios fun$tions is

W6+:!6:!02/:*!2@ *0/ &< appro:)

<ut "4 #isk interfa$e $an support #isks 7ith memory spa$e larger than *0/&< as sho7n

in the ne:t sli#e)

Page 216: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 216/340

2* - .ile Systems

>ighest !(3 capacity

W en$e highest physi$al $apa$ity of the #isk

a$$or#ing to the "4 interfa$e is

2**:!6:6**+6:*!2 @ !25F<

W:ten#e# <"(S fun$tions allo7 to a$$ess #isk

7ith si=es greater than *0/ &< through <8

translation)

:ten#e# servi$es reuire that the a##ress of the lo$k is spe$ifie# as a <8 a##ress)

9$A Translation )ethodW a$h uniue $omination of three parameters is

assigne# a uniue in#e: as sho7n elo7

W.irstly all the se$tors of a $ylin#er are in#e:e#

for hea#@0% then 7hen 7hole tra$k has een

in#e:e# the se$tor in the tra$k of same $ylin#er

7ith hea# @! are in#e:e# an# so on up till the en#

of all hea#s

>hen #one 7ith one $ylin#er the same is repeate#

for the ne:t $ylin#er till the en# of $ylin#ers

Page 217: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 217/340

<8 translation is #one y numering 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# seuentially% 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)

9$A Translation methodCylin#er hea# se$

0 0 ! @ 0

0 0 2 @ !0 0 + @ 2

^) ^) ^ ^)

0 0 6+ @ 62

0 ! ! @ 6+

0 ! 2 @ 6/

^) ^) ^ ^)

0 2 ! @ !26

if the CS 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 numer of $ylin#ers% hea#s an#

se$tors must also e kno7n)

)athematical /otation for 9$A translation

W <8 a##ress @ 1C E M K3E SM K S !

>here

C @ Sele$te# $ylin#er numer M @ ;o) of hea#s

@ Sele$te# hea# numer

SM@&a:imum Se$tor numer 

S@ Sele$te# Se$tor numer 

Page 218: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 218/340

26 - ar# 4isk 

8lso $onversely <8 to CS translation $an also e #one using the formulae #is$usse#

in the follo7ing sli#e ut for this the total numer of $ylin#ers% hea#s an# se$tors 7ithin

the #isk geometry shoul# e kno7n)

9$A to C> translationW Conversely <8 a##ress $an e translate# into

CS a##ress

$ylin#er @ <8 ' 1hea#sOperO$ylin#er E

se$torsOperOtra$k3

temp @ <8 b 1hea#sOperO$ylin#er E

se$torsOperOtra$k3

hea# @ temp ' se$torsOperOtra$k 

se$tor @ temp b se$torsOperOtra$k K !

Page 219: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 219/340

26 - ar# 4isk 

4isk 8##ress Pa$ket is a #ata stru$ture use# y e:ten#e# int !+ 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)

(is' Address *ac'et

9$A addressRuadword

?

0ar address of buffer (oubleWord

eserved$yte8

/o. of b loc's to transfer, )a valueno greater than 0>

$yte6

eserved$yte5

ize, hould not be less than 57$yte

(escriptionize#ffset

Page 220: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 220/340

26 - ar# 4isk 

'4 - 5ard %is3, Partition Ta"e

3tended eadW Servi$e use# for e:ten#e# rea# is int !+h'/2h

(n ntry

8@/2

4@#rive H

4SDS"@ far a##ress of 4isk a##ress pa$ket

(n :it

"f C.@0

8@0@ Su$$ess

"f C.@!

8@ rror $o#e

"nterrupt !+'/2 $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$rie# in the sli#e aove)

3tended Write

W Servi$e use# for e:ten#e# 7rite is int !+h'/+h(n ntry8@/+

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 :it"f C.@0

8@0@ Su$$ess

"f C.@!

8@ rror $o#e

Similarly int !+ ' /+ $an e use# to 7rite onto to <8 a##resse# lo$k as #es$rie# in

the sli#e aove)

Page 221: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 221/340

26 - ar# 4isk 

eading a 9$A bloc'Dinc"ude Vdos=hQ

Dinc"ude Vios=hQ

struct %P

unsigned char sieJ

unsigned char reser&ed1Junsigned char "oc3sJ

unsigned char reser&ed'J

unsigned char far HufferJunsigned "ong int "a"odJ

unsigned "ong int "ahidJ

N da!J

char st70UJ

unsigned char uf.1'UJ

#IL: Hf!trJ

&oid main &oid

!uts enter the "a "o6 dou"e 6ordC J

gets stJda!="a"od;ato"stJ

!uts enter the "a high dou"e 6ordC J

gets stJ

da!="ahid;ato"stJ

da!=sie;12J

da!=reser&ed1;0Jda!="oc3s;1J

da!=reser&ed';0J

da!=uffer ; unsigned char far HMR#PR%S,ufJ

 R5;0>'J R%L;0>70J

 RSI;unsigned intda!J

geninterru!t0>1(J!uts enter the !athC J

gets stJ

f!tr ; fo!enst,6J

f6riteuf,.1',1,f!trJ

fc"ose f!trJ

N

Page 222: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 222/340

26 - ar# 4isk 

The aove sli#es list a program that that performs a lo$k rea# operation using the

interrupt !+'/2) 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 gloal variale)

The #rive numer 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' *artitioningW Partition Tale $ontains information pertaining

to #isk partitions)

W Partition Tale 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&.

tructure of *artitioning TableW Total si=e of Partition Tale is *!2 ytes)

W .irst //6 ytes $ontains $o#e 7hi$h loa#s the

 oot lo$k of a$tive partition an# is e:e$ute# at

<oot Time)

W ,est of the 66 ytes is the 4ata part)

W ast t7o ytes of the 4ata part is the Partitiontale signature)

Page 223: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 223/340

26 - ar# 4isk 

0ile ystem for 3ach #..W (n a single #isk there $an e / #ifferent file

systems an# hen$e / #ifferent ()S)

W a$h ()S) 7ill have its in#ivi#ual partition on

#isk)

W 4ata relate# to ea$h partition is store# in a !6-

 ytes $hunk 7ithin the 4ata Part of Partition

Tale)

tructure of (ata *art of *.T.

ignature6 $ytes

*artition into of th partition.57 $ytes

*artition into of 8rd partition.57 $ytes

*artition into of 6nd partition.57 $ytes

*artition into of 5st partition.57 $ytes

(escriptionize

The #ata part $an $ontain information aout four #ifferent partitions for #ifferent

(perating systems) a$h partition information $hunk is !6 ytes long an# the last t7o

 ytes at the en# of the partition tale #ata part is the partition tale signature 7hose value

shoul# e 88** in#i$ating that the $o#e part $ontains vali# e:e$utale $o#e)

Page 224: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 224/340

Page 225: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 225/340

26 - ar# 4isk 

0ile ystem !(

)(# 57bits I 86)$

)(# etended partition can manage dis's ofsizes up to ?. 2$

B

Deni"usr 8

Deni root6

(# 56bit partition53mpty

(escription$it H

X 00 for various #..

3tended partitions 9$A )apped0

Win OB 0AT 57 9$A )apped3

Win OB 0AT 86$

Win OB 0AT 86 9$A )appedC

#"6 $oot )anager A

 A!D (ata partitionsO

 A!D $oo t parti tions?

#"6, 50 M !nstallable file system

 Advanced + ni

Windows /T /T0

)(# 57bits 0AT JM 86)$7

Page 226: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 226/340

Page 227: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 227/340

26 - ar# 4isk 

'7 - Partition Ta"e II

3tended *artitionsM9*

3tended *artition*rimary*artition

1st 9"oc3 of :>tended Partitions

3tended *artition9ogical(rive

*rimary*artition

Page 228: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 228/340

26 - ar# 4isk 

1st 9"oc3 of @e>t :>tended Partitions

9ogical(rive

3tended*artition

ere it $an e seen that the first partition tale maintains information aout the primary

an# e:ten#e# partitions) The se$on# partition tale similarly stores information aout 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 tale that stores information aout the

logi$al partition an# may also $ontain information aout any further e:ten#e# partition) "n

this 7ay the partition tales form a $hain as #epi$te# in the sli#e elo7) The last partition

tale 7ithin the $hain $ontains ?ust a single entry signifying the logi$al #rive)

Page 229: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 229/340

26 - ar# 4isk 

Chain of 3tended *artitions

Primary Partition

Logica" %ri&e

Logica" %ri&e

:>tended Partition

:>tended Partition:>tended Partition

Logica" %ri&e0000

M9*

3tended *artition 3ample13AE:0100 33 C0 8E D0 BC 00 7C FB-50 07 50 1F FC BE 1B 7C 3.....|.P.P....|13AE:0110 BF 1B 06 50 57 B9 E5 01-F3 A4 CB BD BE 07 B1 04 ...PW...........13AE:0120 38 6E 00 7C 09 75 13 83-C5 10 E2 F4 CD 18 8B F5 8n.|...........13AE:0130 83 C6 10 49 74 19 38 2C-74 F6 A0 B5 07 B4 07 8B ...!".8#".......13AE:0140 F0 AC 3C 00 74 FC BB 07-00 B4 0E CD 10 EB F2 88 ..$."...........13AE:0150 4E 10 E8 46 00 73 2A FE-46 10 80 7E 04 0B 74 0B %..F.&'.F..(..".13AE:0160 80 7E 04 0C 74 05 A0 B6-07 75 D2 80 46 02 06 83 .(.."......F...13AE:0170 46 08 06 83 56 0A 00 E8-21 00 73 05 A0 B6 07 EB F...)...*.&.....13AE:0180 BC 81 3E FE 7D 55 AA 74-0B 80 7E 10 00 74 C8 A0 ..>.+U."..(.."..13AE:0190 B7 07 EB A9 8B FC 1E 57-8B F5 CB BF 05 00 8A 56 .......W.......) 13AE:01A0 00 B4 08 CD 13 72 23 8A-C1 24 3F 98 8A DE 8A FC .....,../.....13AE:01B0 43 F7 E3 8B D1 86 D6 B1-06 D2 EE 42 F7 E2 39 56 C..........B..9) 13AE:01C0 0A 77 23 72 05 39 46 08-73 1C B8 01 02 BB 00 7C .,.9F.&......|13AE:01D0 8B 4E 02 8B 56 00 CD 13-73 51 4F 74 4E 32 E4 8A .%..)...&"%2..13AE:01E0 56 00 CD 13 EB E4 8A 56-00 60 BB AA 55 B4 41 CD )......)...U.A.13AE:01F0 13 72 36 81 FB 55 AA 75-30 F6 C1 01 74 2B 61 60 .,6..U.0..."13AE:0200 6A 00 6A 00 FF 76 0A FF-76 08 6A 00 68 00 7C 6A ........|13AE:0210 01 6A 10 B4 42 8B F4 CD-13 61 61 73 0E 4F 74 0B ...B....&.".13AE:0220 32 E4 8A 56 00 CD 13 EB-D6 61 F9 C3 49 6E 76 61 2..).......!n13AE:0230 6C 69 64 20 70 61 72 74-69 74 69 6F 6E 20 74 61 ; <,""on "13AE:0240 62 6C 65 00 45 72 72 6F-72 20 6C 6F 61 64 69 6E =.E,,o, o;n13AE:0250 67 20 6F 70 65 72 61 74-69 6E 67 20 73 79 73 74 ? o<,"n? &@&"13AE:0260 65 6D 00 4D 69 73 73 69-6E 67 20 6F 70 65 72 61 .&&n? o<,13AE:0270 74 69 6E 67 20 73 79 73-74 65 6D 00 00 00 00 00 "n? &@&".....13AE:0280 00 00 0000 0000 0000-00 00 00 0000 00 0000 ................13AE:0290 00 00 0000 0000 0000-00 00 00 0000 00 0000 ................13AE:02A0 00 00 0000 0000 0000-00 00 00 0000 00 0000 ................

13AE:02B0 00 00 00 00 00 2C 44 63-48 E0 48 E0 00 00 80 01 .....#D......13AE:02C0 01 00 0C A4 FF FF 3F 00-00 00 FC 8A 38 01 00 A5 ....../.....8...13AE:02D0 C1 FF 0F 4A FF FF 3B 8B-38 01 0A 62 90 03 00 00 ......8..=....

13AE:02E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AE:02F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.

The aove #ump sho7s the #ump of the #ata part of the first partition tale 7hi$h has t7o

!6 ytes entries% the values in the entries $an e interprete# as the values sho7n in the

follo7ing sli#e)

Page 230: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 230/340

26 - ar# 4isk 

#irst Partition

System I% ; 0c ; Windo6s #T(' !artition L9 M!!ed

first "oc3 ; (#

@o= of "oc3s ; 01(77afc

end cy"inderD ; 10'(

end sec D ; 2( indicating a L9 dis3

Second Partition

System I% ; 0f ; :>tended 6indo6s !artition

Start "oc3 re"ati&e to the start ; 01(77( ; '07'74.

@o= of "oc3s ; 0(802'0a ; .848(8(0

-d 100 '00

1'A2:0100 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0110 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01$0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01'0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0140 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01#0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:01&0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0170 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01A0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01C0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:01%0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0120 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0180 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$00 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$10 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$$0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0$'0 00 00 0000 0000 0000-00 00 0000 0000 0000

1'A2:0$40 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$#0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$&0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0$70 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$A0 00 00 0000 0000 0000-00 00 00 0000 00 0000

13AE:02B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 A6 ................

13AE:02C0 C1 FF 0B 59 FF FF 3F 00-00 00 FC 8A 38 01 00 5A ...../.....8..H13AE:02D0 C1 FF 05 0E FF FF 3B 8B-38 01 3B 8B 38 01 00 00 .......8..8...13AE:02E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AE:02F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.

ere is the information foun# in the partition tale of first e:ten#e# partition tale 7hi$h

implies another e:ten#e# an# a logi$al partition)

Page 231: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 231/340

26 - ar# 4isk 

#irst Part itionSystem 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 !artitionStart "oc3 re"ati&e to the start ; 01(77( ; '07'74.Start "oc3 !hysica" ; 01(77( B 01(77( ; '4112425 ; 082.4.0

@o= of "oc3s ; 01(77( ; '07'74.

-d 100 '00

1'A2:0100 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0110 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01$0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01'0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0140 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01#0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:01&0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0170 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01A0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:010 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:01C0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:01%0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0120 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0180 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$00 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$10 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$$0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1 'A 2: 0 $' 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 00 0 0 0 0 0 0 0 0 0 0

1'A2:0$40 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$#0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$&0 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$0 00 00 0000 0000 0000-00 00 00 0000 00 0000 1'A2:0$70 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0$A0 00 00 0000 0000 0000-00 00 00 0000 00 0000

13AE:02B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 5B ...............I

13AE:02C0 C1 FF 0B 0E FF FF 3F 00-00 00 FC 8A 38 01 00 0F ....../.....8...13AE:02D0 C1 FF 05 4A FF FF 76 16-71 02 94 4B 1F 01 00 00 ......q..J....13AE:02E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AE:02F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.

ere is information in the partition tale 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)

Page 232: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 232/340

26 - ar# 4isk 

#irst Part itionSystem 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 !artitionStart "oc3 re"ati&e to the start of e>tended !artition ; '4112425 ; 082.4.0Start "oc3 !hysica" ; 01(77(5 B '4112425 ; (81915 ; 2172'.

@o= of "oc3s ; 11f8 ; 177'7170

Page 233: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 233/340

'8 - *eading :>tended Partition

:>tended PartitionLogica" %ri&e

0(802'0(# 1(77#+

L9;0 M9* L9 ;1(779(9

:>tended PartitionLogica"

%ri&e

Logica"

%ri&e

'nd Partition

Ta"e

1(779(9

*e"ati&e start ; 1(779(9

'4112425

(# 1(77#+

Page 234: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 234/340

29 - ,ea#ing :ten#e# Partition

:>tended

Partition

Logica"

%ri&e

Logica"

%ri&e

Logica"

%ri&e

(rd Partition Ta"e

@e>t Partition Ta"e in +hain

'4112425

(81915

*e"ati&e

ddress ;

'411242h

Physica" L9

; (81915

8ove sli#es sho7s the information $olle$te# as yet 7hi$h in#i$ates the logi$al #rive

there starting <8 lo$ks% the numer of lo$k % the hi##en lo$ks et$) The follo7ing

sli#e sho7s the $ontents of the #ata part of partition tale of the last e:ten#e# partition)

1'A2:0100 00 00 0000 0000 0000-00 00 00 0000 00 0000

1'A2:0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

1'A2:01$0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

1'A2:0$A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00

sPipped

13AE:02B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 10 ................13AE:02C0 C1 FF 07 4A FF FF 3F 00-00 00 55 4B 1F 01 00 00 ...../...UJ....13AE:02D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AE:02E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

13AE:02F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.

"t has ?ust one #ata entry for the logi$al #rive in#i$ating that this is the partition tale in

the $hain) The #etail of the $ontents this partition tale are sho7n elo7)

Page 235: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 235/340

29 - ,ea#ing :ten#e# Partition

#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 !artions@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 numer of lo$ks 7ithin)

11#981(779(9

(# (# (# (#

1(779(9 1(779(9

Page 236: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 236/340

29 - ,ea#ing :ten#e# Partition

@u""

M9*1ST Partition

Ta"e'nd Partition

Ta"e

(rd Partition

Ta"e

Dinc"ude Vdos=hQ

Dinc"ude Vios=hQstruct %P

unsigned char sieJunsigned char reser&ed1J

unsigned char "oc3sJ

unsigned char reser&ed'Junsigned char far HufferJ

unsigned "ong int "a"odJunsigned "ong int "ahidJ

N da!J

struct Part:ntry

uns igned char 9oota"e #" agJ

unsigned char Start5eadJ

unsigned char StartSectorJ

unsigned char Start+y"inderJ

unsigned char SystemI%J

unsigned char :nd5eadJ

unsigned char :ndSectorJunsigned char :nd+y"inderJ

unsigned "ong s9eginJunsigned "ong Sect+ountJ

NJ

Page 237: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 237/340

29 - ,ea#ing :ten#e# Partition

struct PartTa"e

unsigned char code 2UJstruct Part:ntry eUJ

unsigned int signatureJ

NJ

struct %P da!J&oid *eadL9unsigned int dri&e,

unsigned "ong int "a"o, unsigned "ong int "ahi,unsigned char far H uffer, int nsects

da!="a"od ; "a"oJ

da!="ahid;"ahiJ

da!=sie;12J

da!=reser&ed1;0J

da!="oc3s;nsectsJ

da!=reser&ed';0J

da!=uffer ;ufferJ// unsigned char far HMR#PR%S,ufJ

 R5;0>'J R%L;dri&eJ

 RSI;uns igned intda!Jgeninterru!t0>1(J

N

&oid etPart unsigned char dri&e,

unsigned "ong int "o6, unsigned "ong int high

struct PartTa"e !J

unsigned int Ssec, :secJ

unsigned int Scy", :cy"J

unsigned "ong int 9SecJint iJ

*eadL9dri&e,"o6,high, unsigned char H !,1Jif !=signature ;; 0>aa..

for i;0J iVJi BB

if !=eiU=SystemI% Y; 0

Ssec ; !=eiU=StartSectorJ

Ssec ; Ssec VV 'J

Scy" ; !=eiU=Start+y"inderJ

Hunsigned char H Scy"B1 ;Hunsigned char HSsecB1J

:sec ; !=eiU=:ndSectorJ:sec ; :sec VV 'J

:cy" ; !=eiU=:nd+y"inder J

Page 238: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 238/340

29 - ,ea#ing :ten#e# Partition

Hunsigned char H :cy"B1;

Hunsigned char H:secB1J

!rintf Start 5ead ; d n Start Sector ;

d n Start +y"inder ; dn :nd 5ead ;d n :nd Sector ; d n :nd +y"inder ;

dn 9oot *ecord 6ith res!ect to start of !artition ;

"dn +ount of sectors from oot se ctor ;

"dn System I%; > L9 Lo6 ; "d,!=eiU=Start5ead, !=eiU=StartSector 0>(f,

Scy",!=eiU=:nd5ead, !=eiU=:ndSector 0>(f,

:cy", !=eiU=s9egin, !=eiU=Sect+ount,!=eiU=SystemI%,"o6J

if !=eiU=SystemI%;; 0>0f

etPartdri&e,"o6B!=eiU=s9egin,0J

9Sec ; !=eiU=s9eginJgetchJ

Ne"se

!rintf ParTition unused or un3no6nnJ

NN

e"se

!rintf@ot a Partition Ta"enJ

N

&oid main

etPart0>70,0,0J

N

8ove is a listing of a simple program that rea#s the partition tale using the e:ten#e#

!+ servi$es) "t then #isplays the $ontents of the #ata part of the partition tale rea#) .or

this purpose it uses various #ata stru$tures #esigne# in refle$tion of the partition tale 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 tale)

Page 239: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 239/340

29 - ,ea#ing :ten#e# Partition

2et (rive *arameters#n 3ntry@

 A> ] ?(9 ] (rive number 

(@! ] Address of result buffer #n 3it@

Carry Clear A> ] (@! ] result buffer 

Carry et A> ] 3rror Code

The partition tale #ata entry also stores the CS a##ress of the starting lo$k) <ut this

a##ress is left insignifi$ant if a <8 enale #isk is in uestion) o7ever <8 a##ress

$an e use# in pla$e of the CS a##ress% an# in $ase CS a##ress is reuire# it $an e

$al$ulate# if the total numer of tra$ks% se$tors an# hea#s are kno7n) To get the total

numer of tra$ks% se$tors an# hea# the aove #es$rie# servi$e $an e use#)

Page 240: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 240/340

29 - ,ea#ing :ten#e# Partition

(0 - #i"e System %ata Structures LS@, 9P9

Page 241: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 241/340

29 - ,ea#ing :ten#e# Partition

8ove sli#es sho7s the stru$ture of result uffer use# y e:ten#e# !+ servi$es) "f a

e:ten#e# servi$e returns a value it 7ill e store# in the result uffer as #es$rie# aove)

Hinclude Ibios.hJHinclude Idos.hJ

struct 3+9T$+003N

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;

Page 242: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 242/340

29 - ,ea#ing :ten#e# Partition

&oid main

c"rscrJ

 R5 ; 0>7J

 R%L ; 0>70J

r=sie ; (0J

 RSI ; unsigned i nt rJ

geninterru!t 0>1(J

!rintf 5eads ; "dn Sectors ; "dn

Trac3s/+y"inders ; "dn 9yte s !er sector ;

dn 9"oc3 count Lo6 6ord ;

"dn 9"oc3 count 5i Word ; "dn,

r=heads, r=sectors, r=cy"inders,

r=ytes!ersector,r="ocount,r=hicountJ

N

The aove program uses a ,SUT<U.., #ata stru$ture in refle$tion of the result

 uffer #es$rie# in previous sli#es) "t uses the interrupt !+'/ to get the #rive

 parameters an# then #isplays the re$eive# total numer of se$tors% hea#s an# $ylin#ers)

Dinc"ude Vios=hQDinc"ude Vdos=hQ

struct *:S)LT9)##:* unsigned int sieJ

unsigned int infof"agsJ

unsigned "ong int cy"indersJunsigned "ong int headsJ

unsigned "ong int sectorsJunsigned "ong int "ocountJ

unsigned "ong int hicountJunsigned int ytes!ersectorJunsigned "ong int config!trJ

N rJ&oid getdr&!aram unsigned int dri&e,

struct *:S)LT9)##:* H r!tr c"rscrJ

 R5 ; 0>7J R%L ; dri&e Jr!tr-Qsie ; (0J

 RSI ; unsigned int r!trJgeninterru!t 0>1(J

N

Page 243: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 243/340

29 - ,ea#ing :ten#e# Partition

&oid main

char st1.UJunsigned "ong int "ainde>J

unsigned int cy"inder, head , sector, tem!J!uts :nter the L9 addressJgets stJ

"ainde> ; ato"stJgetdr&!aram 0>70,rJ

cy"inder ; "ainde> / r=headsHr=sectorsJtem! ; "ainde> r=headsHr=sectorsJhead ; tem! / r=sectorsJ

sector ; tem! r=sectors B 1J!rintf 5eads ; d sectors ; d

cy"inders ; d , head, sector, cy"inderJ

N

This is also a uite similar program only #ifferen$e is that it also translates a <8 a##ress

into CS a##ress an# #isplays it% for this purpose it gets the #rive parameters to kno7 the

total numer of hea#s% se$tors an# $ylin#ers)

9/ %9ogical ector /umber&C > 5 ; Pa rtition Ta"e

5 5 ; 9oot 9"oc3

$oot $loc' has 9/ M F !f the bloc's are indeed from the boot bloc' suchthat the boot bloc' has inde M ,Then this inde iscalled 9/.F 9/ is relative inde from the start of logical drive,not the physical drive.

#or fi>ed dis35idden 9"oc3s ;@o= of Sec/Trac3

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) asolute3% 7hereas S; a##ress is the a##ress from the

start of logi$al partition i)e relative)

Page 244: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 244/340

29 - ,ea#ing :ten#e# Partition

3ample

Logica"

%ri&e

Logica"

%ri&e

L9;1(779(9B(#

LS@ ; 0 #irst Logica"

Sector 

L9;0 LS@;'

#irst Logica" 9"oc3 in dri&e

L9 ; (#

LS@ ; 0

LS@;'

LS@;1

LS@;1

L9;1(779(9

@o LS@

L9;'411242

L9;'411242B(#

LS@;0

8s in the aove 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)

ConclusionF 9$A is physical or absolute address.F 9/ is relative address with respect to the start of9ogical (rive.

Page 245: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 245/340

29 - ,ea#ing :ten#e# Partition

0ile ystem (ata tructuresF $!# *arameter $loc' %$*$&F (rive *arameter $loc' %(*$&F 0ile Control $loc' %0C$&

F 0AT 56, 0AT 57, 0AT 86F )aster 0ile Table %)0T&

To un#erstan# the file systems of 4(S an# >in#o7s the aove 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)

 Anatomy of a 0AT based file system

)ser %ata*oot %ir 

#T 1'120AT0AT

9oot

9"oc3

+"ust '

System rea

8ove 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 tale3 starts) 8 typi$al

volume 7ill $ontain t7o $opies of .8T) 8fter .8T the root #ire$tory is situate# 7hi$h

$ontain information aout 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)

Page 246: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 246/340

29 - ,ea#ing :ten#e# Partition

ClustersF A cluster is a collection of contiguous bloc's.F +ser (ata is d ivided into clustersF /umber of b loc's within a cluster is in power of 6.

F Cluster size can vary depending upon the size ofthe dis'.F (# has a built in limit of 56? b loc's per cluster.F $ut practically limit of 7 bloc's per cluster hasbeen established.F We will learn more about the size of clusters, later.

$*$ %$!# *arameter $loc'&F ituated within the $oot $loc'.F Contains vital information about the f ile system.

<"(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)

Page 247: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 247/340

29 - ,ea#ing :ten#e# Partition

$*$ %$!# *arameter $loc'&

Reserved Sectors. The number of sectors

from the Partition Boot Sector to the startof the first file allocation table, including

the Partition Boot Sector. The minimumvalue is 1.

OR!"#"$

Sectors Per %luster. The number of sectors

in a cluster. The default cluster si&e for avolume de'ends on the dis( si&e and thefile s)stem.

B*T$"#"!

B)tes 'er Sector. The si&e of a hard+are

sector. suall) -1.

OR!"#"B

/eaningField

0engthB)te

Offset

Root $ntries. The total number of f ile nameentries that can be stored in the root folder

of the volume.

OR!"#11

umber of file allocation tables 2FATs3. The

number of co'ies of the file allocation tableon the volume. T)'icall), the value of this

field is .

B*T$"#1"

Small Sectors. The number of sectors onthe volume if the number fits in 14 bits

24--5-3. For volumes larger than 4--54sectors, this field has a value of " a nd the

0arge Sectors field is used instead.

OR!"#15

umber of 6eads.OR!"#1A

Sectors 'er Trac(.OR!"#17

Sectors 'er file allocation table 2FAT3.umber of sectors occu'ied b) each of thefile allocation tables on the volume.

OR!"#14

/edia T)'e. Provides information about themedia being used. A value of "#F7indicates a hard dis(.

B*T$"#1-

0arge Sectors. If the Small Sectors field is&ero, this field contains the total number of

sectors in the volume. If Small Sectors isnon&ero, this field contains &ero..

!OR!"#"

6idden Sectors.!OR!"#1%

%urrent 6ead. ot used b) the FAT file

s)stem. 2Reserved3

B*T$"#-

Ph)sical !is( umber. This is related tothe BIOS 'h)sical dis( number. Flo'')

drives are numbered starting +ith "#"" forthe A dis(. Ph)sical hard dis(s are

numbered starting +ith "#7". The value ist)'icall) "#7" for hard dis(s, regardless ofho+ man) 'h)sical dis( drives e#ist,

because the value is onl) relevant if the

device is the startu' dis(.

B*T$"#8

S)stem I!. $ither FAT1 or FAT14,

de'ending on the format of the dis(.

7 b)tes"#54

9olume 0abel.11 b)tes"#B

9olume Serial umber. A uni:ue number

that is created +hen )ou format thevolume.

8 b)tes"#;

Signature. /ust be either "#;, "#7 or

"#< in order to be recogni&ed b)indo+s.

B*T$"#4

Page 248: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 248/340

29 - ,ea#ing :ten#e# Partition

(1 - #i"e System %ata Structures II 9oot "oc3

+ser(ata

oot(ir 

0AT0AT

*eser&ed 9"oc3s

#T Sie Sie of *oot %ir  

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 numer of reserve# se$tor% se$tors o$$upie# y .8T

$opies E numer of .8T $opies an# the the numer of lo$ks reserve# for root #ir)

!nside a $oot $loc'F Contains Code and (ata

 4mp codepart#/ame$!#

*arameter $loc'

codepart@

F $oot $loc' eecutes at $ooting time.

The aove 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)

Page 249: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 249/340

29 - ,ea#ing :ten#e# Partition

0000 2 'C 70 $A $% & '4 # F W - ( 4 V

000 47 4 4' 00 0$ 01 01 00 I C 0010 0$ 20 00 40 0 80 07 00 ?

001 1$ 00 0$ 00 00 00 00 00 00$0 00 00 00 00 00 00 $7 21 00$ C & $A $0 $0 $0 $0 $0 6 W

00'0 $0 $0 $0 $0 $0 $0 4 41 8 A

00' #4 '1 '$ $0 $0 $0 '' C7 T 1 $ ' 0040 2 %1 C 8C &1 0& %

004 & 00 C# & 0012 # 1 ; ( V 00#0 ## 8 $$ 0# 7&2 00 7 ) J 00# 42 0$ 1 0 8C8' A4 0 N 000 18 % 00 &C C4# 82 08 = 2 00 '42 $4 &% $0 C1 77 N .L 00&0 2 &2 01 ' 2'A A1 :

00& 1C &C ' 0&A #& 8C = E K 000 &# 0 0 CA 0$ # 0$ u V 00 0 C' 10 &' 2%'' C7 82 s ' 0070 0 % &% A 410 7 8& L 8 007 1 0' 4 1C1' # 12 8 V 00A0 0' 4 02 1' %1 & 11 8 (

00A 0 7 4 8C 7# 82 _ 8 V 000 $000 8& 2 #2 0 0' ` 00 C' 4 8& 8' 014 8C 11 8 00C0 42 82 1 8 000& 2 $ N a M00C 01&$ '2 ' $%&4 1& 0 r > -t _00%0 1 0 2 % &%8' A 1 L a

00% &4 '% 42 &4 07' C& $0 t 5 Nt 0020 ' 8 &$ 2& 2%% 82 02 E r 002 % &% & A& 2&8 &% AC L L 0080 7 0' 80 AC 740 &4 0C ? t 008 4 &4 1' 4 02 0& 00 t 0100 C% 10 2 28 2$ &% 2 L

010 2 2 0 &% 221 C% 1 L 0110 #2 18 8 04C% 17 2 ` 011 1 &% &% 1A% 4# 82 L L 2 01$0 A 42 0% 8& 210' 4 8C N 8 01$ 1' # 82 1 042 C$ 00 V 01'0 &$ %& 2A 00 0$&0 00 #$ r p

01' #0 0 #' A 01A 10 71 + SZ Z 0140 4 1 A$ $0# 7 7$ 8 014 '' %$ 8& 8 718& 8 4$ ' 01#0 & CA 8& & 1AA 8$ A ( 01# 2 C0 CC 0$ 0ACC 01 010 0$ 0 &2 0$ 02&# 04 4 u

01 4$ 84 A #$4 C% 1' V . 01&0 1 1 &$ 0A 40&# 01 4$ a a r ? u 01& 0' #2 0 47 &#&& C' 0' I u O 010 1 01 $& 0% 0A47 2 & I n (01 1C 7 4 $0&' &7 &' a 6 id s y s0170 &4 # % $0 47 &' t e m d i s P

017 88 0% 0A 44 7&' $0 % i s P01A0 47 $8 48 $0 #&$ &$ 8 I / ! e r r o01A &$ 88 0% 0A #$# &0 C r e p 6010 1 ' # $0 &4 # $0 a c e t < e01 47 &' $C$0 1 2 d i sP U a n01C0 4$0 &4 #2 $0 &0 d t< e n p

01C &$# &' &' $01 2 &7 r e ss a n y01%0 $0 # &7 0%0A 00 00 P ey 01% 47 48 $0 $0 $0$0 $0 $0 I !0120 #' #7 #' 4% #'44 48 #' S 9 S" S % ! S012 $0$0 $0 #' #7#' &8 01 S9 S 0180 00 41 00 0&0 A A _ Z

018 00 27 ' 88 0000 ## AA E )

8ove 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 otaine# from the

aove <P<)

9ogical drive@ Aize@ 5 )b %popularly 5 )b&9ogical sectors@ bh M 6??$ytes per sector@ B56ectors per Cluster@ 5

Cluster size@ B560ile system@ 0AT56/umber of copies of 0AT@ 6ectors per 0AT@ Otart sector for 0AT5@ reserved sectors M 5tart sector for 0AT6@ reserved sectors Q

size of 0AT M 5 Q O M5oot (! ector@ reserved sectors Q

6 K %size of 0AT& M 5 Q 6 K O M 5O

Page 250: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 250/340

oot (! 3ntries@ 3 M 66ize of oot dir @ 66 K 86 M 57?$loc's occupied by root dir M 57? " B56 M 56nd Cluster tart ector@ root d ir sectors Q

size of root dir in bloc's M 5O Q 5 M 883nding Cluster@ 6?? 88 " sector per cluster Q 5

M 6??"88 Q 5 M 6??)edia (escriptor@ 0>eads@ 6

>idden sectors@ erial1olume!(@ 6A?7C351olume 9abel@

.ollo7ing is another #ump sho7ing the oot lo$k for a .8T !6 system)

0000 2 'C 70 4% #' 44 48 #' F " S % ! S

000 '# $2 '0 00 0$ 0 0 00 # 0 0010 0$ 00 0$ 00 00 8 CC 00

001 '8 00 88 00 '8 00 00 00 b b 00$0 # #8 0 00 0 00 $7 '# G D #00$ C A# $C 42 48 $0 42 41 U N ! N A

00'0 4% 4# $0 $0 $0 $0 4 41 " 2 8 A00' #4 '1 ' $0 $0 $0 '' C7 T 1 ' 0040 2 %1 C 80 &2 %7

004 00$0 2 C0 8C% 00 &C =00#0 ' 42 $4 &% $4 C1 77 N .L . 00# 2 'C 01 &$ 1C' 2 'A F r :000 A1 1C &C $ ' 0& = E 00 $ A #& 8C &#0 0 CA K u 00&0 0$ # 0$ 0C' 10 &' V s

00& 2 '' C7 A 410 7 8& ' 8 000 1 0' 4 1C1' # 12 8 V 00 0' 4 02 1' %1 & 11 8 ( 0070 0 7 4 8C 7# 82 _ 8 V 007 $000 8& 2 #2 0 0' ` 00A0 C' 4 8& 8' 014 8C 11 8

00A 42 82 1 8 0000 2 2 N a 000 00&$ '7 $ '$% &4 1& r 7 -t 00 0 1 0 2 A1&% 8' A _ L 00C0 1 &4 '$ 42 &407 ' C& a t $N t 00C $0' 8 &$ 22 %C A0 E r 00%0 8 &% 4 &% 80 AC 7 L L

00% 40 &4 0C 4 &41' 4 02 ? t t 0020 0& 00 C% 102 28 A0 002 8% &% 2 2 A08C &% 2 L L 0080 21 C% 1 C% 17$ ## )008 1A #$ 0 01 00 00 2 0100 ' 00 &$ 2 #A # $4 E r G V .

010 2 0 &C 8CC& 4 80 = 8 0110 '% &% C& 4 84$7 &% C 5 L 8 L 011 %7 7 42 8$ 742 8 C N N 01$0 0 7 &% C 2A0' 00 00 L 01$ $008 C 4 8 8 01'0 0' 4 1C %0 8

01' C1 2A 10 2 #208 C ` 0140 4A 4A A 4 0%'$ 24 8& 8 $ 014 2$ 0' 4 8C 1'# 82 2 8 V 01#0 4A #$ #0 0 #'A 01 A + S Z Z01# 10 71 4 17 7$ '' 8 '010 %$ 8& 8 71 8&8 4$ &

01 CA 8& & 1A A8$ A 2 ( 01&0 C0 CC 0$ 0A CC 01 0$ 01& 0 &2 0$ 02 &#04 4 4$ u 010 84 A # $4C% 1' 1 V . a01 1 &$ 0 40 &#01 4$ 0' a r ? u 0170 #2 0 47 &# 08 C' 41 ` Iu A

017 00 00 0 A 00 2 _ Z 01A0 042 #4 4C 44#$ $0 $0 N T, % 01A $0$0 $0 $0 0%0A #$ # e010 %8 & # $04 7 &' m o (e d i s01 &' $0 8 &$$0 8 &4 P s or o t01C0 # &$ $0 %# 4 7 < e r m e d i

01C 1 $2 88 0% 0A44 7 &' a % i s01%0 $0 # &$ &$8 &$ 88 P er r o r 01% 0% 0A #0 &$ #&' &' $0 +r e s s0120 1 2 &7 $0 # &7 $0 a n y P e y012 &48 $0 &$ #&' &4 1 t o re s t a0180 &$ &4 0% 0A 0000 00 00 r t

018 00 00 00 AC C% ## AA )

Page 251: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 251/340

+! - .ile System 4ata Stru$tures "" 1<oot lo$k3

.ollo7ing is the #etail of information rea# from the aove #ump 7hi$h #es$ries the

volume in uestion)

9ogical sectors@ M 7BfBb M 576$ytes per sector@ 6h M B56ectors per Cluster@ ?Cluster size@ ?KB56 M O70ile system@ 0AT57/umber of copies of 0AT@ 6ectors per 0AT@ CC> M 6tart sector for 0AT5@ reserved bloc's M ?tart sector for 0AT6@ reserved bloc's Q

bloc's per 0AT M ? Q CC> M ( M 656oot (! ector@ reserved bloc's Q

6K%size of 0AT& M ? Q6KCC M 5A M 57oot (! 3ntries@ 6> M B56ize of oot (ir B56 K 86 M 578? M 86 bloc's

ize of oot (ir B56 K 86 M 578? M 86 bloc's6nd Cluster tart ector@ root d ir start bloc's Q

bloc's in root dir M 5A Q 6> M 57 Q 86 M ?3nding Cluster@ %%logical bloc's start of user databloc's&"bloc's per cluster&

Q 5 M% 576 ? &"? Q 5 M B65?)edia (escriptor@ 0?

>eads@ 6BB>idden sectors@ 78erial1olume!(@ 6CAB$C8B1olume 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 asrea#13 fun$tion $an e use# to rea# a lo$k an# as7rite13 $an e

use# to 7rite on it as #es$rie# in the sli#e elo7 7here nse$t is the numer of se$tor to

 e rea#'7ritten)

Page 252: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 252/340

+! - .ile System 4ata Stru$tures "" 1<oot lo$k3

eading" Writing a $loc'F absread% &

is used to read a bloc' given its 9/

F abswrite% &is used to write a bloc' given its 9/

absread%int drive, int nsects, long lsec, void Kbuffer&;

abswrite%int drive, int nsects, long lsec, void Kbuffer&;

Page 253: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 253/340

+! - .ile System 4ata Stru$tures "" 1<oot lo$k3

(' - #i"e System %ata Structures III %P9

<esi#es the <P< another #ata stru$ture $an e use# euivalently $alle# the 4P< 14rive

 parameter lo$k3) The operating system translates the information in <P< on #isk into the4P< 7hi$h is maintaine# main memory) This #ata stru$ture $an e a$$esse# using the

un#o$umente# servi$e 2!'+2) "ts #etail is sho7n in the sli#e elo7)

#n 3ntry@ A> M 86h(9 ] for current (rive

5 for A@ (rive6 for $@ (rive8 for C@ (rive

#n 3it@(@$D M far address of (*$

+ndocumented ervices %!/T 65>"86>&

The 4P< $ontains the information sho7n in the tale elo7) This information $an e

#erive# from the <P< ut is pla$e# in memory in the form of 4P<)

(*$ %(rive *arameter $loc'&

6ighest cluster number 2number of data

cluster =13

OR!"!h

6ighest sector number +ithin a clusterB*T$"8h

umber of FAT>sB*T$"7h

umber of reserved sectors at beginningof drive

OR!"4h

umber of root director) entriesOR!"<h

umber of first sector c ontaining userdata

OR!"Bh

Shift count to convert clusters into sectorsB*T$"-h

B)tes 'er sectorOR!"h

nit number +ithin device driverB*T$"1h

!rive number 2""h ? A@, "1h ? B@, etc3B*T$""h

!escri'tionSi&eOffset

Page 254: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 254/340

+! - .ile System 4ata Stru$tures "" 1<oot lo$k3

(*$ %(rive *arameter $loc'&

/edia I! b)teB*T$1;h

""h if dis( accessed, FFh if notB*T$17h

Address of device driver header!OR!15h

Sector number of first director) sectorOR!11h

Pointer to ne#t !PB!OR!1<h

number of sectors 'er FATOR!"Fh

%luster at +hich to start search for free

s'ace +hen +riting, usuall) the lastcluster a llocated

OR!1!h

umber of free clusters on drive, FFFFh if

not (no+n

OR!1Fh

!escri'tionSi&eOffset

The follo7ing $o#e sho7s ho7 the servi$e 2!'+2 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)

-13A6:0100 o #3213A6:0102 n" 21

13A6:0104

-< AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13A6 EML13A6 MML13A6 CML13A6 !PL0102 %) UP E! PN %H %A P %C13A6:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML00A7 EML13A6 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P %C13A6:0104 D3E3 MN BK#CN

-; 7:13;2

00A7:13D0 00 00 00 02 00 00-01 00 02 E0 00 21 00 20 ......... ..*.00A7:13E0 0B 09 00 13 00 56 34 12-00 F0 0A FF FF FF FF 00 .....)4.... .....00A7:13F0 00 C9 06 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....

00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ........... .....00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....00A7:1450 A7 05 ..

Page 255: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 255/340

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 byteshighest sec no within a cluster M hift count to convert sec to clust M eserved sectors at the begining of drive M 50AT copies M 6oot directory entries M 3 M 660irst sector containing user data M 65> M 88>ighest cluster number M b6 M 6??/umber of sectors per fat M O M Oector number of first directory M 58 M 5O

The follo7ing $o#e sho7s ho7 the servi$e 2!'+2 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)

-13A6:0100 o #3213A6:0102 n" 21

13A6:0104

-< AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13A6 EML13A6 MML13A6 CML13A6 !PL0102 %) UP E! PN %H %A P %C13A6:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML00A7 EML13A6 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P %C13A6:0104 0000 ADD IBKM!Q#AN DM:13D2L05

-; 7:13;2

00A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ......... .....00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....)4.... .....

00A7:13F0 00 AA CB 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....

00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ........... .....00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ........... .....00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....00A7:1450 A7 05 ..

Page 256: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 256/340

+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 Bbytes per sector M 6> M B56>ighest sector number within a cluster M >ence ec. per cluster M highest sec. within a

cluster Q 5 M Q 5 M ?shift count M 8reserved sectors M ?/umber of 0ats M 6oot (ir 3ntries M 6> M B560irst sector containing user data M 5C M ?>ighest cluster number M cbb> M B65?/o of sectors per 0AT M CC M 6

ector number of 0irst directory M 5A M 57

Dinc"ude Vios=hQDinc"ude Vdos=hQ

struct 9P9

unsigned int ytes!ersecJ

unsigned char sec!erc"ustJ

unsigned int reser&edsecsJunsigned char fatsJ

unsigned int rootdirentsJ

unsigned int sma""secsJunsigned char mediaJ

unsigned int fatsecsJ

unsigned int secs!ertrac3J

unsigned int headsJ

Page 257: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 257/340

+2 - .ile System 4ata Stru$tures """ 14P<3

unsigned "ong int hiddensecsJ

unsigned "ong int hugesecsJunsigned char dri&enoJ

unsigned char reser&edJ

unsigned char ootsignatureJ

unsigned "ong int &o"umeidJunsigned char &o"ume"ae"11UJ

unsigned char fi"esystem7UJNJ

struct oot"oc3

unsigned char um!instruction(UJ

unsigned char osname7UJ

struct 9P9 !J

unsigned char code7UJNJ

&oid n!uts char H!, int n

int i J

for i ;0JiVnJiBB

!utch!iUJ

N

&oid main &oid

struct oot"oc3 J

c"rscrJ

asread0,1,0,J!rintfum! instruction ; >n ,

=um!instructionJ!rintfOS ; J

n!uts =osname,7J!utsnJ

!rintf@o of ytes !er sector ; d n@o of sectors

!er c"uster ; dn @o of reser&ed sectors ;

d , =!=ytes!ersec,=!=sec!erc"ust, =!=reser&edsecsJ

!rintf@o of #Ts ; dn@o of *oot %irectoryentry ; d n@o of Sma"" sectors ; d

 nMedia descri!tor ; >5 n#T sectors ;

dSectors !er trac3 ; d n@o of 5eads ;

d n@o of hidden sectors ; "d n@o= of

huge sectors ; "d n%ri&e numer ; >

 n*eser&ed ; >5 n9oot Signature ; >5 n$o"ume I% ; "> n , =!=fats,

=!=rootdirents, =!=sma""secs,

=!=media, =!=fatsecs,

=!=secs!ertrac3, =!=heads,=!=hiddensecs, =!=hugesecs,

=!=dri&eno, =!=reser&ed,=!=ootsignature,=!=&o"umeidJ

Page 258: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 258/340

+2 - .ile System 4ata Stru$tures """ 14P<3

!uts $o"ume @ame ;J

n!uts =!=&o"ume"ae",11J!uts nJ

!uts #i"e system ;J

n!uts =!=fi"esystem,7J!utsnJ

getchJN

The aove program $reates a #ata stru$ture in refle$tion of the <P< an# rea#s the oot

re$or# of the volume using asrea#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 Vios=hQ

struct %P9 unsigned char dri&enoJunsigned char unitnoJ

unsigned int ytes!ersecJ

unsigned char highestsecinc"ustJunsigned char shiftcountJ

unsigned int reser&edsecsJunsigned char fatsJ

unsigned int rootentriesJunsigned int firstuserdatasecJ

unsigned int highestc"ustnumerJ //on"y for 12 and 1'

it #Tsunsigned int secs!erfatJ

unsigned int firstdirsecJunsigned int ddheaderoffJ

unsigned int ddheadersegJ

Page 259: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 259/340

+2 - .ile System 4ata Stru$tures """ 14P<3

unsigned char mediaJ

unsigned char accessedJunsigned int ne>td!offJ

unsigned int ne>td!segJunsigned int searchstartJ

unsigned int freec"ustJ

NJ&oid main &oid

struct %P9 far H!trJ

struct %P9 d!Jc"rscrJ

 Rasm!ush %SJ

 Rasm!ush 9AJ R5;0>('J

 R%L;1Jgeninterru!t 0>'1J

!tr ; struct %P9 far HMR#PR%S,R9AJ

d!;H!trJ Rasm !o! 9AJ

 Rasm !o! %SJ!rintf%ri&e @o ; >n,d!=dri&enoJ

!rintf)nit @o ; >n,d!=unitnoJ

!rintf9ytes !er sector ; dn,d!=ytes!ersecJ!rintf5ighest sector numer 6ithin a c"uster ;

dn,d!=highestsecinc"ustJ!rintfShift +ount ; dn,d!=shiftcountJ

!rintf*eser&ed sectors ; dn,d!=reser&edsecsJ!rintfnumer of #Ts ; dn,d!=fatsJ

!rintf*oot enteries ; dn,d!=rootentriesJ

!rintf#irst )ser data sec ; dn,d!=firstuserdatasecJ!rintf5ighest+"uster numer ;

dn,d!=highestc"ustnumerJ!rintf@o of Sectors !er #T ; dn,d!=secs!erfatJ

!rintf#irst directory Sector ; dn,d!=firstdirsecJ

!rintf%% header offset ; >n,d!=ddheaderoffJ

!rintf%% header segment ; >n,d!=ddheadersegJ!rintfMedia I%; dn,d!=mediaJ

!rintf%is3 accessed recent"y; dn,d!=accessedJ!rintf@e>t %P9 offset address ; dn,d!=ne>td!offJ

!rintf@e>t %P9 segment address ;

dn,d!=ne>td!segJ!rintfPoint 6here to start the search for ne>t c"uster;

dn,d!=searchstartJ!rintf#ree c"uster; dn,d!=freec"ustJ

getchJN

The aove program is #oing is the same using the 4P< rather than <P<)

Page 260: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 260/340

Page 261: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 261/340

Page 262: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 262/340

+2 - .ile System 4ata Stru$tures """ 14P<3

Contents of oot (irectory of a 0AT56 ystem-13AD:0100 o #3213AD:0102 o n" 2113AD:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13AD EML13AD MML13AD CML13AD !PL0102 %) UP E! PN %H %A P %C13AD:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML13AD MML13AD CML13AD !PL0104 %) UP E! PN %H %A P %C13AD:0104 D 3E3 MN BK#CN

-; 7:13;200A7:13D0 00 00 00 02 00 00-01 00 02 E0 00 21 00 20 ...........*.00A7:13E0 0B 09 00 13 00 56 34 12-00 F0 0A FF FF FF FF 00 .....)4.........

00A7:13F0 00 C8 06 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B7 13 10 00 ................00A7:1440 DF 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....

00A7:1450 A7 05 ..-q 

Contents of oot (irectory of a 0AT56 ystem

- 1000 0 13

-; 1000 200

13AD:1000 E5 5F 41 4E 53 20 20 20-54 58 54 20 10 BB 19 70 .RA%M OKO ...<

13AD:1010 3C 33 3C 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3$3...,S.....13AD:1020 41 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 AC.<..<.. ..O,.13AD:1030 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13AD:1040 43 50 41 50 45 52 20 20-54 58 54 20 00 BB 19 70 CPAPE OKO ...<13AD:1050 3C 33 3C 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3$3...,S.....13AD:1060 54 45 53 54 20 20 20 20-54 58 54 20 18 AB 29 70 OEMO OKO ..<

13AD:1070 3C 33 3C 33 00 00 AE 70-3C 33 4A 00 31 00 00 00 $3$3...<$3.1...13AD:1080 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13AD:1090 3C 33 3C 33 00 00 D5 70-3C 33 4B 00 B3 8A 00 00 $3$3...<$3J.....

13AD:10A0 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13AD:10B0 3C 33 3C 33 00 00 22 71-3C 33 4B 00 26 00 00 00 $3$3..Vq$3J....13AD:10C0 52 4F 4F 54 20 20 20 20-54 58 54 20 18 25 55 71 O OKO .XUq 

13AD:10D0 3C 33 3C 33 00 00 56 71-3C 33 4B 00 0D 00 00 00 $3$3..)q$3J.....

"n the aove t7o sli#es first the $ontents of 4P< are rea# to fin# the start of the root

#ire$tory) Using this lo$k numer the $ontents of root #ire$tory are rea#% as it $an e

seen they $ontain numer of .C<s ea$h $ontaining information aout a file 7ithin the

#ire$tory)

The user #ata area is #ivi#e# into $lusters) The first $luster in user #ata area is numere# 2

in a .8T ase# systems) 8 $luster is not the same as lo$k an# also there are no system

$alls availale 7hi$h use the $luster numer) 8ll the system $alls use the S; a##ress) "f

the $luster numer is kno7n it shoul# e $onverte# into S; to a$$ess the lo$ks 7ithin

the $luster) &oreover all the information aout file management uses the $luster numer

Page 263: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 263/340

+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 numer into S;)

)ser %ata*oot

%irectory0AT0AT

*eser&ed 9"oc3 +"ust '

9"oc3s for #T

Converting a Cluster H into ector H

#irst 9"oc3 of )ser %ata

@o= of entriesH('/yte s !er "oc3

using the information the aove sli#e the follo7ing formula $an e #evise# as sho7n in

the sli#e elo7 to $onvert the $luster numer into S;)

/o. of ystem Area $loc's Meserved $loc' Q ector per 0AT K /o. of0AT-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 numer from the .C< of a file

an# then $onverts the $luster numer in se$tor to get its starting lo$k)

Page 264: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 264/340

+2 - .ile System 4ata Stru$tures """ 14P<3

(irectory (ump %Again&

- 1000 0 13

-; 1000 200

13AD:1000 E5 5F 41 4E 53 20 20 20-54 58 54 20 10 BB 19 70 .RA%M OKO ...<

13AD:1010 3C 33 3C 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3$3...,S.....

13AD:1020 41 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 AC.<..<.. ..O,.13AD:1030 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13AD:1040 43 50 41 50 45 52 20 20-54 58 54 20 00 BB 19 70 CPAPE OKO ...<13AD:1050 3C 33 3C 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3$3...,S.....13AD:1060 54 45 53 54 20 20 20 20-54 58 54 20 18 AB 29 70 OEMO OKO ..<

13AD:1070 3C 33 3C 33 00 00 AE 70-3C 33 4A 00 31 00 00 00 $3$3...<$3.1...13AD:1080 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13AD:1090 3C 33 3C 33 00 00 D5 70-3C 33 4B 00 B3 8A 00 00 $3$3...<$3J.....13AD:10A0 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13AD:10B0 3C 33 3C 33 00 00 22 71-3C 33 4B 00 26 00 00 00 $3$3..Vq$3J....13AD:10C0 52 4F 4F 54 20 20 20 20-54 58 54 20 18 25 55 71 O OKO .XUq 

13AD:10D0 3C 33 3C 33 00 00 56 71-3C 33 4B 00 0D 00 00 00 $3$3..)q$3J.....

#i"e +ontents ;F C&", L 4

F M"," M"o, L S4 Y 2 '1 21 L 69

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) ere the $ontents of the

file $an e seen on the right si#e $olumn)

Cluster (ump

- 1000 0 69 1

-; 1000

13AD:1000 74 68 69 73 20 69 73 20-61 20 74 65 78 74 20 66 "& & "T" f

13AD:1010 69 6C 65 20 75 73 65 64-20 74 6F 20 73 74 6F 72 &; "o &"o,13AD:1020 65 20 73 6F 6D 65 20 74-65 73 74 20 74 65 78 74 &o "&" "T"13AD:1030 2E 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

13AD:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................-q 

Page 265: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 265/340

+2 - .ile System 4ata Stru$tures """ 14P<3

ere is another e:ample using a .8T !6 system)

 Another 3ample with 0 AT57 bit ystem

(*$ (ump-13AD:0100 o #3213AD:0102 n" 2113AD:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13AD EML13AD MML13AD CML13AD !PL0102 %) UP E! PN %H %A P %C13AD:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML13AD MML13AD CML13AD !PL0104 %) UP E! PN %H %A P %C13AD:0104 D 3E3 MN BK#CN

-; 7:13;200A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ..............00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....)4.........

00A7:13F0 00 98 CB 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B7 13 10 00 ................00A7:1440 DF 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....

00A7:1450 A7 05 ..-q 

Page 266: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 266/340

+2 - .ile System 4ata Stru$tures """ 14P<3

( - #T1' #i"e System II, #T12 #i"e System

ere is another e:ample 7hi$h e:amines the $ontents of a file for a .8T !6 system)

.irstly the 4P< is rea# as sho7n "n the follo7ing sli#e)

 Another 3ample with 0 AT57 bit ystem(*$ (ump-13AD:0100 o #3213AD:0102 n" 2113AD:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13AD EML13AD MML13AD CML13AD !PL0102 %) UP E! PN %H %A P %C13AD:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML13AD MML13AD CML13AD !PL0104 %) UP E! PN %H %A P %C13AD:0104 D 3E3 MN BK#CN

-; 7:13;200A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ..............00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....)4.........

00A7:13F0 00 98 CB 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B7 13 10 00 ................00A7:1440 DF 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....

00A7:1450 A7 05 ..-q 

(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- 1000 5 10 20

-; 1000 400013AD:1000 4E 45 57 20 56 4F 4C 55-4D 45 20 08 00 0000 00 %EW )NUE .....13AD:1010 00 00 00 0000 00 61 76-2D 33 00 00 00 00 00 00 ......-3......

13AD:1020 41 52 00 65 00 63 00 79-00 63 00 0F 00 21 6C 00 A... @....*.13AD:1030 65 00 64 00 00 00 FF FF-FF FF 00 00 FF FF FF FF .;.............

13AD:1040 52 45 43 59 43 4C 45 44-20 20 20 16 00 4E 79 5E ECCNED ..%@Z13AD:1050 2F 33 2F 33 00 007A 5E-2F 33 02 00 00 00 00 00 [3[3..Z[3......13AD:1060 42 20 00 49 00 6E 00 66-00 6F 00 0F 00 72 72 00 B .!.n.f.o...,,.

13AD:1070 6D 00 61 00 74 00 69 00-6F 00 00 00 6E 00 00 00 .."..o...n...13AD:1080 01 53 00 79 00 73 00 74-00 65 00 0F 00 72 6D 00 .M.@.&. "....,.

13AD:1090 20 00 56 00 6F 00 6C 00-75 00 00 00 6D 00 65 00 .).o.......13AD:10A0 53 59 53 54 45 4D 7E 31-20 20 20 16 00 4E 79 5E MMOE(1 ..%@Z13AD:10B0 2F 33 2F 33 00 007A 5E-2F 33 03 00 00 00 00 00 [3[3..Z[3......

13AD:10C0 41 64 00 50 00 62 00 31-00 2E 00 0F 00 6A 74 00 A;.P.=. 1.....".13AD:10D0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............

13AD:10E0 44 50 42 31 20 20 20 20-54 58 54 20 00 57 81 69 DPB1 OKO .W.

13AD:10F0 36 33 36 33 00 00 07 78-36 33 0A 00 8A 06 00 00 6363...T63......13AD:1100 44 50 42 32 20 20 20 20-54 58 54 20 18 12 AE 69 DPB2 OKO ...13AD:1110 36 33 36 33 00 00 03 75-36 33 0B 00 5F 06 00 00 6363...63..R...13AD:1120 46 49 52 53 54 20 20 20-20 20 20 10 08 6F ED 56 F!MO ..o.) 13AD:1130 3C 33 3C 33 00 00 EE 56-3C 33 0C 00 00 00 00 00 $3$3...)$3......13AD:1140 53 45 43 4F 4E 44 20 20-20 20 20 10 08 50 EF 56 MEC%D ..P.) 

13AD:1150 3C 33 3C 33 00 00 F0 56-3C 33 12 00 00 00 00 00 $3$3...)$3......

The root #ire$tory $ontains a $olle$tion of .C<s) The .C< for the file in uestion is

sear$he# from 7here the first $luster of the file $an e get)

Page 267: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 267/340

+2 - .ile System 4ata Stru$tures """ 14P<3

Cont13AD:12C0 43 50 41 50 45 52 20 20-54 58 54 20 00 9D 7D 6F CPAPE OKO ..+o13AD:12D0 3C 33 3C 33 00 00 60 05-72 28 29 00 4F 8F 00 00 $3$3...,S....13AD:12E0 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 ...n."......".

13AD:12F0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............13AD:1300 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .%... .O.....13AD:1310 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 T.". .D.o.....13AD:1320 E5 45 57 54 45 58 7E 31-54 58 54 20 00 32 09 73 .EWOEK(1OKO .2.&

13AD:1330 3C 33 3C 33 00 00 0A 73-3C 33 00 00 00 00 00 00 $3$3...&$3......13AD:1340 54 45 53 54 20 20 20 20-54 58 54 20 18 32 09 73 OEMO OKO .2.&

13AD:1350 3C 33 3C 33 00 00 17 73-3C 33 45 00 27 00 00 00 $3$3...&$3E.]...

F Con"n"&F M L 39D L27F C&", L 45F M L S45 Y 2 '8 01C0 L 3D8

8fter $al$ulating the se$tor numer 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 numer of $luster the suseuent $lusters numers 7ithin the

file $hain $an e a$$esse# from the .8T)

0ile (ump- 1000 5 3;8 8

-; 1000

13AD:1000 74 68 69 73 20 69 73 20-61 20 74 65 73 74 20 74 "& & "&" "13AD:1010 65 78 74 20 66 69 6C 65-20 66 6F 72 20 31 36 20 T" f fo, 1613AD:1020 62 69 74 20 46 41 54 00-00 00 00 00 00 00 00 00 =" FAO.........13AD:1030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

13AD:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................-q 

Page 268: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 268/340

+2 - .ile System 4ata Stru$tures """ 14P<3

9arger 0ile ContentsF 9arger files would be comprised of numerousclusters.F The first Cluster H can be read from 0C$ for rest

of the Cluster, a chain is maintained within the 0AT.

0AT56F 0AT is a simple table which contains clusternumber of each file.F 0AT56 will have 56bit wide entries and can have6`56 entries maimum.F Although some of these entries may be reserved.

Page 269: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 269/340

+2 - .ile System 4ata Stru$tures """ 14P<3

0ile #rganization

O

55

56 ] bit

56

8

7

B

Start +"uster D

0C$

Cont

3#0

7

?

O

5

55

6`56

8ove sli#es sho7 ho7 a $luster $hain for a file is maintaine# in the .8T) The first

$luster numer is in the .C<) Suseuent $lusters 7ill e a$$esse# from the .8T using

the previous $luster numer as in#e: to look up into the .8T for the ne:t $luster numer)

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)

Page 270: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 270/340

+2 - .ile System 4ata Stru$tures """ 14P<3

+nused 0AT 3ntriesF eserved 3ntries M 00> X 007>

F 3#0 value M 00> X 000>

F 0irst Two Clusters M ,5

F 0ree Cluster M

F )a. range of Cluster H M 6 X 030>

F Total H of Clusters of 0AT56 M 033>

Cluster ize (eterminationtempof M size of dis' " no. of entries in 0AT %033>&if % temp J 867?&

use higher 0AT57 or 0AT86elseN

choose the nearest value Q temp greater thantemp, which is a power of 6,et this to be the Cluster size M bytesize of Cluster in $loc's M

Cluster size in $ytes " $ytes per $loc'P

/o. of 3ntries of 0AT M/o. of $loc's in dis' in +ser (ata Area " izeof Cluster in $loc's.

There $an various volume 7ith various si=es 7ith .8T!2 or .8T!6) The numer of

entries for .8T !2 or .8T!6 are limite# then the uestion 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 numer of entries might e same ut the si=e of

$luster may e #ifferent) The $luster si=e $an vary from *!2 ytes to +2 in po7ers of 2

#epen#ing upon the volume si=e) The aove sli#e sho7s ho7 the $luster si=e an# the

e:a$t numer of reuire# .8T entries $an e #etermine#)

Page 271: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 271/340

+2 - .ile System 4ata Stru$tures """ 14P<3

(. - #T1' #i"e System Se"ecting a 1'-it entry 6ithin#T1' System

There is no primitive #ata type of !2 its) <ut the entries in !2 it .8T are !2 its 7i#e)

Three $onse$utive ytes in .8T !2 7ill $ontain t7o entries) The follo7ing sli#e sho7s an

algorithm that $an e use# to e:tra$t these entries from a .8T !2 #ata stru$ture)

electing a 56bit entry within 0AT56offset M cluster /o K 8"6temp M cluster /o K 8U6if %temp MM &N

Then the entry is e ven, consider the word at this

offset. )a'e a 56bit value, by selecting the low/ibble of the high byte o f this. +se this /ibble asthe higher bits. And use the low byte as the lowereight bits.

PelseN

The entry is odd, consider the word at this offset.elect the high /ibble of the low byte as lower bits. And selec t high byte as the higher ?bits.

P

3ample

5?h

75h

?Bh67h5?h K 8 " 6 M

6h5?Bh K 8 " 6 M

Page 272: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 272/340

+2 - .ile System 4ata Stru$tures """ 14P<3

Contents of (*$-13A6:0100 o #3213A6:0102 n" 2113A6:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13A6 EML13A6 MML13A6 CML13A6 !PL0102 %) UP E! PN %H %A P %C

13A6:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML13A6 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P %C13 A6 :01 04 0 000 AD D IB KM !Q #A NDM:13D2L00

-; 7:13;2

00A7:13D0 00 00 00 02 00 00-01 00 02 E0 00 21 00 20 ...........*.00A7:13E0 0B 09 00 13 00 56 34 12-00 F0 0A FF FF FF FF 00 .....)4.........00A7:13F0 00 CF 0A 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ................00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....00A7:1450 A7 05 ..

Contents of ##T- 1000 0 13 -; 1000 20013A6:1000 E5 5F 41 4E 53 20 20 20-54 58 54 20 10 BB 19 70 .RA%M OKO ...<13A6:1010 3C 33 3C 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3$3...,S.....13A6:1020 E5 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 .C.<..<....O,.13A6:1030 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13A6:1040 E5 50 41 50 45 52 20 20-54 58 54 20 00 BB 19 70 .PAPE OKO ...<13A6:1050 3C 33 3D 33 00 00 60 05-72 28 02 00 4F 8F 00 00 $3L3...,S.....13A6:1060 54 45 53 54 20 20 20 20-54 58 54 20 18 AB 29 70 OEMO OKO ..<13A6:1070 3C 33 3C 33 00 00 AE 70-3C 33 4A 00 31 00 00 00 $3$3...<$3.1...13A6:1080 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13A6:1090 3C 33 3C 33 00 00 D5 70-3C 33 4B 00 B3 8A 00 00 $3$3...<$3J.....13A6:10A0 E5 4F 4F 54 20 20 20 20-54 58 54 20 18 4D 4E 70 .O OKO .%<13A6:10B0 3C 33 3C 33 00 00 22 71-3C 33 4B 00 26 00 00 00 $3$3..Vq$3J....13A6:10C0 52 4F 4F 54 20 20 20 20-54 58 54 20 18 25 55 71 O OKO .XUq 13A6:10D0 3C 33 3C 33 00 00 62 71-3C 33 4B 00 A5 8A 00 00 $3$3..=q$3J.....13A6:10E0 E5 44 55 4D 50 20 20 20-54 58 54 20 18 7B 8A 71 .DUP OKO .^.q 13A6:10F0 3C 33 3C 33 00 00 A7 71-3C 33 91 00 B4 02 00 00 $3$3...q$3......13A6:1100 43 44 55 4D 50 20 20 20-54 58 54 20 18 7B 8A 71 CDUP OKO .^.q 13A6:1110 3C 33 3C 33 00 00 63 72-3C 33 91 00 98 02 00 00 $3$3..,$3......13A6:1120 E5 30 58 58 20 20 20 20-54 4D 50 20 18 1C 42 57 .0KK OP ..BW 13A6:1130 3D 33 3D 33 00 00 43 57-3D 33 93 00 54 0B 00 00 L3L3..CWL3..O...13A6:1140 41 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 AC.<..<....O,.13A6:1150 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13A6:1160 43 50 41 50 45 52 20 20-54 58 54 20 00 BB 19 70 CPAPE OKO ...<13A6:1170 3C 33 3D 33 00 00 43 57-3D 33 93 00 54 0B 00 00 $3L3..CWL3..O...

13A6:1180 44 50 42 44 55 4D 50 20-54 58 54 20 18 72 EC 64 DPBDUP OKO .,.; 13A6:1190 3D 33 3D 33 00 00 02 65-3D 33 02 00 C4 04 00 00 L3L3...L3......13A6:11A0 44 44 20 20 20 20 20 20-54 58 54 20 18 A4 13 65 DD OKO ...13A6:11B0 3D 33 3D 33 00 00 3B 65-3D 33 05 00 0E 00 00 00 L3L3..L3......

ere 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 CP8P,)TNT)

Page 273: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 273/340

.ollo7ing sli#e sho7s the #ump for the .8T!2 for the parti$ular volume)

Contents of 0AT- 1000 0 1 9

-; 1000 2200

13A6:1000 F0 FF FF 03 40 00 FF 6F-00 07 80 00 09 A0 00 0B ...._..o........13A6:1010 C0 00 0D E0 00 0F 00 01-11 20 01 13 40 01 15 60 ......... .._..

13A6:1020 01 17 80 01 19 A0 01 1B-C0 01 1D E0 01 1F 00 02 ........... .....13A6:1030 21 20 02 23 40 02 25 60-02 27 80 02 29 A0 02 2B * ._.X.]....13A6:1040 C0 02 2D E0 02 2F 00 03-31 20 03 33 40 03 35 60 ..-..[..1 .3_.513A6:1050 03 37 80 03 39 A0 03 3B-C0 03 3D E0 03 3F 00 04 .7..9....L ../..13A6:1060 41 20 04 43 40 04 45 90-09 00 00 00 00 00 00 FF A .C_.E.........13A6:1070 CF 04 4D E0 04 4F 00 05-51 20 05 53 40 05 55 60 ...... .M_.U

13A6:1080 05 57 80 05 59 A0 05 5B-C0 05 5D E0 05 5F 00 06 .W....I..Q ..R..13A6:1090 61 20 06 63 40 06 65 60-06 67 80 06 69 A0 06 6B ._..?....`13A6:10A0 C0 06 6D E0 06 6F 00 07-71 20 07 73 40 07 75 60 ....o..q .&_.13A6:10B0 07 77 80 07 79 A0 07 7B-C0 07 7D E0 07 7F 00 08 ...@..^..+.....13A6:10C0 81 20 08 83 40 08 85 60-08 87 80 08 89 A0 08 8B . .._..........13A6:10D0 C0 08 8D E0 08 8F 00 09-FF 2F 09 FF 4F 09 95 60 .........[. ...

13A6:10E0 09 97 80 09 FF AF 09 9B-C0 09 9D F0 FF FF 0F 00 ................

Using the root #ire$tory entry an# the .8T $ontents the $ontents of the file $an e

a$$esse#)

Contents of 0!93- 1000 0 =2 1

-; 1000

13A6:1000 0D 0A 0D 0A 31 2E 20 57-68 61 74 20 77 6F 75 6C ....1. W" o13A6:1010 64 20 62 65 20 74 68 65-20 6F 75 74 70 75 74 20 ; = " o"<"

13A6:1020 6F 66 20 74 68 65 20 66-6F 6C 6C 6F 77 69 6E 67 of " foon?13A6:1030 3A 0D 0A 0D 0A 6D 61 69-6E 28 20 29 0D 0A 7B 0D :....nS ..^.13A6:1040 0A 09 69 6E 74 20 61 5B-31 30 5D 20 3B 0D 0A 09 ..n" I10Q ...13A6:1050 70 72 69 6E 74 66 20 28-20 22 25 75 20 25 75 22 <,n"f S VX XV13A6:1060 2C 20 61 2C 20 26 61 20-29 20 3B 0D 0A 7D 0D 0A # # ..+..13A6:1070 0D 0A 41 6E 73 2E 0D 0A-09 49 66 20 74 68 65 20 ..An&....!f "

- 1000 =3 1

-; 1000

13A6:1000 0D 0A 0D 0A 31 2E 20 57-68 61 74 20 77 6F 75 6C ....1. W" o13A6:1010 64 20 62 65 20 74 68 65-20 6F 75 74 70 75 74 20 ; = " o"<"

13A6:1020 6F 66 20 74 68 65 20 66-6F 6C 6C 6F 77 69 6E 67 of " foon?13A6:1030 3A 0D 0A 0D 0A 6D 61 69-6E 28 20 29 0D 0A 7B 0D :....nS ..^.13A6:1040 0A 09 69 6E 74 20 61 5B-31 30 5D 20 3B 0D 0A 09 ..n" I10Q ...13A6:1050 70 72 69 6E 74 66 20 28-20 22 25 75 20 25 75 22 <,n"f S VX XV13A6:1060 2C 20 61 2C 20 26 61 20-29 20 3B 0D 0A 7D 0D 0A # # ..+..13A6:1070 0D 0A 41 6E 73 2E 0D 0A-09 49 66 20 74 68 65 20 ..An&....!f "

Page 274: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 274/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

Cont- 1000 0 =4 1

-; 1000

13A6:1000 65 20 69 73 20 6E 6F 74-20 69 6E 63 6C 75 64 65 & no" n;13A6:1010 64 20 62 79 20 23 69 6E-63 6C 75 64 65 2C 20 68 ; =@ n;#

13A6:1020 65 6E 63 65 20 74 68 65-0D 0A 09 4C 69 6E 6B 65 n "...Nn

13A6:1030 72 20 45 72 72 6F 72 2E-0D 0A 2D 2D 2D 2D 2D 2D , E,,o,...------13A6:1040 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------13A6:1050 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------13A6:1060 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------13A6:1070 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------

- 1000 0 =5 1

-; 1000

13A6:1000 6E 67 20 70 6F 69 6E 74-20 66 6F 72 6D 61 74 73 n? <on" fo,"&13A6:1010 20 6E 6F 74 20 6C 69 6E-6B 65 64 0D 0A 09 41 62 no" n`;...A=

13A6:1020 6E 6F 72 6D 61 6C 20 70-72 6F 67 72 61 6D 20 74 no, <,o?, "13A6:1030 65 72 6D 69 6E 61 74 69-6F 6E 0D 0A 0D 0A 09 54 ,n"on.....O13A6:1040 68 69 73 20 65 72 72 6F-72 20 6F 63 63 75 72 73 & ,,o, o,&13A6:1050 20 62 65 63 61 75 73 65-20 74 68 65 20 66 6C 6F =& " fo13A6:1060 61 74 69 6E 67 20 70 6F-69 6E 74 20 65 6D 75 6C "n? <on" 13A6:1070 61 74 6F 72 20 69 73 20-6E 6F 74 20 69 6E 69 74 "o, & no" n"

Cont- 1000 0 =6 1

-; 1000

13A6:1000 74 68 65 20 66 6F 6C 6C-6F 77 69 6E 67 3A 0D 0A " foon?:..13A6:1010 0D 0A 6D 61 69 6E 28 20-29 0D 0A 7B 0D 0A 09 69 ..nS ..^...

13A6:1020 6E 74 20 61 5B 33 5D 5B-34 5D 20 3D 20 7B 20 31 n" I3QI4Q L 113A6:1030 2C 20 32 2C 20 33 2C 20-34 2C 20 34 2C 20 33 2C # 2# 3# 4# 4# 3#13A6:1040 20 32 2C 20 31 2C 20 37-2C 20 38 2C 20 39 2C 20 2# 1# 7# 8# 9#13A6:1050 30 20 7D 20 3B 0D 0A 09-70 72 69 6E 74 66 20 28 0 + ...<,n"f S13A6:1060 20 22 5C 6E 20 25 75 20-25 75 22 2C 20 61 20 2B V\n X XV# 13A6:1070 20 31 2C 20 26 61 20 2B-20 31 20 29 20 3B 0D 0A 1# 1 ..

-q 

Page 275: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 275/340

+* - .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

numer is the .C< entry an# the suseuent $lusters $an e #etermine# y traversing the

$hain for that file in the .8T!6 #ata stru$ture)

0ile #rganization

O

55

57 ] bit

5

6

8

7

B

Start +"uster D

0C$

Cont

3#0

7

?

O5

55

6`57

 ;ot all the entries in .8T!6 7ill e use#% the follo7ing sho7s 7hi$h ones of the entry are

reserve#)

Page 276: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 276/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

+nused 0AT 3ntriesF eserved 3ntries M 000> X 0007>

F 3#0 value M 000> X 0000>

F 0irst Two Clusters M ,5

F 0ree Cluster M

F )a. range of Cluster H M 6 X 0030>

F Total H of Clusters of 0AT57 M 0033>

The follo7ing sli#e sho7s the $ontent of the 4P< for a .8T!6 volume) Same int

2!h'+2 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 (*$-13A6:0100 o #3213A6:0102 n" 2113A6:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13A6 EML13A6 MML13A6 CML13A6 !PL0102 %) UP E! PN %H %A P %C13A6:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML13A6 MML13A6 CML13A6 !PL0104 %) UP E! PN %H %A P %C13A6:0104 D3E3 MN BK#CN

-; 7:13;2

00A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ..............

00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....)4.........00A7:13F0 00 7D CB 00 00 00 00 00-00 00 00 00 00 00 00 00 .+..............00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ................

00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....00A7:1450 A7 05 ..-q 

ere the sli#e sho7s the $ontents of the root #ire$tory #epi$ting the .C< of a file name#

CP8P,)TNT) The $ontrol information aout this file $an e rea# from the #ump)

Page 277: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 277/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

Cont13A6:1320 E5 45 57 54 45 58 7E 31-54 58 54 20 00 32 09 73 .EWOEK(1OKO .2.&13A6:1330 3C 33 3C 33 00 00 0A 73-3C 33 00 00 00 00 00 00 $3$3...&$3......13A6:1340 54 45 53 54 20 20 20 20-54 58 54 20 18 32 09 73 OEMO OKO .2.&13A6:1350 3C 33 3C 33 00 00 17 73-3C 33 45 00 27 00 00 00 $3$3...&$3E.]...13A6:1360 46 49 4C 45 20 20 20 20-54 58 54 20 18 81 83 73 F!NE OKO ...&13A6:1370 3C 33 3C 33 00 00 8D 73-3C 33 54 00 99 02 00 00 $3$3...&$3O.....13A6:1380 E5 30 58 58 20 20 20 20-54 4D 50 20 18 65 A6 68 .0KK OP ..13A6:1390 3D 33 3D 33 00 00 A7 68-3D 33 08 00 12 63 00 00 L3L3...L3.....13A6:13A0 41 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 AC.<..<....O,.13A6:13B0 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........

13A6:13C0 43 50 41 50 45 52 20 20-54 58 54 20 00 9D 7D 6F CPAPE OKO ..+o

13A6:13D0 3C 33 3D 33 00 00 A7 68-3D 33 08 00 12 63 00 00 $3L3...L3.....13A6:13E0 46 44 50 42 20 20 20 20-54 58 54 20 18 05 56 69 FDPB OKO ..)13A6:13F0 3D 33 3D 33 00 00 BD 69-3D 33 29 00 BA 04 00 00 L3L3...L3.....13A6:1400 46 44 44 20 20 20 20 20-54 58 54 20 18 48 E4 75 FDD OKO ..13A6:1410 3D 33 3D 33 00 00 23 76-3D 33 2A 00 13 00 00 00 L3L3..L3'.....

The aove sli#es sho7s that the first $luster of the file is 000) The follo7ing sli#e sho7s

the $ontents of .8T) The .8T is loa#e# firstly in memory at the offset a##ress !000)

a$h entry o$$upies 2 ytes) So the in#e: 000 7ill e lo$ate# at !000 K 000E2 @

!0!0) 8t !0!0% 0009 is store# 7hi$h is the ne:t $luster of the file% using 0009 as

in#e: 7e look up at !0!2% 7hi$h stores 00**% 7hi$h means 00** is the ne:t $luster)

Contents of 0AT- 1000 5 8

-; 1010

13A6:1010 09 00 55 00 FF FF FF FF-FF FF FF FF FF FF FF FF ..U.............13A6:1020 00 00 00 00 FF FF FF FF-FF FF FF FF FF FF FF FF ................

13A6:1030 FF FF FF FF FF FF FF FF-FF FF 1E 00 1F 00 20 00 .............. .13A6:1040 21 00 FF FF FF FF FF FF-46 00 00 00 00 00 00 00 *.......F.......13A6:1050 00 00 FF FF 5A 00 00 00-00 00 00 00 00 00 00 00 ....H...........13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1080 00 00 00 00 00 00 00 00-00 00 FF FF 47 00 48 00 ............G..

-; 10

13A6:10A0 56 00 57 00 58 00 ..M.....).W.K.13A6:10B0 59 00 FF FF 5B 00 5C 00-5D 00 5E 00 5F 00 60 00 ...I.\.Q.Z.R..13A6:10C0 61 00 62 00 63 00 64 00-65 00 66 00 67 00 68 00 .=..;..f.?..

13A6:10D0 69 00 6A 00 6B 00 6C 00-FF FF FF FF 00 00 00 00 .. ..........13A6:10E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:10F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

13A6:1100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................-q 

using 00** as in#e: 7e look up at !088 to fin# the ne:t $luster numer an# so on)

Page 278: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 278/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

(2 - #i"e Organiation

 ;o7 $onverting all those $luster numer in previous le$ture into S; 7e get the starting

S; for ea$h $luster).or $luster H 0009 an# **h

Contents of 0!93- 1000 5 1f8 8

-; 1000

13A6:1000 65 65 6E 20 64 65 6C 65-74 65 64 20 61 63 63 69 n ;"; 13A6:1010 64 65 6E 74 6C 79 20 61-6E 64 20 69 66 20 79 6F ;n"@ n; f @o

13A6:1020 75 0D 0A 77 61 6E 74 20-74 6F 20 63 6F 70 79 20 ..n" "o o<@13A6:1030 61 6C 6C 20 65 78 65 63-75 74 61 62 6C 65 20 66 T"= f13A6:1040 69 6C 65 73 20 74 6F 20-74 68 65 20 73 70 65 63 & "o " &<13A6:1050 69 66 69 65 64 20 64 69-72 65 63 74 6F 72 79 2C f; ;,"o,@#13A6:1060 20 79 6F 75 20 68 61 76-65 20 74 6F 0D 0A 72 65 @o "o..,13A6:1070 63 6F 6D 70 69 6C 65 20-61 6C 6C 20 74 68 65 20 o< "

- 1000 5 458 8

-; 1000

13A6:1000 20 2A 2F 0D 0A 0D 0A 09-77 68 69 6C 65 20 28 20 '[..... S13A6:1010 71 20 21 3D 20 4E 55 4C-4C 20 29 0D 0A 09 7B 0D q *L %UNN ...^.

13A6:1020 0A 09 09 73 20 3D 20 72-20 3B 0D 0A 09 09 72 20 ...& L , ....,13A6:1030 3D 20 71 20 3B 0D 0A 09-09 71 20 3D 20 71 20 2D L q ....q L q -13A6:1040 3E 20 6C 69 6E 6B 20 3B-0D 0A 09 09 72 20 2D 3E > n` ...., -> 13A6:1050 20 6C 69 6E 6B 20 3D 20-73 20 3B 0D 0A 09 7D 0D n` L & ...+.13A6:1060 0A 0D 0A 09 2A 78 20 3D-20 72 20 3B 0D 0A 7D 0D ....'T L , ..+.13A6:1070 0A 0D 0A 2F 2A 20 64 69-73 70 6C 61 79 73 20 74 ...[' ;&<@& "

.or $luster *6 an# *5

Cont- 1000 5 460 8

-; 1000

13A6:1000 20 61 72 72 2C 20 62 76-61 6C 2C 20 65 76 61 6C ,,# =# 13A6:1010 2C 20 28 20 70 20 2B 20-31 20 29 2C 20 6C 61 73 # S < 1 # &

13A6:1020 74 73 75 62 20 29 20 3B-0D 0A 0D 0A 09 09 61 72 "&= ......,13A6:1030 72 5B 70 5D 2B 2B 20 3B-0D 0A 09 7D 0D 0A 7D 0D ,I<Q ...+..+.13A6:1040 0A 0D 0A 77 6F 72 6B 20-28 20 69 6E 74 20 2A 61 ...o,` S n" '13A6:1050 72 72 2C 20 69 6E 74 20-6C 61 73 74 73 75 62 20 ,,# n" &"&=13A6:1060 29 0D 0A 7B 0D 0A 09 69-6E 74 20 70 2C 20 6A 2C ..^...n" <# #13A6:1070 20 6E 75 6D 20 3B 0D 0A-0D 0A 09 66 6F 72 20 28 n .....fo, S

- 1000 5 468 8

-; 1000

13A6:1000 09 09 09 09 72 20 3D 20-30 20 3B 0D 0A 09 09 09 ...., L 0 .....

13A6:1010 09 62 72 65 61 6B 20 3B-0D 0A 09 09 7D 0D 0A 09 .=,` ....+...13A6:1020 7D 0D 0A 09 70 72 69 6E-74 66 20 28 20 22 25 64 +...<,n"f S VX; 13A6:1030 22 2C 20 72 65 73 75 6C-74 20 29 20 3B 0D 0A 7D V# ,&" ..+13A6:1040 0D 0A 0D 0A 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ....------------13A6:1050 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------13A6:1060 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D ----------------

13A6:1070 2D 2D 2D 2D 2D 2D 2D 2D-2D 2D 2D 2D 2D 2D 2D 2D -----------------q 

Page 279: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 279/340

Page 280: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 280/340

+* - .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# TST)TNT

 )o n ;, F & %EW )NUE )o M, %=, & 2CA5-BC35

D,"o,@ of F:\

22-09-05 03:00 P 1#674 ;P=1."T"22-09-05 02:40 P 1#631 ;<=2."T"28-09-05 10:55 A $D!> f,&"28-09-05 10:55 A $D!> &on; 28-09-05 10:55 A $D!> ",; 28-09-05 01:44 P 1#210 ;,<=f."T"28-09-05 10:58 A 248 ",."T"28-09-05 02:25 P 60#775 ,oo"f."T"28-09-05 02:24 P 39 "&"."T"28-09-05 02:28 P 665 f."T"29-09-05 01:05 P 25#362 C<<,."T"

29-09-05 01:13 P 1#210 f;<=."T"29-09-05 02:49 P 80#999 f;;."T"29-09-05 03:02 P 1#305 ff"."T"29-09-05 03:06 P 2#657 ff."T"29-09-05 03:52 P 0 ;,."T"

13 FS& 177#775 =@"&3 D,S& 213#278#720 =@"& f,

Contents of oot 9isting

 ;o7 on the same volume the file TST)TNT is #elete#) ets analyse the $ontents of the

root #ire$tory no7)

- 1000 5 10 20

-;1000 5000

13A6:1000 4E 45 57 20 56 4F 4C 55-4D 45 20 08 00 00 00 00 %EW )NUE .....13A6:1010 00 00 00 00 00 00 61 76-2D 33 00 00 00 00 00 00 ......-3......

13A6:1020 41 52 00 65 00 63 00 79-00 63 00 0F 00 21 6C 00 A...@....*.13A6:1030 65 00 64 00 00 00 FF FF-FF FF 00 00 FF FF FF FF .;.............13A6:1040 52 45 43 59 43 4C 45 44-20 20 20 16 00 4E 79 5E ECCNED ..%@Z13A6:1050 2F 33 2F 33 00 00 7A 5E-2F 33 02 00 00 00 00 00 [3[3..Z[3......13A6:1060 42 20 00 49 00 6E 00 66-00 6F 00 0F 00 72 72 00 B .!.n.f.o...,,.13A6:1070 6D 00 61 00 74 00 69 00-6F 00 00 00 6E 00 00 00 .."..o...n...

13A6:1080 01 53 00 79 00 73 00 74-00 65 00 0F 00 72 6D 00 .M.@.&."....,.13A6:1090 20 00 56 00 6F 00 6C 00-75 00 00 00 6D 00 65 00 .).o.......13A6:10A0 53 59 53 54 45 4D 7E 31-20 20 20 16 00 4E 79 5E MMOE(1 ..%@Z13A6:10B0 2F 33 2F 33 00 00 7A 5E-2F 33 03 00 00 00 00 00 [3[3..Z[3......13A6:10C0 41 64 00 50 00 62 00 31-00 2E 00 0F 00 6A 74 00 A;.P.=.1... ..".13A6:10D0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............

13A6:10E0 44 50 42 31 20 20 20 20-54 58 54 20 00 57 81 69 DPB1 OKO .W.13A6:10F0 36 33 36 33 00 00 07 78-36 33 0A 00 8A 06 00 00 6363...T63......13A6:1100 44 50 42 32 20 20 20 20-54 58 54 20 18 12 AE 69 DPB2 OKO ...13A6:1110 36 33 36 33 00 00 03 75-36 33 0B 00 5F 06 00 00 6363...63..R...13A6:1120 46 49 52 53 54 20 20 20-20 20 20 10 08 6F ED 56 F!MO ..o.) 13A6:1130 3C 33 3C 33 00 00 EE 56-3C 33 0C 00 00 00 00 00 $3$3...)$3......

13A6:1140 53 45 43 4F 4E 44 20 20-20 20 20 10 08 50 EF 56 MEC%D ..P.) 13A6:1150 3C 33 3C 33 00 00 F0 56-3C 33 12 00 00 00 00 00 $3$3...)$3......13A6:1160 54 48 49 52 44 20 20 20-20 20 20 10 08 1B F1 56 O!D ....) 13A6:1170 3C 33 3C 33 00 00 F2 56-3C 33 13 00 00 00 00 00 $3$3...)$3......

Contents of oot After (eleting

Page 281: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 281/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

Cont13A6:1180 E5 52 45 45 20 20 20 20-54 58 54 20 18 89 4C 57 .EE OKO ..NW 13A6:1190 3C 33 3C 33 00 00 4D 57-3C 33 1D 00 F8 00 00 00 $3$3..W$3......13A6:11A0 E5 52 56 50 42 46 20 20-54 58 54 20 18 85 43 6C .)PBF OKO ..C13A6:11B0 3C 33 3C 33 00 00 62 6C-3C 33 10 00 AF 00 00 00 $3$3..=$3......13A6:11C0 E5 52 56 50 42 46 20 20-54 58 54 20 18 08 BB 6C .)PBF OKO ...13A6:11D0 3C 33 3C 33 00 00 83 6D-3C 33 10 00 BA 04 00 00 $3$3...$3......

13A6:11E0 E5 4F 4F 54 46 20 20 20-54 58 54 20 18 45 D3 6D .OF OKO .E. 13A6:11F0 3C 33 3C 33 00 00 F8 6D-3C 33 11 00 6F 4F 00 00 $3$3...$3..o..

13A6:1200 E5 4F 4F 54 46 20 20 20-54 58 54 20 18 04 CF 6E .OF OKO ...n13A6:1210 3C 33 3C 33 00 00 F8 6D-3C 33 1D 00 6F 4F 00 00 $3$3...$3..o..13A6:1220 44 52 56 50 42 46 20 20-54 58 54 20 18 04 CF 6E D)PBF OKO ...n13A6:1230 3C 33 3C 33 00 00 83 6D-3C 33 22 00 BA 04 00 00 $3$3...$3V.....

13A6:1240 54 52 45 45 20 20 20 20-54 58 54 20 18 05 CF 6E OEE OKO ...n13A6:1250 3C 33 3C 33 00 00 4D 57-3C 33 23 00 F8 00 00 00 $3$3..W$3.....13A6:1260 52 4F 4F 54 46 20 20 20-54 58 54 20 18 04 CF 6E OF OKO ...n13A6:1270 3C 33 3C 33 00 00 36 73-3C 33 24 00 67 ED 00 00 $3$3..6&$3.?...13A6:1280 E5 5F 41 4E 53 20 20 20-54 58 54 20 10 9D 7D 6F .RA%M OKO ..+o13A6:1290 3C 33 3C 33 00 00 60 05-72 28 29 00 4F 8F 00 00 $3$3...,S....

13A6:12A0 E5 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 .C.<..<....O,.13A6:12B0 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13A6:12C0 E5 50 41 50 45 52 20 20-54 58 54 20 00 9D 7D 6F .PAPE OKO ..+o13A6:12D0 3C 33 3D 33 00 00 60 05-72 28 29 00 4F 8F 00 00 $3L3...,S....13A6:12E0 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 ...n."......".13A6:12F0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............

13A6:1300 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .%... .O.....13A6:1310 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 T.". .D.o.....

The entry for TST)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:*

Cont13A6:1320 E5 45 57 54 45 58 7E 31-54 58 54 20 00 32 09 73 .EWOEK(1OKO .2.&13A6:1330 3C 33 3C 33 00 00 0A 73-3C 33 00 00 00 00 00 00 $3$3...&$3......13A6:1340 E5 45 53 54 20 20 20 20-54 58 54 20 18 32 09 73 .EMO OKO .2.&13A6:1350 3C 33 3C 33 00 00 17 73-3C 33 45 00 27 00 00 00 $3$3...&$3E.]...13A6:1360 46 49 4C 45 20 20 20 20-54 58 54 20 18 81 83 73 F!NE OKO ...&

13A6:1370 3C 33 3C 33 00 00 8D 73-3C 33 54 00 99 02 00 00 $3$3...&$3O.....13A6:1380 E5 30 58 58 20 20 20 20-54 4D 50 20 18 65 A6 68 .0KK OP ..13A6:1390 3D 33 3D 33 00 00 A7 68-3D 33 08 00 12 63 00 00 L3L3...L3.....13A6:13A0 41 43 00 70 00 61 00 70-00 65 00 0F 00 54 72 00 AC.<..<....O,.13A6:13B0 2E 00 74 00 78 00 74 00-00 00 00 00 FF FF FF FF ..".T.".........13A6:13C0 43 50 41 50 45 52 20 20-54 58 54 20 00 9D 7D 6F CPAPE OKO ..+o13A6:13D0 3C 33 3D 33 00 00 A7 68-3D 33 08 00 12 63 00 00 $3L3...L3.....

13A6:13E0 46 44 50 42 20 20 20 20-54 58 54 20 18 05 56 69 FDPB OKO ..)13A6:13F0 3D 33 3D 33 00 00 BD 69-3D 33 29 00 BA 04 00 00 L3L3...L3.....13A6:1400 46 44 44 20 20 20 20 20-54 58 54 20 18 48 E4 75 FDD OKO ..13A6:1410 3D 33 3D 33 00 00 31 76-3D 33 2A 00 67 3C 01 00 L3L3..1L3'.?$..13A6:1420 E5 46 41 54 20 20 20 20-54 58 54 20 18 96 2C 78 .FAO OKO ..#T13A6:1430 3D 33 3D 33 00 00 37 78-3D 33 6D 00 1A 05 00 00 L3L3..7TL3.....

13A6:1440 46 46 41 54 20 20 20 20-54 58 54 20 18 96 2C 78 FFAO OKO ..#T13A6:1450 3D 33 3D 33 00 00 50 78-3D 33 6E 00 19 05 00 00 L3L3..PTL3n.....13A6:1460 46 46 49 4C 45 20 20 20-54 58 54 20 18 11 97 78 FF!NE OKO ...T13A6:1470 3D 33 3D 33 00 00 D3 78-3D 33 6D 00 61 0A 00 00 L3L3...TL3....13A6:1480 44 49 52 20 20 20 20 20-54 58 54 20 18 49 9A 7E D! OKO .!.(13A6:1490 3D 33 3D 33 00 00 9B 7E-3D 33 6F 00 AC 03 00 00 L3L3...(L3o.....

13A6:14A0 44 49 52 44 20 20 20 20-54 58 54 20 18 7B C0 7E D!D OKO .^.(13A6:14B0 3D 33 3D 33 00 00 C1 7E-3D 33 45 00 AC 03 00 00 L3L3...(L3E.....13A6:14C0 44 44 44 45 4C 20 20 20-54 58 54 20 18 49 F7 7E DDDEN OKO .!.(13A6:14D0 3D 33 3D 33 00 00 F8 7E-3D 33 70 00 13 00 00 00 L3L3...(L3<.....

<ut 7hen the 4", $omman# e:e$ute on the same volume the file #oes not sho7)

Page 282: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 282/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

 )o n ;, F & %EW )NUE )o M, %=, & 2CA5-BC35

D,"o,@ of F:\

22-09-05 03:00 P 1#674 ;P=1."T"22-09-05 02:40 P 1#631 ;<=2."T"28-09-05 10:55 A $D!> f,&"28-09-05 10:55 A $D!> &on; 28-09-05 10:55 A $D!> ",; 28-09-05 01:44 P 1#210 ;,<=f."T"28-09-05 10:58 A 248 ",."T"28-09-05 02:25 P 60#775 ,oo"f."T"28-09-05 02:28 P 665 f."T"29-09-05 01:05 P 25#362 C<<,."T"29-09-05 01:13 P 1#210 f;<=."T"29-09-05 02:49 P 80#999 f;;."T"29-09-05 03:02 P 1#305 ff"."T"29-09-05 03:06 P 2#657 ff."T"29-09-05 03:52 P 940 ;,."T"29-09-05 03:54 P 0 ;,;."T"

13 FS& 178#676 =@"&3 D,S& 213#278#720 =@"& f,

Contents of oot 9isting After (eleting

 ;o7 letMs see the $ontents of the file y $onverting the first $luster numer in the .C<

into S; an# taking its #ump) >e get the follo7ing sli#e)

Contents of 0ile After (eleting- 1000 5 3;8 1

-; 1000

13AD:1000 74 68 69 73 20 69 73 20-61 20 74 65 73 74 20 74 "& & "&" "13AD:1010 65 78 74 20 66 69 6C 65-20 66 6F 72 20 31 36 20 T" f fo, 1613AD:1020 62 69 74 20 46 41 54 00-00 00 00 00 00 00 00 00 =" FAO.........

13AD:1030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13AD:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................-q 

The $ontents of the file are still there)

Page 283: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 283/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

So 7e infer the follo7ing)

(eleted 0ilesF 3B at the start of file entry is used to mar' thefile as deleted.F The contents of file still remain on dis'.F The contents can be recovered by placing a validfile name, character in place of 3B and thenrecovering the chain of file in 0AT.F !f somehow the c lusters used by deleted file hasbeen overwritten by some other file, it cannot berecovered.

 ;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 aout su-#ire$tories) "n the $ontents of the aove given

root #ire$tory noti$e an entry name# SC(;4) The attriute 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 ub(irectories- 1000 5 240 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 50 EF 56 . ..P.) 13A6:1010 3C 33 3C 33 00 00 F0 56-3C 33 12 00 00 00 00 00 $3$3...)$3......13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 50 EF 56 .. ..P.) 

13A6:1030 3C 33 3C 33 00 00 F0 56-3C 33 00 00 00 00 00 00 $3$3...)$3......13A6:1040 53 55 42 31 20 20 20 20-20 20 20 10 08 B1 07 57 MUB1 ....W 13A6:1050 3C 33 3C 33 00 00 08 57-3C 33 16 00 00 00 00 00 $3$3...W$3......13A6:1060 53 55 42 32 20 20 20 20-20 20 20 10 08 23 0A 57 MUB2 ...W 13A6:1070 3C 33 3D 33 00 00 0B 57-3C 33 17 00 00 00 00 00 $3L3...W$3......

- 1000 5 268 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 23 0A 57 . ...W 13A6:1010 3C 33 3C 33 00 00 0B 57-3C 33 17 00 00 00 00 00 $3$3...W$3......

13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 23 0A 57 .. ...W 13A6:1030 3C 33 3C 33 00 00 0B 57-3C 33 12 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 33 20 20 20 20-20 20 20 10 08 9A 0E 57 MUB3 ....W 13A6:1050 3C 33 3D 33 00 00 0F 57-3C 33 18 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

Page 284: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 284/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

"n the entries 7ithin SC(;4 7e see an entry SU<2) "ts starting $luster is 00!5) This

value is $onverte# into S; an# the $ontents rea#) The sli#e aove 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<+)

Cont- 1000 5 270 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 9A 0E 57 . ....W 13A6:1010 3C 33 3C 33 00 00 0F 57-3C 33 18 00 00 00 00 00 $3$3...W$3......13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 9A 0E 57 .. ....W 

13A6:1030 3C 33 3C 33 00 00 0F 57-3C 33 17 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 34 20 20 20 20-20 20 20 10 08 AF 12 57 MUB4 ....W 13A6:1050 3C 33 3D 33 00 00 13 57-3C 33 19 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

- 1000 5 278 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 AF 12 57 . ....W 13A6:1010 3C 33 3C 33 00 00 13 57-3C 33 19 00 00 00 00 00 $3$3...W$3......

13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 AF 12 57 .. ....W 13A6:1030 3C 33 3C 33 00 00 13 57-3C 33 18 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 35 20 20 20 20-20 20 20 10 08 0D 17 57 MUB5 ....W 13A6:1050 3C 33 3D 33 00 00 18 57-3C 33 1A 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

The follo7ing sli#e sho7s the $ontents of SU<* an# also the $ontents of file

&G.")TNT in SU<*)

Cont- 1000 5 280 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 0D 17 57 . ....W 13A6:1010 3C 33 3C 33 00 00 18 57-3C 33 1A 00 00 00 00 00 $3$3...W$3......13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 0D 17 57 .. ....W 

13A6:1030 3C 33 3C 33 00 00 18 57-3C 33 19 00 00 00 00 00 $3$3...W$3......13A6:1040 4D 59 46 49 4C 45 20 20-54 58 54 20 18 00 23 57 F!NE OKO ..W 13A6:1050 3C 33 3C 33 00 00 25 57-3C 33 1B 00 15 00 00 00 $3$3..XW$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

- 1000 5 288 8

-; 1000

13A6:1000 73 6E 66 6B 73 6E 66 73-6E 66 61 73 6E 7A 78 63 &nf`&nf&nf&nT13A6:1010 73 64 63 0D 0A 00 00 00-00 00 00 00 00 00 00 00 &;.............

13A6:1020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

-q 

Page 285: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 285/340

+* - .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$rie# in the sli#e elo7)

The . and . . (irectories

cd .gives the current path

cd . .goes one level bac'wards.

 ;oti$e the $ontents of SC(;4 #ire$tory) The ) entry has the $luster numer 00!2

7hi$h is the $luster numer for the SC(;4 #ire$tory an# the )) entry has $luster numer

7hi$h in#i$ates the higher level #ire$tory 7hi$h is the root #ire$tory)

. and .. ub(irectories- 1000 5 240 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 50 EF 56 . ..P.) 13A6:1010 3C 33 3C 33 00 00 F0 56-3C 33 12 00 00 00 00 00 $3$3...)$3......13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 50 EF 56 .. ..P.) 

13A6:1030 3C 33 3C 33 00 00 F0 56-3C 33 00 00 00 00 00 00 $3$3...)$3......13A6:1040 53 55 42 31 20 20 20 20-20 20 20 10 08 B1 07 57 MUB1 ....W 13A6:1050 3C 33 3C 33 00 00 08 57-3C 33 16 00 00 00 00 00 $3$3...W$3......13A6:1060 53 55 42 32 20 20 20 20-20 20 20 10 08 23 0A 57 MUB2 ...W 13A6:1070 3C 33 3D 33 00 00 0B 57-3C 33 17 00 00 00 00 00 $3L3...W$3......

- 1000 5 268 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 23 0A 57 . ...W 13A6:1010 3C 33 3C 33 00 00 0B 57-3C 33 17 00 00 00 00 00 $3$3...W$3......

13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 23 0A 57 .. ...W 13A6:1030 3C 33 3C 33 00 00 0B 57-3C 33 12 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 33 20 20 20 20-20 20 20 10 08 9A 0E 57 MUB3 ....W 13A6:1050 3C 33 3D 33 00 00 0F 57-3C 33 18 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

8lso e:amine the $ontents of SU<2 #ire$tory the ) #ire$tory has $luster numer 00!5h

7hi$h the $luster numer for SU<2 an# the )) entry has the $luster numer 00!2 7hi$h

is the $luster numer of its parent #ire$tory SC(;4

Same $an e oserve# for SU<+% SU</% SU<* or any other su-#ire$tory in uestion)

Page 286: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 286/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

Cont- 1000 5 270 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 9A 0E 57 . ....W 13A6:1010 3C 33 3C 33 00 00 0F 57-3C 33 18 00 00 00 00 00 $3$3...W$3......13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 9A 0E 57 .. ....W 

13A6:1030 3C 33 3C 33 00 00 0F 57-3C 33 17 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 34 20 20 20 20-20 20 20 10 08 AF 12 57 MUB4 ....W 13A6:1050 3C 33 3D 33 00 00 13 57-3C 33 19 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

- 1000 5 278 8

-; 1000

13A6:1000 2E 20 20 20 20 20 20 20-20 20 20 10 00 AF 12 57 . ....W 13A6:1010 3C 33 3C 33 00 00 13 57-3C 33 19 00 00 00 00 00 $3$3...W$3......

13A6:1020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 AF 12 57 .. ....W 13A6:1030 3C 33 3C 33 00 00 13 57-3C 33 18 00 00 00 00 00 $3$3...W$3......13A6:1040 53 55 42 35 20 20 20 20-20 20 20 10 08 0D 17 57 MUB5 ....W 13A6:1050 3C 33 3D 33 00 00 18 57-3C 33 1A 00 00 00 00 00 $3L3...W$3......13A6:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................13A6:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

So this ho7 C4) $omman# gives the $urrent path an# C4)) moves to the one higher level

#ire$tory)

Page 287: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 287/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

(4 - #T(' #i"e System

etMs no7 perform fe7 more e:periments to see ho7 long file names are manage#)

>in#o7s $an have long file names up to 2** $hara$ters) .or This purpose a file is $reate#7ith a long file name as sho7n in the sli#e elo7)

.ollo7ing sho7s the result of 4", $omman# on the same volume)

9ong 0ile/ame$o"ume in dri&e 5 is @:W $OL)M:$o"ume Seria" @umer is 70((-(#48

%irectory of 5C

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>t1 #i"es 0 ytes

1 %irs 08,8,02 ytes free

Page 288: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 288/340

+* - .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#)

(rive *arameter $loc'-0AFC:0100 o #320AFC:0102 n" 210AFC:0104

-<

 AKL3200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML0AFC EML0AFC MML0AFC CML0AFC !PL0102 %) UP E! PN %H %A P %C0AFC:0102 CD21 !%O 21

-< AKL3200 BKL13D2 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000

DML00A7 EML0AFC MML0AFC CML0AFC !PL0104 %) UP E! PN %H %A P %C0AFC:0104 06 PUM EM

-; 7:13;2

00A7:13D0 07 07 00 02 0F 04-08 00 02 00 02 B0 01 87 ..............

00A7:13E0 C3 C4 00 90 01 56 34 12-00 F8 0A FF FF FF FF 00 .....)4.........00A7:13F0 00 7A C3 00 00 00 00 00-00 00 00 00 00 00 00 00 ...............00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 06 0B 10 00 ................

00A7:1440 2E 0A 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..H..... .....

00A7:1450 A7 05 ..

Using the information in 4P< the root #ire$tory entries are rea# an# are eing sho7n in

the sli#e elo7)

(irectory 3ntry- 1000 7 190 20

-; 10000AFC:1000 4E 45 57 20 56 4F 4C 55-4D 45 20 08 00 00 00 00 %EW )NUE .....0AFC:1010 00 00 00 00 00 00 04 4F-2E 33 00 00 00 00 00 00 ........3......0AFC:1020 41 4E 00 65 00 77 00 20-00 46 00 0F 00 DD 6F 00 A%... .F....o.

0AFC:1030 6C 00 64 00 65 00 72 00-00 00 00 00 FF FF FF FF .;..,.........0AFC:1040 4E 45 57 46 4F 4C 7E 31-20 20 20 10 00 41 09 50 %EWFN(1 ..A.P

0AFC:1050 2E 33 2E 33 00 00 0A 50-2E 33 02 00 00 00 00 00 .3.3...P.3......0AFC:1060 42 20 00 49 00 6E 00 66-00 6F 00 0F 00 72 72 00 B .!.n.f.o...,,.0AFC:1070 6D 00 61 00 74 00 69 00-6F 00 00 00 6E 00 00 00 .."..o...n...0AFC:1080 01 53 00 79 00 73 00 74-00 65 00 0F 00 72 6D 00 .M.@.&."....,.

0AFC:1090 20 00 56 00 6F 00 6C 00-75 00 00 00 6D 00 65 00 .).o.......0AFC:10A0 53 59 53 54 45 4D 7E 31-20 20 20 16 00 44 09 50 MMOE(1 ..D.P0AFC:10B0 2E 33 2E 33 00 00 0A 50-2E 33 03 00 00 00 00 00 .3.3...P.3......0AFC:10C0 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 ...n."......".0AFC:10D0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............0AFC:10E0 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .%... .O.....

0AFC:10F0 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 T.". .D.o.....0AFC:1100 E5 45 57 54 45 58 7E 31-54 58 54 20 00 9D 11 50 .EWOEK(1OKO ...P0AFC:1110 2E 33 2E 33 00 00 12 50-2E 33 00 00 00 00 00 00 .3.3...P.3......0AFC:1120 E5 79 00 73 00 74 00 65-00 6D 00 0F 00 A4 2E 00 .@.&."........0AFC:1130 74 00 78 00 74 00 00 00-FF FF 00 00 FF FF FF FF ".T."...........0AFC:1140 E5 6C 00 20 00 74 00 68-00 65 00 0F 00 A4 20 00 .. ."...... .

0AFC:1150 66 00 61 00 74 00 31 00-36 00 00 00 20 00 73 00 f..".1.6... .&.0AFC:1160 E5 66 00 69 00 6C 00 65-00 20 00 0F 00 A4 74 00 .f.... ....".

Page 289: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 289/340

+* - .8T!2 .ile System 1Sele$ting a !2-it entry 7ithin .8T!2 System3

Cont0AFC:1170 6F 00 20 00 63 00 68 00-65 00 00 00 63 00 6B 00 o. ....... .0AFC:1180 E5 74 00 68 00 69 00 73-00 69 00 0F 00 A4 73 00 ."...&.....&.0AFC:1190 20 00 61 00 20 00 6E 00-65 00 00 00 77 00 20 00 .. .n..... .0AFC:11A0 E5 48 49 53 49 53 7E 32-54 58 54 20 00 9D 11 50 .!M!M(2OKO ...P0AFC:11B0 2E 33 2E 33 00 00 12 50-2E 33 00 00 00 00 00 00 .3.3...P.3......0AFC:11C0 41 52 00 65 00 63 00 79-00 63 00 0F 00 21 6C 00 A...@....*.

0AFC:11D0 65 00 64 00 00 00 FF FF-FF FF 00 00 FF FF FF FF .;.............

0AFC:11E0 52 45 43 59 43 4C 45 44-20 20 20 16 00 86 A7 63 ECCNED ....0AFC:11F0 3C 33 3C 33 00 00 A8 63-3C 33 08 00 00 00 00 00 $3$3...$3......0AFC:1200 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 ...n."......".0AFC:1210 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............0AFC:1220 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .%... .O.....

0AFC:1230 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 T.". .D.o.....0AFC:1240 E5 45 57 54 45 58 7E 31-54 58 54 20 00 8C F8 56 .EWOEK(1OKO ...) 0AFC:1250 57 33 57 33 00 00 F9 56-57 33 00 00 00 00 00 00 W3W3...)W3......0AFC:1260 E5 61 00 6D 00 65 00 2E-00 74 00 0F 00 43 78 00 ......"...CT.0AFC:1270 74 00 00 00 FF FF FF FF-FF FF 00 00 FF FF FF FF "...............0AFC:1280 E5 6B 00 20 00 6C 00 6F-00 6E 00 0F 00 43 67 00 .`. ..o.n...C?.

0AFC:1290 20 00 66 00 69 00 6C 00-65 00 00 00 20 00 6E 00 .f...... .n.0AFC:12A0 E5 20 00 66 00 69 00 6C-00 65 00 0F 00 43 20 00 . .f......C .0AFC:12B0 74 00 6F 00 20 00 63 00-68 00 00 00 65 00 63 00 ".o. .......0AFC:12C0 E5 74 00 68 00 69 00 73-00 20 00 0F 00 43 69 00 ."...&. ...C.0AFC:12D0 73 00 20 00 61 00 20 00-6E 00 00 00 65 00 77 00 &. .. .n.....0AFC:12E0 E5 48 49 53 49 53 7E 31-54 58 54 20 00 8C F8 56 .!M!M(1OKO ...) 

0AFC:12F0 57 33 57 33 00 00 F9 56-57 33 00 00 00 00 00 00 W3W3...)W3......0AFC:1300 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 ...n."......".

Cont0AFC:1310 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............0AFC:1320 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .%... .O.....0AFC:1330 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 T.". .D.o.....0AFC:1340 E5 45 57 54 45 58 7E 31-54 58 54 20 00 26 85 5A .EWOEK(1OKO ..H0AFC:1350 57 33 57 33 00 00 86 5A-57 33 00 00 00 00 00 00 W3W3...HW3......0AFC:1360 44 61 00 6D 00 65 00 73-00 2E 00 0F 00 0A 74 00 D...&... ...".

0AFC:1370 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF T.".............0AFC:1380 03 74 00 20 00 6C 00 6F-00 6E 00 0F 00 0A 67 00 .". ..o.n....?.0AFC:1390 20 00 66 00 69 00 6C 00-65 00 00 00 20 00 6E 00 .f...... .n.0AFC:13A0 02 20 00 74 00 6F 00 20-00 65 00 0F 00 0A 78 00 . .".o. .....T.0AFC:13B0 70 00 65 00 72 00 69 00-6D 00 00 00 65 00 6E 00 <..,......n.0AFC:13C0 01 49 00 20 00 61 00 6D-00 20 00 0F 00 0A 6E 00 .!. ... ....n.

0AFC:13D0 65 00 77 00 20 00 66 00-69 00 00 00 6C 00 65 00 .. .f......0AFC:13E0 49 41 4D 4E 45 57 7E 31-54 58 54 20 00 26 85 5A !A%EW(1OKO ..H0AFC:13F0 57 33 57 33 00 00 86 5A-57 33 00 00 00 00 00 00 W3W3...HW3......0AFC:1400 52 4F 4F 54 48 20 20 20-54 58 54 20 18 0F 95 5C O OKO ...\0AFC:1410 57 33 57 33 00 00 96 5C-57 33 0E 00 13 00 00 00 W3W3...\W3......0AFC:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

0AFC:1430 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................0AFC:1440 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................0AFC:1450 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................0AFC:1460 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................0AFC:1470 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

" n the aove 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)

Page 290: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 290/340

 ;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 reuire# in .8T+2 so the stru$ture for <P< use# in .8T+2 is

#ifferent)

0at86 $*$ tructure

Page 291: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 291/340

+5 - .8T+2 .ile System 

Page 292: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 292/340

+5 - .8T+2 .ile System 

There $an e #ifferent volumes 7ith #ifferent volume si=es) The #evi$e #river for file

han#ling 7oul# reuire 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<)

Page 293: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 293/340

+5 - .8T+2 .ile System 

Page 294: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 294/340

+5 - .8T+2 .ile System 

0at Type (eterminationif9P9R#TS12 Y; 0

#TS ; 9P9R#TS12J

e"se#TS ; 9P9R#TS('J

if9P9RTotSec12 Y; 0

TotSec ; 9P9RTotSec12Je"se

TotSec ; 9P9RTotSec('J%ataSec ; TotSec < 9P9R*es&dSec+nt B 9P9R@um#Ts H #TS B

*oot%irSectorsJ

+ountof+"usters ; %ataSec / 9P9RSecPer+"usJ

if+ountof+"usters V 07. /H $o"ume is #T1' H/

e"se if+ountof+"usters V 2..'. /H $o"ume is #T12 H/

e"se

 /H $o"ume is #T(' H/

Page 295: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 295/340

+5 - .8T+2 .ile System 

(7 - #T(' #i"e System II

.ollo7ing sli#e sho7s ho7 the $hain of $lusters is maintaine# in a .8T+2 ase# system)

0ile #rganization

O

55

86 ] bit

5

6

8

7

B

Start +"uster D

0C$

Cont

3#0

7

?

O5

55

6`6?

Page 296: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 296/340

+5 - .8T+2 .ile System 

0at86 3ntryW a$h entry is of +2-its si=e ut only

lo7er 2-its are use#)

W igher /-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)

Page 297: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 297/340

+5 - .8T+2 .ile System 

0at86 0ile ystem

Clust8Clust60AT60AT5

*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)

tarting ector H for a Cluster tarting ector M eserved ect. Q 0atize K

0atCopies Q %cluster H 6& Ksize of cluster 

 ;o7 7e #etermine all the parameters in the aove sli#e for a $ertain volume to translate a

$luster numer into S;)

Page 298: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 298/340

+5 - .8T+2 .ile System 

eserved $loc's

(ffset !/ @ 0:0 @ ,eserve# Se$t) @ 0:002/

0000 EB 58 90 4D 53 57 49 4E . K . M W ! % 235 88 144 77 83 87 73 780008 34 2E 31 00 02 20 24 00 4 . 1 . . . 52 46 49 0 2 32 36 00010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 00018 3F 00 F0 00 3F 00 00 00 / . . . / . . . 63 0 240 0 63 0 0 00020 41 29 54 02 3E 25 00 00 A O . > X . . 65 41 84 2 62 37 0 00028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0

0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 80 01 29 F1 17 79 2D 4E . . . . @ - % 128 1 41 241 23 121 45 780048 4F 20 4E 41 4D 45 20 20 % A E 79 32 78 65 77 69 32 320050 20 20 46 41 54 33 32 20 F A O 3 2 32 32 70 65 84 51 50 320058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244

0060 7B 8E C1 8E D9 BD 00 7C ^ . . . . . . | 123 142 193 142 217 189 0 1240068 88 4E 02 8A 56 40 B4 08 . % . . ) _ . . 136 78 2 138 86 64 180 80070 CD 13 73 05 B9 FF FF 8A . . & . . . . . 205 19 115 5 185 255 255 1380078 F1 66 0F B6 C6 40 66 0F . f . . . _ f . 241 102 15 182 198 64 102 150080 B6 D1 80 E2 3F F7 E2 86 . . . . / . . . 182 209 128 226 63 247 226 1340088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183

0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 2480098 83 7E 16 00 75 38 83 7E . ( . . 8 . ( 131 126 22 0 117 56 131 126

Copies of 0AT

(ffset !6 @ 0:!0 @ Count of .8TMS @ 0:0002

0000 EB 58 90 4D 53 57 49 4E . K . M W ! % 235 88 144 77 83 87 73 780008 34 2E 31 00 02 20 24 00 4 . 1 . . . 52 46 49 0 2 32 36 00010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 00018 3F 00 F0 00 3F 00 00 00 / . . . / . . . 63 0 240 0 63 0 0 00020 41 29 54 02 3E 25 00 00 A O . > X . . 65 41 84 2 62 37 0 00028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0

0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 80 01 29 F1 17 79 2D 4E . . . . @ - % 128 1 41 241 23 121 45 780048 4F 20 4E 41 4D 45 20 20 % A E 79 32 78 65 77 69 32 320050 20 20 46 41 54 33 32 20 F A O 3 2 32 32 70 65 84 51 50 320058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244

0060 7B 8E C1 8E D9 BD 00 7C ^ . . . . . . | 123 142 193 142 217 189 0 1240068 88 4E 02 8A 56 40 B4 08 . % . . ) _ . . 136 78 2 138 86 64 180 80070 CD 13 73 05 B9 FF FF 8A . . & . . . . . 205 19 115 5 185 255 255 1380078 F1 66 0F B6 C6 40 66 0F . f . . . _ f . 241 102 15 182 198 64 102 150080 B6 D1 80 E2 3F F7 E2 86 . . . . / . . . 182 209 128 226 63 247 226 134

0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 1830090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 2480098 83 7E 16 00 75 38 83 7E . ( . . 8 . ( 131 126 22 0 117 56 131 126

ector per 0AT copy

Offset 51 $<4# Sectors occ"pie* )y singe 9A, $<$$$$4:5>

0000 EB 58 90 4D 53 57 49 4E . K . M W ! % 235 88 144 77 83 87 73 780008 34 2E 31 00 02 20 24 00 4 . 1 . . . 52 46 49 0 2 32 36 00010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 00018 3F 00 F0 00 3F 00 00 00 / . . . / . . . 63 0 240 0 63 0 0 0

0020 41 29 54 02 3E 25 00 00 A O . > X . . 65 41 84 2 62 37 0 00028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0

0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 80 01 29 F1 17 79 2D 4E . . . . @ - % 128 1 41 241 23 121 45 780048 4F 20 4E 41 4D 45 20 20 % A E 79 32 78 65 77 69 32 320050 20 20 46 41 54 33 32 20 F A O 3 2 32 32 70 65 84 51 50 320058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244

0060 7B 8E C1 8E D9 BD 00 7C ^ . . . . . . | 123 142 193 142 217 189 0 1240068 88 4E 02 8A 56 40 B4 08 . % . . ) _ . . 136 78 2 138 86 64 180 80070 CD 13 73 05 B9 FF FF 8A . . & . . . . . 205 19 115 5 185 255 255 1380078 F1 66 0F B6 C6 40 66 0F . f . . . _ f . 241 102 15 182 198 64 102 150080 B6 D1 80 E2 3F F7 E2 86 . . . . / . . . 182 209 128 226 63 247 226 1340088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183

0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 2480098 83 7E 16 00 75 38 83 7E . ( . . 8 . ( 131 126 22 0 117 56 131 126

Page 299: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 299/340

+5 - .8T+2 .ile System 

Cluster H for oot (irectory

(ffset // @ 0:2C @ 0:0000 0002

0000 EB 58 90 4D 53 57 49 4E . K . M W ! % 235 88 144 77 83 87 73 780008 34 2E 31 00 02 20 24 00 4 . 1 . . . 52 46 49 0 2 32 36 00010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 00018 3F 00 F0 00 3F 00 00 00 / . . . / . . . 63 0 240 0 63 0 0 00020 41 29 54 02 3E 25 00 00 A O . > X . . 65 41 84 2 62 37 0 00028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0

0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 80 01 29 F1 17 79 2D 4E . . . . @ - % 128 1 41 241 23 121 45 780048 4F 20 4E 41 4D 45 20 20 % A E 79 32 78 65 77 69 32 320050 20 20 46 41 54 33 32 20 F A O 3 2 32 32 70 65 84 51 50 320058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244

0060 7B 8E C1 8E D9 BD 00 7C ^ . . . . . . | 123 142 193 142 217 189 0 1240068 88 4E 02 8A 56 40 B4 08 . % . . ) _ . . 136 78 2 138 86 64 180 80070 CD 13 73 05 B9 FF FF 8A . . & . . . . . 205 19 115 5 185 255 255 1380078 F1 66 0F B6 C6 40 66 0F . f . . . _ f . 241 102 15 182 198 64 102 150080 B6 D1 80 E2 3F F7 E2 86 . . . . / . . . 182 209 128 226 63 247 226 1340088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183

0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 2480098 83 7E 16 00 75 38 83 7E . ( . . 8 . ( 131 126 22 0 117 56 131 126

ize of Cluster in ectors

(ffset !+ @ 0:04 @ 0:20 @ +2 lo$ks

0000 EB 58 90 4D 53 57 49 4E . K . M W ! % 235 88 144 77 83 87 73 780008 34 2E 31 00 02 20 24 00 4 . 1 . . . 52 46 49 0 2 32 36 00010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 00018 3F 00 F0 00 3F 00 00 00 / . . . / . . . 63 0 240 0 63 0 0 00020 41 29 54 02 3E 25 00 00 A O . > X . . 65 41 84 2 62 37 0 00028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0

0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 80 01 29 F1 17 79 2D 4E . . . . @ - % 128 1 41 241 23 121 45 780048 4F 20 4E 41 4D 45 20 20 % A E 79 32 78 65 77 69 32 320050 20 20 46 41 54 33 32 20 F A O 3 2 32 32 70 65 84 51 50 320058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244

0060 7B 8E C1 8E D9 BD 00 7C ^ . . . . . . | 123 142 193 142 217 189 0 1240068 88 4E 02 8A 56 40 B4 08 . % . . ) _ . . 136 78 2 138 86 64 180 8

0070 CD 13 73 05 B9 FF FF 8A . . & . . . . . 205 19 115 5 185 255 255 1380078 F1 66 0F B6 C6 40 66 0F . f . . . _ f . 241 102 15 182 198 64 102 150080 B6 D1 80 E2 3F F7 E2 86 . . . . / . . . 182 209 128 226 63 247 226 1340088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183

0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 2480098 83 7E 16 00 75 38 83 7E . ( . . 8 . ( 131 126 22 0 117 56 131 126

So using all this information 7e $al$ulate the S; for $luster numer 2 as sho7n the

sli#e elo7 for this parti$ular volume)

Page 300: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 300/340

+5 - .8T+2 .ile System 

tarting ector for Cluster H 6Starting Se$tor @ ,eserve# Se$t) K .atSi=e E

.atCopies K 1$luster H - 23 E

si=e of $luster @ 0:002/ K 0:0000 2*+ E

0:0002 K 12 23 E 0:20

@ 0:/880

@ !9!0/4

To e:amine the $ontents of a file first a file is $reate# 7hose $ontents are also sho7n in

the sli#e)

Creation of a 0ile on oot(irectory

an# is store# as myfile)t:t on the root #ire$tory)

Page 301: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 301/340

+5 - .8T+2 .ile System 

Creation of a 0ile on oot(irectory

 ;o7 7e e:amine the $ontents of $luster numer 2 7hi$h $ontains the root #ire$tory as

alrea#y seen in the previous sli#es)

000000000000 0000 E5 41 47 45 46 49 4C 45 53 59 53 26 00 3B A2 31 .AGEF!NEMM..1000000000010 0010 A8 32 84 33 00 00 53 4E 84 33 03 00 00 60 01 00 .2.3..M%.3.....000000000020 0020 57 49 4E 44 4F 57 53 20 20 20 20 10 00 4C A2 31 W!%DWM ..N.1000000000030 0030 A8 32 21 34 00 00 A3 31 A8 32 03 0A 00 00 00 00 .2*4...1.2......

000000000040 0040 4E 54 4C 44 52 20 20 20 20 20 20 27 08 00 71 A7 %OND ]..q.000000000050 0050 03 31 A8 32 00 00 71 A7 03 31 85 8E B0 D0 03 00 .1.2..q..1......

000000000060 0060 4E 54 44 45 54 45 43 54 43 4F 4D 27 00 00 D1 A4 %ODEOECOC]....000000000070 0070 03 31 A8 32 00 00 D1 A4 03 31 9E 8F CC B9 00 00 .1.2.....1......000000000080 0080 42 4F 4F 54 20 20 20 20 49 4E 49 06 18 30 25 32 BO !%!..0X2000000000090 0090 A8 32 21 34 0E 00 5C 33 A8 32 F0 AD D3 00 00 00 .2*4..\3.2......0000000000A0 00A0 42 20 00 53 00 65 00 74 00 74 00 0F 00 4A 69 00 B .M.."."....0000000000B0 00B0 6E 00 67 00 73 00 00 00 FF FF 00 00 FF FF FF FF n.?.&...........0000000000C0 00C0 01 44 00 6F 00 63 00 75 00 6D 00 0F 00 4A 65 00 .D.o.......

Cluster H 6

0000000034E0 34E0 E5 59 46 49 4C 45 20 20 54 58 54 20 18 67 CC 16 .F!NE OKO .?..0000000034F0 34F0 21 34 21 34 00 00 CD 16 21 34 00 00 00 00 00 00 *4*4....*4......000000003500 3500 4D 59 46 49 4C 45 20 20 54 58 54 20 18 67 CC 16 F!NE OKO .?..000000003510 3510 21 34 21 34 09 00 CD 16 21 34 C9 29 29 00 00 00 *4*4....*4....000000003520 3520 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................000000003530 3530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Page 302: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 302/340

+5 - .8T+2 .ile System 

.rom the information from aove sli#es the lo7 an# high 7or#s of the first $luster

numer is otaine# an# is sho7n in the sli#e elo7) The higher / its of the $luster

numer shoul# e ignore# as #is$usse# earlier)

Cluster H within 0C$Cluster H o7 >or# @ 29C9

Cluster H i >or# @ 0009

0009 29C9 0... .... @ 009 29C9

Using the $luster numer aove the S; for this $luster is #etermine# as sho7n in the

sli#e elo7)

0ile (ata ectorsStarting Se$tor @ ,eserve# Se$t) K .atSi=e E

.atCopies K 1$luster H - 23 E

si=e of $luster 

@ 002/ K 2*+ E 2 K

1929C9 23 E 0:20

@ /880 K !2*+0

@ !2*+0

@ !92+*5!2

Page 303: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 303/340

+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 (ataD< of NM% 19235712

0000 74 68 69 73 20 69 73 20 " & & 116 104 105 115 32 105 115 320008 66 69 6C 65 20 74 6F 20 f " o 102 105 108 101 32 116 111 320010 74 65 73 74 20 46 41 54 " & " F A O 116 101 115 116 32 70 65 840018 33 32 20 66 69 6C 65 20 3 2 f 51 50 32 102 105 108 101 32

0020 73 74 72 75 63 74 75 72 & " , " , 115 116 114 117 99 116 117 1140028 65 00 00 00 00 00 00 00 . . . . . . . 101 0 0 0 0 0 0 00030 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00040 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00048 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0

0050 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00058 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00060 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00068 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 00 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 7 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 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 00 0 8 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 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 0 9 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 0 A 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 B 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 0 B 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 C 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 C 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 D 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 D 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 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 E 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 F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 0 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 1 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 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 2 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 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 3 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 1 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 4 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 1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 5 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 6 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 7 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 1 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 00 1 8 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 1 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 9 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 1 A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 A 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 1 B 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 B 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 C 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 C 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 D 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 D 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 1 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 E 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 1 F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 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

"n the .8T+2 there is another spe$ial reserve# lo$k $alle# .S"nfo se$tor) The lo$k

$ontains some information reuire# 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 reuire#) This $al$ulation

at the time of allo$ation is not feasile 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)

Page 304: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 304/340

+5 - .8T+2 .ile System 

Page 305: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 305/340

+5 - .8T+2 .ile System 

(8 - @e6 Techno"ogy #i"e System @T#S

The follo7ing sli#e sho7s the anatomy of an ;T.S ase# system) The .8T an# root

#ire$tory has een repla$e# y the &.T) "t 7ill generally have t7o $opies the other $opy7ill e a mirror image of the original) ,ests of the lo$ks are reserve# for user #ata) "n the

mi##le of the volume is a $opy of the first !6 &T. re$or# 7hi$h are very important to the

system)

+ser (ata+ser (ata)0T%)irror&

)0T

9oot 9"oc3 +o!y of #irst 12 M#T records

Page 306: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 306/340

The follo7ing sli#es sho7 the <oot se$tor stru$ture for a ;T.S ase# system)

/T0 2eneral $oot ector tructur 

$nd of Sector/ar(er

OR!"#"1F$

Bootstra'%ode

84 b)tes"#-8

$#tended BPB87 b)tes"#8

BPB- b)tes"#"B

O$/ I!0OC0OC"#"5

Dum'Instruction

5 b)tes"#""

Field NameField LengthByte Offset

Page 307: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 307/340

+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)

P@& M"o,:C@ 0# M; 1# M"o, 1

00000000:EB 52 90 4E 54 46 53 20 -20 20 20 00 02 08 00 00 ..%OFM ........00000010:00 00 00 00 00 F8 00 00 -3F 00 FF 00 3F 00 00 00 ......../.../...00000020:00 00 00 00 80 00 80 00 -4A F5 7F 00 00 00 00 00 ...............00000030:04 00 00 00 00 00 00 00 -54 FF 07 00 00 00 00 00 ........O.......00000040:F6 00 00 00 01 00 00 00 -14 A5 1B 74 C9 1B 74 1C ..........."..". 00000050:00 00 00 00 FA 33 C0 8E -D0 BC 00 7C FB B8 C0 07 .....3.....|.... 00000060:8E D8 E81 6 00B8 00 0D -8E C0 33 DB C6 06 0E 00 ..........3..... 00000070:10 E8 5300 68 00 0D 68 -6A 02 CB 8A 16 24 00 B4 ..M......... 00000080:08 CD 13 73 05 B9 FF FF -8A F1 66 0FB6 C6 40 66 ...&......f..._f 00000090:0F B6 D1 80 E2 3F F7 E2 -86 CD C0 ED 06 41 66 0F ...../.......Af. 000000A0:B7 C9 66 F7 E1 66 A3 20 -00 C3 B4 41 BB AA 55 8A..f..f....A..U. 000000B0:16 24 00 CD 13 72 0F 81 -FB 55 AA 75 09 F6 C1 01 ....,...U..... 000000C0:74 04 FE 06 14 00 C3 66 -60 1E 06 66 A1 10 00 66 "......f..f...f000000D0:03 06 1C 00 66 3B 06 20 -00 0F 82 3A 00 1E 66 6A ....f....:..f 000000E0:00 66 50 06 53 66 68 10 -00 01 00 80 3E 14 00 00 .fP.Mf.....>... 000000F0:0F 85 0C00 E8B3 FF 80 -3E 14 00 00 0F 84 61 00 ........>...... 00000100:B4 42 8A 16 24 00 16 1F -8B F4 CD 13 66 58 5B 07 .B........fK I.. 00000110:66 58 66 58 1F EB 2D 66 -33 D2 66 0FB7 0E 18 00 fKfK.-f3.f...... 00000120:66 F7 F1 FE C2 8A CA 66 -8B D0 66 C1 EA 10 F7 36 f......f..f....6 00000130:1A 00 86 D6 8A 16 24 00 -8A E8 C0 E4 06 0A CC B8............... 00000140:01 02 CD 13 0F 82 19 00 -8C C0 05 20 00 8E C0 66 ..............f 00000150:FF 06 10 00 FF 0E 0E 00 -0F 85 6F FF 07 1F 66 61 ..........o...f

00000160:C3 A0 F8 01 E8 09 00 A0 -FB 01 E8 03 00 FB EB FE ................00000170:B4 01 8B F0 AC 3C 00 74 -09 B4 0E BB 07 00 CD 10 .....$."........00000180:EB F2 C3 0D 0A 41 20 64 -69 73 6B 20 72 65 61 64 .....A ;&` ,;00000190:20 65 72 72 6F 72 20 6F -63 63 75 72 72 65 64 00 ,,o, o,,;.000001A0:0D 0A 4E 54 4C 44 52 20 -69 73 20 6D 69 73 73 69 ..%OND & &&000001B0:6E 67 00 0D 0A 4E 54 4C -44 52 20 69 73 20 63 6F n?...%OND & o000001C0:6D 70 72 65 73 73 65 64 -00 0D 0A 50 72 65 73 73 <,&&;...P,&&000001D0:20 43 74 72 6C 2B 41 6C -74 2B 44 65 6C 20 74 6F C",A"D "o000001E0:20 72 65 73 74 61 72 74 -0D 0A 00 00 00 00 00 00 ,&","........000001F0:00 00 00 00 00 00 00 00 -83 A0 B3 C9 00 00 55 AA ..............U.

ample of /T0 $oot $loc'

ector *er Cluster M?

P@& M"o,:C@ 0# M; 1# M"o, 100000000:EB 52 90 4E 54 46 53 20 -20 20 20 00 02 08 00 00 ..%OFM ........

00000010:00 00 00 00 00 F8 00 00 -3F 00 FF 00 3F 00 00 00 ......../.../...00000020:00 00 00 00 80 00 80 00 -4A F5 7F 00 00 00 00 00 ...............00000030:04 00 00 00 00 00 00 00 -54 FF 07 00 00 00 00 00 ........O.......00000040:F6 00 00 00 01 00 00 00 -14 A5 1B 74 C9 1B 74 1C ..........."..". 00000050:00 00 00 00 FA 33 C0 8E -D0 BC 00 7C FB B8 C0 07 .....3.....|.... 00000060:8E D8 E816 00B8 00 0D -8E C0 33 DB C6 06 0E 00 ..........3..... 00000070:10 E8 53 00 68 00 0D 68 -6A 02 CB 8A 16 24 00 B4 ..M......... 00000080:08 CD 1373 05 B9 FF FF -8A F1 66 0FB6 C6 40 66 ...&......f..._f 00000090:0F B6 D1 80 E2 3F F7 E2 -86 CD C0 ED 06 41 66 0F ...../.......Af. 000000A0:B7 C9 66 F7 E1 66 A3 20 -00 C3 B4 41 BB AA 55 8A..f..f....A..U. 000000B0:16 24 00 CD 13 72 0F 81 -FB 55 AA 75 09 F6 C1 01 ....,...U..... 000000C0:74 04 FE 06 14 00 C3 66 -60 1E 06 66 A1 10 00 66 "......f..f...f000000D0:03 06 1C 00 66 3B 06 20 -00 0F 82 3A 00 1E 66 6A ....f....:..f 000000E0:00 66 50 06 53 66 68 10 -00 01 00 80 3E 14 00 00 .fP.Mf.....>... 000000F0:0F 85 0C00 E8B3 FF 80 -3E 14 00 00 0F 84 61 00 ........>...... 00000100:B4 42 8A 16 24 00 16 1F -8B F4 CD 13 66 58 5B 07 .B........fKI .. 00000110:66 58 66 58 1F EB 2D 66 -33 D2 66 0FB7 0E 18 00 fKfK.-f3.f...... 00000120:66 F7 F1 FE C2 8A CA 66 -8B D0 66 C1 EA 10 F7 36 f......f..f....6 00000130:1A 00 86 D6 8A 16 24 00 -8A E8 C0 E4 06 0A CC B8

............... 00000140:01 02 CD 13 0F 82 19 00 -8C C0 05 20 00 8E C0 66 ..............f 00000150:FF 06 10 00 FF 0E 0E 00 -0F 85 6F FF 07 1F 66 61 ..........o...f

00000160:C3 A0 F8 01 E8 09 00 A0 -FB 01 E8 03 00 FB EB FE ................00000170:B4 01 8B F0 AC 3C 00 74 -09 B4 0E BB 07 00 CD 10 .....$."........00000180:EB F2 C3 0D 0A 41 20 64 -69 73 6B 20 72 65 61 64 .....A ;&` ,;00000190:20 65 72 72 6F 72 20 6F -63 63 75 72 72 65 64 00 ,,o, o,,;.000001A0:0D 0A 4E 54 4C 44 52 20 -69 73 20 6D 69 73 73 69 ..%OND & &&

000001B0:6E 67 00 0D 0A 4E 54 4C -44 52 20 69 73 20 63 6F n?...%OND & o000001C0:6D 70 72 65 73 73 65 64 -00 0D 0A 50 72 65 73 73 <,&&;...P,&&000001D0:20 43 74 72 6C 2B 41 6C -74 2B 44 65 6C 20 74 6F C",A"D "o000001E0:20 72 65 73 74 61 72 74 -0D 0A 00 00 00 00 00 00 ,&","........000001F0:00 00 00 00 00 00 00 00 -83 A0 B3 C9 00 00 55 AA ..............U.

)0T 0ile Cluster H

)0T 0ile Cluster H M

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)

Page 308: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 308/340

+9 - ;e7 Te$hnology .ile System 1;T.S3

)0T !nternal tructure

mall (irectoryecord

9arge 0ile ecord

mall 0ile ecord

9og 0ile

)0T

.ollo7ing sli#e sho7s the #etail aout the first !6 system entries 7ithin the &.T)

Page 309: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 309/340

+9 - ;e7 Te$hnology .ile System 1;T.S3

Page 310: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 310/340

+9 - ;e7 Te$hnology .ile System 1;T.S3

0 - %isassem"ing the @T#S ased fi"e

 ;o7 in the follo7ing e:ample a file is $reate# an# its entry is sear$he# in the &.T) The

follo7ing sli#e sho7s that the name of the file $reate# is TST)TNT)

Creation of a 0ile on /T01olume

This sli#e sho7 the $ontents of the file $reate#)

Creation of a 0ile on /T01olume

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)

Page 311: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 311/340

+9 - ;e7 Te$hnology .ile System 1;T.S3

$oot ector of the 1olume0000 EB 52 90 4E 54 46 53 20 . . % O F M 235 82 144 78 84 70 83 320008 20 20 20 00 02 08 0 0 00 . . . . . 32 32 32 0 2 8 0 00010 00 00 00 00 00 F8 00 00 . . . . . . . . 0 0 0 0 0 248 0 00018 3F 00 FF 00 3F 00 00 00 / . . . / . . . 63 0 255 0 63 0 0 00020 00 00 00 00 80 00 80 00 . . . . . . . . 0 0 0 0 128 0 128 00028 44 A2 D7 01 00 00 00 00 D . . . . . . . 68 162 215 1 0 0 0 00030 00 00 0C 00 00 00 00 00 . . . . . . . . 0 0 12 0 0 0 0 00038 24 7A 1D 00 00 00 00 00 . . . . . . 36 122 29 0 0 0 0 00040 F6 00 00 00 01 00 00 00 . . . . . . . . 246 0 0 0 1 0 0 0

0048 6A 94 9C 86 D4 9C 86 78 . . . . . . T 106 148 156 134 212 156 134 120

0050 00 00 00 00 FA 33 C0 8E . . . . . 3 . . 0 0 0 0 250 51 192 142

0058 D0 BC 00 7C FB B8 C0 07 . . . | . . . . 208 188 0 124 251 184 192 70060 8E D8 E8 16 00 B8 00 0D . . . . . . . . 142 216 232 22 0 184 0 1 30068 8E C0 33 DB C6 06 0E 00 . . 3 . . . . . 142 192 51 219 198 6 14 0

0070 10 E8 53 00 68 00 0D 68 . . M . . . 16 232 83 0 104 0 13 1040078 6A 02 CB 8A 16 24 00 B4 . . . . . . 106 2 203 138 22 36 0 1800080 08 CD 13 73 05 B9 FF FF . . . & . . . . 8 205 19 115 5 185 255 2550088 8A F1 66 0F B6 C6 40 66 . . f . . . _ f 138 241 102 15 182 198 64 1020090 0F B6 D1 80 E2 3F F7 E2 . . . . . / . . 15 182 209 128 226 63 247 2260098 86 CD C0 ED 06 41 66 0F . . . . . A f . 134 205 192 237 6 65 102 15

00A0 B7 C9 66 F7 E1 66 A3 20 . . f . . f . 183 201 102 247 225 102 163 3200A8 00 C3 B4 41 BB AA 55 8A . . . A . . U . 0 195 180 65 187 170 85 13800B0 16 24 00 CD 13 72 0F 81 . . . . , . . 22 3 6 0 205 19 114 15 129

00B8 FB 55 AA 75 09 F6 C1 01 . U . . . . . 251 8 5 170 117 9 246 193 100C0 74 04 FE 06 14 00 C3 66 " . . . . . . f 116 4 254 6 20 0 195 102

00C8 60 1E 06 66 A1 10 00 66 . . f . . . f 96 3 0 6 102 161 16 0 10200D0 03 06 1C 00 66 3B 06 20 . . . . f . 3 6 28 0 102 59 6 3200D8 00 0F 82 3A 00 1E 66 6A . . . : . . f 0 15 130 58 0 30 102 10600E0 00 66 50 06 53 66 68 10 . f P . M f . 0 102 80 6 83 102 104 1 6

00E8 00 01 00 80 3E 14 00 00 . . . . > . . . 0 1 0 128 62 20 0 0

00F0 0F 85 0C 00 E8 B3 FF 80 . . . . . . . . 15 133 12 0 232 179 255 12800F8 3E 14 00 00 0F 84 61 00 > . . . . . . 62 20 0 0 15 132 97 0

0100 B4 42 8A 16 24 00 16 1F . B . . . . . 180 6 6 138 22 36 0 22 3 10108 8B F4 CD 13 66 58 5B 07 . . . . f K I . 139 244 205 19 102 88 91 7

0110 66 58 66 58 1F EB 2D 66 f K f K . . - f 102 8 8 102 8 8 31 235 45 1020118 33 D2 66 0F B7 0E 18 00 3 . f . . . . . 51 210 102 15 183 14 24 00120 66 F7 F1 FE C2 8A CA 66 f . . . . . . f 102 247 241 254 194 138 202 102

0128 8B D0 66 C1 EA 10 F7 36 . . f . . . . 6 139 208 102 193 234 16 247 540130 1A 00 86 D6 8A 16 24 00 . . . . . . . 26 0 134 214 138 22 36 0

0138 8A E8 C0 E4 06 0A CC B8 . . . . . . . . 138 232 192 228 6 10 204 1840140 01 02 CD 13 0F 82 19 00 . . . . . . . . 1 2 205 19 15 130 25 00148 8C C0 05 20 00 8E C0 66 . . . . . . f 140 192 5 32 0 142 192 1020150 FF 06 10 00 FF 0E 0E 00 . . . . . . . . 255 6 16 0 255 14 14 0

0158 0F 85 6F FF 07 1F 66 61 . . o . . . f 15 133 111 255 7 31 102 970160 C3 A0 F8 01 E8 09 00 A0 . . . . . . . . 195 160 248 1 232 9 0 160

0168 FB 01 E8 03 00 FB EB FE . . . . . . . . 251 1 232 3 0 251 235 2540170 B4 01 8B F0 AC 3C 00 74 . . . . . $ . " 180 1 139 240 172 60 0 1160178 09 B4 0E BB 07 00 CD 10 . . . . . . . . 9 180 14 187 7 0 205 16

0180 EB F2 C3 0D 0A 41 20 64 . . . . . A ; 235 242 195 13 10 65 32 1000188 69 73 6B 20 72 65 61 64 & , ; 105 115 107 32 114 101 97 1000190 20 65 72 72 6F 72 20 6F , , o , o 32 101 114 114 111 114 32 1110198 63 63 75 72 72 65 64 00 , , ; . 99 99 117 114 114 101 100 0

01A0 0D 0A 4E 54 4C 44 52 20 . . % O N D 13 10 78 84 76 68 82 32

01A8 69 73 20 6D 69 73 73 69 & & & 105 115 32 109 105 115 115 10501B0 6E 67 00 0D 0A 4E 54 4C n ? . . . % O N 110 103 0 13 10 78 84 7601B8 44 52 20 69 73 20 63 6F D & o 68 82 32 105 115 32 99 11101C0 6D 70 72 65 73 73 65 64 < , & & ; 109 112 114 101 115 115 101 100

01C8 00 0D 0A 50 72 65 73 73 . . . P , & & 0 13 10 80 114 101 115 115

01D0 20 43 74 72 6C 2B 41 6C C " , A 32 6 7 116 114 108 43 65 10801D8 74 2B 44 65 6C 20 74 6F " D " o 116 4 3 68 101 108 32 116 111

01E0 20 72 65 73 74 61 72 74 , & " , " 32 114 101 115 116 97 114 11601E8 0D 0A 00 00 00 00 00 00 . . . . . . . . 13 10 0 0 0 0 0 0

0 1 F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 001F8 83 A0 B3 C9 00 00 55 AA . . . . . . U . 131 160 179 201 0 0 85 170

.ollo7ing sli#es sho7s various parameters otaine# from <P<)

00F0 0F 85 0C 00 E8 B3 FF 80 . . . . . . . . 15 133 12 0 232 179 255 12800F8 3E 14 00 00 0F 84 61 00 > . . . . . . 62 2 0 0 0 15 132 97 00100 B4 42 8A 16 24 00 16 1F . B . . . . . 180 66 138 22 36 0 22 310108 8B F4 CD 13 66 58 5B 07 . . . . f K I . 139 244 205 19 102 88 91 70110 66 58 66 58 1F EB 2D 66 f K f K . . - f 102 88 102 88 31 235 45 102

0118 33 D2 66 0F B7 0E 18 00 3 . f . . . . . 51 210 102 15 183 14 24 00120 66 F7 F1 FE C2 8A CA 66 f . . . . . . f 102 247 241 254 194 138 202 1020128 8B D0 66 C1 EA 10 F7 36 . . f . . . . 6 139 208 102 193 234 16 247 540130 1A 00 86 D6 8A 16 24 00 . . . . . . . 26 0 134 214 138 22 36 00138 8A E8 C0 E4 06 0A CC B8 . . . . . . . . 138 232 192 228 6 10 204 1840140 01 02 CD 13 0F 82 19 00 . . . . . . . . 1 2 205 19 15 130 25 00148 8C C0 05 20 00 8E C0 66 . . . . . . f 140 192 5 32 0 142 192 1020150 FF 06 10 00 FF 0E 0E 00 . . . . . . . . 255 6 16 0 255 14 14 00158 0F 85 6F FF 07 1F 66 61 . . o . . . f 15 133 111 255 7 31 102 970160 C3 A0 F8 01 E8 09 00 A0 . . . . . . . . 195 160 248 1 232 9 0 1600168 FB 01 E8 03 00 FB EB FE . . . . . . . . 251 1 232 3 0 251 235 2540170 B4 01 8B F0 AC 3C 00 74 . . . . . $ . " 180 1 139 240 172 60 0 1160178 09 B4 0E BB 07 00 CD 10 . . . . . . . . 9 180 14 187 7 0 205 160180 EB F2 C3 0D 0A 41 20 64 . . . . . A ; 235 242 195 13 10 65 32 100

0188 69 73 6B 20 72 65 61 64 & ` , ; 105 115 107 32 114 101 97 1000190 20 65 72 72 6F 72 20 6F , , o , o 32 101 114 114 111 114 32 1110198 63 63 75 72 72 65 64 00 , , ; . 99 99 117 114 114 101 100 001A0 0D 0A 4E 54 4C 44 52 20 . . % O N D 13 1 0 78 84 76 68 82 3201A8 69 73 20 6D 69 73 73 69 & & & 105 115 32 109 105 115 115 10501B0 6E 67 00 0D 0A 4E 54 4C n ? . . . % O N 110 103 0 13 10 78 84 7601B8 44 52 20 69 73 20 63 6F D & o 68 8 2 32 105 115 32 99 111

01C0 6D 70 72 65 73 73 65 64 < , & & ; 109 112 114 101 115 115 101 10001C8 00 0D 0A 50 72 65 73 73 . . . P , & & 0 13 10 80 114 101 115 11501D0 20 43 74 72 6C 2B 41 6C C " , A 32 67 116 114 108 43 65 10801D8 74 2B 44 65 6C 20 74 6F " D " o 116 43 68 101 108 32 116 11101E0 20 72 65 73 74 61 72 74 , & " , " 32 114 101 115 116 97 114 11601E8 0D 0A 00 00 00 00 00 00 . . . . . . . . 13 10 0 0 0 0 0 001F0 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 001F8 83 A0 B3 C9 00 00 55 AA . . . . . . U . 131 160 179 201 0 0 85 170

Sector Per +"uster ; 0007 M#T +"uster D ;000c0000h;472('

Page 312: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 312/340

.or ;T.S simply the follo7ing formula 7ill e use# to translate the se$tor numer into

$luster numer)

ector H M Cluster H K ector *er Cluster 

(etermining the ector H fromCluster H

.ollo7ing sli#e sho7s ho7 the se$tor numer for the &.T on this volume 7as

$al$ulate#) The first lo$k of &.T no this volume is 629!/*6)

)0T Cluster H K ? M ector

?786 K ? M 76O5B7

76O5B6

(isassembling the 0ile

Page 313: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 313/340

/0 - 4isassemling the ;T.S ase# file

.rom the lo$k numer 629!/*6 entries 7ere sear$he# for TST)TNT an# this file entry

7as foun# at the lo$k numer 629!*20)

0000 46 49 4C 45 30 00 03 00 F ! N E 0 . . . 70 73 76 69 48 0 3 00008 55 55 12 04 00 00 00 00 U U . . . . . . 85 85 18 4 0 0 0 0

0 0 1 0 0 3 0 0 0 1 0 0 3 8 0 0 0 1 0 0 . . . . 8 . . . 3 0 1 0 5 6 0 1 0

0 0 1 8 7 0 0 1 0 0 0 0 0 0 0 4 0 0 0 0 < . . . . . . . 1 1 2 1 0 0 0 4 0 0

0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 2 8 0 6 0 0 0 0 0 0 2 0 0 0 0 0 0 0 . . . . . . . 6 0 0 0 3 2 0 0 0

0 0 3 0 0 A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 1 0 0 0 0 0 0 0 00 0 3 8 1 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 . . . . . . . 1 6 0 0 0 9 6 0 0 0

0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 0 4 8 4 8 0 0 0 0 0 0 1 8 0 0 0 0 0 0 . . . . . . . 7 2 0 0 0 2 4 0 0 0

0 0 5 0 E 1 3 E 2 9 2 B A D 1 2 C 6 0 1 . > P . . . . 2 2 5 6 2 4 1 4 3 1 7 3 1 8 198 1

0 0 5 8 0 3 8 6 7 D 3 F A D 1 2 C 6 0 1 . . + / . . . . 3 1 3 4 1 2 5 6 3 1 7 3 1 8 198 1

0 0 6 0 0 3 8 6 7 D 3 F A D 1 2 C 6 0 1 . . + / . . . . 3 1 3 4 1 2 5 6 3 1 7 3 1 8 198 1

0 0 6 8 0 B B 0 8 2 6 D B 7 1 2 C 6 0 1 . . . . . . . 1 1 1 7 6 1 3 0 10 9 1 8 3 1 8 198 10 0 7 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . 3 2 0 0 0 0 0 0 0

0 0 7 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 8 0 0 0 0 0 0 0 0 0 0 B 0 1 0 0 0 0 . . . . . . . . 0 0 0 0 1 1 1 0 0

0 0 8 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 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 9 8 3 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 . . . < . . . 4 8 0 0 0 1 1 2 0 0 0

0 0 A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 . . . . . . . . 0 0 0 0 0 0 4 00 0 A 8 5 2 0 0 0 0 0 0 1 8 0 0 0 1 0 0 U . . . . . . . 8 2 0 0 0 2 4 0 1 0

0 0 B 0 0 5 0 0 0 0 0 0 0 0 0 0 0 5 0 0 . . . . . . . . 5 0 0 0 0 0 5 0

0 0 B 8 E 1 3 E 2 9 2 B A D 1 2 C 6 0 1 . > P . . . . 2 2 5 6 2 4 1 4 3 1 7 3 1 8 198 10 0 C 0 E 1 3 E 2 9 2 B A D 1 2 C 6 0 1 . > P . . . . 2 2 5 6 2 4 1 4 3 1 7 3 1 8 198 1

0 0 C 8 E 1 3 E 2 9 2 B A D 1 2 C 6 0 1 . > P . . . . 2 2 5 6 2 4 1 4 3 1 7 3 1 8 198 10 0 D 0 E 1 3 E 2 9 2 B A D 1 2 C 6 0 1 . > P . . . . 22 5 6 2 4 1 4 3 1 7 3 1 8 198 1

0 0 D 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 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 0 E 8 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . 3 2 0 0 0 0 0 0 0

00F0 08 03 74 00 65 00 73 00 . . " . . & . 8 3 116 0 101 0 115 000F8 74 00 2E 00 74 00 78 00 " . . . " . T . 116 0 46 0 116 0 120 0

0100 74 00 2E 00 54 00 58 00 " . . . O . K . 116 0 46 0 84 0 8 8 00108 40 00 00 00 28 00 00 00 _ . . . S . . . 64 0 0 0 40 0 0 00110 00 00 00 00 00 00 05 00 . . . . . . . . 0 0 0 0 0 0 5 00118 10 00 00 00 18 00 00 00 . . . . . . . . 16 0 0 0 24 0 0 00120 06 B0 B6 4A 9B 7E DA 11 . . . . ( . . 6 176 182 74 155 126 218 170128 A9 46 00 50 8D 39 66 58 . F . P . 9 f K 169 70 0 80 141 57 102 88

0130 80 00 00 00 38 00 00 00 . . . . 8 . . . 128 0 0 0 56 0 0 00138 00 00 18 00 00 00 01 00 . . . . . . . . 0 0 24 0 0 0 1 00140 1E 00 00 00 18 00 00 00 . . . . . . . . 30 0 0 0 24 0 0 00148 68 65 6C 6C 6F 20 74 68 o " 104 101 108 108 111 32 116 1040150 69 73 20 69 73 20 61 20 & & 105 115 32 105 115 32 9 7 320158 4E 54 46 53 20 74 65 73 % O F M " & 78 84 70 83 32 116 101 115

0160 74 20 66 69 6C 65 00 00 " f . . 116 32 102 105 108 101 0 00168 FF FF FF FF 82 79 47 11 . . . . . @ G . 255 255 255 255 130 121 71 17

0170 2000 54 00 6500 78 00 . O. . T . 32 0 84 0 101 0120 0

0178 74 00 20 00 44 00 6F 00 " . . D . o . 116 0 32 0 68 0 111 0

0180 63 00 75 00 6D 00 65 00 . . . . 99 0 117 0 109 0 101 00188 6E 00 74 00 2E 00 74 00 n . " . . . " . 110 0 116 0 46 0 116 0

0 1 9 0 7 8 0 0 7 4 0 0 0 0 00 0 0 0 0 T . " .. . . . 12 0 0 1 1 6 0 0 0 0 0

0 1 9 8 8 0 0 0 0 0 0 0 1 8 0 0 0 0 00 . . . .. . . . 12 8 0 0 0 2 4 0 0 00 1 A 0 0 0 0 0 1 8 0 0 0 0 0 0 0 1 0 0 . . . . . . . . 0 0 2 4 0 0 0 1 0

0 1 A 8 0 0 0 0 0 0 0 0 1 8 0 0 0 00 0 . . . . . . . . 0 0 0 0 2 4 0 0 00 1 B 0 F F F F F F F F 8 2 7 9 4 7 1 1 . . . . . @ G . 25 5 2 5 5 2 5 5 25 5 1 3 0 1 2 1 7 1 1 7

0 1 B 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 1 C 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 C 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 1 D 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 D 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 1 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 00 1 E 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 1 F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . . . . . . . . 0 0 0 0 0 0 0 0

0 1 F 8 0 0 0 0 0 0 0 0 0 0 0 0 0 A 0 0 . . . . . . . . 0 0 0 0 0 0 1 0 0 2 2 2 2 2 2

The aove #ump sho7s the file name as 7ell as the $ontents of the file are store# in this

entry) as the file een larger it 7oul# not have een possile 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)

Page 314: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 314/340

/0 - 4isassemling 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

 Accessing /T0 volume in (#

W ;T.S volume $an not e a$$esse# in 4(S

using 4(S ase# fun$tion like asrea#1 3

et$)

W 4(S #evi$e #rivers #oes not un#erstan#

the ;T.S #ata stru$tures like &.T et$)

W "f ;T.S volume is a$$esse# in 4(S% it 7ill

fire the error of "nvali# &e#ia)

>ow to Access /T0 volume using$!# 0unctions

W "f the system has oote# in 4(S then a ;T.S volume $an e a$$esse# y an "n#ire$t

&etho#% using <"(S fun$tions))

W This te$hniue makes use of physi$al

a##resses)

W Se$tor $an e a$$esse# y $onverting their

S; into <8 a##ress an# then using the

<8 a##ress in e:ten#e# <"(S fun$tions to

a$$ess the #isk se$tors)

Page 315: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 315/340

/0 - 4isassemling the ;T.S ase# file

Translating 9/ to 9$A

/T0 *artition $loc'#ther 0ile ystem

@o= of Physica" 9"oc3s

for other Partition

5idden 9"oc3s

<8 @ ;o) of Physi$al <lo$ks in other Partition K

i##en <lo$ks K S;

W 8ll this information $an e retrieve# from the

Partition Tale K <oot <lo$k 

Page 316: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 316/340

/0 - 4isassemling the ;T.S ase# file

1 - %is3 )ti"ities

Dinc"ude Vstdio=hQDinc"ude Vdos=hQ

Dinc"ude Vios=hQDinc"ude Va""oc=hQ

ty!edef struct tagfc

un signe d cha r fi"e name 7UJ

unsigned char e>t(UJ

unsigned char attriJ

unsigned char reser&ed 10UJ

unsigned int time,dateJ

unsigned int firstc"usterJ

unsigned "ong int sieJ

N#+9J

ty!edef struct tag9P9

un signed int yte s!er secJ

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"ae"11UJ

unsigned char fi"esystem7UJ

N9P9J

struct oot"oc3

unsigned char um!inst(UJ

unsigned char osname7UJ

9P9 !J

unsigned char code7UJ

NJ

%P9 far H getd!int dri&e

%P9 far Hd!;%P9 far H0J

 Rasm !ush d sJ

 Rasm mo& ah,0>('

 Rasm mo& d",yte !tr dri&eJ

 Rasm mo& d>,d sJ

 Rasm int 0>'1J

 Rasm !o! ds

 Rasm cm! a",0> ff 

 Rasm e finish

 Rasm mo& 6ord !tr d!B',d>

 Rasm mo& 6ord !tr d!,>

return d!J

finishC

return %P9 far H0J

N

Page 317: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 317/340

/0 - 4isassemling the ;T.S ase# file

&oid main &oid

unsigned char fi"ename8UJ

struct oot"oc3 J

unsigned char e>tUJ#+9 H dirufferJ

unsigned int H #TJ

%P9 dJ

%P9 far H d!!trJ

int i,f"agJ

unsigned int c"usterJ

!uts:nter fi"enameCJ

gets fi"ename J

!uts:nter :>tensionJ

getse>tJ

if asread0>0.,1,0,;;0

!uts SuccessJ

e"se

!uts#ai"ureJ

e>it0J

N

#T ;ma""oc.1'J

diruffer;ma""oc=!=rootdirents H ('Jasread0>0.,=!=fatsecs,=!=reser&edsecsB1,#TJ

asread0>0.,=!=rootdirentsH('/=!=ytes!ersec,=!=fatsecsH=!=fatsB=!=reser&edsecs ,dirufferJ

i ; 0J f"ag;0J

6hi"eiV=!=rootdirents

ifstrncm!ifi"ename,dirufferiU=fi"ename,str"enfi"ename;;0

if strncm!ie>t,dirufferiU=e>t,str"ene>t;;0

f"ag;1J

c"uster ; dirufferiU=firstc"usterJ!rintfn#irst c"uster ; > ,c"usterJ

6hi"e c"uster V 0>###0

asread0>0.,1,=!=reser&edsecsBc"uster/'.2,#TJ

c"uster ; #Tc"uster'.2UJ!rintf n@e>t +"uster is C>,c"usterJ

N

N

if f"ag ;;1

rea3J

iBBJ

Ne"se

iBBJ

N

N

The aove 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 seuential sear$h) "f the file name an# e:tension is foun# the first

$luster numer is use# to look up into the .8T for suseuent $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#)

Page 318: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 318/340

/0 - 4isassemling the ;T.S ase# file

(is' +tilities.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)

W ui$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)

(is' *artitioning oftwareW >rite the $o#e part of partition tale to

appropriately loa# the <oot <lo$k of a$tive partition in primary partition tale)

W Pla$es #ata in the partition tale regar#ing

 primary an# e:ten#e# partitions)

W 8s per spe$ifi$ation of the user assigns a

appropriate si=e to primary an# e:ten#e#

 partition y mo#ifying their #ata part)

Page 319: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 319/340

/0 - 4isassemling the ;T.S ase# file

can (is'urface can for $ad ectors

W It attempts to -rite a )ock2

W After -rite it rea*s )ack the )ock contents2W 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 pacing the

appropriate co*e for )a* c"ster so that they

may not )e aocate* to any fie2

9ost ChainsW 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)

9oo'ing for 9ost ChainsW .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#)

Page 320: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 320/340

/0 - 4isassemling the ;T.S ase# file

Cross eferencesW "f a $luster lie in more than one file

$hain% then its sai# to e Cross

,eferen$e#)

W Cross referen$es $an pose great prolems)

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

then it in#i$ates a $ross referen$e)

W To solve the prolem only one referen$e

shoul# e maintaine#)

5

3#0

O

B(

.

4

11

1(

1

(efragmenterW Disk fragmentation is "n-ante*2

W 9ragmentation means that c"sters of a same fie are not

contig"o"sy pace*= rather they are far apart= increasing seek

time hence access time2

W So its *esira)e that fies c"sters may )e pace* contig"o"sy=

this can )e *one )y compaction or *efragmentation2

W Defragmentation Soft-are reser;es space for each fie 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 ocaiBe* c"ster tore*"ce seek time2

W Defragmentation has high comp"tation cost an* th"s cannot

)e performe* freZ"enty2

0ile estorationW 9A, str"ct"re pro;i*es the possi)iity of reco;ering a fie

after *eetion= if its c"sters -ere contig"o"s an* ha;e not )een

o;er?-ritten2W DOS perform fie *eetion )y pacing $<>: at the first )yte of

it 9C. entry an* pacing $_s 6meaning a;aia)e7 in the entries

for the fie c"sters in the 9A,2

W ,-o task sho"* )e performe* s"ccessf"y to "n*eete a fie

?? Repacing the $<>: entry in 9C. )y a ;ai* fie name

character2

?? pacing the appropriate ;a"es in 9A, for

representation of fie c"ster chain2

W If any one of the a)o;e cannot )e *one then the fie cannot )e

f"y reco;ere*2

Page 321: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 321/340

/0 - 4isassemling the ;T.S ase# file

' - Memory Management

)emory )anagementW Un#erstan#ing of the #ata stru$tures an#

te$hniues use# for memory management)

W Stu#y of the overall memory areas use# y

operating system an# appli$ations)

The follo7ing sli#e sho7s the memory map of the first !&< of ,8&) The first 6/0< is

$alle# $onventional ,8& an# the higher +/< is $alle# system memory) Some of the

memory areas are reserve# for spe$ial purposes as #es$rie# y the sli#e rest is user area

7here user appli$ation $an resi#e)

)emory )ap

Shado6 *M

)nused

Te>t %is!"ay

ra!hics %is!"ay

+ommand=+om

Transient Part

)ser !!"ications

+ommand=+om *esident

Part

Other %e&ice %ri&ers

MS%OS=Sys

IO=Sys

%OS %ata rea

9IOS %ata rea

I$T

3arlier *Cs % 6 bit Address $us

Converted A)% 7 E$ &

ystem )emory% 8? E$ &

@ >

O @ 0000>

 A @ >

0 @ >

0 @ 0000>

Page 322: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 322/340

/0 - 4isassemling 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 6bit or 86bit Address $us

3panded )emory %7 E$&

3tended )emory%higher than 5 )$&

Conventional A) %7 E$&

ystem A) %8? E$&

3panded )emoryW also $alle# &S

W $an e a$$esse# using a #river $alle# &&+6)N

W this #river allo7s the use of unuse# memory 7ithin

system memory)

3tended )emoryW also $alle# N&S

W $an e a$$esse# y installing the #river "&&)SGS

W this #river enale the e:ten#e# memory y shifting from

,eal to Prote$te# &o#e)

Page 323: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 323/340

/0 - 4isassemling the ;T.S ase# file

(ual )odes in >igher *Csigher PCs $an operate in t7o mo#es

W ,8 &(4

W P,(TCT4 &(4

eal )odeW 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 "&&)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)

*rotected )odeW 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$$essile thatin$lu#es the Conventional% :pan#e# an# :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)

Page 324: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 324/340

/0 - 4isassemling the ;T.S ase# file

)emory )anagement in (#W 4(S uses the $onventional memory first 6/0 < for its

memory management)

W 8##itional 6/ < $an e utili=e# y installing

&&+6)N an# a##itional 6/ < in the start ofe:ten#e# memory y installing "&&)SGS

W Smallest allo$atale unit in 4(S is a Paragraph% not a

<yte)

*aragraphW >henever memory is to e allo$ate# 4(S allo$ates memory in form of

Paragraph)

W 8 Paragraph $an e u n#erstoo# from the follo7ing e:ample

$onsi#er t7o Phys i$al 8##ress es

!2+/ D 0000

!2+* D 0000

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

!2+*0

4ifferen$e @ !0

W 8 #ifferen$e of ! in Segment a##ress $ause a #ifferen$e of !0 in Physi$al

a##ress)W 4(S loa#er assign a seg ment a##ress 7henever memory area is allo$ate#%

hen$e a $h ange of ! in Segment a##ress 7ill impart a # ifferen$e of !6 4 _ !0

in physi$al a##ress)

(ata tructures for )emory)anagement

W 4(S makes use of various 4ata Stru$tures for &emory

&anagementD

W &C< 1 &emory Control <lo$k 3

W < 1 nvironment <lo$k 3

W PSP 1 Program Segment Prefi: 3

Page 325: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 325/340

/0 - 4isassemling the ;T.S ase# file

)C$ or Arena >eader W &C< is use# to $ontrol an allo$ate# lo$k in memory)

W very allo$ate# lo$k 7ill have a &C< efore the start

of lo$k)

W &C< is a !6-ytes large stru$ture)

eserved or contains the program name in

case of higher versions of (#.

B$yte Z55[

Contains number of *aragraphs controlled by

the )C$.

8Word

Contains the egment address of the **

and the program controlled by )C$.

5Word

Contains G)- if the )C$ controls allocated

memory and G^- if it controls free space.

$yte

OffsetSie

3nvironment $loc'W Contains nvironment information like nvironment

variales an# file paths for that program

**W is situate# efore the start of a pro$ess)

W $ontains $ontrol information like 4T8 1 4isk Transfer

8rea3 an# $omman# line parameters)

Page 326: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 326/340

/0 - 4isassemling 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 nvironment <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)

Typical )emory #rganization

0ree

^

*rogram

**

)

3.$

)

*rogram

**

)

3.$

)

 All the )C$ forms a chain. !f the address of first )C$ is 'nown the segment

address of net )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.

>ow to Access the tart of ChainW 8n #o$umente# servi$e $an e use# to otain the

a##ress of the first &C<)

W Servi$e 2!'*2 is use# for this purpose)

W This servi$e returns

The a##ress of 4(S internal #ata stru$tures in S D <N

W /-ytes ehin# the a##ress returne# lies the far a##ressof 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)

Page 327: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 327/340

/0 - 4isassemling the ;T.S ase# file

-13B0:0100 o #52

13B0:0102 n" 2113B0:0104

-< AKL5200 BKL0000 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13B0 EML13B0 MML13B0 CML13B0 !PL0102 %) UP E! PN %H %A P %C

13B0:0102 CD21 !%O 21

-< AKL5200 BKL0026 CKL0000 DKL0000 MPLFFEE BPL0000 M!L0000 D!L0000DML13B0 EML00A7 MML13B0 CML13B0 !PL0104 %) UP E! PN %H %A P %C13B0 :01 04 0 000 AD D IB K M!Q #A N

DM:0026LFF

-; 7:2200A7:0020 00 00 08 02 EA 15-A7 00 CE 00 A7 00 5A 00 ............H.00A7:0030 70 00 24 00 70 00 80 00-00 00 00 00 00 00 7C 03 <..<.........|.00A7:0040 00 00 72 03 00 00 04 04-00 00 D9 02 04 80 C6 0D ..,.............

00A7:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..%UN ......00A7:0060 00 AB 73 03 0E 00 00 00-00 03 01 00 04 00 00 00 ..&.............00A7:0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................00A7:0080 00 FF FF 00 00 00 00 0E-00 00 00 05 FF 9F 08 02 ................00A7:0090 82 14 D3 28 2E FE D7 28-2E FE D7 28 2E FE D3 28 ...S...S... S...S00A7:00A0 2E FE ..

-q 

The aove sli#e sho7s ho7 servi$e 2!'*2 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 numer 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:00208:0000 4D 08 00 03 02 09 0E 1F-53 44 00 CD 21 EB FE 26 .......MD. .*..0208:0010 51 0A 02 CE 00 9A F0 FE-4B 42 44 00 08 02 53 25 .......JBD ...MX0208:0020 281810 00080803 00-02672D 2728902B A0 S........?-]S..

0208:0030 BF1F00 4F0D0E00 00-00 009CAE8F 141F96 ...............0208:0040 B9A3FF 00010203 04-05 14073839 3A3B3C ...........89:$

0208:0050 3D3E3F 0C000F08 00-00 00000010 0E00FF L>/.............0208:0060 501810 00100003 00-02 675F4F50 825581 P........?RP.U.0208:0070 BF1F00 4F0D0E00 00-00 009C8E8F 281F96 ............S..

-D 40C:0040C:0000 4D 0D 04 A2 00 00 06 00-43 4F 4D 4D 41 4E 44 00 .......CA%D.040C:0010 CD 20 FF 9F 00 9A F0 FE-1D F0 7F 01 0D 04 4B 01 . ............J.040C:0020 0D0456 010D040D 04-01 03010002 FFFFFF ..).............

040C:0030 FFFFFF FFFFFFFF FF-FFFFFF FFB804FA 05 ................040C:0040 0D0414 0018000D 04-FF FFFFFF00 000000 ................

040C:0050 050000 00000000 00-000000 00000000 00 ................040C:0060 CD21CB 00000000 00-000000 00002020 20 .*...........0 40 C: 00 7 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 -0 0 0 0 0 0 0 0 0 0 2 0 2 0 2 0 . . .. .

-D 4AF:004AF:0000 4D 00 00 07 00 73 1A 52-65 71 75 69 72 65 64 20 ....&.q,; 04AF:0010 00 01 00 00 00 00 00 00-87 06 00 00 FF FF FF FF ................04AF:0020 FFFFFF FFFFFFFF FF-FFFFFF FFFFFFFF FF ................

04AF:0030 433A5C 57494E44 4F-57 535C5445 4D505C C:\W!%DWM\OEP\04AF:0040 736373 352E746D 70-00 00000000 000000 &&5."<........

04AF:0050 000000 00000000 00-000000 00000000 00 ................04AF:0060 000000 00000000 00-000000 00000000 00 ................04AF:0070 002076 616C7565 20-6E 6F742061 6C6C6F . no"o

-D 4B7:004B7:0000 4D 0D 04 6D 00 61 72 61-6D 65 74 65 72 20 76 61 ...,", 04B7:0010 43 4F 4D 53 50 45 43 3D-43 3A 5C 57 49 4E 44 4F CMPECLC:\ W!%D04B7:0020 57535C 53595354 45-4D 33325C43 4F4D4D WM\MMOE32\C 

04B7:0030 414E44 2E434F4D 00-41 4C4C5553 455253 A%D.C.ANNUMEM04B7:0040 50524F 46494C45 3D-43 3A5C444F 43554D PF!NELC:\DCU 

04B7:0050 457E31 5C414C4C 55-53457E 31004150 50 E(1\ANNUME(1.APP04B7:0060 444154 413D433A 5C-44 4F43554D 457E31 DAOALC:\DCUE(104B7:0070 5C7964 6B5C4150 50-4C 49437E31 00434F \@;`\APPN!C(1.C

-D 525:00525:0000 4D 26 05 7A 08 8E DB C5-44 4F 53 58 00 58 5B 1F .....DM K.KI.0525:0010 CD20A0 0D009AC0 00-00 00DE010D 044B01 . ............J.

0525:0020 0D0456 010D040D 04-01 01010002 FFFFFF ..).............0525:0030 FFFFFF FFFFFFFF FF-FFFFFF FF12D2E8 00 ................0525:0040 360514 00180026 05-FF FFFFFF00 000000 6..............

0525:0050 050000 00000000 00-000000 00000000 00 ................0525:0060 CD21CB 00000000 00-000000 00032020 20 .*...........

0 52 5: 00 7 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 -0 0 0 0 0 0 0 0 0 0 2 0 2 0 2 0 . . .. .

-D DA0:00DA0:0000 4D 03 0E 61 00 61 6E 6E-6F 74 20 72 75 6E 20 74 ...nno" ,n "0DA0:0010 43 4F 4D 53 50 45 43 3D-43 3A 5C 57 49 4E 44 4F CMPECLC:\ W!%D0DA0:0020 57535C 53595354 45-4D 33325C43 4F4D4D WM\MMOE32\C 0DA0:0030 414E44 2E434F4D 00-41 4C4C5553 455253 A%D.C.ANNUMEM0DA0:0040 50524F 46494C45 3D-43 3A5C444F 43554D PF!NELC:\DCU 

0DA0:0050 457E31 5C414C4C 55-53457E 31004150 50 E(1\ANNUME(1.APP0DA0:0060 444154 413D433A 5C-44 4F43554D 457E31 DAOALC:\DCUE(1

0DA0:0070 5C7964 6B5C4150 50-4C 49437E31 00434F \@;`\APPN!C(1.C

-D E02:00E02:0000 5A 03 0E FC 91 27 8A 05-44 45 42 55 47 00 9D 00 H....]..DEB UG...0E02:0010 CD20FF 9F009AF0 FE-1D F0DE010D 044B01 . ............J.

0E02:0020 0D0456 010D040D 04-01 03010002 FFFFFF ..).............0E02:0030 FFFFFF FFFFFFFF FF-FFFFFF FFA10DB9 49 ...............!

0E02:0040 140E14 00180003 0E-FF FFFFFF00 000000 ................0E02:0050 050000 00000000 00-000000 00000000 00 ................

0E02:0060 CD21CB 00000000 00-000000 00002020 20 .*...........0 E0 2: 00 7 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 -0 0 0 0 0 0 0 0 0 0 2 0 2 0 2 0 . . .. .-

Page 328: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 328/340

/0 - 4isassemling the ;T.S ase# file

( - @on-+ontiguous memory a""ocation

Hinclude Istdio.hJHinclude Iconio.hJ

Hinclude Ibios.hJHinclude Idos.hJ

typedef struct tag)C$ Nunsigned char sig;

unsigned int pspseg;unsigned int paras;

unsigned char reservedZ55[;P)C$;

void main %void&N

unsigned int seg,off;unsigned int far K temp;

unsigned long i;char stZ6[;)C$ far K pm cb; YA>MB6 ;geninterrupt%65&;

seg M Y3;off M Y$D;

off M off ;temp M %unsigned int far K& )EY0*%seg,off&;

seg M K%tempQ5&;pm cb M %)C$ far K&)EY0*%seg,Ktemp&;while %pmcbJsig MM _)_&

Nprintf%negme nt Address of ** is U,pmcbJpspseg&;

printf%n/o of *aras controlled by )C$ M Un,pmcbJparas&;seg M seg Q pmcbJparas Q 5;pm cb M %)C$ far K&)EY0*%seg ,Ktemp&;

Pif %pmcbJsig MM _^_&N

printf%n9ast )C$ found&;

printf%n/o of free *aras M U,pmcbJparas&;i M %pmcbJparas&K579;ltoa%i,st,5&;printf%n9argest contigous bloc' M &;puts %st&;

PP

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 suseuent &C<s an# traverse the &C<s to rea$h

the last &C<)

Page 329: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 329/340

/0 - 4isassemling the ;T.S ase# file

/onContiguous AllocationW arlier (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 availale to a$$ommo#ate it)

W 026 an# higher pro$essors support non-$ontiguous allo$ation)

W 026 support Segmentation in Prote$te# &o#e% i)e) a pro$ess is

su#ivi#e# into segment of variale si=e an# ea$h segment or fe7

segments of the pro$ess $an e pla$e# any7here in memory

W 0+6 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 :e$ution)

W The key to su$h non-$ontiguous allo$ation systems is the

a##ressing te$hniue)

 Address TranslationW "n Prote$te# &o#e the #ire$t metho# of

seg E !0 K offset for ogi$al to Physi$al

a##ress translation is #is$ar#e# an# an

in#ire$t metho# is a#opte#)

Page 330: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 330/340

Page 331: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 331/340

The follo7ing sli#e sho7s the stru$ture of #es$riptors of 026 an# 0+6 pro$essors

9imit %95B ] 9&

$ase %$5B ] $&

 Acces s $as e%$68$57&

ights

eserved

9im %95B ] 9&

$ase %$5B ] $&

 Access $as e%$68$57&

ights

9ase Limit

9' <9(1 % 0 $ L12 <L18

L7

6

B

8

5

?6?7 (escriptor 

W <ase 1<+! <03 $ontains the ase a##ress of Segment 7ithin the

/F< Physi$al spa$e)

W imit 1!9 03 #efine the length of segment in units of ytes

if F @ 0 an# in units of / 1pages3 if F@ !)

This allo7 the Segment to e of !& if F @ 0 an# of /F if F @ !)

?8?7 ( escriptor 

7

6

B

8

5

(escriptorW 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 / times the limit fiel#) "f F @ 0 multiplier is !A if F @ !

multiplier is /)

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 8VD the (perating System o ften uses this it to

in#i$ate that the segment #es$rie# y the 4es$riptor is availale in

memory

Page 332: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 332/340

/+ - ;on-Contiguous memory allo$ation

egment (escriptor W "f the 4es$riptor #es$ries a memory segment then the 8$$ess ,ights <yte 7ill

have the follo7ing meaning)

W PD Present it% if P @ ! Segment is Present%if P @ 0 Segment is not Present)

W 4PD 4es$riptor Privilege level 00 for highest an# !! for lo7est ) o7

 privilege level memory area $an not a$$ess a memory area 7ith high

 privilege 7hereas vi$e versa is T,U)

W SD "n#i$ates #ata or $o#e segment if S @ ! or a System 4es$riptor if S @ 0)

W D :e$utale% if @ 0 Then itMs a 4ata'Sta$k Segment%

if @ ! Then itMs a Co#e Segment)

W ND "f @ 0 then N in#i$ates the #ire$tion of e:pansion of the Segment)

"f N @ 0 Segment e:pan#s up7ar#s 1i)e) 4ata Segment3

"f N @ ! Segment e:pan#s #o7n7ar#s 1i)e) Sta$k Segment3

"f @! then N in#i$ates if the privilege level of Co#e Segment is

ignore# 1N @ 03 or oserve# 1N @ !3)

W 8 8$$esse# is set 7henever the Segment is set)

 AWD3(*

9

*

9im %95B ] 9&

$ase %$5B ] $&

9ase9'(-912

P %PL 0 TKP:

9ase Limit

9' < 9(1 0 0 0 L12 <L18 7

6

B

8

5

ystem (escriptor S Access $yte

(escriptor TableW F4TD Floal 4es$riptor Tale

W 4TD o$al 4es$riptor Tale

W "4TD "nterrupt 4es$riptor TaleW F4T an# 4T $an have up to !92 entries% ea$h of -

 ytes 7i#th)

W "4T $an have up to 2*6 entries)

Page 333: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 333/340

/+ - ;on-Contiguous memory allo$ation

- ddress trans"ation in Protected mode

elector W 8 Sele$tor is $alle# a Sele$tor e$ause it a$ts as an

in#e: into the 4es$riptor Tale to sele$t a F4T or 4T

entry)

*9T!

5B 6 5

equested *rivilege 9evel

%>ighest&55 %9owest&

T! M 2lobalT! M 5 9ocal

elector !nde

elects a (esc riptor Table entry0rom 9(T or 2(T

Segment *egister 

Page 334: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 334/340

/+ - ;on-Contiguous memory allo$ation

 Address Translation in*rotected )ode

W 8ll the tales are maintaine# in &ain &emory)

W Segment ,egisters are use# as Sele$tors)W The 4es$riptor ntry sele$te# from the 4es$riptor Tale

is pla$e# in a hi##en $a$he to optimi=e a##ress

translation)

Page 335: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 335/340

Page 336: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 336/340

// - 8##ress translation in Prote$te# mo#e

Control egisterW 0+6 an# aove 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 ere 7e 7ill illustrate only the least signifi$ant it of

C,0)

W The least signifi$ant it of C,0 is P-it 7hi$h $an e

set to enale Prote$te# &o#e 8##ressing an# $an e

$leare# to enter ,eal &o#e)

*3

C

)oving to *rotected )odeW Prote$te# &o#e $an e entere# y setting the P it of C,0% ut

 efore this some other initiali=ation must e #one) The follo7ing

steps a$$omplish the s7it$hing from ,eal to Prote$te# &o#e

$orre$tly)!) "nitiali=e the "nterrupt 4es$riptor Tale% so it $ontains vali# "nterrupt

gates for at least the first +2 "nterrupt type numers) The "4T may

$ontain up to 2*6% -yte interrupt gates #efining all 2*6 interrupt

types)

2) "nitiali=e the F4T% so it $ontains a ;U 4es$riptor% at 4es$riptor 0an# vali# 4es$riptor for at least one 4ata an# one Sta$k)

+) S7it$h to Prote$te# y setting the P-it in C,0)

/) Perform a "ntraSegment 1near3 c&P to flush the "nternal Pre-fet$hueue)

*) oa# all the 4ata Sele$tors 1Segment ,egisters3 7ith their initialSele$tors Values)

6) The 0+6 is no7 in Prote$te# &o#e)

1irusesW Viruses are spe$ial program having aility to eme#

themselves in a system resour$es an# there on propagate

themselves)

State of VirusesW 4ormant StateD 8 Virus in #ormant state has

eme##e# itself 7ithin an# is oserving 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)

Page 337: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 337/340

// - 8##ress translation in Prote$te# mo#e

. - $iruses

Types of 1irusesW Partition Tale Virus

W <oot Se$tor VirusW .ile Viruses

>ow *artition Table 1irus Wor'sW ,he Partition ,a)e Co*e is e<ec"te* at )oot time to choose the Acti;e Partition 2

W Partition ,a)e Vir"ses em)e* themse;es in the Partition ,a)e of the *isk2

W If the Vir"s Co*e is arge an* cannot )e accommo*ate* in the Co*e Part of :&4?

)ytes Partition ,a)e )ock then it may aso "se other Physicay A**resse * .ocks

to resi*e itsef2

W (ence at .oot time -hen Partition ,a)e is to )e e<ec"te* to seect the Acti;e

Partition= the ;ir"s e<e c"tes2 ,he Vir"s -hen e<ec"te* oa*s itsef in the Memory=

-here it can not )e reache* )y the OS an* then e<ec"tes the origina Partiti on ,a)e

Co*e 6store* in some other )ocks after infection7 so that the system may )e )oote*

propery2

W +hen the system )oots the Vir"s -i )e resi*ent in memory an* -i typicay

intercept &5( 6the *is k interr"pt72

W +hene;er a *isk operation occ"rs in t &5( occ"rs2 ,he Vir"s on occ"rrence of &5(

checks if remo;a)e me*ia has )een accesse* thro"gh int &5(2 If so then it -i copy

its co*e propery to the *isk first Physica .ock 6an* other )ocks *epen*ing "pon

siBe of Vir"s Co*e72 ,he remo;a)e *isk is no- infecte*2

W If the *isk is no- remo;e* an* is then "se* in some other system= the (ar* Dri;e

of this system -i not )e infecte* "ness the system is )oote* from this *isk2 .e ca"se

ony on )ooting from this remo;a)e *i sk its first physica )ock -i get the chance

to )e e<ec"te*2

>ow *artition Table 1irus 9oads

itself W The transient part of Comman#)Com loa#s itself su$h that its

last yte is loa#e# in the last yte of Conventional &emory) "f

someho7 there is some &emory eyon# Comman#)ComMs

transient part it 7ill not e a$$essile y 4(S)

W 8t /0D!+ a 7or# $ontains the amount of <s in

Conventional &emory 7hi$h is typi$ally 6/0)

W "f the value at /0D!+ is someho7 re#u$e# to 6+ the

transient part of Comman#)Com 7ill loa# itself su$h that its

last yte is loa#e# at the last yte of 6+< mark in

Conventional ,8&)

W "n this 7ay last 2< 7ill e left unuse# y 4(S) This

amount of memory is use# y the Virus a$$or#ing to its o7n

si=e)

Page 338: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 338/340

// - 8##ress translation in Prote$te# mo#e

>ow $oot ector 1irus Wor'sW <oot Se$tor also 7orks in almost the same pattern% the

only #ifferen$e is that it 7ill eme# itself 7ithin the <oot

<lo$k Co#e)

0ile 1irusesW Various Viruses eme#s themselves in #ifferent

e:e$utale files)

W Theoreti$ally any file that $an $ontain any e:e$utale

$o#e% a Virus $an e eme##e# into it) i)e) )C(&% )N

are e:e$utale files so Viruses $an e eme##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

eme##e# into them% an# even if they are someho7

eme##e# they 7ill never get a $han$e to e:e$ute itself)

C#) 0ileW 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#ean# 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

Page 339: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 339/340

// - 8##ress translation in Prote$te# mo#e

>ow C#) 0ile 1irus !nfects0iles

W 8 C(& .ile Virus if resi#ent may infe$t C(& .iles on

e:e$ution)

W Typi$ally C(& .ile Virus 7ill "nterrupt 2! Servi$e

/<) This Servi$e is use# to loa# a Program)

W >henever a Program is to e oa#e# int 2! Servi$e H

/< is use# to oa# a Program) The Virus if resi#ent 7ill

$he$k the parameters of this Servi$e to get the file path) "f

the .ile is )C(& .ile then the Virus appen#s itself to the

file an# tempers 7ith the first +-ytes of )C(& .ile so

that the e:e$ution ran$hes to the Virus Co#e 7hen the

 program is e:e$ute#)

>ow C#) 1irus 9oads !tself W >hen a file is oa#e# in &emory it 7ill o$$upy a numer of

Paragraphs $ontrolle# y some &C<)

W "f the file is infe$te# the Virus is also loa#e# 7ithin the &emory

8rea allo$ate# to the Program)

W "n this $ase the Virus #oes not e:ist as an "n#epen#ent Program as

it #oes not have its o7n PSP) "f the Program is terminate# the Virus

Co#e 7ill also e unloa#e# 7ith the program) The Virus 7ill try to

attain an "n#epen#ent Status for 7hi$h it nee#s to relo$ate itself an#

$reate its o7n PSP an# &C< in &emory)

W >hen the program runs the Virus Co#e e:e$utes first) The Virus

$reates an &C<% #efines a ne7 PSP initiali=es the PSP an#relo$ates itself% up#ates the last &C<% so that it $an e:ist as an

"n#ivi#ual Program% an# then transfers the e:e$ution a$k to the

(riginal Program Co#e)

W ;o7 if the (riginal Program Terminates the Virus 7ill still

remain resi#ent)

Page 340: System Programming - CS609 Handouts[1]

8/13/2019 System Programming - CS609 Handouts[1]

http://slidepdf.com/reader/full/system-programming-cs609-handouts1 340/340

// - 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)

0ree *aras

^

1irus **

*rogram

**

)

0ree *aras+pdated

^

**

1irus

)

**

)

*aras

>ow the 1irus elocates itself 

3D3 0ile 1irusesW The N .ile Viruses also 7orks the same 7ay in

relo$ating themselves)

W The main #ifferen$e in C(& .ile an# 4(S N .ile is

that the C(& .ile starts its e:e$ution from the first

instru$tion% 7hereas the entry point of e:e$ution in N

.ile $an e any7here in the Program)

W The entry point in $ase of N .ile is tempere# y the

Virus 7hi$h is store# in a 25-yte hea#er in N .ile)