Anúncio
Anúncio

Mais conteúdo relacionado

Anúncio
Anúncio

Loader

  1. 1
  2.  A loader is a system program that performs the loading function.  many also support relocation & linking  others have a separate linker and loader  Basic Functions  bringing an object program into memory  starting its execution 2
  3.  Object program:  contains translated instructions and data from the source program.  specifies addresses in memory where these items are to be loaded. 3
  4.  Allocation: allocate space in memory for the programs  Linking: Resolve symbolic references between object files  combines two or more separate object programs  supplies the information needed to allow references between them  Relocation: Adjust all address dependent locations, such as address constants, to correspond to the allocated space  modifies the object program so that it can be loaded at an address different from the location originally specified  Loading: Physically place the machine instructions and data into memory 4
  5. 5
  6.  Compile and Go  Also known as assemble-and-go  The assembler run in one part of memory  place the assembled machine instructions and data, as they are assembled, directly into their assigned memory locations  When the assembly is completed, the assembler causes a transfer to the starting instruction of the program 6
  7. 7 Source program deck Compile-and-go translator (eg.assembler) Program loaded in memory Assembler memory
  8.  A portion of memory is wasted  It is necessary to re-translate (assemble) the user's program file every time it is run.  It is very difficult to handle multiple segments  Makes it very difficult to produce orderly modular programs. ADVANTAGES  Easy to implement  Involves no extra procedures 8
  9.  Use of object deck.  Addition of new program(loader)  Allows to write subroutines in several different languages. 9
  10. 10
  11.  Its operation is very simple  no linking or relocation  Fits the general loader scheme model  Object deck is punched on card instead of being placed directly in memory.  Makes more core available to memory. 11
  12. 12
  13. SOURCE DECK INPUT TO ABSOLUTE ASSEMBLER OBJECT DECK OUTPUT FROM ABSOLUTE ASSEMBLER MAIN PROGRAM MAIN PROGRAM Location Instruction MAIN START 100 BALR 12,0 100 BALR 12,0 USING MAIN+2,12 102 : : : : 120 L 15,142(0,12) L 15,ASORT 124 BALR 14,15 BALR 14,15 126 : : : : : : : ASORT DC F’400’ 244 F’400’ END 248 SQRT subroutine SQRT subroutine SQRT START 400 400 : USING *,15 : : : : : BR 14 476 BCR 15,14 END 478 13 Call SQRT Address of SQRT Compute square root return
  14.  Address conflict occurs if more than one subroutine.  If changes were made to MAIN that increased its length to more than 300 bytes  the end of MAIN (at 100 + 300 = 400) would overlap the start of SQRT (at 400)  It would then be necessary to assign SQRT to a new location  changing its START and re-assembling it?!  Furthermore, it would also be necessarily to modify all other subroutines that referred to the address of SQRT. 14
  15.  Actual load address must be specified  The programmer must be careful not to assign two subroutines to the same or overlapping locations  Difficult to use subroutine libraries (scientific and mathematical) efficiently  important to be able to select and load exactly those routines that are needed 15
  16.  Allocation - by programmer  Linking - by programmer  Relocation - None required-loaded where assembler assigned  Loading - by loader 16
  17.  Allocation – by programmer  Linking – by programmer  Relocation – by assembler  Loading – by loader 17
  18.  The main program A wishes to transfer to subprogram B.  The programmer, in program A, could write a transfer instruction (e g, BSR B) to subprogram B.  The assembler does not know the value of this symbol reference and will declare it as an error 18
  19.  The assembler pseudo-op EXT followed by a list of symbols indicates that the symbols are defined in other programs but referenced in the present program  If a symbol is defined in one program and referenced in others,  insert it into a symbol list following the pseudo-op ENT. 19
  20. 20 MAIN ORG $10 EXT SUBROUT BSR SUBROUT DONE HLT
  21.  Automatically executed when the computer is first turned on  Loads the first program to be run: usually the O/S itself begins at address 0 in memory  loads the O/S starting at address 80  After all code is loaded, bootstrap jumps to address 80.  No H or E records, no control information 21
  22.  Linking  Relocation  Loading 22
  23.  Relocating loaders or relative loaders:  loaders that allow for program relocation.  Two methods for specifying relocation as part of the object program:  1. A Modification record  describe each part of the object code that must be changed when the program is relocated  M0000_16 23
  24.  Bit mask: A relocation bit/byte associated with each word of object code  S for Absolute: does not need modification  R for Relative: needs relocation  X for external.  Example  T00106119SFE00S4003S0E01R 24
  25.  Pass 1  Allocate and assign each program location in core.  Create a symbol table filling in the values of the external symbols.  Pass 2  Load the actual program text.  Perform the relocation modification of any address constants needing to be altered.  Resolve external references. (linking) 25
  26.  External Symbol Table (ESTAB)  stores the name and address of each external symbol in the set of programs being loaded.  Indicates in which program the symbol is defined.  A hash table is generally used.  Program Load Address (PROGADDR)  beginning address in memory where the linked program is to be loaded.  supplied by the O/S 26
  27.  Control Section Address (CSADDR)  starting address assigned to the CS currently being scanned by the loader  Its value is added to all relative addresses within the control section to convert them to actual addresses 27
  28.  Pass 1: concerned only w/Header records  PROGADDR is obtained from O/S  CSADDR is set accordingly  All external symbols are entered into External Symbol Table (ESTAB)  Their addresses are obtained by adding values specified in header to CSADDR (- First ORG?!)  Starting address and length of each CS are determined. CSADDR = CSADDR + CSLEN  Print Load Map 28
  29. Progra m/CS Symbol Address Length Test 0040 0046 EXE 0060 ProgA 0086 0010 LISTA 0090 ProgB 0096 6 29
  30.  Does actual loading, relocation, and linking  As each Text record is read  The object code is moved to the specified address (plus the current value of CSADDR)  When “R” is encountered, the value is added or subtracted from the indicated location in memory  When “X” is encountered resolve symbol from ESTAB  Last step: transfer control to loaded program to begin execution, as indicated in the End record 30
  31.  Allocating subroutines to prevent reassembling the code every time a subroutine changes  Binary Symbolic Subroutine (BSS) Loader  The program length information is for allocation.  Bit Mask is used for relocation  The transfer vector is used to solve the problem of linking 31
  32.  The assembler assembles Provides the loader  Object program + relocation information  Prefixed with information about all other program it references (transfer vector).  The length of the entire program  The length of the transfer vector portion 32
  33.  A transfer vector consists of  addresses containing names of the subroutines referenced by the source program  if a Square Root Routine (SQRT) was referenced and was the first subroutine called, the first location in the transfer vector could contain the symbolic name SQRT.  The statement calling SQRT would be translated into a branch to the location of the transfer vector associated with SQRT 33
  34.  loads the text and the transfer vector  loads each subroutine identified in the transfer vector.  place a transfer instruction to the corresponding subroutine in each entry in the transfer vector.  The execution of the call SQRT statement result in a branch to the first location in the transfer vector  which contains a branch to the location of SQRT. 34
  35. 35 MAIN START EXTERN SORT EXTERN ERR4 ST 14,SAVE L 1,F’9’ BAL 14,SQRT C 1,=F’3’ BNE ERR L 14,SAVE BR 14 SAVE DS F’1’ END Rel. relocation Addr. Bit 0 00 ‘SQRT’ 4 00 ‘ERRb’ 8 01 ST 14,36 12 01 L 1,40 16 01 BAL 14,0 20 01 C 1,44 24 01 BC 7,4 28 01 L 14,36 32 0 BCR 15,14 34 0 36 00 40 00 9 44 00 3 Program length=48 bytes Transfer vector=8 bytes
  36. Absolute address Relative address MEMORY LENGTH 400 0 BC 15,448 404 4 BC 15,526 408 8 ST 4,436 412 12 L 1,440 416 16 BAL 14,400 420 20 C 1,444 48 BYTES 424 24 BC 7,404 428 28 L 4,436 432 32 BCR 15,14 436 36 440 40 9 444 44 3 448 48 SQRT 78 BYTES 36
  37. 1. Relocation bits are used to solve the problem of relocation. 2. Transfer vector is used to solve the problem of linking. 3. Program length information is used to solve the problem of allocation. 37
  38. 1. Not well suited for loading or storing external data 2. Transfer vector increases the size of the object program in memory. 3. Not good for data segement 38
  39.  Direct linking loader is a general relocatable loader.  Most popular loading scheme  Allows programmer multiple procedure segments and multiple data segments and of giving him complete freedom in referencing data or instruction contained in other segments. 39
  40.  The assembler(translator) provides 1. The length of segment 2. A list of all entries and their relative location within the segment 3. A list of all external symbols 4. Information as to where address constants are loaded in the segment and a description of how to revise their values. 5. The machine code translation of the source program and the relative addresses assigned 40
  41.  External Symbol Dictionary (ESD) record: Entries and Externals  (TXT) records control the actual object code translated version of the source program.  The Relocation and Linkage Directory (RLD) records relocation information  The END record specifies the starting address for execution 41
  42. 42 Program Card no. 1JOHN START 2 ENTRY RESULT 3 EXTRN SUM 4 BALR 12,0 5 USING *,12 6 ST 14,SAVE 7 L 1,POINTER 8 L 15,ASUM 9 BALR 14,15 10 ST 1,RESULT 11 L 14,SAVE 12 BR 14 13 TABLE DC F’1,7,9,10,3’ 14 POINTER DC A(TABLE) 15 RESULT DS F 16 SAVE DS F 17 ASUM DC A(SUM) 18 END TRANSLATION Rel. loc. 0 BALR 12,0 2ST 14,54(0,12) 6L 1,46(0,12) 10L 15,58(0,12) 14BALR 14,15 16ST 1,50(0,12) 20L 14,54(0,12) 24BCR 15,14 26 1 30 7 34 9 38 10 42 3 46 28 50 -------- 54 ------- 58 ? 62
  43. Reference no. symbol type Relative location length 1 JOHN SD 0 62 2 RESULT LD 50 ------- 3 SUM ER ----- --------- 43 Referenc e no symbol flag length Relative location 14 POINTER + 4 46 17 SUM + 4 58
  44. REFERENCE NO RELATIVE LOCATION OBJECT CODE 4 0 BALR 12,0 6 2 ST 14,54(0,12 7 6 L 1,46(0,12) 8 10 L 15,58(0,12) 9 14 BALR 14,15 10 16 ST 1,50(0,12) 11 20 L 14,54(0,12 12 24 BCR 15,14 13 26 1 13 30 7 13 34 9 13 38 10 13 42 3 14 46 28 17 58 44
  45.  It is necessary to allocate, relocate, link, and load all of the subroutines each time in order to execute a program  loading process can be extremely time consuming.  Though smaller than the assembler, the loader absorbs a considerable amount of space  Dividing the loading process into two separate programs a binder and a module loader can solve these problems. 45
  46.  A binder is a program that performs the same functions as the direct linking loader  allocation, relocation, and linking  Outputs the text in a file rather than memory  called a load module.  The module loader merely has to physically load the module into memory. 46
  47.  Core image builder:  Produces a load module that looks very much like a "snapshot" or "image" of a section of core,  Called Core image module.  Link editor, can keep track of the relocation Information  The load module can be further relocated  The module loader must perform allocation and relocation as well as loading  No linking. 47
  48.  If a subroutine is referenced but never executed  if the programmer had placed a call statement in the program but was never executed because of a condition that branched around it  the loader would still incur the overhead or linking the subroutine.  All of these schemes require the programmer to explicitly name all procedures that might be called. 48
  49.  If the total amount of memory required by all subroutines exceeds the amount available  The module loader loads the only the procedures as they are needed.  Allocating an overlay structure  The Flipper or overlay supervisor is the portion of the loader that actually intercepts the "calls" and loads the necessary procedure. 49
  50.  Suppose a program consisting of five subprograms (A{20k},B{20k}, C{30k}, D{10k}, and E{20k}) that require 100K bytes of core.  Subprogram A only calls B, D and E;  subprogram B only calls C and E;  subprogram D only calls E  subprogram C and E do not call any other routines  Note that procedures B and D are never in used the same time; neither are C and E. 50
  51. 51 100K A(20K) B(20K) C(30K) D(10k) E(20K) Subroutine calls between the procedures E B C A D 0 20K 40K 60K 80K 100K Possible storage assignment of each procedure A(20K) B(20K) D(10K) C(30K) E(20K) 70 K Overlay structure
  52.  The loading and linking of external references are postponed until execution time.  The loader loads only the main program  If the main program should  execute a branch to an external address,  reference an external variable  The loader is called  Only then has the segment containing the external reference loaded. 52
  53.  Advantage  No overhead is incurred unless the procedure to be called or referenced is actually used.  System is dynamically reconfigured.  Disadvantage  Overhead and complexity incurred bez postponed 53
  54.  Assembler and programmer performs allocation, relocation and linking  Loader loads the object deck  Assembler pass two types of information  Machine instruction with assigned core locations  Entry point of the program 54
  55.  Text cards(for instructions and data)  Transfer Cards(to hold entry point to program) 55 Card column contents 1 Card type=0(for text card identifier) 2 Count of number of bytes(1 b/c) of info. On card 3-5 Address at which data on card is to be put 6-7 Empty (validation) 8-72 Instructions and data to be loaded 73-80 Card sequence number Card Column Contents 1 Card type=1(transfer card identifier) 2 Count=0 3-5 Address of entry point 6-72 Empty 73-80 Card sequence number
  56. 56 INITIALIZE Set CURLOC to location in characters 3-5 READ CARD Transfer to location CURLOC Set LNG to count in character 2 Move LNG bytes of text from characters 8-72 to location CURLOC Card type ? Type=0 Type=1
  57. Source card reference Relative address Sample program 1 0 PG1 START 2 ENTRY PG1ENT1,PG1ENT2 3 EXTRN PG2ENT1,PG2 4 20 PG1ENT1 ----------- 5 30 PG1ENT2 ---------- 6 40 DC A(PG1ENT1) 7 44 DC A(PG1ENT2+15) 8 48 DC A(PG1ENT2-PG1ENT1-3) 9 52 DC A(PG2) 10 56 DC A(PG2ENT1+PG2-PG1ENT1+4) 11 12 0 PG2 START 13 ENTRY PG2ENT1 14 EXTRN PG1ENT1,PG1ENT2 15 16 PG2ENT1 16 24 DC A(PG1ENT1) 17 28 DC A(PG1ENT2+15) 18 32 DC A(PG1ENT2-PG1ENT1-3) 57
  58. 58 Source card reference Name Type ID Relative address length 1 PG1 SD 01 0 60 2 PG1ENT1 LD --- 20 --- 2 PG1ENT2 LD ---- 30 --- 3 PG2 ER 02 ---- --- 3 PG2ENT1 ER 03 ---- --- Source card reference Relativ e addres s content s comments 6 40-43 20 7 44-47 45 =30 +15 8 48-51 7 =30 – 20 - 3 9 52-55 0 Unknown to PG1 ESD card for PG1 TXT cards
  59. Source card reference ESD ID Length(byte s) Flag + or - Relative address 6 01 4 + 40 7 01 4 + 44 9 02 4 + 52 10 03 4 + 56 10 02 4 + 56 10 01 4 - 56 59 RLD card for PG1
  60. 60 Source card reference Name Type ID Relative address length 12 PG2 SD 01 0 36 13 PG2ENT1 LD --- 16 --- 14 PG1ENT1 ER 02 --- --- 14 PG1ENT2 ER 02 ---- --- Source card reference Relativ e addres s content s comments 16 24-27 0 17 28-31 15 18 32-35 -3 ESD card for PG2 TXT card FOR PG2
  61. Source card reference ESD ID Length(byte s) Flag + or - Relative address 16 02 4 + 24 17 03 4 + 28 18 03 4 + 32 18 02 4 + 32 61 RLD card for PG2
  62.  Pass 1  Input object decks  Initial Program Load Address(IPLA)  Program Load Address(PLA)  Global External Symbol Table(GEST)  A copy of input to be used later by pass2  A printed listing the load map 62
  63.  Pass 2  Copy of the Input program inputted to pass1  Initial Program Load Address(IPLA)  Program Load Address(PLA)  Global External Symbol Table(GEST)  An array, the Local External Symbol Array(LESA) 63
  64.  GEST(Global External Symbol Table)  Used to store the external symbols definitions  LD and SD of and ESD card are stored  In pass1 absolute core address is assigned and stored with symbol name. 64 External symbol( 8 byte) Assigned core address( 4 byte) “PG1bbbbb” 104 “PG1ENT1b” 124 “PG1ENT2b” 134 “PG2bbbbb” 168 “PG2ENT1b” 184
  65.  LESA(Local External Symbol Array)  Used to establish a correspondence between the ESD ID numbers, used on ESD and RLD cards and external symbols absolute address  Maximum 255 entries 65 Inde x by ID Assigned core address of corresponding symbol( 4 byte) 1 104 2 124 3 134 4 --- ----- 254 ----- 256 ----
  66.  Pass 1  Allocate Segments  Initial Program Load Address (IPLA)  Assign each segment the next table location after the preceding segment.  Define Symbols  SD  LD  ER?! 66
  67. 67
  68.  ESD record types is processed differently.  SD The LENGTH of the segment is temporarily saved in the variable SLENGTH.  LD does not require any processing during pass 2.  ER The Global External Symbol Table (GEST) is searched for match with the ER symbol  If found in the GEST, Substitute value  If it is not found  error 68
  69.  TXT: the text is copied from the record to the relocated core location (PLA + ADDR).  RLD: The value to be used for relocation and linking is extracted from the GEST  If Flag is Plus the value is added, if Flag is minus the value is subtracted from the address constant  The relocated address of the address constant is the sum of the PLA and the ADDR field specified on the RLD record. 69
  70.  END: The execution start address is 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/E0F record  The loader transfers control to the loaded program at the address specified by current contents of the execution, address variable (EXADDR) 70
  71. 71
Anúncio