Sie sind auf Seite 1von 7

Loaders and Linkers

Loading, Relocation, and Linking


z

Loading which brings the object program into memory for execution. Relocation which modifies the object program so that it can be loaded at an address different from the location originally specified. Linking which combines two or more separate object programs and supplies the information needed to allow references between them.

Loaders and Linkers


z

A loader is a system program that performs the loading function. Many loaders also support relocation and linking. Some systems have a linker (or linkage editor) to perform the linking operations and a separate loader to handle relocation and loading.
3

Basic loader functions


z

The fundamental functions of a loader is

bringing an object program into memory and starting its execution.

Absolute loader
z

It is very simple.

All operations are accomplished in a single


pass.
z

z z

An object program is loaded at the address specified on the START directive. No relocation or linking is needed. The loader jumps to the address specified on the END directive to begin execution of the loaded program.
5

Algorithm for an absolute loader


begin read Header record verify program name and length read first Text record while record type 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 end 6

48 occupies two bytes in char form. 48 occupies one byte in binary form.

xxx indicates no Text record

Disadvantages of the scheme of absolute loaders


z

This scheme needs the programmer to specify the actual address at which it will be loaded into memory. This scheme make it difficult to use subroutine libraries efficiently.

the subroutines must be pre-assigned


absolute addresses.

Bootstrap loader
z

When a computer is turned on or restarted, a special type of absolute loader, called bootstrap loader, is executed.

The bootstrap loader loads the first program to be run by the computer usually an operating system, from the boot disk (e.g., a hard disk or a floppy disk)

Bootstrap loader for SIC/XE

10

Bootstrap loader for SIC/XE (contd)

11

Example: Bootstrap loader for x86 systems


z

On x86 systems, when the CPU is powered on or reset, it sets its registers to a known state and jumps to the starting address of boot ROM. The boot ROM code reads the first block of the floppy or the hard disk into memory location zero and then jumps to location zero. The program in the first block in turn loads a slightly larger operating system boot program from a known place on the disk into memory, and it jumps to that program. The just loaded program loads in the operating system and starts it.

There can be even more steps such as a boot manager that decides from which disk partition to read the operating system boot program.
12

Why not just load the operating system directly?


z

An operating system loader cannot be stored in a small space (usually a disk block).

The operating system loader contains


sophisticated code.
z

The first-level loader typically is only able to load a single-segment program from a file with a fixed name in the top-level directory of the boot disk.
13

Das könnte Ihnen auch gefallen