System Software Notes 5TH Sem Vtu
System Software Notes 5TH Sem Vtu
3.0 Introduction
The Source Program written in assembly language or high level language will be converted to object program, which is in the machine language form for execution. This conversion either from assembler or from compiler , contains translated instructions and data values from the source program, or specifies addresses in primary memory where these items are to be loaded for execution. This contains the following three processes, and they are, Loading - which allocates memory location and brings the object program into memory for execution - (Loader) Linking- which combines two or more separate object programs and supplies the information needed to allow references between them - (Linker) Relocation - which modifies the object program so that it can be loaded at an address different from the location originally specified - (Linking Loader)
PNSIT, Bangalore
System Software
Source Program
Translator
Object Program
Loader
Memory
Source Program
Assembler
Object Program
Loader
PNSIT, Bangalore
System Software
Source Program
Assembler
Object Program
Executable Code
Loader
PNSIT, Bangalore
System Software
Object Program
Memory Figure 3.3.1: The Role of Absolute Loader The algorithm for this type of loader is given here. The object program and, the object program loaded into memory by the absolute loader are also shown. Each byte of assembled code is given using its hexadecimal representation in character form. Easy to read by human beings. Each byte of object code is stored as a single byte. Most machine store object programs in a binary form, and we must be sure that our file and device conventions do not cause some of the program bytes to be interpreted as control characters. Begin read Header record verify program name and length read first Text record while record type is <> 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
PNSIT, Bangalore
System Software
PNSIT, Bangalore
System Software
PNSIT, Bangalore
System Software This needs the design and implementation of a more complex loader. The loader must provide program relocation and linking, as well as simple loading functions.
3.4.1 Relocation
The concept of program relocation is, the execution of the object program using any part of the available and sufficient memory. The object program is loaded into memory wherever there is room for it. The actual starting address of the object program is not known until load time. Relocation provides the efficient sharing of the machine with larger memory and when several independent programs are to be run together. It also supports the use of subroutine libraries efficiently. Loaders that allow for program relocation are called relocating loaders or relative loaders.
The relocation bit method is used for simple machines. Relocation bit is 0: no modification is necessary, and is 1: modification is needed. This is specified in the columns 10-12 of text record (T), the format of text record, along with relocation bits is as follows. 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 Twelve-bit mask is used in each Text record (col:10-12 relocation bits), since each text record contains less than 12 words, unused words are set to 0, and, any value that is to be modified during relocation must coincide with one of these 3-byte segments. For absolute loader, there are no relocation bits column 10-69 contains object code. The object program with relocation by bit mask is as shown below. Observe FFC - means all ten words are to be modified and, E00 - means first three records are to be modified. HCOPY 000000 00107A T0000001EFFC1400334810390000362800303000153C0003 T00001E15E000C00364810610800334C0000000003000000 T0010391EFFC04003000003030103FD8105D280030... T0010570A 8001000364C0000F1001000 T00106119FE0040030E01079508039DC10792C0036... E000000
PNSIT, Bangalore
System Software EXTREF (external reference) - The EXTREF statement names symbols used in this (present) control section and are defined elsewhere. ex: EXTREF RDREC, WRREC EXTREF LISTB, ENDB, LISTC, ENDC How to implement EXTDEF and EXTREF The assembler must include information in the object program that will cause the loader to insert proper values where they are required in the form of Define record (D) and, Refer record(R). Define record The format of the Define record (D) along with examples is as shown here. Col. 1 Col. 2-7 Col. 8-13 Col.14-73 D Name of external symbol defined in this control section Relative address within this control section (hexadecimal) Repeat information in Col. 2-13 for other external symbols
Example records D LISTA 000040 ENDA 000054 D LISTB 000060 ENDB 000070 Refer record The format of the Refer record (R) along with examples is as shown here. Col. 1 Col. 2-7 Col. 8-73 R Name of external symbol referred to in this control section Name of other external reference symbols
Example records R LISTB ENDB LISTC ENDC R LISTA ENDA LISTC ENDC R LISTA ENDA LISTB ENDB Here are the three programs named as PROGA, PROGB and PROGC, which are separately assembled and each of which consists of a single control section. LISTA, ENDA in PROGA, LISTB, ENDB in PROGB and LISTC, ENDC in PROGC are external definitions in each of the control sections. Similarly LISTB, ENDB, LISTC, ENDC in PROGA, LISTA, ENDA, LISTC, ENDC in PROGB, and LISTA, ENDA, PNSIT, Bangalore 9
System Software LISTB, ENDB in PROGC, are external references. These sample programs given here are used to illustrate linking and relocation. The following figures give the sample programs and their corresponding object programs. Observe the object programs, which contain D and R records along with other records. 0000 PROGA START EXTDEF EXTREF .. . LDA +LDT LDX . . EQU EQU WORD WORD WORD WORD WORD END 0 LISTA, ENDA LISTB, ENDB, LISTC, ENDC LISTA LISTB+4 #ENDA-LISTA * * ENDA-LISTA+LISTC 000014 ENDC-LISTC-10 FFFFF6 ENDC-LISTC+LISTA-1 00003F ENDA-LISTA-(ENDB-LISTB) 000014 LISTB-LISTA FFFFC0 REF1 03201D 77100004 050014
0020 0023 0027 0040 0054 0054 0057 005A 005D 0060
REF1 REF2 REF3 LISTA ENDA REF4 REF5 REF6 REF7 REF8
0000
PROGB
0036 REF1 003A REF2 003D REF3 0060 0070 0070 0073 0076 0079 LISTB ENDB REF4 REF5 REF6 REF7
START EXTDEF EXTREF .. . +LDA LDT +LDX . . EQU EQU WORD WORD WORD WORD
0 LISTB, ENDB LISTA, ENDA, LISTC, ENDC LISTA LISTB+4 #ENDA-LISTA * * ENDA-LISTA+LISTC ENDC-LISTC-10 ENDC-LISTC+LISTA-1 ENDA-LISTA-(ENDB-LISTB) 000000 FFFFF6 FFFFFF FFFFF0 10 03100000 772027 05100000
PNSIT, Bangalore
0000
PROGC
0018 REF1 001C REF2 0020 REF3 0030 0042 0042 0045 0045 004B 004E LISTC ENDC REF4 REF5 REF6 REF7 REF8
START EXTDEF EXTREF .. .. +LDA +LDT +LDX . . EQU EQU WORD WORD WORD WORD WORD END
0 LISTC, ENDC LISTA, ENDA, LISTB, ENDB LISTA LISTB+4 #ENDA-LISTA * * ENDA-LISTA+LISTC ENDC-LISTC-10 ENDC-LISTC+LISTA-1 ENDA-LISTA-(ENDB-LISTB) LISTB-LISTA 000030 000008 000011 000000 000000 03100000 77100004 05100000
H PROGA 000000 000063 D LISTA 000040 ENDA 000054 R LISTB ENDB LISTC ENDC . . T 000020 0A 03201D 77100004 050014 . . T 000054 0F 000014 FFFF6 00003F 000014 FFFFC0 M000024 05+LISTB M000054 06+LISTC M000057 06+ENDC M000057 06 -LISTC M00005A06+ENDC M00005A06 -LISTC PNSIT, Bangalore 11
System Software M00005A06+PROGA M00005D06-ENDB M00005D06+LISTB M00006006+LISTB M00006006-PROGA E000020 H PROGB 000000 00007F D LISTB 000060 ENDB 000070 R LISTA ENDA LISTC ENDC . T 000036 0B 03100000 772027 05100000 . T 000007 0F 000000 FFFFF6 FFFFFF FFFFF0 000060 M000037 05+LISTA M00003E 06+ENDA M00003E 06 -LISTA M000070 06 +ENDA M000070 06 -LISTA M000070 06 +LISTC M000073 06 +ENDC M000073 06 -LISTC M000073 06 +ENDC M000076 06 -LISTC M000076 06+LISTA M000079 06+ENDA M000079 06 -LISTA M00007C 06+PROGB M00007C 06-LISTA E H PROGC 000000 000051 D LISTC 000030 ENDC 000042 R LISTA ENDA LISTB ENDB . T 000018 0C 03100000 77100004 05100000 . T 000042 0F 000030 000008 000011 000000 000000 M000019 05+LISTA M00001D 06+LISTB M000021 06+ENDA M000021 06 -LISTA M000042 06+ENDA M000042 06 -LISTA M000042 06+PROGC M000048 06+LISTA PNSIT, Bangalore 12
System Software M00004B 06+ENDA M00004B 006-LISTA M00004B 06-ENDB M00004B 06+LISTB M00004E 06+LISTB M00004E 06-LISTA E The following figure shows these three programs as they might appear in memory after loading and linking. PROGA has been loaded starting at address 4000, with PROGB and PROGC immediately following.
PNSIT, Bangalore
13
System Software
For example, the value for REF4 in PROGA is located at address 4054 (the beginning address of PROGA plus 0054, the relative address of REF4 within PROGA). The following figure shows the details of how this value is computed.
The initial value from the Text record T0000540F000014FFFFF600003F000014FFFFC0 is 000014. To this is added the address assigned to LISTC, which is 4112 (the beginning address of PROGC plus 30). The result is 004126. That is REF4 in PROGA is ENDA-LISTA+LISTC=4054-4040+4112=4126.
PNSIT, Bangalore
14
System Software Similarly the load address for symbols LISTA: PROGA+0040=4040, LISTB: PROGB+0060=40C3 and LISTC: PROGC+0030=4112 Keeping these details work through the details of other references and values of these references are the same in each of the three programs.
Symbol
Address 4000
Length 63
LISTA ENDA PROGB LISTB ENDB PROGC LISTC ENDC PNSIT, Bangalore
System Software
System Software Modification record of the object programs. The algorithm for Pass 2 of Linking Loader is given below.
System Software The question here is can we improve the efficiency of the linking loader. Also observe that, even though we have defined Refer record (R), we havent made use of it. The efficiency can be improved by the use of local searching instead of multiple searches of ESTAB for the same symbol. For implementing this we assign a reference number to each external symbol in the Refer record. Then this reference number is used in Modification records instead of external symbols. 01 is assigned to control section name, and other numbers for external reference symbols. The object programs for PROGA, PROGB and PROGC are shown below, with above modification to Refer record ( Observe R records).
PNSIT, Bangalore
18
System Software
PNSIT, Bangalore
19
System Software
Symbol and Addresses in PROGA, PROGB and PROGC are as shown below. These are the entries of ESTAB. The main advantage of reference number mechanism is that it avoids multiple searches of ESTAB for the same symbol during the loading of a control section
Ref No. 1 2 3 4 5
PNSIT, Bangalore
20
System Software
Ref No. 1 2 3 4 5
R N ef o. 1 2 3 4 5
Sy bol m PR G O C L A IST E D N A L T IS B E D N B
PNSIT, Bangalore
21
System Software
System Software load time. The Other Alternatives are Linkage editors, which perform linking prior to load time and, Dynamic linking, in which linking function is performed at execution time
Library
Linking loader
Memory
The above diagram shows the processing of an object program using Linking Loader. The source program is first assembled or compiled, producing an object program. A linking loader performs all linking and loading operations, and loads the program into memory for execution.
System Software often allow the user to specify that external references are not to be resolved by automatic library search linking will be done later by linking loader linkage editor + linking loader savings in space Object Program(s)
Library
Linkage Editor
Linked program
Relocating loader
Memory
PNSIT, Bangalore
24
System Software (and if) they are needed. The actual loading and linking can be accomplished using operating system service request.
THEADR specifies the name of the object module. MODEND specifies the end of the module. PUBDEF contains list of the external symbols (called public names). PNSIT, Bangalore 25
System Software EXTDEF contains list of external symbols referred in this module, but defined elsewhere. TYPDEF the data types are defined here. SEGDEF describes segments in the object module ( includes name, length, and alignment). GRPDEF includes how segments are combined into groups. LNAMES contains all segment and class names. LEDATA contains translated instructions and data. LIDATA has above in repeating pattern. Finally, FIXUPP is used to resolve external references.
System Software
___________________
PNSIT, Bangalore
27