System Programming and administration

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.
Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Machine Independent Assembler Features
Loaders and Linkers Object Program contains the information:
Assembler Design Options
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Chapter 6: Machine dependent Assembler Features
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
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.
CS2422 Assembly Language & System Programming January 2, 2007.
Loader- Machine Independent Loader Features
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
Loader- Machine Dependent Loader Features
CS2422 Assembly Language & System Programming December 26, 2006.
Machine-Independent Assembler Features
Assembler – Machine Independent Features. Literals Design idea  Let programmers to be able to write the value of a constant operand as a part of the.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
PART I SISTEM UTILITIES LECTURE 4.1 LINK_LOAD Ştefan Stăncescu 1.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
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.
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.
Hello world !!! ASCII representation of hello.c.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
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.
Machine dependent Assembler Features
Machine Independent Assembler Features
Assembler Design Options
Assembler Design Options
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
CSCE Fall 2013 Prof. Jennifer L. Welch.
Loaders and Linkers.
Memory Management Tasks
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
CSCE Fall 2012 Prof. Jennifer L. Welch.
Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described.
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:

System Programming and administration Lecture 6 Loaders and Linkers

Outline Basic Loader Functions Absolute Loaders A simple bootstrap loader Machine-Dependent Loader Relocation Program linking Question / Answer

Basic Loader Functions Three fundamental processes to run an object program Loading Brings object program into memory for execution. Relocation Modifies the object program so that it can be loaded at an address different from the location originally specified Linking Combines two or more separate object programs and supplies information needed to allow cross-references. “Loader and linker” may be a single system program Loader: loading and relocation Linker: linking Linking Loader

Absolute loader Header record Text record End record The most fundamental functions of a loader – bringing an object program into memory and starting its execution. No linking and relocation needed Records in object program perform Header record Check the Header record for program name, starting address, and length (available memory) Text record Bring the object program contained in the Text record to the indicated address End record Transfer control to the address specified in the End record

Design of an Absolute Loader For a simple absolute loader, all functions are accomplished in a single pass as follows: The Header record of object programs is checked to verify that the correct program has been presented for loading. As each Text record is read, the 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.

Loading an absolute program Figure 5.1

Loading an absolute program Figure 5.1

Algorithm for an absolute loader Figure 5.2 Most machines store object codes in binary form Less space and loading time Not good for reading

Object Code Representation Character form (e.g. Figure 5.1 (a)) Each byte of assembled code is given using its hexadecimal representation in character form Easy to read by human beings Binary form Each byte of object code is stored as a single byte Most machine store object programs in a binary form

A simple bootstrap loader Bootstrap Loader (usually in ROM) 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 Bootstrap loader The bootstrap itself begins at address 0 It loads the OS 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 for 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 if A<48 then goto GETC A  A - 48 (0x30) if A<10 then return A  A-7 return ASCII value of 0~9 : 0x30~39 A~F : 0x41~46

Bootstrap loader for Figure 5.3

Bootstrap loader for Figure 5.3

Machine-Dependent Loader Feature Motivation Shortcoming of an absolute loader Programmer needs to specify the actual address at which it will be loaded into memory. It is difficult to run several programs concurrently, sharing memory between them. It is difficult to use subroutine libraries. Solution: A more complex loader that provides Program relocation Program linking

Relocation Loaders that allow for program relocation are called relocating or relative loaders. Two methods for specifying relocation as part of the object program Modification records For a small number of relocations required when relative or immediate addressing modes are extensively used Relocation bits For a large number of relocations required when only direct addressing mode can be used in a machine with fixed instruction format (e.g., the standard SIC machine)

Object program with modification record

Relocation Bits If there are many addresses needed to be modified, it is more efficient to use a relocation bit, instead of a modification record, to specify every relocation. When the instruction format is fixed There is a relocation bit for each word of the object program Relocation bits are put together into a bit mask If the relocation bit corresponding to a word of object code is set to 1, the program’s starting address will be added to this word when the program is relocated

Relocation Bits A bit value of 0 indicates that no modification is necessary or unused words A new Text record is created for proper alignment

Program linking Goal Resolve the problems with EXTREF and EXTDEF from different control sections A program is a logical entity that combines all of the related control sections. Control sections could be assembled together, or they could be assembled independently of one another. Control sections are to be linked, relocated, and loaded by loaders. Example Program and object code in Figure 5.9 Use modification records for both relocation and linking address constant external reference

Programs after linking and loading

Relocation and linking operations performed on REF4

Two passes linking loader A linking loader usually makes two passes over its input: Because some external symbols are processed before read Two Passes Logic Pass 1: assign addresses to all external symbols Pass 2: perform the actual loading, relocation, and linking

Linking loader: Pass 1 Assign address to all external symbols Only processes Header Record and Define Record Builds an external symbol table (ESTTAB) its name its address in which control section the symbol is defined Program Load Address (PROGADDR) The beginning address in memory where the linked program is to be loaded (supplied by OS). Control Section Address (CSADDR) The starting address assigned to the control section currently being scanned by the loader. CSADDR is added to all relative addresses within the control section

Linking loader: Pass 1 Add symbol to ESTAB Control section name: (name, CSADDR)  ESTAB Get control section name from H record If the first control section CSADDR = PROGADDR When E record is encountered, read the next control section CSADDR = CSADDR + CSLTH (known from H record) EXTDEF: (name, CSADDR + value in the record)  ESTAB Get EXTDEF from D record

Linking loader: Pass 2 Perform the actual loading, relocation, and linking Only processes Text Record and Modification Record Get address of external symbol from ESTAB When read T record Moving object code to the specified address When read M record (+/-) EXTREF in M records are handled Last step: transfer control to the address in E If more than one transfer address: use the last one If no transfer: transfer control to the first instruction (PROGADDR)

Linking loader: Improve efficiency We can make the linking loader algorithm more efficient by Assigning a reference number to each external symbol referred to in a control section 01: control section name 02~: external reference symbols Using this reference number (instead of the symbol name) in Modification records Avoiding multiple searches of ESTAB for the same symbol during the loading of a control section. Search of ESTAB for each external symbol can be performed once and the result is stored in a table indexed by the reference number. The values for code modification can then be obtained by simply indexing into the table.

Question / Answer What is loader and explain various loader schemes?