3.2machine-dependent loader features

12
1 Machine-dependent loader features 2 Relocation Loaders that allow for program relocation are called relocating loaders or relative loaders. The need for program relocation is a consequence of the change to larger and more powerful computers. We would like to run several programs on a more advanced machine.

Upload: abhishek-gera

Post on 18-Nov-2014

3.678 views

Category:

Documents


36 download

TRANSCRIPT

Page 1: 3.2Machine-Dependent Loader Features

1

Machine-dependent loader features

2

Relocation

Loaders that allow for program relocation are called relocating loaders or relative loaders.The need for program relocation is a consequence of the change to larger and more powerful computers.• We would like to run several programs on a

more advanced machine.

Page 2: 3.2Machine-Dependent Loader Features

2

3

Schemes for relocationModification record• A modification record is used to describe each part of

the object code that must be changed when the program is relocated.

Relocation bit• A relocation bit associated with each word of object

code is used to indicate whether or not this word should be changed when the program is relocated.

Hardware relocation• Some computers provide a hardware relocation

capability that eliminates some of the need for the loader to perform program relocation.

4

Modification recordIn the object program, there is one Modification record for each value that must be changed during relocation.Each modification record specifies the starting address and length of the field whose value is to be altered.

Col. 1 MCol. 2-7 Starting location of the address field to be modified, relative to the

beginning of the program Col. 8-9 Length of the address field to be modified, in half-bytes

If the field contains an odd number of half-bytes, the starting location begins in the middle of the first byte.

Col. 1 MCol. 2-7 Starting location of the address field to be modified, relative to the

beginning of the program Col. 8-9 Length of the address field to be modified, in half-bytes

If the field contains an odd number of half-bytes, the starting location begins in the middle of the first byte.

Page 3: 3.2Machine-Dependent Loader Features

3

5

Object program with relocation by Modification record

Relocatable

the same as the absolute program with starting address 0

Modification records

6

Example of a SIC/XE program (1/3)

actual address

Page 4: 3.2Machine-Dependent Loader Features

4

7

Example of a SIC/XE program (2/3)

8

Example of a SIC/XE program (3/3)

Page 5: 3.2Machine-Dependent Loader Features

5

9

Relocatable program for a standard SIC machine

The standard SIC machine does not use relative addressing. Therefore, in this program the addresses in all the instructions except RSUB must be modified when the program is relocated. This would enlarge the size of the object program.

10

Relocation bitOn a machine that • primarily uses direct addressing and • has a fixed instruction format,

it is often more efficient to specify relocation using the technique of the relocation bit.A relocation bit associated with each word of object code is used to indicate whether or not this word should be changed when the program is relocated.• If the relocation bit corresponding to a word of object code is

set to 1, the program’s starting address is to be added to this word when the program is relocated.

• A bit value of 0 indicates that no modification is necessary.• The bits corresponding to unused words are set to 0.

Page 6: 3.2Machine-Dependent Loader Features

6

11

Object program with relocation by bit mask

1111111111002

bit mask

111111111100

1110000000002111000000000

each relocation bit is associated with a 3-byte segment of object code in the Text record.

does not coincide with a 3-byte segment

12

Program linking

To link control sections together.• External definition• External reference

The assembler evaluate as mush of an expression as it can. The remaining terms are passed on to the linking loader via Modification records.

Page 7: 3.2Machine-Dependent Loader Features

7

13

evaluate by assembler

PROGA

14

PROGB

Page 8: 3.2Machine-Dependent Loader Features

8

15

PROGC

After linking and loading

Page 9: 3.2Machine-Dependent Loader Features

9

Relocation and linking operations performed on REF4 from PROGA

18

Algorithm for a linking loader

Two passes• Pass 1 assigns address to all external

symbols.• Pass 2 performs the actual loading, relocating,

and linking.

Page 10: 3.2Machine-Dependent Loader Features

10

19

Main data structure for a linking loader (cont’d)

An external symbol table ESTAB, • It is used to store the name and address of each external

symbol in the set of control section being loaded.• A hash organization is often used for ESTAB.

A variable, program load address, PROGADDR• It is the beginning address in memory where the linked

program is to be loaded.• Its value is supplied by the operating system.

A variable, control section address, CSADDR• It contains the starting address assigned to the control

section currently being scanned by the loader. • This value is added to all relative addresses within the

control section to convert them to actual addresses.

20

Algorithm for Pass 1 of a linking loader

get PROGADDR from operating systemset CSADDR to PROGADDR // for first control section while not end of input do {

read next input // head record for control sectionset CSLTH to control section lengthsearch ESTAB for control section nameif found {

set error flag // duplicate external symbol

} else {enter control section name into ESTAB with

value CSADDR}

while record type != ‘E’ {read next input recordif record type == ‘D’ {

for each symbol in record {search ESTAB for symbol nameif found {

set error flag // duplicate external symbol

} else {enter symbol into ESTAB withvalue (CSADDR+indicated

address)}

}}

}add CSLTH to CSADDR // starting address for next control section}

Page 11: 3.2Machine-Dependent Loader Features

11

21

Algorithm for Pass 2 of a linking loaderset CSADDR to PROGADDRset EXECADDR to PROGADDRwhile not end of input {

read next input record // head recordset CSLTH to control section lengthwhile record type != ‘E’ {

read next input recordif record tyoe == ‘T’ {

if object code is in character form, convert into internal representationmove object code from record to location (CSADDR + specified address)

} else if record type ==‘M’ {search ESTAB for modifying symbol nameif found {

add or subtract symbol value at location (CSADDR + specified address)}}}if an address is specified {

set EXECADDR to (CSADDR + specified address)add CSLTH to CSADDR

}}jump to location given by EXECADDR // to start execution of loaded program

A transfer address would be placed in the End record for a main program but not for a subroutine.

22

ESTAB

4124ENDC

4112LISTC

005140E2PROGC

40D3ENDB

40C3LISTB

007F4063PROGB

4054ENDA

4040LISTA

00634000PROGA

LengthAddressSymbolname

Controlsection

Page 12: 3.2Machine-Dependent Loader Features

12

Reference number

The reference number 01 is assigned to control section name

•Each external reference in a control section is assigned a reference number.

•The main advantage of this reference-number mechanism is that it avoids multiple searches of ESTAB for the same symbol during the loading of control section.

• An external reference symbol can be looked up once in ESTAB once for each control section that uses it.

• The values for code modification can then be obtained by simply indexing into an array of these values.

•Each external reference in a control section is assigned a reference number.

•The main advantage of this reference-number mechanism is that it avoids multiple searches of ESTAB for the same symbol during the loading of control section.

• An external reference symbol can be looked up once in ESTAB once for each control section that uses it.

• The values for code modification can then be obtained by simply indexing into an array of these values.