Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.

Slides:



Advertisements
Similar presentations
Loaders Dr. Monther Aldwairi 10/21/2007 Dr. Monther Aldwairi.
Advertisements

1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Chapter 3 Loaders and Linkers
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida.
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Machine Independent Assembler Features
Loaders and Linkers Object Program contains the information:
Machine-Independent Loader Features
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Machine-Dependent Assembler Features (SIC/XE Assembler) Instruction Formats, Addressing Modes, and Program Relocation.
Chapter 6: Machine dependent Assembler Features
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Loader- Machine Independent Loader Features
Assembler – Machine Dependent Features
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
Loader- Machine Dependent Loader Features
CS2422 Assembly Language & System Programming December 7, 2006.
CS2422 Assembly Language & System Programming November 30, 2006.
Topic 1: Introduction to Computers and Programming
CS2422 Assembly Language & System Programming December 26, 2006.
Assembler (Basic Functions)
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent.
G.Umamaheswari Lect/IT R.M.D.EC system software
Loader and Linker.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
UNIT III LOADERS AND LINKERS. This Unit gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Feature Loader.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
ADHIPARASAKTHI ENGINEERING COLLEGE
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
Machine dependent Assembler Features
CC410: System Programming
System Programming and administration
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Loaders and Linkers.
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Machine Independent Assembler Features
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

Loader

Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler

Role of Loader and Linker Source Program Assembler Object Program Linker Executable Code Loader Object program ready for execution Memory

Loader is a system s/w that makes a program ready for execution, by copying the file from secondary memory to main memory for execution. It is usually part of Operating system. The main task of the loader is to bring binary executable image into main memory and bind the relocatable addresses into absolute addresses. The binary image of a program consists of following parts :- Header – it shows the type of file (executable or library file) Text – it shows the actual code of the program List of shared libraries - libraries that have been used in the object file

Design of The absolute loader – An absolute object file consists of three part- 1)The start address of the program 2)The object instructions 3)The address of the first executable instruction. This is placed in the object file by assembler in response to the END directive. It is either the address specified by the END or, in the absence of such an address is identical to the first address of the program. The loader reads the first item and loads the rest of object file into successive memory locations.

Algorithm for absolute loader:- Begin Read Header record Verify program name and length Read first text record While record type is not ‘E’ do begin if object code is in character form { convert into internal representation } read next object program record end Jump to the address specified in End Record end

Role of Absolute Loader Object Program Absolute Loader Object program ready for execution Memory

Object Program H COPY A T E T 00101E 15 0C C F T E E0205D 30203F D8205D … T C C0000 F E … T C E

Absolute Loader Advantage - Simple and efficient Disadvantage - the need for programmer to specify the actual address - difficult to use subroutine libraries

Bootstrap Loader

A Simple Bootstrap Loader When a computer is first tuned 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 It is permanently stored in ROM. So it can not be erased.

Example (SIC bootstrap loader) The bootstrap itself begins at address 0 It loads the OS at 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.

Algorithm of bootstrap loader 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

GETC reads one character and convert it into hexadecimal digit. For example, the ASCII code for ‘1’ through ‘9’ are converted to the numeric values 1 through 9. and codes for ‘A’ through ‘F’ ( 41 to 46 Hex) are converted to the values 10 through 15. this is accomplished by subtracting 48 ( 30 in Hex) from the character codes of 0-9 and by subtracting 55 (37 in Hex) from the codes of A-F ASCII value of 0~9 : 0x30~39 A~F : 0x41~46

Machine Dependent Loader Features Relocation Program Linking

Example of Relocation LineLoc Source statementObject code 50000COPY START FIRST STL RETADR17202D LDB #LENGTH69202D 13 BASE LENGTH CLOOP+JSUB RDREC4B A LDA LENGTH D COMP# JEQ ENDFIL JSUB WRREC4B10105D J CLOOP3F2FEC 45001AENDFIL LDA EOF D STA BUFFER0F LDA# STA LENGTH0F200D JSUB WRREC4B10105D 70002A 80002DEOF BYTE C’EOF’454F RETADR RESW LENGTH RESW BUFFER RESB 4096

RDREC CLEAR XB DWRREC CLEAR XB (omitted)

Instructions at line no 15,35 & 65 are the only items whose values are affected by relocation. We use modification records for the relocation purpose. Each modification record specifies the starting address and the length of the field whose value to be altered. It then describes the modification to be performed. Modification record col 1: M col 2-7: relocation address col 8-9: length (halfbyte) col 10: flag (+/-) col 11-17: segment name

Modification Record H  COPY  T   1D  17202D  69202D   …  4B105D  3F2FEC  T  00001D  13  0F2016   0F200D  4B10105D  3E2003  454F46 T   1D  B410  B400  B440   …   57C003  B850 T   1D  3B2FEA   4F0000  F1 ..  53C003  DF2008  B850 T   07  3B2FEF  4F0000  05 M   05+COPY M   05+COPY M   05+COPY E 

Begin Get PROGADDR from OS While not end of input do { read next record while record type != ‘E’ do { read next input record while record type = ‘T’ do {move object code from record to location ADDR + specified address } while record type = ‘M’ add PROGADDR at the location PROGADDR + specified address } end Relocation Loader Algorithm

Modification record scheme is not well suited for use with all machine architectures and if many instructions require relocation then the number of modification record will be very large. To solve this problem we can use relocation bit method. If the relocation bit corresponding to a word of object code is set to 1, the program’s starting address is to be added to this word when the program is relocated. Relocation bit - 0: no modification is necessary - 1: modification is needed Twelve-bit mask is used in each Text record Since each text record contains < 12 words Unused words are set to 0

Text record format Text record col 1: T col 2-7: starting address col 8-9: length (byte) col 10-12: relocation bits col 13-72: object code

Relocatable Program for SIC LineLoc Source statementObject code 50000COPYSTART FIRSTSTLRETADR CLOOPJSUBRDREC LDALENGTH COMPZERO CJEQENDFIL FJSUBWRREC JCLOOP3C ENDFILLDAEOF00002A STABUFFER0C BLDATHREE00002D 60001ESTALENGTH0C JSUBWRREC LDLRETADR RSUB4C AEOFBYTEC’EOF’454F DTHREEWORD ZEROWORD RETADRRESW LENGTHRESW BUFFERRESB4096

RDRECLDXZERO CLDAZERO FRLOOPTDINPUTE0105D JEQRLOOP30103D RDINPUT D8105D COMPZERO BJEQEXIT ESTCHBUFFER,X TIXMAXLEN2C105E JLTRLOOP38103F EXITSTXLENGTH ARSUB4C DINPUTBYTEX’F1’F EMAXLENWORD WRRECLDXZERO WLOOPTDOUTPUTE JEQWLOOP ALDCHBUFFER,X DWDOUTPUTDC TIXLENGTH2C JLTWLOOP RSUB4C OUTPUTBYTEX’05’05 255ENDFIRST

Relocation by Bit Mask H COPY A T E FFC T 00001E 15 E00 0C C F … T E FFC E0105D 30103F D8105D … T C C0000 F T FE E DC1079 2C0036 … E Here the bit mask FFC (representing the bit string ) In the first text record specifies that all 10 words of object code are to be modified during relocation. Similarly bit mask E00 represents that the first 3 words are to be modified.

Machine Independent Loader Features Automatic library search Loader options

Automatic library search :- This feature allows a programmer to use standard subroutines without explicitly including them in the program to be loaded. So programmer can use any subroutine by just mentioning their names. The subroutines are automatically fetched from the library, linked with the main program and loaded. Loader maintains an External Symbol Table (ESTAB) for these external symbols. The loader searches the library specified for routines that contain the definitions of these symbols, and process the subroutines found by this search. In most cases a special file structure is used for libraries. This structure contains a directory that gives the name of each routine and a pointer to its address within the file. NamePointer

Loader Options :- Many loader allow user to specify options that modify the standard processing. Loaders have a special command language that is used to specify the options. Options:- 1)INCLUDE 2)DELETE 3)CHANGE 4)LIBRARY

1)INCLUDE:- this loader option allows the selection of alternative sources of input. For example, the command INCLUDE program-name (library name) Might direct the loader to read the designated object program from a library and treat it as the primary loader input. 2) DELETE:- it allows the user to delete external symbols or entire control sections. For example, the command DELETE csect-name might instruct the loader to delete the name control section from the set of programs being loaded. 3) CHANGE :- it allows the user to change name1 to name 2 in the program. For example CHAMGE name1, name 2 Might cause the external symbol name1 to be changed to name 2 wherever it appears in the object programs

LineLoc Source statementObject code 50000COPY START CLOOP+JSUB RDREC4B JSUB WRREC4B10105D JSUB WRREC4B10105D RDREC CLEAR XB DWRREC CLEAR XB (omitted) Example of Relocation INCLUDE READ(ULIB) INCLUDE WRITE(ULIB) DELETE RDREC,WRREC CHANGE RDREC, READ CHANGE WRREC, WRITE

These command would direct the loader to include control sections READ & WRITE from the library ULIB, and to delete the control sections RDREC and WRREC from the load. The first CHANGE command would cause all external references to symbol RDREC to be changed to refer to symbol.