Loaders

mohammedarif89 37,050 views 33 slides Apr 09, 2013
Slide 1
Slide 1 of 33
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33

About This Presentation

No description available for this slideshow.


Slide Content

Loaders

Loader & its Functions
A loader is a system program, which takes the object code
of a program as input and prepares it for execution.
Loader Function : The loader performs the following
functions :
Allocation - The loader determines and allocates the required
memory space for the program to execute properly.
Linking -- The loader analyses and resolve the symbolic
references made in the object modules.
Relocation - The loader maps and relocates the address
references to correspond to the newly allocated memory
space during execution.
Loading - The loader actually loads the machine code
corresponding to the object modules into the allocated
memory space and makes the program ready to execute.

Label opcode address
01 ; This is
02 ; a comment
03start .begin x200
04here LOAD sum
05 ADD a
06 STORE sum
07 LOAD b
08 SUB one
09 STORE b
0A SKIPZ
0B JMP here
0C LOAD sum
0D HALT
0Esum .data x000
0Fa .data x005
10 b .data x003
11one .data x001
12 .end start
Assembly program
Cont….
object code file
Program name: start
Starting address text: x200
Length of text in bytes: x14
Starting address data: x20A
Length of data in bytes: 8

0001000000001001
0010000000001001
0011000000000111
0001000000001000
0100000000001000
0011000000000110
1001000000000000
1000111111111000
0001000000000001
0111000000000000
0000000000000000
0000000000000101
0000000000000011
0000000000000001
H
e
a
d
e
r
Text
Data

Types of Loader
1.- Compile-and-Go Loaders:
2.- Absolute Loader
3.- Bootstrap Loader
4.- Operating System: Loading application programs
3.1- The Process concept.
3.2- Creating a process.
5.- Relocating Loaders
4.1- Relocation bits
4.2- Relocation maps (modification records)

Compile-and-Go Loaders:
A compile and go loader is one in which the assembler
itself does the processes of compiling then place the
assembled instruction inthe designated memory loactions.
The assembly process is first executed and then the
assembler causes a transfer to the first instruction of the
program.
E.G. WATFOR FORTRAN compiler
This loading scheme is also called assmble-and-go

Advantages and Disadvantages
Advantages of Compile-and-go loaders:
Simple and easier to implement.
No additional routines are required to load the compiled code
into the memory.
Dis advantages of Compile-and-go loaders:
Wastage im memory spave due to the presence of the assembler.
There is a need to re-assemble the code every time it is to be run.
It becomes increasingly difficult to handle large number of
segments when the input code is written in a variety of HLL say
one routine in pascal and one in FORTRAN and so on.
Such loader make designing modular programs and systems near
impossible.

Absolute Loader
Assembler object code file
Program name: start
Starting address text: x200
Length of text in bytes: x14
Starting address data: x20A
Length of data in bytes: 8

0001000000001001
0010000000001001
0011000000000111
0001000000001000
0100000000001000
0011000000000110
1001000000000000
1000111111111000
0001000000000001
0111000000000000
0000000000000000
0000000000000101
0000000000000011
0000000000000001
Header
Text section
Data section
Absolute loader:
The absolute loader will load the
program at memory location x200:
1.- The header record is checked to
verify that the correct program has
been presented for loading.
2.- Each text record is read and
moved to the indicate address in
memory
3.- When the “end” record (EOF) is
encountered, the loader jumps to the
specified address to begin execution.

Cont….
The four functions as performed in and absolute loader are :
1.Allocation
2.Linking
3.Relocation
4.Loading
Advantages of Absolute Loader :
Simple, easy to design and implement.
Since more core memory is available to the user there is no memory
limit.
Dis advantages of Absolute Loader :
The programmer must specifically tell the assembler the address where
the program is to be loaded.
When subroutines are referenced, the programmer must specify their
address whenever they are called.

Loading object code into memory
Program name: start
Starting address text: x200
Length of text in bytes: x14
Starting address data: x20A
Length of data in bytes: 8

0001000000001001
0010000000001001
0011000000000111
0001000000001000
0100000000001000
0011000000000110
1001000000000000
1000111111111000
0001000000000001
0111000000000000
0000000000000000
0000000000000101
0000000000000011
0000000000000001
Header
Text section
Data section
Run time environment
Text
Data
Stack
Heap
Object code file (disk)

Bootstrapping:
Computers execute programs stored in main memory, and
initially the operating system is on the hard disk.

When the computer is turned on it does not have an operating
system loaded in memory and the hardware alone cannot do
the operations of an OS. To solve this paradox a special
program called bootstrap loader is created.

Bootstrapping continued…
This program does not have the full functionality of
an operating system, but it is capable of loading into
memory a more elaborated software (i.e. loader2)
which in its turn will load the operating system.

Once the OS has been loaded the loader transfers the
control of the computer system to the operating
system.

Bootstrapping continued…
Early programmable computers had toggle switches
on the front panel to allow the operator to place the
bootloader into the program store before starting the
CPU.
In modern computers the bootstrapping process
begins with the CPU executing software contained in
ROM at a predefined address whose elementary
functionality is to search for devices eligible to
participate in booting, and load a small program
from a special section of a device.

Bootstrapping continued…
BOOT PROG
ROM
I/O
LOADER 2
OS
I/O OPERATIONS
CPU
MEMORY

BOOT PROG
ROM
I/O
LOADER 2
OS
I/O OPERATIONS
CPU
MEMORY
LOADER2
Bootstrapping continued…

In earlier computers data had to be hand loaded as specified
before, but nowadays a small piece of software called
loader helps us to avoid the manual loading.

Bootstrapping continued…
STORE LC
READ
LC LC + 1
IF (EOF) PC 0
ELSE JMP 100000
OS will be loaded here
100000
0
LOADER 2
LC = 0
99998
LC = Location Counter

BOOT PROG
ROM
I/O
LOADER 2
OS
I/O OPERATIONS
CPU
OS
LOADER2
Bootstrapping continued…

The above diagram can be explained in the following steps.
1. Check hardware
2. Initiate I/O to load the loader 2 program into memory
3. Loader 2 loads the OS and passes control to it
Bootstrapping continued…

We have seen that once the OS has control over the
system , it can create an environment for programs
to run.
The operating system will load device drivers and
other programs that are needed for the normal
operation of the computer system.
Conclusion

Operating system

The Process Concept

Once the operating system takes control of the
computer system, an applications program (object
module) can be loaded into memory to be executed.
When the program is loaded into memory a process is
created.
What is a process?


Programs and processes

Process
Definition:
A program in execution
An asynchronous activity
The “locus of control” of a procedure in
execution
It is manifested by the existence of a
process control block (PCB) in the operating
system.

Process Continued…
The activity of a process is controlled by a data
structure called Process Control Block(PCB).
A PCB is created every time a program is loaded
to be executed.
So, a process is defined by a PCB-Program
couple.

PROGRAM
S
T
A
C
K

Base code
Limit Code
IP or PC
Stack Pointer
Registers
Interrupt Flags
MODE
.….
State
Structure of the PCB
Process name or ID
Pointer to next PCB
….
…..

PCB
stack
Program
OS code
Load
Create
Process Creation

PCB
Memory
OS
Load
Create
Process Creation
code
data
header
symbol
table
Disk
code
data
stack
bss
heap
Process working space
object file

Process working space (run-time environment)
code
data
stack
bss
heap
Process working space
or
Run-time environment
Program text (write protected)
Constants / initialized data
Global and static variables
Dynamically allocated variables
Dynamic link, return address,
Local variables, function
Parameters, …
x = 4;
int y = 7;
int z;
malloc(n);

code
data
stack
bss
heap
Process working space
x = 4;
int y = 7;
int z;
malloc(n);
Local
Local
Local
Local
Local
Local
Parameter
Parameter
Dynamic Link
Return Address
void sub(float total, int part ) {
int List[5];
float sum;

}
sum
bss: means “block started
by symbol” and has that
name for historical reasons.

Relocating Loaders
Absolute loaders loads a program on a specific
memory location but it is often desirable to have
two or more programs residing in memory sharing
the different resources of a computer system.
It would be impractical to assign starting addresses
to each program to plan program execution.
A loader able to load a program into memory
wherever there is room for it is called a relocating
loader.

Relocation bits
Assemblers generate code that starts at address zero but it can also emit
with each line of text (code) relocation bits indicating what fields in the
object code must be modified when the program is loaded in an address
different from zero.
For example, if the program will be loaded at address 40, a relocation bits equal to “1”
indicates what part of the instruction must be modified:
Loc# Len reloc text Loc# text

00 3 01113 33 35 00 13 74 76

Label opcode address address

00 copy zero older
03 copy one old
06 read limit
08 write old
10 comp load older
12 add old

14 store new

16 sub limit

18 brpos finalL

20 write new

22 copy old older
25 copy new old
28 br comp
30 final write limit
32 stop
33 zero CONST 0
34 0ne CONST 1
35 older SPACE
36 old SPACE
37 new SPACE
38 limit SPACE
source program
Loc# Len reloc text

00 3 011 13 33 35
03 3 011 13 34 36
06 2 011 12 38
08 2 01 08 36
10 2 01 03 35
12 2 01 02 36
14 2 01 07 37
16 2 01 06 38
18 2 01 01 30
20 2 01 08 37

22 3 011 13 36 35
25 3 011 13 37 36
28 2 01 00 10

30 2 01 08 38
32 2 01 11
33 1 0 00
34 1 0 01
35
36
37
38
before relocation after relocation
Loc# text

40 13 73 75
43 13 34 36
46 12 78
48 08 76
50 03 75
52 02 76
54 07 77
56 06 78
58 01 70
60 08 77

62 13 76 75
65 13 77 76
68 00 50

70 08 378
72 11
73 00
74 01
75
76
77
78
Relocation constant to be added is 40

2.- Relocation maps (modification records)
Interleaving relocation bits with the program text makes cumbersome the
process of loading the text directly into memory.
This problem can be resolve by collecting all relocation bits into a single
contiguous relocation map that we will call the relocation section of the
object code file.
The relocation section will be appended to the text and data sections.
The header will contain the entry point and length of the relocation section
in the object module.

Program name: start
Starting address text
Length of text in bytes
Starting address data
Length of data in bytes
Starting address reloc. Sect.
Length of relocation section
Header
Text section
Data section
Relocation section
Tags