You are on page 1of 20
DESIGN OF AN ABSOLUTE Loy 168 responding punched card code (8, hexadecimal gq t is byte here is & COT oles, 12-01-89, whereas a hexadecimal py 8? column punched Wi in row 1). Thus, when a card is read, it ig stor a ‘column with a single Pun i core as $0 contiguous BYTES ext cards tor nstructions and deta) Contents an Card type * 0 (for text card identifier) CCount of number of bytes (1 byte per column) of information on 2 ‘Address at which data on card is to be put i 35 Empty (could be used for validity checking) Br Cadac intr Transfer cards (to hold entry point to program) Cardcolumn Contents : 1 Card type = 1 (transfer card identifier) 2 Count = 0 35 Address of entry point 672 Empty 7380 Card sequence number FIGURES.10 Card formats for an absolute loader The algorithm for an absolute loader is quite si i ier cnt of ses of ext cards terminated ya teeta the loader should read one card at a time, moving the text to the ioe , until the transfer card is Teached. At this point the 7 a is only necessary to transfer to the entry |. A flowchart for this Process is illustrated 5.3 DESIGNOF A DIRECT-LINKING LOADER In this sectic 7 Ceriain hae ate of an IBM 360-type directlinking loader is presented. vera structures) nas (Primarily related to the IBM PL/I implementation and 8) hi a only the simples )! ae been omitted, and where alternative formats are possible, e desi . sembler (Chapt) ‘owed Will parallel those taken in the design of an a Note that because the direct-linking loader needs to know Scanned with CamScanner READ CARD. Set CURLOC to location in characters 35 Transfer to location CURLOC Set LNG to count in character 2 ‘Move LNG bytes of text from characters 8-72 to location CURLOC GURE 5.11 Absolute loader absolute (load time) values of some external symbols before it can perform modifications on address constants, it requires two passes. 3.1 Specification of Problem 0 be performed by its jecessary tO instruction by nsither at haracters, he organization of the IBM 360 facilitates the tasks t locating loader. On the IBM 7094, a direct access machine, it wast 1m almost all instructions. In the 360, i Ocation is accomplished by the use of the base register, which is S08 assembler nor the loader. Therefore, the 360 relocatins loader ' P 'a (full word constants, © Ns exactly like nonrelocatable dat Scanned with CamScanner d ECT LINKING DESIGN OF ADIRI Lonoen Ln ‘TEST ‘START “18 ie {DATA : . DATA 0c F —ND might be asemoled as: Rel. bee, Instruction/iate ok 19610,15). 6 5 Regurdles of where the programs loaded, the L instruction willbe ‘unchangea as long as DATA remains 96 bytes from the beginning 5 The contents of the base repster (15) obviously willbe differen, depending upon the program's load location, ; (nthe other hand, consider modifying the above example: DATA oo Fe DATALOC = DC AIDATA) END DATALOC must contain the absolute address of DAT, The assembler knows From the bein oe The assembler knows only that DATA is 96 bytes from the beginning of the Nr Must add to this the load address of the ADAT ee sacthe Brogram in Finding the actual absolute address to be contained in. DATALOC, Let us clarify the ‘Scope of the address constant Problem. An address constant ‘may be (1) absolute; (2) simple relocatal ible; or (3) complex r fable. wa the address constant 1-LOC2) will be: 1, Absolute if L¢ OC1 and LOC? are twa relocatable symbols defined internal Sproat =the asembler can ealulate theacteleaee gee + Simple relocatable i LOCI is a relocatable symbol withi rocedure Vv SSID het ees oS ea en Srence between relative location of LOCI and value of LOC2, but the lo: . ader must perf ing the program load adda A carbtee ble if LOCI and LOC? are entries to some other 7° Tica 0 2 LOC a ei 1 he catesiated “Y the loader, Scanned with CamScanner OADERS u wm 360 direct-linking loader processes progra bee FORTRAN compiler, or PLT complet Ret a by the asm. source program nor_the assembler symbol table is WARE oo inking. ae four sections to the object deck (and four corresponding card formats): ww External Symbol Dictionary cards (ESD) 4 Instructions and data cards, called “text” of program (TXT) Relocation and Linkage Directory 'cards (RLD) Wf End card (END) ‘The ESD cards contain the information necessary to build dhe external symbol dictionary or symbol table. External symbols are symbols that can be referred beyond the subroutine level. The normal labels in the source program are used only by the assembler, and information about them is not included in the object deck, EXAMPLE ‘Assume program B has a table called NAMES; it can be accessed by program A as follows. A START EXTRN NAMES cg 1,ADDRNAME get address of NAME table ADDRNAME oc A(NAMES) END B START ENTRY NAMES: NAMES oc ean END There are three types of external symbols, as illustrated in the above: 1. Segment Definition (SD) — name on START or CSECT card. od 2. Local Definition (LD) — specified on ENTRY card. There must be 10 in same program with same name. 3. Extemal Reference (ER) — specified on EXTRN card. There must bel Scanned with CamScanner % DESIGN OF A DIRECT LINKING LOADER corresponding ENTRY, START, of CSECT card in another program with same name. Each SD and ER symbol is assigned a un assembler. This number is called the symb« conjunction with the RLD cards. The TXT cards contain block: data is to be placed. Once the loader hi i mber (¢.g., 1,2,3,.. .) by the ors identifier, or ID, and is used in of data and the relative address at which the | + ger has decided where to load the program, it PLA) to the relative address and moves merely adds the Program Load Address ( d the ‘it into the resulting location. The data on the a card may be instruc. tions, nontelocated data, or initial values of address constants, EXAMPLE Relative address Instruction A START EXTRN NAMES USING “15 o L ALPHA “4 BCR 15,14 46 ———_ [Skipped by assembler) 48 ALPHA oc Fs 52 ALLOC oc AIALPHA) 56 ADDRNAME oc AINAMES) The TXT card produced is: Relative address = 40 Data portion = 58 10 FO 30 O7FE XX XX 00 00 00 05 00 00 00 30 00 00 00 00 Length of data portion = 20 bytes The RLD cards contain the following information. 1. The location and length for relocation or linking 2, The external symbol by which the address constant should be modified (added or subtracted) 3. The operation to be performed (add or subtract) Rather than using the act implied in section 5.1.6 used. There are various ID is only a single by of each address constant that needs to be changed ual external symbol's name on the RLD card, a8 and Figure 5.8, the external symbol’s identifier, of ID, is Teasuns for this, the major one probably beg that the ‘te long, compared to the eight bytes occupied bv the Scanned with CamScanner VW noes ul F : that a considerable amount of space is saved on the RLD cards, es ; F : nibol oe this space-saving technique causes increased loader complexity 9 ve grown Tater. ss!" receding PFOB" ce! - Phe following RLD cards am segment used as an example for TXT cards would Flag Length Rel, loc. 0 + 4 52 ot + 4 56 a se that A's signed ID is O1 and NAMES’ asigned 1D is 02. This RLD the loader to add the absolute load address of A to the contents ; formation tells tive location 52 and then add the absolute load address of NAMES to the relative location 56. END card specifies the end of the object deck. If the assembler END card jysa symbol in the operand field, it specifies a start of execution point for the ene program all subroutines). This address is recorded on the END card. al card required to specify the end of a collection of object decks. ‘There isa fin é ‘the 360 loaders usually use either a loader terminate (LDT) or End of File (G0F) card. | egntents fF EsD : TXT Subroutine A RLD : END EsD XT Subroutine B ke END EsD sivoune Bt END EOF or LOT eam programs PGI and PG2 in Figure 5.12 illustrate a wide renge of and RID iad linking situations. Figures 5.13 and 5.14 display the ESD, TXT, Fry, Figur er roduced by the assembler for PGI and PG2, respectively. a aeated -15 depicts the contents of main storage after the programs have Teas rate located, linked, and loaded. The reader should examine {oH carefully and validate the correctness and reasons for each Yae- ‘Pecific points in these examples should be noted. Both PG1 and PG2 Sia "an address constant ofthe form A(PGIENT2-PGIENT 1-3). It should be Scanned with CamScanner FA DIRECT LINKING LOADER a DESIGN OF Source . tac ‘sores ‘Sample prograrn (s0ure? iT . Senn PGIENTIPGIENT2 3 EXTRN — PGZENT1PG2 ; ‘ 20. PGIENTI = = 8 30 PGIENTZ. aporenr) 7 “ oc AIPGIENT2+15) : & oc ‘AiPGIENT2-PG1ENT1-3) ° = oc A(PG2) : 9 82 oc AIPGZENT1#PG2-PG TENT 144) u * END START 2 0 Paz START scent ; “ EXTAN PGIENT1,PGIENT2 “ 2 1 = 6 6 PG2ENT: zi ecven™ ® 2B pc, AIPGIENT2+15) @ 32 oc AIPGIENT2-PG1ENT1-3) . i END 3 FIGURES.12 Sample procedures PGI and PG2 reassusing to note in Figure 5.15 that both instances of this address constant (location 152, 200) have the same value — 7. Since both PGIENT2 and {ENT are symbols internal to PG1, the assembler, processing PG1, can com- wte the entise expression and determine the value of 7. We see in Figure 5.13 that the TXT card for location 48-51 contains the 7 and there are no associated RLD cards for this address constant. On the other hand, these symbols are exter- nal to PG2; thus, the assembler, while processing PG2, has no means of evaluat ing the address constant. This is illustrated in Figure 5.14. The TXT card for relative locations 32-35 contains a -3, the only part of the address constant that can be calculated by the assembler. The last two RLD cards tell the loader to add the value of ID 03, which is PGIENT2, to locations 32-35 and then subtract the value of 3D 02, which is PGIENT1. When processed by the loader, this address constant in PG2 will indeed have the same value as the one in PG1. Since the directlinking loader may encounter external references in an object deck which cannot be evaluated until a later object deck is processed, this (7? of loader requires two passes. Their functions are very similar to those of the two passes of an assembler. The major function of pass 1 of a directinking loader is to allocate and assign each program a location in core and create # Scanned with CamScanner ; | LOADERS “175 me ESO cards source card reference Neme Type 1D address Length 1’ PG1 so 01 ° 60 2 PGIENTI Lo —_ 20 ho 2 PGIENT2 Lo -- 30 — 3 PG2 ER 02 a _ 3 PG2ENT1 ER 03 -- — TXT cards (only the interesting ones, 1.e. thdse involving address constants) Source card reference Relative address Contents Comments 6 40-43 20 7 44-47 45 = 30415 8 4851 7 = 30203 9 5255 unknown to PG1 56-59 =-20+4 RLD cards . Flag Sourcecard reference ESDID Length (bytes) tor= Relative address 6 o1 4 + 40 7 oO 4 + a4 9 02 4 + 52 10 03 4 + 68 02 4 + 86 01 4 - 56 FIGURE 5.13 Object deck program PGL symbol table filling in the values of the external symbols. The major function Of pass 2 is to load the actual program text and perform the relocation modifica- tion of any address constants needing to be altered. The first pass allocates and assigns staiage locations to all segments and stores the values of all external symbols in a symbol table. These external symbols ‘Ppear as local definitions on the ESD cards of another assembled program. For ‘very external reference symbol there must be a corresponding internal symbol in some other program. The loader inserts the absolute address of all of ed &xtema symbols in the symbol table. In the second pass, the loader placts © text into the assigned locations and performs the relocation task, noe jeotabe constants, Figure 5.16 depicts the interplay between the passe aderin a direct-linking loading scheme. Scanned with CamScanner ve DESIGN OF A DIRECT LINKING LOADER ‘Source card reference 12 PG2 13 PG2ENTI 4 PGIENTI 4 PGIENT2 (only the interesting ones) Relative address 2427 28-31 32.25 ALD cards Length flag ESD ID (bytes) Source card reference 16 a 4 7 03 4 8 03 4 18 02 4 FIGURE 5.14 Object deck program PG2 .2 Specification of Data Structures next step in our design procedure is to identify the data bases required by pass of the loader. ass | data bases: 1. Input object decks. 2. A parameter, the Initial Program Load Address (IPLA) supplied by the programmer or the operating system, that specifies the address to load the first segment. 3. A Program Load Address (PLA) counter, used to keep track of each segment’s assigned location. 4. A table, the Global External Symbol Table (GEST), that is used to store each external symbol and its corresponding assigned core address. 5. A copy of the input to be used later by pass 2. This may be stored on a” auxiliary storage device, such as magnetic tape, disk, or drum, oF the original object decks may be reread by the loader a second time for pass 6. A printed listing, the load map, that specifies each external symbol and its assigned value. Scanned with CamScanner LOADERS ™ "p61 loaded at location 104 FG loaded at location 168 G2 FIGURES.15 Main storage after loading programs PG1 and PG2 Pass 2 data bases: i 1. Copy of object programs inpu‘ted to pass 1 2. The Ina Program Load Address parameter (IPLA) . The Program Load Address counter (PLA an 4. The Global External Symbol Table (GEST), prepared by ti. ane ing each external symbol and its corresponding absolute @ SS ae 5. An array, the Local External Symbol Array (LESA), WING Ty oo esp establish a correspondence between the ESD ID ett aadress = RLD cards, and the corresponding external symbol’s # lue Scanned with CamScanner GN OF A DIRECT LINKING LOADER 78 DESI _ From assemblers Cepy of and compilers ‘object decks Segments Toaded in memory GURES.16 Two pass direct-linking loader scheme 5.3.3 Format of Data Bases The third step in our design procedure is to’ specify the format and content of cach of the data bases. The major data bases are depicted in Figure 5.17. Copy of object decks input orject / decks External Symbol Array Printed load map \ \ptnitiat Program \ |] Load Address {IPLA) Global External Symbol Table (GEST) FIGURE 5.17 Use of data bases by loader passes Scanned with CamScanner ‘0 and detail the actual card deck format that is used by various {BM inking loaders. The specific card format is not crucial, but good example of the various techniques used to encode QBlECT DECK on discussed several times; Figures §.18, 5.19, 5 sue object deck he ' sal, depict in 370 or 360 direct these figures present & ation. ee EXTERNAL SYMBOL TABLE ob 1 External Symbol Table (GEST) is used to store the external symbols ‘ened by means of a Segment Definition (SD) or Local Definition (LD) entry egxternal Symbol Dictionary (ESD) ¢ard. When these symbols are en countered during pass 1, they are assigned an absolute core address; this address js stored, along with the symbol, in the GEST as illustrated in Figure 5.22. ‘The reader may wish to review the discussion on symbol tables and searching/ sorting techniques presented in Chapter 3 in conjunction with the design of an Columes Contents 1 Hexadecimal byte X02" (card punch 12-2-9) 24 Characters ESD. 514 Blank 15-16 ESD identifier (1D) for program name (SD) or external symbol (ER) (IDs unique within program) or blank for entry (LD), see box below 17-24 Name, padded with blanks, 5 ESD typecode(TYPE) [TYPE Hexaavcimal code 2628 Relative address or blank (ADDR), see box below 29 Blank 3032 Length of program otherwise blank (LENGTH) 3372 Blank 7380 Card sequence number ESO forms and conventions Type ID ADUR Length Program name ( (seg SD th of program mentecteane 1 Zero Length of p e inet det Lp Relative address | — External reference ER {The unique 1D numbers ore usu Figi URES.18 ESD card format Unique number — eet lelly assigned sequentially.) Scanned with CamScanner Columns ~ 1 24 6 68 9-10 VW12 13-16 172 73-80 DESIGN OF A DIRECT LINKING LOADER Contents Hexadecimal byte X'02" Characters TXT Blank Relative address of first data byte (ADDR) a Count (BC) = number of bytes of Information In cc. 17-72 Hank . From 1 to 56 data bytes (Instructions and “date” look the same) Card sequence number FIGURES5.19 TXT card format Contents Hexadecimal byte X'02" Characters RLO- Blank 1D corresponding to 8 number assigned to SD or ER on ESD carg Flag byte (see box below) Relative address of first byte of address constant (ADDR) Blank Card sequence number Flag byte conventions bits 03 4 FIGURE 5.20 RLD card format Columns 1 24 5 68 9-72 7380 Not used Length (in bytes) of address constant 00 = one byte 01 = two bytes 10= three bytes 11 = four bytes Omeans add ESD address to address constant ‘1 means subtract ESD address from address constant Contents Hexadecimal byte x'02" Characters END Blank Start of execution entry (ADDR), If other than beginning of 0 ‘gram (specified on assembly END card) Blank Card sequence number FIGURE 521. END card format Scanned with CamScanner LOADERS we <—$_ 12 vt per entry > ‘Assigned address (4-bytes) (decimal) “PGIbbbbb” “PGIENTID" “PGIENT2b” “pG2bbbbb” “PG2ENTIO” notation: This sample GEST content It based upon the example In Figures 6.12 and 5.15. FIGURE5.22. Global External Symbol Table (GEST) format assembler. The GEST has the same general use and characteristics as the ax sembler’s Symbol Table. LOCAL EXTERNAL SYMBOL ARRAY ‘As mentioned earlier, the external symbol to be used for relocation or linking is identified on the RLD cards by means of an ID number rather than the symbol’s name. The ID number must match an SD or ER entry on the ESD cards. This technique both saves space on the RLD cards and speeds processing by eliminat- ing many searches of the Global External Symbol Table. Itis necessary to establish a correspondence between an ID number on an RLD card and the absolute core address value. The ESD cards contain the ID numbers and the symbols they correspond to, while the information relating these symbols to absolute core address values may be found in the GEST. In pass 2 of the loader the GEST and ESD information for each individual object deck is merged to produce the local external symbol array that directly relates ID number and Value, In principle it is necessary to create a separate LESA for each segment, but since the LESAs are only produced one at a time, the same array can be reused for each segment. Figure 5.23 depicts the format of the Local External Symbol Array (LESA). Note that unlike the case with the GEST, it is not ay to search the LESA; given an ID number, the corresponding value is tten as LESA(ID) and can be immediately obtained. 534 Algorithm The following fe sowing two flowcharts (Figs, 5.24 and 5.25) describe an algorithm for a ‘etlinking loader for an IBM System/360type computer While they ilustrate Scanned with CamScanner DESIGN OF A DIRECT LINKING LOADER, <— A bytes per entry ———> Assigned core ee symbol (4bytes) (decimal) ious 255 entries maximum Indexed by 'dentifier Number (ID) er Sens tae won eFC seen read ner. and 8, FIGURES23 Local External Symbol Array (LESA) format Most of the logical processes involved, these flowcharts are still a simplification Of the operations performed in a complex loader. In particular, many “special” features, such as COMMON Segments, library processing, dynamic loading and dynamic linking, are not explicitly included (many of them are discussed in the Problems section and in later chapters), ‘ ¢ Pass 1 ~ auiocate segments and define symbols The purpose of the first La to assign a location to each Segment, and thus to define the values of all oe tie Symbols. Since we wish to minimize the amount of core storage required for the ‘otal program, we will assign each segment the next available location ater Scanned with CamScanner ponoers Write copy of card for pass 2 | LD VALUE + PLA + ADDR Tow ERROR: ie if symbol duplicated use of name and value START or ENTRY in GEST 2 symbol ‘fname and value for load map FIGURES24 Detated pass 1 flowchart Scanned with CamScanner non A DIRECT LINKING LOADER we . pest ow where it can load the Preceding segment. 11 is necessary for the loader (0 kn ddress (IPLA), is normally first segment. This address, the Initial Program toa ns the programmer may determined by the operating system. In some S the IPLA is a parameter specify the IPLA, in either case we will assume tat ‘Supplied to the loader. LA) is set to the Initial Program Loag Initially, the Program Load Address (PI ad and a copy written for use by pasy Address (IPLA). An ont ei Xt RLD, END, or LDT/EOP ttn 2. The card can be one o} ie re scessing equed during pas 10 the nex Moa Ree vis processed in different Ways depending upon the a synbol LD or ER. If a segment definition ESD card ig type of external : LENGTH, from the card is temporarily saved in the vari. ready the lene ge, VALUE, to be asigned to this symbol set 4p the dese he PLA. The symbol adits asiged value are then sored in ae cae a ready existedin the GEST, there must have been a Previouy csr ESD with the same name — this is an error. The symbol and its value m pind aspart of the load map. A similar process is used for LD symbols; the value to be assigned is set to the current PLA plus the ‘telative address, ADD} indicated on the ESD card The ER symbols donot requir any processing dung pass 1. When an END card is encountered, the program load address is incremented by the length ofthe segment and saved in SLENGTH, becoming the PLA forthe next segment. When the LDT or EOF card is finally read, pass 1 is completed and control transfers to pass 2. . Pass 2 - load text and relocate/link address constants After all the seg. ments have been assigned locations and the external symbol: Is have been defined by pass I, itis possible to complete the loading by loading the text and adjusting (relocation or linking) address constants. At the end of pass 2, the loader will transfer control to the loaded program. The following simple rule is often used to determine where to commence execution: 1. If an address is specified on the END card, that address is used as the execution start address, 2. Otherwise, execution will commence at the beginning of the first segment. At the beginning of pass 2 the program load address is init.alized as in pass 1, and the execution start address (EXADDR) is set to IPLA. The cards are read One by one from the object deck file left by pass 1. Each of the five types of cards is processed differently, as follows: ESD CARD Each of the ESD card types is processed differently. Scanned with CamScanner 1. sonnets Move BC bytes from card columns 17-72 to location (PLA + ADDR) EXADOR + (PLA+ADDA) get VALUE from LESA (1D) Set LESA(ID) = PLA Add VALUE to contents of cont location of ji (pLa+ Aon) |_| (PLA+ ADDR) FIGURES 25 Det pas 2 Nowchart Scanned with CamScanner we SUMMARY ily saved in the variable SD-type ESD. The LENGTH of the segment 1s temporary array. LESA(ID), | SLENGTH. The appropriate entry in the local externa sy! S duress. is set to the current value of the Program Ls oad A processing during pass 2 . jt require any ” LD-type ESD. The LD-type ESD does n0 GEST) i ne Exteanal Symbol Table (ces) 's searched for a ER-type ESD The Global ir tig aot found, the correspon ing segment or match with the ER symbol FFT ine gymbol is found inthe GEST, itg an enol. a entry must be miss vnnanesponding Local External Symbol Array entry, Value is extracted and te LESA(ID), 1s set eal #0 TXT on card is read, the text is copied from the card to the appropriate When aT? relocated core locauon (PLA + ADDR). RLDCARD oo 10 be used for relocation and linking is extracted from the local uci abel array as specified by the ID flak, ie., LESA(ID). Depending upon the flag setting (plus or minus) the value is either added to or subtracted om the address constant. The actual relocated address of the address constant computed as the sum of the PLA and the ADDR field specified on the RLD. rd. ND CARD If an execution start address is specified on the END card, it is saved in the vari- able EXADDR after being relocated by the PLA, The Program Load Address is incremented by the length of the segment and saved in SLENGTH, becoming the PLA for the next segment. LDT/EOF CARD The loader transfers control to the loaded Program at the address specified by current contents of the execution address variable (EXADDR). 5.4 SUMMARY The four basic functions of a loader are allocation, linking, relocation, and load- ing. The various types of loaders (e.g., “‘compile-and-go,” absolute, relocating, directlinking, dynamic loading, and dynamic linking) differ primarily in the manner in which the four basic functions are accomplished. A ‘pical ditectJinking loader requires two passes. The first pass alec Space for the segments and defines the values of the external symbols: 3 Scanned with CamScanner Ss 187 Loaner ss actually loads the text and uses the global external symbol table, oy by pass 1, to relocate and link the address constants. produ ugh their purposes are quite different, the design of the direct-linking See ‘many similarities to the design of an assembler. In patticular, the use aie table is important in both cases. a9 Scanned with CamScanner

You might also like