Chapter 3 Loaders and Linkers
-- Basic Loader Functions
Tzong-Jye Liu
Department of Information Engineering and Computer Science
Feng Chia University
tjliu@[Link]
Three processes to run an object program
n Loading
n Brings object program into memory
n Relocation
n Modifies the object program so that it can be loaded at an address
different from the location originally specified
n Linking
n Combines two or more separate object programs and supplies
information needed to allow cross-references.
n “Loader and linker” may be a single system program
n Loader: loading and relocation
n Linker: linking Linking Loader
System Programming 2
Absolute loader
n No linking and relocation needed
n Records in object program perform
n Header record
n Check the Header record for program name,
starting address, and length (available
memory)
n Text record
n Bring the object program contained in the
Text record to the indicated address
n End record
n Transfer control to the address specified
in the End record
System Programming 3
Loading an absolute program
Figure 3.1, pp. 125
0x002039 0x001033
0x001033 ~ 0x002039 之間空白
System Programming 4
Loading an absolute program
Figure 3.1, pp. 125
No text record
System Programming 5
Algorithm for an absolute loader
Figure 3.2, pp. 126
Most machines store object codes in binary form
• Less space and loading time
• Not good for reading
System Programming 6
Object Code Representation
n Character form (e.g. Figure 3.1 (a))
n Each byte of assembled code is given using its
hexadecimal representation in character form
n Easy to read by human beings
n Binary form
n Each byte of object code is stored as a single byte
n Most machine store object programs in a binary form
System Programming 7
A simple bootstrap loader
n Bootstrap Loader (usually in ROM)
n 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
n SIC bootstrap loader
n The bootstrap itself begins at address 0
0
n It loads the OS starting address 0x80 Bootstrap
Loader “F1” device
n No header record or control
information, the object code is
consecutive bytes of memory O.S.
80
n After load the OS, the control is O.S.
transferred to the instruction at address
80.
System Programming 8
Algorithm for SIC/XE 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 0x04 = ^D : end of file
if A<48 then goto GETC
A ¬ A-48 (0x30)
if A<10 then return ASCII value of
A ¬ A-7 - 0~9 : 0x30~0x39
return - A~F : 0x41~0x46
System Programming 9
Bootstrap loader for SIC/XE
-- Figure 3.3, pp. 128
Base
X
System Programming 10
Bootstrap loader for SIC/XE
-- Figure 3.3, pp. 128
System Programming 11