Presentation is loading. Please wait.

Presentation is loading. Please wait.

System Programming and administration

Similar presentations


Presentation on theme: "System Programming and administration"— Presentation transcript:

1 System Programming and administration
Lecture 6 Loaders and Linkers

2 Outline Basic Loader Functions Absolute Loaders
A simple bootstrap loader Machine-Dependent Loader Relocation Program linking Question / Answer

3 Basic Loader Functions
Three fundamental processes to run an object program Loading Brings object program into memory for execution. Relocation Modifies the object program so that it can be loaded at an address different from the location originally specified Linking Combines two or more separate object programs and supplies information needed to allow cross-references. “Loader and linker” may be a single system program Loader: loading and relocation Linker: linking Linking Loader

4 Absolute loader Header record Text record End record
The most fundamental functions of a loader – bringing an object program into memory and starting its execution. No linking and relocation needed Records in object program perform Header record Check the Header record for program name, starting address, and length (available memory) Text record Bring the object program contained in the Text record to the indicated address End record Transfer control to the address specified in the End record

5 Design of an Absolute Loader
For a simple absolute loader, all functions are accomplished in a single pass as follows: The Header record of object programs is checked to verify that the correct program has been presented for loading. As each Text record is read, the object code it contains is moved to the indicated address in memory. When the End record is encountered, the loader jumps to the specified address to begin execution of the loaded program.

6 Loading an absolute program Figure 5.1

7 Loading an absolute program Figure 5.1

8 Algorithm for an absolute loader Figure 5.2
Most machines store object codes in binary form Less space and loading time Not good for reading

9 Object Code Representation
Character form (e.g. Figure 5.1 (a)) Each byte of assembled code is given using its hexadecimal representation in character form Easy to read by human beings Binary form Each byte of object code is stored as a single byte Most machine store object programs in a binary form

10 A simple bootstrap loader
Bootstrap Loader (usually in ROM) When a computer is first tuned on or restarted, a special type of absolute loader, the bootstrap loader loads the first program (usually O.S.) to be run into memory Bootstrap loader The bootstrap itself begins at address 0 It loads the OS starting address 0x80 No header record or control information, the object code is consecutive bytes of memory After load the OS, the control is transferred to the instruction at address 80.

11 Algorithm for bootstrap loader
X  0x80 (the address of the next memory location to be loaded) Loop until end of input A  GETC (and convert from ASCII character code to the hexadecimal digit) save the value in the high-order 4 bits of S A  GETC combine the value to form one byte A  (A+S) (X)  (A) (store one char.) X  X + 1 End of loop GETC A¬ read one character from device F1 if (A = 0x04) then jump to 0x80 if A<48 then goto GETC A  A - 48 (0x30) if A<10 then return A  A-7 return ASCII value of 0~9 : 0x30~39 A~F : 0x41~46

12 Bootstrap loader for Figure 5.3

13 Bootstrap loader for Figure 5.3

14 Machine-Dependent Loader Feature Motivation
Shortcoming of an absolute loader Programmer needs to specify the actual address at which it will be loaded into memory. It is difficult to run several programs concurrently, sharing memory between them. It is difficult to use subroutine libraries. Solution: A more complex loader that provides Program relocation Program linking

15 Relocation Loaders that allow for program relocation are called relocating or relative loaders. Two methods for specifying relocation as part of the object program Modification records For a small number of relocations required when relative or immediate addressing modes are extensively used Relocation bits For a large number of relocations required when only direct addressing mode can be used in a machine with fixed instruction format (e.g., the standard SIC machine)

16 Object program with modification record

17 Relocation Bits If there are many addresses needed to be modified, it is more efficient to use a relocation bit, instead of a modification record, to specify every relocation. When the instruction format is fixed There is a relocation bit for each word of the object program Relocation bits are put together into a bit mask If the relocation bit corresponding to a word of object code is set to 1, the program’s starting address will be added to this word when the program is relocated

18 Relocation Bits A bit value of 0 indicates that no modification is necessary or unused words A new Text record is created for proper alignment

19 Program linking Goal Resolve the problems with EXTREF and EXTDEF from different control sections A program is a logical entity that combines all of the related control sections. Control sections could be assembled together, or they could be assembled independently of one another. Control sections are to be linked, relocated, and loaded by loaders. Example Program and object code in Figure 5.9 Use modification records for both relocation and linking address constant external reference

20 Programs after linking and loading

21 Relocation and linking operations performed on REF4

22 Two passes linking loader
A linking loader usually makes two passes over its input: Because some external symbols are processed before read Two Passes Logic Pass 1: assign addresses to all external symbols Pass 2: perform the actual loading, relocation, and linking

23 Linking loader: Pass 1 Assign address to all external symbols
Only processes Header Record and Define Record Builds an external symbol table (ESTTAB) its name its address in which control section the symbol is defined Program Load Address (PROGADDR) The beginning address in memory where the linked program is to be loaded (supplied by OS). Control Section Address (CSADDR) The starting address assigned to the control section currently being scanned by the loader. CSADDR is added to all relative addresses within the control section

24 Linking loader: Pass 1 Add symbol to ESTAB
Control section name: (name, CSADDR)  ESTAB Get control section name from H record If the first control section CSADDR = PROGADDR When E record is encountered, read the next control section CSADDR = CSADDR + CSLTH (known from H record) EXTDEF: (name, CSADDR + value in the record)  ESTAB Get EXTDEF from D record

25 Linking loader: Pass 2 Perform the actual loading, relocation, and linking Only processes Text Record and Modification Record Get address of external symbol from ESTAB When read T record Moving object code to the specified address When read M record (+/-) EXTREF in M records are handled Last step: transfer control to the address in E If more than one transfer address: use the last one If no transfer: transfer control to the first instruction (PROGADDR)

26 Linking loader: Improve efficiency
We can make the linking loader algorithm more efficient by Assigning a reference number to each external symbol referred to in a control section 01: control section name 02~: external reference symbols Using this reference number (instead of the symbol name) in Modification records Avoiding multiple searches of ESTAB for the same symbol during the loading of a control section. Search of ESTAB for each external symbol can be performed once and the result is stored in a table indexed by the reference number. The values for code modification can then be obtained by simply indexing into the table.

27 Question / Answer What is loader and explain various loader schemes?


Download ppt "System Programming and administration"

Similar presentations


Ads by Google