Review 1 2 IEEE 754 Floating Point Standard Kahan pack as much in as could get away with CS61C Machine Structures infinity Not a Number Nan Denorms Lecture 11 Starting a Program 4 rounding modes Stored Program Concept Both data and actual code instructions are stored in the same memory October 4 2000 David Patterson Type is not associated with data bits have no meaning unless given in context http www inst eecs berkeley edu cs61c 1 CS61C L11 Linker UC Regents CS61C L11 Linker UC Regents Things to Remember 1 2 Outline Machine Language Instruction 32 bits representing a single MIPS instruction Compiler R opcode I opcode J opcode rs rs 2 Assembler rt rd shamt funct rt immediate target address Linker Loader Example Instructions formats kept similar Branches Jumps optimized for greater branch distance and hence strange New Logical Shift Instructions and andi or ori sll srl sra 3 CS61C L11 Linker UC Regents Steps to Starting a Program C program foo c 4 Compiler Input High Level Language Code e g C Java Compiler Assembly program foo s Assembler Output Assembly Language Code e g MIPS Note Output may contain pseudoinstructions Object mach lang module foo o Linker Pseudoinstructions instructions that assembler understands but not in machine e g HW 4 For example Loader mov s1 s2 or s1 s2 zero lib o Executable mach lang pgm a out CS61C L11 Linker UC Regents CS61C L11 Linker UC Regents Memory 5 CS61C L11 Linker UC Regents 6 Where Are We Now C program foo c Compiler Assembler Reads and Uses Directives Replace Pseudoinstructions Assembly program foo s Assembler Produce Machine Language Creates Object File Object mach lang module foo o Linker lib o Executable mach lang pgm a out Loader CS61C L11 Linker UC Regents Memory 7 Assembler Directives p A 51 to A 53 Pseudoinstruction Replacement Asm treats convenient variations of machine language instructions as if real instructions Pseudo Real Give directions to assembler but do not produce machine instructions text Subsequent items put in user text segment data Subsequent items put in user data segment globl sym declares sym global and can be referenced from other files asciiz str Store the string str in memory and null terminate it word w1 wn Store the n 32 bit quantities in successive memory words 9 CS61C L11 Linker UC Regents 8 CS61C L11 Linker UC Regents Absolute Addresses in MIPS Which instructions need relocation editing subu sp sp 32 addiu sp sp 32 sd a0 32 sp sw a0 32 sp sw a1 36 sp mul t7 t6 t5 mul t6 t5 mflo t7 addu t0 t6 1 addiu t0 t6 1 ble t0 100 loop slti at t0 101 bne at 0 loop la a0 str lui at left str ori a0 at right str 10 CS61C L11 Linker UC Regents Producing Machine Language 1 2 Simple Case J format jump jump and link Arithmetic Logical Shifts and so on j jal All necessary info is within the instruction already xxxxx Loads and stores to variables in static area relative to global pointer lw sw gp x What about Branches PC Relative address So once pseudoinstructions are replaced by real ones we know by how many instructions to branch What about conditional branches beq bne rs rt address PC relative addressing preserved even if code moves CS61C L11 Linker UC Regents So these can be handled easily 11 CS61C L11 Linker UC Regents 12 Producing Machine Language 2 2 Symbol Table What about jumps j and jal List of items in this file that may be used by other files Jumps require absolute address What are they What about references to data Labels function calling Data anything in the data section variables which may be accessed across files la gets broken up into lui and ori These will require the full 32 bit address of the data First Pass record label address pairs These can t be determined yet so we create two tables Second Pass produce machine code Result can jump to a later label without first declaring it 13 CS61C L11 Linker UC Regents CS61C L11 Linker UC Regents Relocation Table Object File Format List of items for which this file needs the address object file header size and position of the other pieces of the object file What are they text segment the machine code 14 data segment binary representation of the data in the source file Any label jumped to j or jal internal external including lib files relocation information identifies lines of code that need to be handled Any piece of data such as the la instruction symbol table list of this file s labels and data that can be referenced debugging information 15 CS61C L11 Linker UC Regents Where Are We Now C program foo c Compiler What does it do Combines several object o files into a single executable linking Enable Separate Compilation of files Object mach lang module foo o Changes to one file do not require recompilation of whole program Linker lib o Executable mach lang pgm a out Windows NT source is 30 M lines of code And Growing Called a module Link Editor name from editing the links in jump and link instructions Loader Memory 16 Link Editor Linker 1 2 Assembly program foo s Assembler CS61C L11 Linker UC Regents CS61C L11 Linker UC Regents 17 CS61C L11 Linker UC Regents 18 Link Editor Linker 2 2 Four Types of Addresses Step 1 Take text segment from each o file and put them together PC Relative Addressing beq bne never relocate Step 2 Take data segment from each o file put them together and concatenate this onto end of text segments Absolute Address j jal always relocate External Reference usually jal always relocate Step 3 Resolve References Data Reference often lui and ori always relocate Go through Relocation Table and handle each entry That is fill in all absolute addresses CS61C L11 Linker UC Regents 19 20 CS61C L11 Linker UC Regents Resolving References 1 2 Resolving References 2 2 Linker assumes first word of first text segment is at address 0x00000000 To resolve references search for reference data or label in all symbol tables if not found search library files for example for printf Linker knows length of each text and data segment ordering of text and data segments once absolute address is determined fill in the machine code appropriately Linker calculates absolute address of each label to be jumped to internal or external and each piece of data being referenced CS61C L11 Linker UC Regents Output of linker executable file containing text and data plus header 21 Administrivia Reading assignment 22 CS61C L11 Linker UC Regents Where Are We Now C program foo c Compiler P H A 8 8 1 8 4 Assembly program foo s Assembler Object mach lang module foo o Linker lib o Executable mach
View Full Document
Unlocking...