LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-19-2011, 10:00 AM   #1
vishnugopalakrishnan
LQ Newbie
 
Registered: Dec 2011
Location: KERALA
Posts: 2

Rep: Reputation: Disabled
How develop a simple boot loader for linux kernel 3.0


An os is developing using linux kernel 3.0.So a boot loader is required to load the linux kernel 3.0.How develop it.
 
Old 12-19-2011, 10:05 AM   #2
novice06
Member
 
Registered: Mar 2006
Location: Singapore
Distribution: RHEL, CentOS
Posts: 132

Rep: Reputation: 23
why do you want to re-write? Since this is linux, you can use grub.
Actually, you can customize the grub bootloader appearance and wording.
 
Old 12-19-2011, 02:08 PM   #3
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hello Vishnu,

Assuming you're using nasm and you're on an x86 processor, here is an example of boot sector code to print "Hello World"

Quote:
;=============================================================================;
; helloworld.asm: print "Hello world" <strong class="highlight">to</strong> the screen and hang ;
;=============================================================================;

section .text
;=============================================================================;
; start: entry point
start:
[org 0x7c00] ; Self-relocate origin <strong class="highlight">to</strong> 0x7c00
cli ; Disable interrupts

mov si, msg ; Place message in si
call putstr ; Print the string
;-----------------------------------------------------------------------------;
; hang: hang the machine indefinitely
hang:
jmp hang
;-----------------------------------------------------------------------------;
; putstr: print <strong class="highlight">a</strong> string given in si <strong class="highlight">to</strong> the screen
putstr:
pusha ; Push all registers
mov ah, 0eh ;

; putchar: print <strong class="highlight">a</strong> character from the string
putchar:
lodsb ; Get <strong class="highlight">a</strong> character
cmp al, 0 ; Check <strong class="highlight">for</strong> null-terminator
je .return ; NULL found, stop
; Not NULL, print the character
int 0x10
jmp putchar
.return:
popa ; Pop all registers
mov ax, 0
ret ; Return (0 in ax)
;=============================================================================;

section .data ; This always goes at the end of the binary, so putting it at the
; end of the source file makes sense.
;=============================================================================;
msg db 'Hello world', 13, 10, 0 ; The 13, 10, 0 refers <strong class="highlight">to</strong> '\r\n\0' in C/C++.
times 482-($-$$) db 0 ; Fill the binary until it's 512 bytes
dw 0xaa55 ; Boot signature stored as 0x55 0xaa in memory (little endian)
;=============================================================================;

Now, for some reason times isn't working. Actually it should be:

times 510-($-SS) db 0

Check out the above code, if that helps you..
 
Old 12-22-2011, 09:00 AM   #4
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Just out of curiosity, Satyaveer, did you write that yourself, or did you copy and paste from some webpage?


What I'm curious about myself, is that the kernel has to be read, off of a ext4 filesystem, and then JMPed to - how is this accomplished? IS IT IN ASM???!!!! Would LOVE to have a chat with the guy who wrote this!
 
Old 12-22-2011, 01:52 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There are lots of different types of bootloaders for lots of different architectures and situations.
In order to know how to provide any useful advice, one would have to know something about those specifics. My next question would be 'are you sure you need to do this?'. It sounds a lot like re-inventing a well rounded wheel.

There is a prior LQ thread on a similar topic that might be entertaining.

--- rod.
 
Old 12-22-2011, 01:53 PM   #6
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Yes, exactly this is in ASM. And actually a professor(my sir) and my friend helped me in this.
 
Old 12-22-2011, 06:51 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,506

Rep: Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234
At one time ranish had a lot of boot info on his web page. Might see if any mirrors have it still.
 
Old 12-23-2011, 07:57 AM   #8
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Quote:
Originally Posted by Satyaveer Arya View Post
Yes, exactly this is in ASM. And actually a professor(my sir) and my friend helped me in this.
Can you post the code that reads from an ext4 partition? I'd love to take a look at it... (though I'll probably not understand it all).



Are you interested in this type of thing in general? I am. I'm in India too, let's keep in touch... Can I send you a PM through this site?
 
Old 12-23-2011, 01:07 PM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There are two strategies regarding access to the filesystem by a bootloader. The issue is that the bootloader must either have drivers for the hardware and fileystem type built in at boot time (size and complexity), or the bootloader can know a priori where the blocks that store the relevant parts are located on the disk, and simply use low-level functions to get those blocks (smaller and simpler).
The first approach is what grub does. It is fully filesystem aware, and can fetch things from disk using filesystem descriptions (albeit, using its own syntax). The latter approach is what lilo does. At boot time, it just fetches a list of disk blocks, and doesn't know anything about filesystems. All of the work of locating the appropriate blocks is done while Linux is fully up and running, and has the benefit of a fully functioning host to support all of the difficult work. That is why any change to the boot configuration requires you to run lilo before rebooting.
The upshot of this is that you can use grub sources to see how a bootloader reads the filesystem. I've never looked, but I feel certain that it is a fairly complex bit of code. I doubt that much of it is written in assembler.

--- rod.

Last edited by theNbomr; 12-23-2011 at 01:09 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how build a simple boot loader for linux kernel 3.0? vishnugopalakrishnan Linux - Newbie 1 12-19-2011 12:58 PM
no /boot/loader and no /boot/kernel/kernel error message on a free bsd install chownuseradd Linux - Newbie 1 02-09-2008 09:05 PM
Can't boot to another Linux kernel from boot loader Okie2003 Linux - General 6 02-01-2005 09:21 AM
Boot Loader -made simple ? pacer Red Hat 4 11-08-2004 01:37 PM


All times are GMT -5. The time now is 06:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration