• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Loaders
 

Loaders

on

  • 1,240 views

 

Statistics

Views

Total Views
1,240
Views on SlideShare
1,240
Embed Views
0

Actions

Likes
0
Downloads
43
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Loaders Loaders Presentation Transcript

    • Loaders
    • Loader & its Functions A loader is a system program, which takes the object code of a program as input and prepares it for execution. Loader Function : The loader performs the following functions :  Allocation - The loader determines and allocates the required memory space for the program to execute properly.  Linking -- The loader analyses and resolve the symbolic references made in the object modules.  Relocation - The loader maps and relocates the address references to correspond to the newly allocated memory space during execution.  Loading - The loader actually loads the machine code corresponding to the object modules into the allocated memory space and makes the program ready to execute.
    • Cont…. Assembly program object code file Label opcode address Program name: start H01 ; This is Starting address text: x200 e02 ; a comment Length of text in bytes: x14 a03 start .begin x200 Starting address data: x20A d04 here LOAD sum Length of data in bytes: 8 e05 ADD a r06 STORE sum 000100000000100107 LOAD b 001000000000100108 SUB one 001100000000011109 STORE b 00010000000010000A SKIPZ 0100000000001000 Text0B JMP here 00110000000001100C LOAD sum 10010000000000000D HALT 10001111111110000E sum .data x000 00010000000000010F a .data x005 011100000000000010 b .data x003 000000000000000011 one .data x001 000000000000010112 .end start Data 0000000000000011 0000000000000001
    • Types of Loader1.- Compile-and-Go Loaders:2.- Absolute Loader3.- Bootstrap Loader4.- Operating System: Loading application programs 3.1- The Process concept. 3.2- Creating a process.5.- Relocating Loaders 4.1- Relocation bits 4.2- Relocation maps (modification records)
    • Compile-and-Go Loaders: A compile and go loader is one in which the assembler itself does the processes of compiling then place the assembled instruction inthe designated memory loactions. The assembly process is first executed and then the assembler causes a transfer to the first instruction of the program. E.G. WATFOR FORTRAN compiler This loading scheme is also called assmble-and-go
    • Advantages and Disadvantages Advantages of Compile-and-go loaders: Simple and easier to implement. No additional routines are required to load the compiled code into the memory. Dis advantages of Compile-and-go loaders: Wastage im memory spave due to the presence of the assembler. There is a need to re-assemble the code every time it is to be run. It becomes increasingly difficult to handle large number of segments when the input code is written in a variety of HLL say one routine in pascal and one in FORTRAN and so on. Such loader make designing modular programs and systems near impossible.
    • Absolute LoaderAssembler object code file Program name: start Absolute loader: Starting address text: x200 Length of text in bytes: x14 Header The absolute loader will load the Starting address data: x20A Length of data in bytes: 8 program at memory location x200: 0001000000001001 1.- The header record is checked to 0010000000001001 verify that the correct program has 0011000000000111 0001000000001000 been presented for loading. 0100000000001000 Text section 0011000000000110 2.- Each text record is read and 1001000000000000 1000111111111000 moved to the indicate address in 0001000000000001 memory 0111000000000000 0000000000000000 3.- When the “end” record (EOF) is 0000000000000101 0000000000000011 Data section encountered, the loader jumps to the 0000000000000001 specified address to begin execution.
    • Cont…. The four functions as performed in and absolute loader are : 1.Allocation 2.Linking 3.Relocation 4.Loading Advantages of Absolute Loader: Simple, easy to design and implement. Since more core memory is available to the user there is no memory limit. Dis advantages of Absolute Loader: The programmer must specifically tell the assembler the address where the program is to be loaded. When subroutines are referenced, the programmer must specify their address whenever they are called.
    • Loading object code into memory Object code file (disk) Run time environmentProgram name: start HeaderStarting address text: x200Length of text in bytes: x14 TextStarting address data: x20ALength of data in bytes: 8 Data0001000000001001001000000000100100110000000001110001000000001000 Heap0100000000001000 Text section00110000000001101001000000000000100011111111100000010000000000010111000000000000000000000000000000000000000001010000000000000011 Data section0000000000000001 Stack
    • Bootstrapping: Computers execute programs stored in main memory, and initially the operating system is on the hard disk. When the computer is turned on it does not have an operating system loaded in memory and the hardware alone cannot do the operations of an OS. To solve this paradox a special program called bootstrap loader is created.
    • Bootstrapping continued… This program does not have the full functionality of an operating system, but it is capable of loading into memory a more elaborated software (i.e. loader2) which in its turn will load the operating system. Once the OS has been loaded the loader transfers the control of the computer system to the operating system.
    • Bootstrapping continued… Early programmable computers had toggle switches on the front panel to allow the operator to place the bootloader into the program store before starting the CPU. In modern computers the bootstrapping process begins with the CPU executing software contained in ROM at a predefined address whose elementary functionality is to search for devices eligible to participate in booting, and load a small program from a special section of a device.
    • Bootstrapping continued…CPU MEMORY I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
    • Bootstrapping continued… CPU MEMORY LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
    • Bootstrapping continued… In earlier computers data had to be hand loaded as specified before, but nowadays a small piece of software called loader helps us to avoid the manual loading. 0 OS will be loaded here LC = Location Counter 99998 LC = 0 100000 READ STORE LC LC LC + 1 LOADER 2 IF (EOF) PC 0 ELSE JMP 100000
    • Bootstrapping continued… CPU OS LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
    • Bootstrapping continued… The above diagram can be explained in the following steps. 1. Check hardware 2. Initiate I/O to load the loader 2 program into memory 3. Loader 2 loads the OS and passes control to it
    • Conclusion We have seen that once the OS has control over the system , it can create an environment for programs to run. The operating system will load device drivers and other programs that are needed for the normal operation of the computer system.
    • Operating system
    • The Process Concept
    • Programs and processesOnce the operating system takes control of thecomputer system, an applications program (objectmodule) can be loaded into memory to be executed.When the program is loaded into memory a process iscreated. What is a process?
    • Process Definition:  A program in execution  An asynchronous activity  The “locus of control” of a procedure in execution  It is manifested by the existence of a process control block (PCB) in the operating system.
    • Process Continued… The activity of a process is controlled by a data structure called Process Control Block(PCB). A PCB is created every time a program is loaded to be executed. So, a process is defined by a PCB-Program couple.
    • Structure of the PCB Pointer to next PCB ….. Process name or ID Base codePROGRAM Limit….Code IP or PC Stack Pointer S T Registers A State C K MODE Interrupt Flags .….
    • Program Load PCB OS code stackProcess Creation Create
    • Create Process Creation OS stackPCB Load object file heap header bss data data code code symbolProcess working space table Memory Disk
    • Process working space (run-time environment) stack Dynamic link, return address, Local variables, function Parameters, …malloc(n); heap Dynamically allocated variablesint z; bss Global and static variablesint y = 7; data Constants / initialized datax = 4; code Program text (write protected) Process working space or Run-time environment
    • Process working space sum Local Local bss: means “block started void sub(float total, int part ) { by symbol” and has that Local int List[5]; name for historical reasons. float sum; Local … stack Local } Local Parametermalloc(n); heap Parameterint z; bss Dynamic Linkint y = 7; data Return Addressx = 4; code
    • Relocating LoadersAbsolute loaders loads a program on a specificmemory location but it is often desirable to havetwo or more programs residing in memory sharingthe different resources of a computer system.It would be impractical to assign starting addressesto each program to plan program execution.A loader able to load a program into memorywherever there is room for it is called a relocatingloader.
    • Relocation bitsAssemblers generate code that starts at address zero but it can also emitwith each line of text (code) relocation bits indicating what fields in theobject code must be modified when the program is loaded in an addressdifferent from zero.For example, if the program will be loaded at address 40, a relocation bits equal to “1”indicates what part of the instruction must be modified: Loc# Len reloc text Loc# text 00 3 011 13 33 35 00 13 74 76
    • source program before relocation after relocation Label opcode address address Loc# Len reloc text Loc# text00 copy zero older 00 3 011 13 33 35 40 13 73 7503 copy one old 03 3 011 13 34 36 43 13 34 3606 read limit 06 2 011 12 38 46 12 7808 write old 08 2 01 08 36 48 08 7610 comp load older 10 2 01 03 35 50 03 7512 add old 12 2 01 02 36 52 02 76 14 2 01 07 37 54 07 7714 store new 16 2 01 06 38 56 06 78 18 2 01 01 30 58 01 7016 sub limit 20 2 01 08 37 60 08 7718 brpos finalL 22 3 011 13 36 35 62 13 76 7520 write new 25 3 011 13 37 36 65 13 77 76 28 2 01 00 10 68 00 5022 copy old older25 copy new old 30 2 01 08 38 70 08 37828 br comp 32 2 01 11 72 1130 final write limit 33 1 0 00 73 0032 stop 34 1 0 01 74 0133 zero CONST 0 35 7534 0ne CONST 1 36 7635 older SPACE 37 7736 old SPACE 38 7837 new SPACE38 limit SPACE Relocation constant to be added is 40
    • 2.- Relocation maps (modification records)Interleaving relocation bits with the program text makes cumbersome theprocess of loading the text directly into memory.This problem can be resolve by collecting all relocation bits into a singlecontiguous relocation map that we will call the relocation section of theobject code file.The relocation section will be appended to the text and data sections.The header will contain the entry point and length of the relocation sectionin the object module.
    • Program name: startStarting address textLength of text in bytes HeaderStarting address dataLength of data in bytesStarting address reloc. Sect.Length of relocation section Text section Data section Relocation section