Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Loaders
  2. 2. 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.
  3. 3. 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
  4. 4. 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)
  5. 5. 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
  6. 6. 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.
  7. 7. 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.
  8. 8. 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.
  9. 9. 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
  10. 10. 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.
  11. 11. 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.
  12. 12. 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.
  13. 13. Bootstrapping continued…CPU MEMORY I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  14. 14. Bootstrapping continued… CPU MEMORY LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  15. 15. 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
  16. 16. Bootstrapping continued… CPU OS LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  17. 17. 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
  18. 18. 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.
  19. 19. Operating system
  20. 20. The Process Concept
  21. 21. 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?
  22. 22. 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.
  23. 23. 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.
  24. 24. 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 .….
  25. 25. Program Load PCB OS code stackProcess Creation Create
  26. 26. Create Process Creation OS stackPCB Load object file heap header bss data data code code symbolProcess working space table Memory Disk
  27. 27. 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
  28. 28. 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
  29. 29. 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.
  30. 30. 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
  31. 31. 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
  32. 32. 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.
  33. 33. 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