30
Computer Organization & Computer Organization & Assembly Languages Assembly Languages Pu-Jen Cheng Loader and Linker Adapted from the slides prepared by Beck for the book, System Software: An Intro. to Systems Programming , 3rd Ed.

Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Computer Organization & Computer Organization & Assembly Languages Assembly Languages

Pu-Jen Cheng

Loader and Linker

Adapted from the slides prepared by Beck for the book, System Software: An Intro. to Systems Programming , 3rd Ed.

Page 2: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Overview

Basic Loader FunctionsDesign of an Absolute LoaderA Simple Bootstrap Loader

Machine-dependent Loader FeaturesRelocationRelocationProgram Linking

Page 3: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Introduction

To execute an object program, we needsRelocation, which modifies the object program so that it can be loaded at an address different from the location originally specified

Linking, which combines two or more separate object programs and supplies the information needed to allow references between them

Loading and Allocation, which allocates memory location and brings the object program into memory for execution

Page 4: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Assemble-and-go Loader

CharacteristicThe object code is stored in memory after assemblySingle JUMP instruction

AdvantageSimple, developing environment

DisadvantageWhenever the assembly program is to be executed, it has to be assembled again

Page 5: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Design of an Absolute Loader

Absolute ProgramAdvantage

Simple and efficientDisadvantage

The need for programmer to specify the actual addressThe need for programmer to specify the actual addressDifficult to use subroutine libraries

Page 6: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Algorithm for an Absolute Loader

beginread Header recordverify program name and lengthread first Text recordwhile record type <> ’E’ dobeging{if object code is in character form, convert intointernal representation}

move object code to specified location in memoryread next object program record

endjump to address specified in End record

end

Page 7: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Loading of an Absolute Program

Page 8: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Loading of an Absolute Program

Page 9: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

A Simple Bootstrap Loader

Bootstrap LoaderWhen a computer is first tuned on or restarted, a special type of absolute loader, called bootstrap loader is executedThis bootstrap loads the first program to be run by the computer -- usually an operating system

Example (SIC bootstrap loader)Example (SIC bootstrap loader)The bootstrap itself begins at address 0 It loads the OS starting address 0x80No header record or control information, the object code is consecutive bytes of memory

Page 10: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Bootstrap Loader for SIC/XE

Page 11: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Relocating Loaders

MotivationEfficient sharing of the machine with larger memory and when several independent programs are to be run togetherSupport the use of subroutine libraries efficiently

T th d f if i l tiTwo methods for specifying relocationModification recordRelocation bit

Each instruction is associated with one relocation bitThese relocation bits in a Text record is gathered into bit masks

Page 12: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Modification Record

For complex machinesAlso called RLD specification

Relocation and Linkage Directory

Modification recordcol 1: Mcol 2-7: relocation address col 8-9: length (halfbyte)col 10: flag (+/-)col 11-17: segment name

Page 13: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

An SIC/XE ExampleLine Loc Source statement Object code

5 0000 COPY START 010 0000 FIRST STL RETADR 17202D12 0003 LDB #LENGTH 69202D13 BASE LENGTH15 0006 CLOOP +JSUB RDREC 4B10103620 000A LDA LENGTH 03202625 000D COMP #0 29000030 0010 JEQ ENDFIL 33200735 0013 JSUB WRREC 4B10105D35 0013 +JSUB WRREC 4B10105D40 0017 J CLOOP 3F2FEC45 001A ENDFIL LDA EOF 03201050 001D STA BUFFER 0F201655 0020 LDA #3 01000360 0023 STA LENGTH 0F200D65 0026 +JSUB WRREC 4B10105D70 002A J @RETADR 3E200380 002D EOF BYTE C’EOF’ 454F4695 0030 RETADR RESW 1100 0033 LENGTH RESW 1105 0036 BUFFER RESB 4096

Page 14: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

115 . READ RECORD INTO BUFFER120 . 125 1036 RDREC CLEAR X B410130 1038 CLEAR A B400132 103A CLEAR S B440133 103C +LDT #4096 75101000135 1040 RLOOP TD INPUT E32019140 1043 JEQ RLOOP 332FFA145 1046 RD INPUT DB2013150 1049 COMPR A,S A004155 104B JEQ EXIT 332008160 104E STCH BUFFER,X 57C003165 1051 TIXR T B850170 1053 JLT RLOOP 3B2FEA175 1056 EXIT STX LENGTH 134000180 1059 RSUB 4F0000185 105C INPUT BYTE X’F1’ F1195 .200 . WRITE RECORD FROM BUFFER 205 .210 105D WRREC CLEAR X B410212 105F LDT LENGTH 774000215 1062 WLOOP TD OUTPUT E32011220 1065 JEQ WLOOP 332FFA 225 1068 LDCH BUFFER,X 53C003230 106B WD OUTPUT DF2008235 106E TIXR T B850

...(omitted)

Page 15: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Object Code with Modification Records

Page 16: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Relocation BitFor simple machinesRelocation bit

0: No modification is necessary1: Modification is needed

T l bit k i d i h T t d

Text recordcol 1: Tcol 2-7: starting address col 8-9: length (byte)col 10-12: relocation bitscol 13-72: object code

Twelve-bit mask is used in each Text recordSince each text record contains less than 12 wordsUnused words are set to 0Any value that is to be modified during relocation must coincide with one of these 3-byte segments

e.g. line 210

Page 17: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Relocatable Program for SIC

Line Loc Source statement Object code

5 0000 COPY START 010 0000 FIRST STL RETADR 14003315 0003 CLOOP JSUB RDREC 48103920 0006 LDA LENGTH 00003625 0009 COMP ZERO 28003030 000C JEQ ENDFIL 30001535 000F JSUB WRREC 48106140 0012 J CLOOP 3C000345 0015 ENDFIL LDA EOF 00002A45 0015 ENDFIL LDA EOF 00002A50 0018 STA BUFFER 0C003955 001B LDA THREE 00002D60 001E STA LENGTH 0C003665 0021 JSUB WRREC 48106170 0024 LDL RETADR 08003375 0027 RSUB 4C000080 002A EOF BYTE C’EOF’ 454F4685 002D THREE WORD 3 00000390 0030 ZERO WORD 0 00000095 0033 RETADR RESW 1100 0036 LENGTH RESW 1105 0039 BUFFER RESB 4096

Page 18: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

110 . 115 . SUBROUTINE TO READ RECORD INTO BUFFER120 . 125 1039 RDREC LDX ZERO 040030130 103C LDA ZERO 000030135 103F RLOOP TD INPUT E0105D140 1042 JEQ RLOOP 30103D145 1045 RD INPUT D8105D150 1048 COMP ZERO 280030155 104B JEQ EXIT 301057160 104E STCH BUFFER,X 548039165 1051 TIX MAXLEN 2C105E170 1054 JLT RLOOP 38103F175 1057 EXIT STX LENGTH 100036180 105A RSUB 4C0000185 105D INPUT BYTE X’F1’ F1190 105E MAXLEN WORD 4096 001000195 .200 . SUBROUTINE TO WRITE RECORD FROM BUFFER 205 .210 1061 WRREC LDX ZERO 040030215 1064 WLOOP TD OUTPUT E01079220 1067 JEQ WLOOP 301064 225 106A LDCH BUFFER,X 508039230 106D WD OUTPUT DC1079235 1070 TIX LENGTH 2C0036240 1073 JLT WLOOP 381064 245 1076 RSUB 4C0000 250 1079 OUTPUT BYTE X’05’ 05 255 END FIRST

Page 19: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Object Code with Bit Masks

Page 20: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Program Linking

GoalResolve the problems with EXTREF and EXTDEF from different control sections

Use modification records for both relocation and linkingAddress constantExternal reference

Page 21: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Example Program

Page 22: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Object Code of Example Program

Page 23: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Example Program

Page 24: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a
Page 25: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Example Program

Page 26: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a
Page 27: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a

Program Linking Example

Load address for control sectionsPROGA 004000 63PROGB 004063 7FPROGC 0040E2 51

Load address for symbolsLISTA: PROGA+0040=4040LISTA: PROGA+0040 4040LISTB: PROGB+0060=40C3LISTC: PROGC+0030=4112

REF4 in PROGAENDA-LISTA+LISTC=14+4112=4126T0000540F000014FFFFF600003F000014FFFFC0M00005406+LISTC

Page 28: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a
Page 29: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a
Page 30: Computer Organization & Assembly Languagespjcheng/course/asm2008/asm_linkload.pdf · A Simple Bootstrap Loader Bootstrap Loader ¾When a computer is first tuned on or restarted, a