Sunday 8 December 2013

Linux Boot Process ; How Computer Boots Up ??

Linux Boot Process ; How Computer Boots Up ??

The PC boot process is a 3-stage boot process that begins with the BIOS executing a short program that is stored in the Master Boot Record (MBR) of the first physical drive. Since this stage 1 boot loader needs to fit in the MBR, it is limited to 512 bytes and is normally written in assembly language.
  There are a number of boot loaders that can load Linux.

     ● GRUB and LILO are the most commonly use  ones on X86 hardware.
       
     ● EFI is used on the Intel® Itanium® family.



Step by Step & Detailed Linux Boot Process

First Power On the System (PC). After this BIOS will take place.

BIOS :-

Once System start, first step BIOS (Basic Input Output System) will do POST (Power On Self Test). The POST will check all hardware connected to system working correctly or not. Once POST completes, it flushes from the memory, but the BIOS runtime services remain and it searches for devices for bootable disk, that order of preference defined in the complementary metal oxide semiconductor (CMOS) settings. A boot device can be a floppy disk, a CD-ROM, a partition on a hard disk, a device on the network, or even a USB flash memory stick.

Once BIOS detects the bootable device then it executes the MBR (Master Boot Recorder).
1st Stage of the Boot Loader.
MBR is 1st sector (512 Bytes) of the 1st bootable device. In 512 bytes, 3 parts are there :

i. 1st 446 bytes has primary boot loader information.
ii. Next 64 bytes for Partitions (16+16+16+16) for this reason only we are able to make 4 Primary Partitions.
iii. Next 2 bytes for validation check of MBR. (Magic Number)

Now the MBR Loads in to RAM.
First Stage of the boot loader loads it-self in to memory, & finds the second stage boot loader, this is done by looking through the active partition table. When it finds an active partition, it scans the remaining partitions in the table to ensure that they are all inactive. After this verification the active partition’s boot record is reads from the RAM, and it will execute it.
In simple MBR loads the GRUB (Grand Unified Boot loader) from 1st sector of the 1st bootable partition(HDD).

GRUB :-
GRUB has the knowledge of the file system, but older Linux loader LILO didn’t understand filesystem.
The stage 2 boot loader presents a boot menu to the user based on /boot/grub/grub.conf or menu.lst. This contains a boot script. GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
Here the sample of grub.conf file.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS Linux (2.6.32-220.2.1.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.2.1.el6.x86_64 ro root=UUID=92a892bc-b9cd-45a4-be09-4c2df953b2f1 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
initrd /initramfs-2.6.32-220.2.1.el6.x86_64.img
———————————————————————————————
hd0,0 : In this hd0 means the first Hard Disk,& “,0 Means 1st partition. Your Kernel & Initrd presented in the first partition of the first HDD.
In second line will see kernel /vmlinuz.x.x.x.. Instead of /boot/vmlinuz.x.x.x because hd0,0 is boot partition, For third line is also same.

KERNEL :-
Once kernel take place to load,
Mounts the root file system as specified in the “root=” in grub.conf file as read only, to avoid the problem with fsck, compressed kernel image. Typically this is a zImage (compressed image, less than 512KB) or a bzImage (big compressed image, greater than 512KB), that has been previously compressed with zlib. At the head of this kernel image is a routine that does some minimal amount of hardware setup and then decompresses the kernel contained within the kernel image and places it into high memory.
When the kernel is loaded, it immediately initializes and configures the computer’s memory and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices. It then looks for the compressed initrd image in a predetermined location in memory, decompresses it, mounts it, and loads all necessary drivers. Next, it initializes virtual devices related to the file system, such as LVM or software RAID before unmounting the initrd disk image and freeing up all the memory the disk image once occupied.
During the boot of the kernel, the initial-RAM disk (initrd) that was loaded into memory by the stage 2 boot loader is copied into RAM and mounted. This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks. Since the necessary modules needed to interface with peripherals can be part of the initrd, the kernel can be very small, but still support a large number of possible hardware configurations. After the kernel is booted, the root file system is pivoted (via pivot_root) where the initrd root file system is unmounted and the real root file system is mounted.

INIT :-
After the kernel is booted and initialized, the kernel starts the first user-space application.
In a Linux system, the first application started is commonly /sbin/init. INIT is the 1st Process of the linux system, It’s PSID is 1.
First, it runs the/etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization. For example, most systems use a clock, so on them rc.sysinit reads the /etc/sysconfig/clock configuration file to initialize the hardware clock.
The init command then runs the /etc/inittab script to decide which run level os has to come up.

   Most Linux distributions use the following standard run levels 0-6.
  
   0. System halt. (Do NOT set initdefault to this)
   1. Single-user mode. S and s may also be used here.
   2. Multi-user mode with no remote networking.
   3. Multi-user mode with networking. This is the standard
      operating mode of a non-GUI based system. All
      networking daemons are running.
   4. Unused.
   5. Multi-user mode with a GUI. This mode has most of the
      same daemons as run level 3 plus it is running the X
      Window System with a display and window manager.
   6. Reboot. (Do NOT set initdefault to this)

INIT identifies the default run level from /etc/inittab , After this the init command sets the source function library, /etc/rc.d/init.d/functions, for the system, which configures how to start, kill, and determine the PID of a program.
The init program starts all of the background processes by looking in the appropriate rc directory for the runlevel specified as default in /etc/inittab. The rc directories are numbered to corresponds to the runlevel they represent. For instance, /etc/rc.d/rc5.d/ is the directory for runlevel 5.
In /etc/rc.d/rc5.d/ directory what are all files starting with “K” those responsible for Kill the process when system is rebooting or shouting down. And Starting “S” those responsible for Start the process.
After the system is finished booting, it is possible to log in as root and execute these same scripts to start and stop services. For instance, the command/etc/rc.d/init.d/httpd stop stops the Apache HTTP Server.
Each of the symbolic links are numbered to dictate start order. The order in which the services are started or stopped can be altered by changing this number. The lower the number, the earlier it is started. Those symbolic links with the same number are started alphabetically.
One of the last things the init program executes is the /etc/rc.d/rc.local file. This file is useful for system customization.
After the init command has progressed through the appropriate rc directory for the runlevel, the /etc/inittab script forks an /sbin/mingetty process for each virtual console (login prompt) allocated to the runlevel. Runlevels 2 through 5 has all six virtual consoles, while runlevel 1 (single user mode) has one and runlevels 0 and 6 have none. The /sbin/mingetty process opens communication pathways to tty devices, sets their modes, prints the login prompt, accepts the user’s username and password and initiates the login process.
In runlevel 5, the /etc/inittab runs a script called /etc/X11/prefdm. The prefdm script executes the preferred X display manager — gdm, kdm, or xdm, depending on the contents of the /etc/sysconfig/desktop file.
Once finished, the system is operating on runlevel 5 and displaying a login screen.
****************** END of the Boot Process *****************

Monday 28 October 2013

CCS_Programme 03: Implement DFT and IDFT usign Fixed Point Technique in Code Composer Studio

// fixed point implemention of dft and IDFT




#include <stdio.h>

#include <math.h>

#include "input32_DFT_IDFT_float.h"

#include "input32_DFT_IDFT_fixed.h"




#define N 32

#define PI (float)3.1416

#define Q15 (unsigned int)32768

#define Q14 (unsigned int)(Q15>>1)

#define Q8 (unsigned int)256




typedef struct {

float real[N];

float imag[N];


}complex;

complex xn,Xk,xc;



//Declare Structure for storing fixed point numbers

typedef struct {

int real[N];

int imag[N];


}complex_fix;

complex_fix xnn,Xkk,xcc;



float chk_real_fix_dft[N];

float chk_imag_fix_dft[N];

float chk_real_fix_idft[N];

float chk_imag_fix_idft[N];




//declare function prototype for DFT and IDFT Calculation
void dft_fix(complex_fix *g,complex_fix *G,int len);

void idft_fix(complex_fix *g,complex_fix *G,int len);




void main()
{
int n;

 //input values for DFT Calculation

for(n=0;n<N;n++)


{

xn.real[n] = x[n];

xn.imag[n] = 0;

}


//input values for DFT Calculation using Fixed point Technique

for(n=0;n<N;n++)


{

xnn.real[n] = x_fix[n];

xnn.imag[n] = 0;

}

 dft_fix(&xnn,&Xkk,N);

printf ("DFT Fixed Point done\n");


idft_fix(&xcc,&Xkk,N);

printf ("IDFT Fixed Point done\n");


}



void dft_fix(complex_fix *g,complex_fix *G,int len)


{

int n,k;

float alp,alpha,angle =0;

int cf,sf;

long prod1,prod2,sum1 = 0,sum2 = 0;



alp = (2*PI/N);


for (k=0;k<len;k++)


{

G->real[k] = 0;

G->imag[k] = 0;

alpha = alp*k;

angle = 0;

sum1 = 0;

sum2 = 0;

for(n=0;n<len;n++)


{

cf = cos(angle)*Q14; //SI1F14

sf = sin(angle)*Q14; //SI1F14



prod1 = ((long)cf*(long)g->real[n]); //SSI1F29

prod1 += ((long)sf*(long)g->imag[n]); //SSI1F29

prod1 = prod1<<1; //SI1F30



prod2 = ((long)cf*(long)g->imag[n]); //SSI1F29

prod2 -= ((long)sf*(long)g->real[n]); //SSI1F29

prod2 = prod2<<1; //SI1F30



sum1 = sum1+(prod1>>5); //SI6F25

sum2 = sum2+(prod2>>5); //SI6F25



angle = angle+alpha;

}


G->real[k] = (int)(sum1>>16); //SI6F9

chk_real_fix_dft[k] = (float)G->real[k]/(Q15>>6);



G->imag[k] = (int)(sum2>>16); //SI6F9

chk_imag_fix_dft[k] = (float)G->imag[k]/(Q15>>6);


}

}



void idft_fix(complex_fix *g,complex_fix *G,int len)


{

int n,k;

float alp,angle=0,alpha;

int cf,sf;

long prod1,prod2,sum1=0,sum2=0;



alp = (2*PI/N);


for(n=0;n<len;n++)


{

g->real[n] = 0;

g->imag[n] = 0;

alpha = alp*n;

angle = 0;

sum1 =0;

sum2 = 0;


for(k=0;k<len;k++)


{

cf = cos(angle)*Q14; //SI1F14

sf = sin(angle)*Q14; //SI1F14



prod1 = ((long)cf*(long)G->real[k]); //SSI7F23

prod1 -= ((long)sf*(long)G->imag[k]);

prod1 = prod1<<1; //SI7F24



prod2 = ((long)cf*(long)G->imag[k]);

prod2 += ((long)sf*(long)G->real[k]); //SSI7F23

prod2 = prod2<<1; //SI7F24



sum1 = sum1 + (prod1>>5); //SI12F19

sum2 = sum2 + (prod2>>5); //SI12F19


angle = angle +alpha;

}


g->real[n] = (int)(sum1>>16); //SI7F8

chk_real_fix_idft[n] = (float)g->real[n]/(Q15>>7); //for testing CCS calculating with MATLAB Calculation



g->imag[n] = (int)(sum2>>16);

chk_imag_fix_idft[n] = (float)g->imag[n]/(Q15>>7); //for testing CCS calculation with MATLAB Calculation


}

}

MATLAB Programme 03: Implement DFT and IDFT in MATLAB using Fixed point Technique

% Algorithm for Calculating DFT and IDFT using Fixed and Floating Point Technique
clcclear all
close all

N = 32;
M = 16;
x = 0.4 * [ones(1,M),zeros(1,(N-M))];


Q15 = 2^15;
x_fix = fix(Q15 *x); 

X = dft(x,N);
xc = idft(X,N);
stem(real(xc));


%Generate input values for fixed point

fid = fopen('input32_DFT_IDFT_fixed.h','w');
fprintf (fid,'#ifndef\t_INPUT_FIXED_H\n');
fprintf (fid,'#define\t_INPUT_FIXED_H\n');
fprintf (fid,'#define\tSIZE\t%d\n',length(x_fix));
fprintf (fid,'int\tx_fix[SIZE]\t=\t{');
fprintf (fid,'%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n',x_fix);
fseek (fid,-1,0);fprintf (fid,'};\n');
fprintf (fid,'#endif\n');
fclose (fid);

%it will generate input file with coefficent of input signal..
 

Thursday 24 October 2013

CCS_Programme 02: Implement DFT and IDFT usign Floating Point Technique in Code Composer Studio

// DFT and IDFT implementation in CCS V4 using floating point technique
//file name: dft_idft.c
// in this programme input signal is sinusoidal whose coefficent are generated using MATLAB (see previous //post)

#include <stdio.h>
#include <math.h>
#include "input.h"

#define N 32                      //for 32 point DFT and IDFT
#define PI (float)3.1416

typedef struct{
float real[N];
float imag[N];
}complex;

complex xn,Xk,xc;

void dft(complex *g,complex *G,int len);
void idft(complex *g,complex *G,int len);

void main()
{
int n;
for(n=0;n<N;n++)
{
xn.real[n] = x[n];
xn.imag[n] = 0;
}
dft(&xn,&Xk,N);
        printf("DFT done\n");
idft(&xc,&Xk,N);
printf ("IDFT done\n");
}

void dft(complex *g,complex *G,int len)
{
int n,k;
float c,s,alpha,alp,angle=0;

alp = (2*PI/N);
for (k=0;k<len;k++)
{
G->real[k] = 0;
G->imag[k] = 0;
alpha = alp*k;
angle = 0;
for (n=0;n<len;n++)
{
c = cos((angle));
s = sin((angle));
G->real[k] += ((c*g->real[n])+(s*g->imag[n]));
G->imag[k] += ((c*g->imag[n])-(s*g->real[n]));
angle = angle+alpha;
}
}
}

void idft(complex *g,complex *G,int len)
{
int n,k;
float c,s,alpha,alp,angle=0;

alp = (2*PI/N);
for (n=0;n<len;n++)
{
g->real[n] = 0;
g->imag[n] = 0;
alpha = alp*n;
angle = 0;
for (k=0;k<len;k++)
{
c = cos((angle));
s = sin((angle));
g->real[n] += ((c*G->real[k])-(s*G->imag[k]));
g->imag[n] += ((c*G->imag[k])+(s*G->real[k]));
angle = angle+alpha;
}
g->real[n]=g->real[n]/N;
g->imag[n]=g->imag[n]/N;
}
}


// check result of CCS (from watch window) with MATLAB computation result ... you will find that both result are same...

Thursday 17 October 2013

MATLAB Programme 02: Implement DFT and IDFT in MATLAB using floating point Technique



% MATLAB Programme for implemention of DFT and IDFT using floating point technique

% in this programme input signal is sinusoidal signal whose 
amplitude is 0.9.
% this programme generate another coefficient file input.h which is input signal coefficient
% in matlab if we declare function definition then we give definition of function in another file and name of this file is  same as function calling name. in this programme we use two function "dft" and " idft " . whose definition give in another two file dft.m and idft.m

%****************************************************************
%file name :    spectrum.m 

clc; % for clearing window
close all; % for closing previous graphical window
clear all; % for clearing previously values


fs = 8000;
f0 = 1000;
cycles = 4;
N = fix(cycles*fs/f0);
n = 0:1:N-1;
amp = 0.9;
ts = 1/fs;
x = amp*sin(2*pi*f0*n*ts);

X = dft(x,N);

fid = fopen('input.h','w');
fprintf (fid,'#ifndef\t_INPUT_H_\n');
fprintf (fid,'#define\t_INPUT_H_\n\n');
fprintf (fid,'#define\tSIZE\t%d\n\n',length(x));
fprintf (fid,'float\tx[SIZE]\t=\t{');
fprintf (fid,'%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,\n',x);
fprintf (fid,'};\n\n');
fprintf (fid,'#endif\n');
fclose(fid);

xc = idft(X,N);


stem(real(xc));




%*********************************************************

%function defination
%file name :   dft.m

function X= dft(x,N)

for k=0:1:N-1
    X(k+1) = 0;
    for n=0:1:N-1
        X(k+1) = X(k+1) + (x(n+1)*exp(-j*2*pi*n*k/N));
    end

end



%********************************************************

%function defination
%file name :   idft.m


function x= idft(X,N)

for n=0:1:N-1
    x(n+1) = 0;
    for k=0:1:N-1
        x(n+1) = x(n+1) + (X(k+1)*exp(j*2*pi*n*k/N));
    end
end


x=x/N;

%*********************************************************


for implementing DFT and IDFT in Code Composer Studio V4 visit to another post CCS_Programme 02: Implement DFT and IDFT usign Floating Point Technique in Code Composer Studio....

MATLAB Programme 01: Implement DFT Without using inbuilt function

DFT Implementation


DFT is used to convert a signal sample array x(n) of size 1 x N to signal spectral component array X(k) of size 1 x N.
 
 
 
%programme
 
clc;close all;

clear all;

xn = input('Enter the sequence');
 
 
ln = length(xn);
xk = zeros(1,ln);
ixk = zeros(1,ln);
 
%Calculating DFT
for k=0:ln-1
   for n=0:ln-1
xk(k+1) = xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
 
   end
end
%hear xk(k+1); because of in matlab array index start form 1

 
t = 0:ln-1;
subplot(3,2,1);
stem(t,xn);
title ('Input Sequence x(n)');
xlabel('Time Index');
ylabel('Amplitude');
 
t = 0:ln-1;
subplot(3,2,2);
stem(t,xk);
ylabel ('Amplitude');
title ('X(K)');
xlabel ('K');

 

 
t = 0:ln-1;
subplot(3,2,3);
stem(t,abs(xk));
 
 
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');
 
 
t = 0:ln-1;
subplot(3,2,4);
stem(t,angle(xk));
 
ylabel('Phase');
xlabel('K');
title ('Phase Response');


%-------------------------------------------------------------------%

%Output
%Enter the sequence[ 1 2 3 3 2 1]



 

 

Saturday 14 September 2013

Digital Lock for Electronic Gadget using ATMEGA32 Microcontroller

/*
 ========================================================================
          Digital Code Lock With Keyboard Interfacing in AVR
         
 Author    :   Gaurav Kumar Garg
                        garg.gaurav52@gmail.com
          Version Release:  06-19-2013.1
          GNU GPL Licence

          In this project row are connected to first four pin of C Port
          Coloum are connected to first four pin of D Port
 ========================================================================
*/

#include <avr/io.h>
#include <util/delay.h>

unsigned char ch1[4],ch2[4],i;

void delay(unsigned int ch)
{
_delay_ms(ch);
}

void key_init()
{
DDRC=0X0F; //Make port c as output
DDRD=0X00; //Make port D as input
DDRA=0XFF; // Just for testing purpose

}

void lcd_init()
{
DDRB=0xff; // make port b is an output port for display data on lcd
dis_cmd(0x02); // to initilize in 4 bit mode
dis_cmd(0x28);
dis_cmd(0x0c);
delay(250);
}

void lcd_cmd(unsigned char ch)
{
PORTB=ch;
PORTB|=(1<<PB0); // make EN=1
PORTB&=~(1<<PB1); //make r/w=0 for writing
PORTB&=~(1<<PB2); //make  RS =0 for command
delay(250);
PORTB&=~(1<<PB0); // high to low pulse EN = 0

}

void lcd_data(unsigned char ch)
{
PORTB=ch;
PORTB|=(1<<PB0); // make EN=1
PORTB&=~(1<<PB1); //make r/w=0 for writing
PORTB|=(1<<PB2); //make  RS =1 for data
delay(250);
PORTB&=~(1<<PB0); // high to low pulse EN = 0
}

void dis_cmd(unsigned char ch)
{
unsigned char value;
value=ch&0xf0;
lcd_cmd(value);
value=(ch<<4)&(0xf0);
lcd_cmd(value);
delay(20);
}

void dis_data(unsigned char ch)
{
unsigned char value;
value=ch&0xf0;
lcd_data(value);
value=(ch<<4)&(0xf0);
lcd_data(value);
delay(20);
}

void lcd_string(unsigned char ch[])
{
unsigned int i=0;
while (ch[i]!='\0')
{
dis_data(ch[i]);
i++;
// delay(20);
}
}

unsigned char a[4][4]={
'1', '2', '3', '4',
'5', '6', '7', '8',
'9', '0', 'A', 'B',
'C', 'D', 'E', 'F',
 };

char take_value(void)
{
unsigned char rowloc,colloc,key;
// key_init();
// lcd_init();

// while (1)
{
unsigned int i=0;
do
{
PORTC&=0X00; // Ground all row
PORTD=0X0F;
colloc=(PIND & 0X0F);
}while (colloc!=0X0F); // check until all key are released



do
{
delay(20);
colloc=(PIND & 0X0F);
}while (colloc==0x0f); //wait for key press


// Now Checking for particular row
while (1)
{
PORTC=0X0E;
colloc=PIND & 0X0F;
if (colloc!=0x0f)
{
rowloc=0;
//dis_data('0');
break;
}

PORTC=0X0D;
colloc=PIND& 0X0F;
if (colloc!=0x0f)
{
rowloc=1;
//dis_data('1');
break;
}

PORTC=0X0B;
colloc=PIND & 0X0F;
if (colloc!=0x0f)
{
rowloc=2;
// dis_data('2');
break;
}
else
{
PORTC=0x07;
colloc=PIND & 0X0F;
rowloc=3;
//dis_data('3');
break;
}
}

//dis_data('rowloc');
//dis_data('1');   //for testing purpose



// Now Detect coloum pressed
if (colloc==0x0E)
key=a[rowloc][0];

else if (colloc==0x0D)
key=a[rowloc][1];

else if (colloc==0x0B)
key=a[rowloc][2];

else
key=a[rowloc][3];

// ch1[i]=key;
// dis_data(key);

}// end of first while(1) loop

// dis_data(key);
return key;
}// end of main loop


void main()
{
unsigned char key;
key_init();
    lcd_init();

lcd_string("*Enter Password*");
dis_cmd(0xc0);

int flag=1;
for (i=0;i<4;i++)
{
// key=take_value();
ch1[i]=take_value();
key=ch1[i];
lcd_string("*");
// dis_data(key);
// dis_data();
// lcd_string(key);
}

dis_cmd (0x01);
dis_cmd (0x80);
lcd_string("Enter Again");
dis_cmd(0xC0);

for (i=0;i<4;i++)
{
ch2[i]=take_value();
lcd_string ("*");
}

for (i=0;i<4;i++)
{
if (ch1[i]!=ch2[i])
flag=0;

}

dis_cmd (0x01);
dis_cmd (0x80);
if (flag==0)
lcd_string("Wrong Password");
else
lcd_string("Lock Opening...");

if (flag!=0)
{
PORTA|=(1<<PA0); // For Glowing LED if Password enter is correct
}
}



Digital Code Lock ( It will ask you for entering password )



Verifying Password (It will ask to enter password again for verifying )


If we enter correct Password then it will Switch Device ON (Hear RED LED is using as a Device which is connected to PORT PA0 )


Thursday 12 September 2013

What is Compiler and Compilation

Compiler and Compilation :
compiler is nothing but a normal program which translates a source program written in some high-level programming language (such as C, C++, Java and etc.,) into executable files which can be understood by some CPU architecture (such as Intel, ARM, AVR, Microchip etc). For this article I have been searching a lot on net, surprisingly there is limited information available with this regard. But Wikipedia and Aho’s famous book I have used as reference.
The process we are doing to get the binary files( executable files) is nothing but “Compilation”.
What’s Cross Compilation?
Before we discuss about Cross Compilation, we should learn about what is compilation and what is compiler. Then we will go for cross compiler and cross compilation.
First we talk about something general in developing field.

Suppose if you are developing a PC application or server application, then development platform and the target platform are the same.
Here first we discuss about two terms in above line.
1. Development Platform
2. Target Platform
Before going to know about these, we need to know a tickle about the word ‘Platform’ what we used here. What I mean to say about ‘Platform’ is just nothing but the combination of CPU architecture and Operating System.
Now, come to Development Platform, it’s a machine which runs your compiler. With this, you will guess Target Platform. It’s a machine that runs your application. An embedded developer understands this very well.
Native Compiler:
As we said at first, desktop developers used to build the binaries for windows or Linux and to run those applications they will use the same machine. The compiler which is used in this case is called as “Native Compiler”.
Cross Compilation:
The process of building executable files on one machine and run them on another machine when the CPU architecture or the Operating system are different is called “Cross Compilation”.
A special program which is used to do the cross compilation process is nothing but “Cross Compiler”.  Most of the people defined it as Tool Chain.
Just take and example, we are developing the applications for a mobile phone running on some X micro controller. So, we write the program in PC and build that source code (Now a day’s most of the people trying this using Android ADK). After compiling this, we dump the code onto the target machine (our micro controller or mobile) and then we run the application. So, when we are developing the applications on one platform for running it on another platform, with host compiler getting executable files to run on the target is not possible. But with the help of cross compiler the suitable executable files to run on the target is possible.
A compiler consists of three main parts: the frontend, the middle-end, and the backend.
The front end checks whether the program is correctly written in terms of the programming language syntax and semantics. Here legal and illegal programs are recognized. Errors are reported, if any, in a useful way. Type checking is also performed by collecting type information. The frontend then generates an intermediate representation or IR of the source code for processing by the middle-end.
The middle end is where optimization takes place. Typical transformations for optimization are removal of useless or unreachable code, discovery and propagation of constant values, relocation of computation to a less frequently executed place (e.g., out of a loop), or specialization of computation based on the context. The middle-end generates another IR for the following backend. Most optimization efforts are focused on this part.
The back end is responsible for translating the IR from the middle-end into assembly code. The target instruction(s) are chosen for each IR instruction. Register allocation assigns processor registers for the program variables where possible. The backend utilizes the hardware by figuring out how to keep parallel execution units busy, filling delay slots, and so on. Although most algorithms for optimization are in NP, heuristic techniques are well-developed.