SlideShare a Scribd company logo
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            H
01                  ; This is              Starting address text: x200    e
02                  ; a comment            Length of text in bytes: x14   a
03   start          .begin     x200        Starting address data: x20A    d
04   here           LOAD       sum         Length of data in bytes: 8
                                                                          e
05                  ADD        a                                          r
06                  STORE      sum         0001000000001001
07                  LOAD       b           0010000000001001
08                  SUB        one         0011000000000111
09                  STORE      b           0001000000001000
0A                  SKIPZ                  0100000000001000               Text
0B                  JMP        here        0011000000000110
0C                  LOAD       sum         1001000000000000
0D                  HALT                   1000111111111000
0E   sum            .data      x000        0001000000000001
0F   a              .data      x005        0111000000000000
10   b              .data      x003        0000000000000000
11   one            .data      x001        0000000000000101
12                  .end       start                                      Data
                                           0000000000000011
                                           0000000000000001
Types of Loader

1.- Compile-and-Go Loaders:

2.- Absolute Loader

3.- Bootstrap Loader

4.- 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 Loader
Assembler 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 environment

Program name: start            Header
Starting address text: x200
Length of text in bytes: x14
                                                    Text
Starting address data: x20A
Length of data in bytes: 8
                                                    Data
0001000000001001
0010000000001001
0011000000000111
0001000000001000                                    Heap
0100000000001000               Text section
0011000000000110
1001000000000000
1000111111111000
0001000000000001
0111000000000000
0000000000000000
0000000000000101
0000000000000011
                               Data section
0000000000000001                                   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 processes

Once the operating system takes control of the
computer system, an applications program (object
module) can be loaded into memory to be executed.

When the program is loaded into memory a process is
created.

                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 code
PROGRAM
                      Limit….Code
                       IP or PC
                     Stack Pointer
 S
 T
                      Registers
 A                      State
 C
 K                     MODE
                    Interrupt Flags
                        .….
Program        Load
                                     PCB


                    OS             code    stack


Process Creation
                          Create
Create             Process Creation
                        OS
            stack
PCB                          Load
                                       object file



            heap
                                    header
            bss
            data                     data

            code                     code
                                    symbol
Process 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 variables
int z;        bss         Global and static variables
int y = 7;    data        Constants / initialized data
x = 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

                                   Parameter

malloc(n);      heap               Parameter

int z;           bss              Dynamic Link
int y = 7;       data            Return Address
x = 4;          code
Relocating Loaders
Absolute loaders loads a program on a specific
memory location but it is often desirable to have
two or more programs residing in memory sharing
the different resources of a computer system.

It would be impractical to assign starting addresses
to each program to plan program execution.

A loader able to load a program into memory
wherever there is room for it is called a relocating
loader.
Relocation bits
Assemblers generate code that starts at address zero but it can also emit
with each line of text (code) relocation bits indicating what fields in the
object code must be modified when the program is loaded in an address
different 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#        text

00           copy     zero      older     00      3     011       13   33 35      40          13   73 75
03           copy     one       old       03      3     011       13   34 36      43          13   34 36
06           read     limit               06      2     011       12   38         46          12   78
08           write    old                 08      2     01        08   36         48          08   76
10 comp      load     older               10      2     01        03   35         50          03   75
12           add      old                 12      2     01        02   36         52          02   76
                                          14      2     01        07   37         54          07   77
14           store    new                 16      2     01        06   38         56          06   78
                                          18      2     01        01   30         58          01   70
16           sub      limit
                                          20      2     01        08   37         60          08   77
18           brpos    finalL
                                          22      3     011       13 36 35        62          13 76 75
20           write    new                 25      3     011       13 37 36        65          13 77 76
                                          28      2     01        00 10           68          00 50
22           copy     old       older
25           copy     new       old       30      2     01        08 38           70          08 378
28           br       comp                32      2     01        11              72          11
30   final   write    limit               33      1     0         00              73          00
32           stop                         34      1     0         01              74          01
33   zero    CONST    0                   35                                      75
34   0ne     CONST    1                   36                                      76
35   older   SPACE                        37                                      77
36   old     SPACE                        38                                      78
37   new     SPACE
38   limit   SPACE                                              Relocation constant to be added is 40
2.- Relocation maps (modification records)


Interleaving relocation bits with the program text makes cumbersome the
process of loading the text directly into memory.

This problem can be resolve by collecting all relocation bits into a single
contiguous relocation map that we will call the relocation section of the
object 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 section
in the object module.
Program name: start
Starting address text
Length of text in bytes         Header
Starting address data
Length of data in bytes
Starting address reloc. Sect.
Length of relocation section


       Text section



       Data section



   Relocation section

More Related Content

PDF
Unit 3
pm_ghate
 
PPTX
Operating system; Multitasking
FlameDimension95
 
PDF
Program development cyle
eShikshak
 
PPT
presentation on timing diagram
Alisha Korpal
 
PPT
Assembly language
gaurav jain
 
PPTX
x86 architecture
i i
 
PPT
5. spooling and buffering
myrajendra
 
Unit 3
pm_ghate
 
Operating system; Multitasking
FlameDimension95
 
Program development cyle
eShikshak
 
presentation on timing diagram
Alisha Korpal
 
Assembly language
gaurav jain
 
x86 architecture
i i
 
5. spooling and buffering
myrajendra
 

What's hot (20)

PPTX
Direct linking loaders
Satyamevjayte Haxor
 
PPTX
Loaders ( system programming )
Adarsh Patel
 
PPTX
Single pass assembler
Bansari Shah
 
PPTX
System software - macro expansion,nested macro calls
SARASWATHI S
 
PPTX
Direct linking loader
babyparul
 
PPTX
Introduction to loaders
Tech_MX
 
ODP
Anatomy of android application
Nikunj Dhameliya
 
PPTX
Ch 4 linker loader
Malek Sumaiya
 
PPTX
Tcp/ip server sockets
rajshreemuthiah
 
PPTX
Linking in MS-Dos System
Satyamevjayte Haxor
 
PDF
Linker and Loader Explained
Adarsh Kr Sinha
 
PPT
System software
Senthil Kanth
 
PPTX
Two pass Assembler
Satyamevjayte Haxor
 
PPTX
Design of a two pass assembler
Dhananjaysinh Jhala
 
PPTX
Linker and Loader
sonalikharade3
 
PPTX
Unit 4 sp macro
Deepmala Sharma
 
PPTX
Code generation
Aparna Nayak
 
PPTX
Process synchronization in Operating Systems
Ritu Ranjan Shrivastwa
 
PPT
Applet Architecture - Introducing Java Applets
amitksaha
 
PPTX
Unit 3 sp assembler
Deepmala Sharma
 
Direct linking loaders
Satyamevjayte Haxor
 
Loaders ( system programming )
Adarsh Patel
 
Single pass assembler
Bansari Shah
 
System software - macro expansion,nested macro calls
SARASWATHI S
 
Direct linking loader
babyparul
 
Introduction to loaders
Tech_MX
 
Anatomy of android application
Nikunj Dhameliya
 
Ch 4 linker loader
Malek Sumaiya
 
Tcp/ip server sockets
rajshreemuthiah
 
Linking in MS-Dos System
Satyamevjayte Haxor
 
Linker and Loader Explained
Adarsh Kr Sinha
 
System software
Senthil Kanth
 
Two pass Assembler
Satyamevjayte Haxor
 
Design of a two pass assembler
Dhananjaysinh Jhala
 
Linker and Loader
sonalikharade3
 
Unit 4 sp macro
Deepmala Sharma
 
Code generation
Aparna Nayak
 
Process synchronization in Operating Systems
Ritu Ranjan Shrivastwa
 
Applet Architecture - Introducing Java Applets
amitksaha
 
Unit 3 sp assembler
Deepmala Sharma
 
Ad

Similar to Loaders (20)

PPT
Loader
nikhilshrama
 
PDF
loaders and linkers
Temesgen Molla
 
PPTX
Loaders
Koganti Ravikumar
 
PPT
Overall 23 11_2007_hdp
Mohd Arif
 
PDF
loaders-and-linkers.pdfhhhhhccftyghgfggy
rahulyadav957181
 
PPTX
Loader and Its types
Parth Dodiya
 
DOCX
Loaders
Sona Endow
 
PPTX
System software module 1 presentation file
jithujithin657
 
PPTX
Loader and linker.pptx
DrTThendralCompSci
 
PPT
Assembler (2)
Vaibhav Bajaj
 
PPT
System software-loaders
kitturashmikittu
 
PPTX
linker & loader presentation in Compiler Design
AbhishekKumar117405
 
PPT
Loader
jayashri kolekar
 
PPT
Assembler
Maha Lakshmi
 
PPT
Assembler
Maha Lakshmi
 
PPT
loader.ppt
MARADOLORESJUREZMART
 
PPT
Mod 5.3 - Linkers & Loaderss Summary.ppt
ssuser1604c0
 
PPT
11 instruction sets addressing modes
Kanika Thakur
 
PPT
11 instruction sets addressing modes
Sher Shah Merkhel
 
PPT
PattPatelCh05.ppt
DipakShow2
 
Loader
nikhilshrama
 
loaders and linkers
Temesgen Molla
 
Overall 23 11_2007_hdp
Mohd Arif
 
loaders-and-linkers.pdfhhhhhccftyghgfggy
rahulyadav957181
 
Loader and Its types
Parth Dodiya
 
Loaders
Sona Endow
 
System software module 1 presentation file
jithujithin657
 
Loader and linker.pptx
DrTThendralCompSci
 
Assembler (2)
Vaibhav Bajaj
 
System software-loaders
kitturashmikittu
 
linker & loader presentation in Compiler Design
AbhishekKumar117405
 
Assembler
Maha Lakshmi
 
Assembler
Maha Lakshmi
 
Mod 5.3 - Linkers & Loaderss Summary.ppt
ssuser1604c0
 
11 instruction sets addressing modes
Kanika Thakur
 
11 instruction sets addressing modes
Sher Shah Merkhel
 
PattPatelCh05.ppt
DipakShow2
 
Ad

More from Mohd Arif (20)

PPT
Bootp and dhcp
Mohd Arif
 
PPT
Arp and rarp
Mohd Arif
 
PPT
User datagram protocol
Mohd Arif
 
PPT
Project identification
Mohd Arif
 
PPT
Project evalaution techniques
Mohd Arif
 
PPT
Presentation
Mohd Arif
 
PPT
Pointers in c
Mohd Arif
 
PPT
Peer to-peer
Mohd Arif
 
PPT
Overview of current communications systems
Mohd Arif
 
PPT
Objectives of budgeting
Mohd Arif
 
PPT
Network management
Mohd Arif
 
PPT
Networing basics
Mohd Arif
 
PPT
Lists
Mohd Arif
 
PPT
Iris ngx next generation ip based switching platform
Mohd Arif
 
PPT
Ip sec and ssl
Mohd Arif
 
PPT
Ip security in i psec
Mohd Arif
 
PPT
Intro to comp. hardware
Mohd Arif
 
PPT
Heap sort
Mohd Arif
 
PPT
H.323 vs. cops interworking
Mohd Arif
 
PPT
H.323
Mohd Arif
 
Bootp and dhcp
Mohd Arif
 
Arp and rarp
Mohd Arif
 
User datagram protocol
Mohd Arif
 
Project identification
Mohd Arif
 
Project evalaution techniques
Mohd Arif
 
Presentation
Mohd Arif
 
Pointers in c
Mohd Arif
 
Peer to-peer
Mohd Arif
 
Overview of current communications systems
Mohd Arif
 
Objectives of budgeting
Mohd Arif
 
Network management
Mohd Arif
 
Networing basics
Mohd Arif
 
Lists
Mohd Arif
 
Iris ngx next generation ip based switching platform
Mohd Arif
 
Ip sec and ssl
Mohd Arif
 
Ip security in i psec
Mohd Arif
 
Intro to comp. hardware
Mohd Arif
 
Heap sort
Mohd Arif
 
H.323 vs. cops interworking
Mohd Arif
 
H.323
Mohd Arif
 

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Software Development Methodologies in 2025
KodekX
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 

Loaders

  • 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. Cont…. Assembly program object code file Label opcode address Program name: start H 01 ; This is Starting address text: x200 e 02 ; a comment Length of text in bytes: x14 a 03 start .begin x200 Starting address data: x20A d 04 here LOAD sum Length of data in bytes: 8 e 05 ADD a r 06 STORE sum 0001000000001001 07 LOAD b 0010000000001001 08 SUB one 0011000000000111 09 STORE b 0001000000001000 0A SKIPZ 0100000000001000 Text 0B JMP here 0011000000000110 0C LOAD sum 1001000000000000 0D HALT 1000111111111000 0E sum .data x000 0001000000000001 0F a .data x005 0111000000000000 10 b .data x003 0000000000000000 11 one .data x001 0000000000000101 12 .end start Data 0000000000000011 0000000000000001
  • 4. Types of Loader 1.- Compile-and-Go Loaders: 2.- Absolute Loader 3.- Bootstrap Loader 4.- 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. 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. 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. Absolute Loader Assembler 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. 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. Loading object code into memory Object code file (disk) Run time environment Program name: start Header Starting address text: x200 Length of text in bytes: x14 Text Starting address data: x20A Length of data in bytes: 8 Data 0001000000001001 0010000000001001 0011000000000111 0001000000001000 Heap 0100000000001000 Text section 0011000000000110 1001000000000000 1000111111111000 0001000000000001 0111000000000000 0000000000000000 0000000000000101 0000000000000011 Data section 0000000000000001 Stack
  • 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. 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. 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. Bootstrapping continued… CPU MEMORY I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  • 14. Bootstrapping continued… CPU MEMORY LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  • 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. Bootstrapping continued… CPU OS LOADER2 I/O OPERATIONS BOOT PROG I/O ROM OS LOADER 2
  • 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. 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.
  • 21. Programs and processes Once the operating system takes control of the computer system, an applications program (object module) can be loaded into memory to be executed. When the program is loaded into memory a process is created. What is a process?
  • 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. 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. Structure of the PCB Pointer to next PCB ….. Process name or ID Base code PROGRAM Limit….Code IP or PC Stack Pointer S T Registers A State C K MODE Interrupt Flags .….
  • 25. Program Load PCB OS code stack Process Creation Create
  • 26. Create Process Creation OS stack PCB Load object file heap header bss data data code code symbol Process working space table Memory Disk
  • 27. Process working space (run-time environment) stack Dynamic link, return address, Local variables, function Parameters, … malloc(n); heap Dynamically allocated variables int z; bss Global and static variables int y = 7; data Constants / initialized data x = 4; code Program text (write protected) Process working space or Run-time environment
  • 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 Parameter malloc(n); heap Parameter int z; bss Dynamic Link int y = 7; data Return Address x = 4; code
  • 29. Relocating Loaders Absolute loaders loads a program on a specific memory location but it is often desirable to have two or more programs residing in memory sharing the different resources of a computer system. It would be impractical to assign starting addresses to each program to plan program execution. A loader able to load a program into memory wherever there is room for it is called a relocating loader.
  • 30. Relocation bits Assemblers generate code that starts at address zero but it can also emit with each line of text (code) relocation bits indicating what fields in the object code must be modified when the program is loaded in an address different 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. source program before relocation after relocation Label opcode address address Loc# Len reloc text Loc# text 00 copy zero older 00 3 011 13 33 35 40 13 73 75 03 copy one old 03 3 011 13 34 36 43 13 34 36 06 read limit 06 2 011 12 38 46 12 78 08 write old 08 2 01 08 36 48 08 76 10 comp load older 10 2 01 03 35 50 03 75 12 add old 12 2 01 02 36 52 02 76 14 2 01 07 37 54 07 77 14 store new 16 2 01 06 38 56 06 78 18 2 01 01 30 58 01 70 16 sub limit 20 2 01 08 37 60 08 77 18 brpos finalL 22 3 011 13 36 35 62 13 76 75 20 write new 25 3 011 13 37 36 65 13 77 76 28 2 01 00 10 68 00 50 22 copy old older 25 copy new old 30 2 01 08 38 70 08 378 28 br comp 32 2 01 11 72 11 30 final write limit 33 1 0 00 73 00 32 stop 34 1 0 01 74 01 33 zero CONST 0 35 75 34 0ne CONST 1 36 76 35 older SPACE 37 77 36 old SPACE 38 78 37 new SPACE 38 limit SPACE Relocation constant to be added is 40
  • 32. 2.- Relocation maps (modification records) Interleaving relocation bits with the program text makes cumbersome the process of loading the text directly into memory. This problem can be resolve by collecting all relocation bits into a single contiguous relocation map that we will call the relocation section of the object 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 section in the object module.
  • 33. Program name: start Starting address text Length of text in bytes Header Starting address data Length of data in bytes Starting address reloc. Sect. Length of relocation section Text section Data section Relocation section