1 / 31

系統程式

系統程式. Chapter 3 : Loaders and Linkers. Expanded Assembly Programs. Object Programs. Libraries. Executables. Assembling Programs for Execution. Assembly Programs. Macro Processors. Core Assemblers. Linkers. Loaders. Assemblers. Fundamental System Software. Assembly Programs.

pepper
Télécharger la présentation

系統程式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 系統程式 Chapter 3: Loaders and Linkers

  2. Expanded Assembly Programs Object Programs Libraries Executables Assembling Programs for Execution Assembly Programs Macro Processors Core Assemblers Linkers Loaders

  3. Assemblers Fundamental System Software Assembly Programs Object Programs Mnemonic op codes Multi-pass One-pass Header records Symbolic operands Text records Assembler directives End records Literals Modification records Symbol-defining stmts Define records Expressions Refer records Program blocks Control sections

  4. Assembly Program 1 Object Program 1 Assembly Program 2 Object Program 2 Assemblers Object Program 3 Assembly Program 3 Fundamental System Software (2)

  5. Assembly Program 1 Object Prog 1 Assembly Program 2 Object Prog 2 Linkers Loaders Assemblers Linkers may combine multiple object codes into a single executable file. Object Prog 3 Assembly Program 3 Fundamental System Software (3)

  6. Assembly Program 1 Object Prog 1 Object Prog 2 Assembly Program 2 Linkers Loaders Assemblers Object Progs A standardized format for the object codes allows linkers to combine object codes created by assemblers and compilers implemented by different providers. Compilers C/C++ ... Programs Fundamental System Software (4)

  7. Assembly Programs Object Progs Assemblers C/C++ ... Programs Object Progs Compilers Linkers Loaders Since the format of object codes is standardized, linkers do not need to know the original computer languages that were used to implement the libraries. Libraries Fundamental System Software (5)

  8. Linkers and Loaders • Loaders bring object programs into memory and start their execution. • Linkers • In most cases all program translators on a particular system produce object programs in the same format. • Discuss why

  9. Simple Loaders • An absolute loader • An absolute loader brings the object code to the memory location chosen by its programmer • Use the algorithm shown in Figure 3.2 to review the operation of a simple loader with Figure 3.1. • Explain the object code and actual object code. • A bootstrap loader • The bootstrap loader loads the first program to be run by the computer--usually an operating system. • Algorithm shown on Figure 3.3 • Bootstrap loaders in ROM (Section 3.4.3)

  10. Absolute Loader

  11. Fetch-Decode-Execute Cycles Source: Charles S. Parker, Understanding Computers Today & Tomorrow, Dryden, 1998

  12. MEMORY ALU (Data Path) address data Registers control Control Unit CPU I/O 2 I/O 1 A Simplified System R AM ROM The CPU loads the very first program , including the bootstrap loader, to be executed from the ROM.

  13. Bootstrap Loader BOOT START 0 CLEAR A LDX #128 LOOP JSUB GETC RMO A,S SHIFTL S,4 JSUB GETC ADDR S,A STCH 0,X TIXR X,X J LOOP GETC TD INPUT JEQ GETC RD INPUT COMP #4 JEQ 80 COMP #48 JLT GETC SUB #48 COMP #10 JLT RETURN SUB #7 RETURN RSUB INPUT BYTE X’F1’ END LOOP EOF ‘0’ <10 A~F

  14. Relocation and Linking • Why relocation? • multiprogramming, libraries,... • Using modification record may not be good for all machine architectures. (Figure 3.6) • Relocation bits and bit masks • required line change (Figure 3.7) • Review Section 2.3.5 • A linkage loader, pp. 134-141 • The assembler does whatever it can do for address calculation. The loader will do the rest.

  15. ? 1111 1111 1100 1110 0000 0000 Relocation Masks

  16. Program Linking 0000 0020 0023 0027 0040 0054 PROGA START 0 EXTDEF LISTA,ENDA EXTREF LISTB, ENDB, LISTC, ENDC . REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA LISTA EQU * . ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA 0054 0057 005A 005D 0060

  17. Program Linking 0000 0020 0023 0027 0040 0054 PROGA START 0 EXTDEF LISTA,ENDA EXTREF LISTB, ENDB, LISTC, ENDC . REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA LISTA EQU * . ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA 0054 0057 005A 005D 0060

  18. Program Linking - PROGB 0000 0036 003A 003D 0060 0070 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA, ENDA, LISTC, ENDC . REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA LISTA EQU * . ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA 0070 0073 0076 0079 007C

  19. Program Linking - PROGB 0000 0036 003A 003D 0060 0070 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA, ENDA, LISTC, ENDC . REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA LISTA EQU * . ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA 0070 0073 0076 0079 007C

  20. Program Linking - PROGC 0000 0018 001C 0020 0030 0042 PROGC START 0 EXTDEF LISTC,ENDC EXTREF LISTA, ENDA, LISTB, ENDB . REF1 LDA LISTA REF2 +LDT LISTB+4 REF3 LDX #ENDA-LISTA LISTA EQU * . ENDA EQU * REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 REF6 WORD ENDC-LISTC+LISTA-1 REF7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA 0042 0045 0048 004B 004E

  21. Pass 1 H and D records Data structure PROGADDR CSADDR CSLTH ESTAB Pass 2 Load maps E and M records Data structure PROGADDR CSADDR EXECADDR CSLTH A Two-Pass Linking Loader What are the R records for? reducing the number of table search operations...

  22. ESTAB

  23. Reference number H^PROGA ^000000^.. D^LISTA ^000040…. R^LISTB ^ENDB ^LISTC ^ENDC …… M^000024^05^+LISTB M^000054^06^+LISTC M^000057^06^+ENDC M^000057^06^-LISTC H^PROGA ^000000^.. D^LISTA ^000040…. R^02LISTB ^03ENDB ^04LISTC ^05ENDC …… M^000024^05^+02 M^000054^06^+04 M^000057^06^+05 M^000057^06^-04

  24. Optional Loader Features • Automatic library search • What? • How? • Enter referred symbols into ESTAB • Search libraries for undefined symbols at the end of pass 1 (and continue the search if necessary) • Issue error messages if undefined symbols still exist

  25. Optional Loader Features • Loader options • INCLUDE program-name(library-name) • DELETE csect-name • CHANGE name1, name2 • LIBRARY MYLIB • NOCALL STDDEV, PLOT, CORREL

  26. Linkage Editor • Linking loaders vs. linkage editors • Frequency of reassembling matters.

  27. The linked program reserves the information for resolving external references. • Edition of linked programs (page 154) • Creation of packages (pp. 154-155) • Timing for linking library functions (page 155)

  28. Dynamic Linking • aka. dynamic loading and load on call • Link the subroutines when they are called • Advantages • Processes share one copy of a subroutine or library. • Processes always use the up-to-dated objects. • Subroutines are loaded only when necessary. • How? Figure 3.14 on page 157 • Binding: the association of an actual addresses with symbolic names

  29. MS-DOS and Windows • MS-DOS • Most MS-DOS compilers and assemblers produce modules. • MS-DOS LINK is a linkage editor. • MS-DOS object module (Figure 3.15) • Windows • *.DLL files

  30. SunOS Linkers • Link-editor and run-time linker • Link-editor linker • Relocation and linking operations are specified using a set of processor-specific codes. • Symbolic references • Library search: archives • Shared objects: dynamic linking • Run-time linker: dynamic linking

More Related