LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 01-03-2009, 03:27 PM   #1
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 0
Where a processor runing Linux read his code after boot ?


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
 
Old 01-03-2009, 03:47 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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 03:49 PM.
 
Old 01-03-2009, 03:54 PM   #3
Drakeo
Senior Member
 
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Slacko,
Posts: 3,716
Blog Entries: 3

Rep: Reputation: 483Reputation: 483Reputation: 483Reputation: 483Reputation: 483
D O S system use virtual ram this is called the swap file system hope this helps.
http://winmac.mvps.org/virtual.html
 
Old 01-03-2009, 04:56 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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-05-2009 at 11:27 PM.
 
Old 01-04-2009, 06:57 AM   #5
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 01-04-2009, 05:31 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 01-04-2009, 07:01 PM   #7
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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
 
Old 01-05-2009, 10:51 AM   #8
J-P V-R
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Talking

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


Thank you infinitely !



Jean - Pierre
 
  


Reply



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 04:27 AM
runing comiled of this code in wine has problem linuxsavar Programming 2 01-18-2008 08:47 AM
configure linux to boot in single processor mode dlnlinux Linux - General 1 08-07-2005 03:53 AM
Force linux to boot in single processor mode dlnlinux Linux - Newbie 2 08-05-2005 02:53 PM
Installing Linux on a dual processor machine (only one processor detected) rocordial Linux - Hardware 1 11-27-2004 02:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:47 PM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Open Source Consulting | Domain Registration