Loaders

9
Loaders & Linkers Compiled By: Girish GS Asst. Professor BNMIT Loaders and Linkers This Chapter gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Features Loader Design Options Implementation Examples System Software for Program Development The following figure shows the various system software used in the development of program. 1 BNMIT-ISE

description

na

Transcript of Loaders

Loaders & Linkers

Compiled By: Girish GS

Asst. Professor

BNMIT

Loaders and LinkersThis Chapter gives you

Basic Loader Functions

Machine-Dependent Loader Features

Machine-Independent Loader Features

Loader Design Options

Implementation Examples

System Software for Program Development

The following figure shows the various system software used in the development of program.

The source program written in assembly language or high level language will be converted into object program, of course by considering macros within the source code. This conversion is either from the assembler or complier contains translated instructions and data values from the source program or specific addresses in memory where these items are to be loaded for execution. The linker combines two or more separate object program and supplies the information needed to allow references between them. Loader loads an executable program and starts its execution.

Basic Loader Functions

Loader: A system software that performs the loading function.The role of loader is shown in figure. In figure assembler (translator) generates the object program and later loaded to the memory by the loader for execution.

Figure. Role of loader

Linker: Some systems have a linker to perform the linking operations and a separate loader to handle relocation and loading

Figure : The Role of both Loader and Linker

Type of loadersThe different types of loaders are:

absolute loader

bootstrap loader

relocating loader (relative loader)

direct linking loader

Design of an absolute Loader

Consider the design of an absolute loader that might be used with the SIC assembler discussed.

We use the same object program (described in assembler) for SIC machine.

Object program

Absolute loader operation is simple because our loader doesnt need to perform neither linking nor program relocation.

All functions are accomplished in one pass

The header record is checked to verify that the correct program has been presented for loading

Text record is then read and 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

The following figure shows a representation of the object program after loading. The contents of memory for which there is no text record are shown as xxxx. This indicates that the previous contents of these locations remain unchanged.Memory addressContents (4x4 Bytes)

0000

0010x x x x x x x x

x x x x x x x xx x x x x x x x

x x x x x x x xx x x x x x x x

x x x x x x x xx x x x x x x x

x x x x x x x x

0FF0

1000

1010

1020

1030x x x x x x x x

1 4 1 0 3 3 4 8

2 0 6 1 3 C 1 0

3 6 4 8 2 0 6 1

0 0 0 0 0 0 x x x x x x x x x x

2 0 3 9 0 0 1 0

0 3 0 0 1 0 2 A

0 8 1 0 3 3 4 C

x x x x x x x xx x x x x x x x

3 6 2 8 1 0 3 0

0 C 1 0 3 9 0 0

0 0 0 0 4 5 4 F

x x x x x x x xx x x x x x x x

3 0 1 0 1 5 4 8

1 0 2 D 0 C 1 0

4 6 0 0 0 0 0 3

x x x x x x x x

2030

2040

2050

2060

2070

2080x x x x x x x x

2 0 5 D 3 0 2 0

3 9 2 C 2 0 5 E

0 0 0 4 1 0 3 0

2 C 1 0 3 6 3 8

x x x x x x x xx x x x x x x x

3 F D 8 2 0 5 D

3 8 2 0 3 F 1 0

E 0 2 0 7 9 3 0

2 0 6 4 4 C 0 0

x x x x x x x xx x 0 4 1 0 3 0

2 8 1 0 3 0 3 0

1 0 3 6 4 C 0 0

2 0 6 4 5 0 9 0

0 0 0 5 x x x x

x x x x x x x x0 0 1 0 3 0 E 0

2 0 5 7 5 4 9 0

0 0 F 1 0 0 1 0

3 9 D C 2 0 7 9

x x x x x x x x

x x x x x x x x

Figure. Program loaded in memoryThe following figure shows the algorithm for absolute loader. Although this processing is extremely simple, there is one aspect that deserves comment. Each byte of assembled code is given using its hexadecimal representation in character form. For example the machine operation code for STL instruction would be represented by the pair of characters 1 and 4. When these are read by loader, they will occupy two bytes of memory 14(hex 31 34)

For execution the operation code must be stored in a single byte with hexadecimal value 14. Thus each pair of bytes must be packed together into one byte.

begin

read Header record

verify program name and length

read first Text record

while record type is ( E do

begin

{if object code is in character form, convert into internal

representation}

move object code to specified location in memory

read next object program record

end

jump to address specified in End record

endAdvantage Simple and efficient

Disadvantage The need for programmer to specify the actual address

Difficult to use subroutine libraries

A Simple Bootstrap Loader When a computer is first turned on or restarted, a special type of absolute loader, called bootstrap loader, is executed.

This bootstrap loads the first program to be run by the computer usually an operating system

We will examine a very simple bootstrap loader for SIC/XE.

The bootstrap begins at address 0 in the memory of the machine as shown below It loads the operating system starting at address 80

Each byte of object code to be loaded is represented on device F1

There is no Header record, End record, or control information (addresses, length, )

The object code from device F1 is always loaded into consecutive bytes of memory, starting at address 80

After loading the object code from device F1, the bootstrap jumps to address 80 to begin the execution of the program

Much of the work of the bootstrap loader is performed by the subroutine GETC

The algorithm for the bootstrap loader is as follows

Begin

X=0x80 (the address of the next memory location to be loaded

Loop

A(GETC (and convert it from the ASCII character

code to the value of 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)

store the value (in A) to the address in register X

X(X+1

End

It uses a subroutine GETC, which is

GETC A(read one character

if A=0x04 then jump to 0x80

if A