LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Hardware > Linux - Embedded
User Name
Password
Linux - Embedded This forum is for the discussion of Linux and embedded devices.

Notices

Reply
 
Thread Tools
Old 01-03-2009, 04:27 PM   #1
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3
Thanked: 0
Where a processor runing Linux read his code after boot ?


[Log in to get rid of this advertisement]
Dear All,


First, please excuse my bad English, I am speaking normaly French, I will
do my best !

Second, a Happy New Year 2009 to you !!!



So, I work normaly with 8 bit µC like PIC 16F or 18F series and I am new to the embedded world of Linux.

Normaly, a 8 bit µC execute a code stored into an internal Flash, ROM or extrnal EEPROM with an internal programm counter.

In the Linux case, I have read that the boot loader ( like U - BOOT )
start the system with loading the Kernel into RAM and pass the control
to the O/S.

My question is as following => when the Kernel has been loaded into the RAM, where the processor take is code for runing ?

In others words, in a 8 bits µC, the only way for the processor to read his code is from the Flash ( or EPROM ) => the programm counter address
the Flash ( or EPROM ) and pass the code readed to the instructions decoder that drive the ALU and the system ( right ??? ).

But, with a processor runing Linux ( and also a PC ), what is the principle ( in the case of a PC, the hard disk drive is not always
readed by the processor => it seems that the processor run is code only
from the RAM ) ?

Can you explain me the principle under that ?

Best regards,


Jean - Pierre
J-P V-R is offline     Reply With Quote
Old 01-03-2009, 04:47 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: atop the Blue Ridge
Distribution: Debian Lenny, CentOS 5.2
Posts: 7,250
Thanked: 31
When booting on a multi-cpu system Linux boots on the first CPU just as if it is booting on a single CPU system. Once the kernel is established and set up it then goes into multi-cpu mode by scheduling threads on all of the available CPUs.
Once the kernel reaches this stage it is no longer sitting on a "master" CPU scheduling "slave" CPUs. All CPUs are equal.

Each processor is not running Linux per se. Each processor is running the thread it is currently assigned and executes application code and kernel code as the thread demands. Interrupts are processed by the CPU on which the interrupt causing event was generated. Thus the kernel interrupt code runs on which ever CPU has the latest interrupt. Likewise the scheduler runs on each CPU when that CPU reaches the next scheduling event.

So at any moment in time, after boot completes, you could have several CPUs running kernel code or one CPU running kernel code or no CPUs running kernel code.

-----------------------
Steve Stites

Last edited by jailbait; 01-03-2009 at 04:49 PM..
jailbait is offline     Reply With Quote
Old 01-03-2009, 04:54 PM   #3
Drakeo
Senior Member
 
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Pclinux, Mandriva, Kubuntu 9.10, Slck13_64-current
Posts: 1,413
Blog Entries: 3
Thanked: 54
D O S system use virtual ram this is called the swap file system hope this helps.
http://winmac.mvps.org/virtual.html
Drakeo is offline     Reply With Quote
Old 01-03-2009, 05:56 PM   #4
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: Open Suse, Fedora, Redhat
Posts: 2,274
Thanked: 74
The boot process starts the same as your microcontroller; executing code from non-volatile memory at a CPU-dependent address as the CPU comes out of reset. The exact nature of this is hardware platform dependent. This code is often called a BIOS. The BIOS determines from where to load further code. It could be from spinning media, a network share, or other non-volatile media. In any case, it would copy the code and data into memory, and pass execution to that code. In the case of Linux on a PC, this code would normally be a boot loader. The boot loader is a little smarter, and knows how to find an operating system; again, from any number of sources. The process is still the same, though. It copies the code and data into memory, and passes execution to it. Ultimately, the OS is executed, and it knows how to proceed, in part based on arguments given to it by the bootloader. If it is Linux, it has a filesystem containing drivers and essential files to proceed with it's startup. That filesystem is typically in a ramdisk, which the bootloader sets up for it (I think; someone correct me on that part). Eventually, it starts a process called 'init', which reads a script from the filesystem (typically called 'inittab'), and it uses the inittab file to perform a full boot, loading drivers and configuring higher level processes.
Make sense?
--- rod.

Last edited by theNbomr; 01-06-2009 at 12:27 AM..
theNbomr is offline     Reply With Quote
Old 01-04-2009, 07:57 AM   #5
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3
Thanked: 0

Original Poster
Thanks a lot for all of your explanations !

In resume, can I say that the processor as the ability to execute directly his programm code from RAM instead of the ROM
after the Kernel startup ( I suppose that the processor have special instructions and register for do that ) ?



Jean - Pierre
J-P V-R is offline     Reply With Quote
Old 01-04-2009, 06:31 PM   #6
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: Open Suse, Fedora, Redhat
Posts: 2,274
Thanked: 74
Quote:
Originally Posted by J-P V-R View Post
Thanks a lot for all of your explanations !

In resume, can I say that the processor as the ability to execute directly his programm code from RAM instead of the ROM
after the Kernel startup ( I suppose that the processor have special instructions and register for do that ) ?



Jean - Pierre
No special instructions are required. The code and data are moved into RAM using methods appropriate for the source, and then a CALL, JUMP, or soft interrupt instruction invokes the specified code. This aspect would be very much CPU dependent. On a x86 family CPU, there may be IO instructions (different from memory read and write instructions) used to access such things as spinning media, network shares, flash drives, etc. These would be used simply to copy the code and data into RAM, at which point it becomes directly executable. This whole business is distinct from those microcontollers that have different address spaces for memory of different types, notably the Intel 8051 family, with it's plethora of addressing modes.

At an advanced phase of the boot sequence, the code may use sharable object libraries. The 'copy to RAM' phase may involve some adjustments by a linking loader, so that libraries' code is loaded, the public symbols are found and the the external references to these are resolved.

Ok, now that I've thought about the process, I have a question of my own. For a compressed kernel image, does the bootloader need to uncompress the kernel image, or does the kernel do that itself, as it begins execution? Inquiring minds wish to know...

--- rod.
theNbomr is offline     Reply With Quote
Old 01-04-2009, 08:01 PM   #7
jailbait
Guru
 
Registered: Feb 2003
Location: atop the Blue Ridge
Distribution: Debian Lenny, CentOS 5.2
Posts: 7,250
Thanked: 31
Quote:
Originally Posted by theNbomr View Post
For a compressed kernel image, does the bootloader need to uncompress the kernel image, or does the kernel do that itself, as it begins execution?
The kernel uncompresses itself.

---------------------
Steve Stites
jailbait is offline     Reply With Quote
Old 01-05-2009, 11:51 AM   #8
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3
Thanked: 0

Original Poster
Talking

Perfect, You answered my question => I am going to sleep in peace this night...


Thank you infinitely !



Jean - Pierre
J-P V-R is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a word processor that can read .SDW files newbiesforever Linux - General 3 02-17-2008 05:27 AM
runing comiled of this code in wine has problem linuxsavar Programming 2 01-18-2008 09:47 AM
configure linux to boot in single processor mode dlnlinux Linux - General 1 08-07-2005 04:53 AM
Force linux to boot in single processor mode dlnlinux Linux - Newbie 2 08-05-2005 03:53 PM
Installing Linux on a dual processor machine (only one processor detected) rocordial Linux - Hardware 1 11-27-2004 03:16 AM


All times are GMT -5. The time now is 11:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration