What register needs to be set for booting linux kernel .

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Tomar
Posts: 4
Joined: Sat Mar 30, 2013 12:11 pm

What register needs to be set for booting linux kernel .

Post by Tomar »

I am new to bootloader stuff and going through u-boot code and looking into file zimage.c file with boot_zimage function and following are comments from boot_zimage function

Set %ebx, %ebp, and %edi to 0, %esi to point to the boot_params * structure, and then jump to the kernel. We assume that %cs is * 0x10, 4GB flat, and read/execute, and the data segments are 0x18, * 4GB flat, and read/write. U-boot is setting them up that way for * itself in arch/i386/cpu/cpu.c.

Now these comment says set ebp,ebx and edi resgister to value 0 and now my question is everytime i need to set these register to 0 before giving control to linux in case of x86 architecture., or its very much uboot specific.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: What register needs to be set for booting linux kernel .

Post by dozniak »

Very end of https://www.kernel.org/doc/Documentation/x86/boot.txt
At entry, the CPU must be in 32-bit protected mode with paging
disabled; a GDT must be loaded with the descriptors for selectors
__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat
segment; __BOOS_CS must have execute/read permission, and __BOOT_DS
must have read/write permission; CS must be __BOOT_CS and DS, ES, SS
must be __BOOT_DS; interrupt must be disabled; %esi must hold the base
address of the struct boot_params; %ebp, %edi and %ebx must be zero.
Learn to read.
Tomar
Posts: 4
Joined: Sat Mar 30, 2013 12:11 pm

Re: What register needs to be set for booting linux kernel .

Post by Tomar »

So are you saying every bootloader(Grub,uboot,LILO etc) has to follow this protocol to boot linux/x86 ??
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: What register needs to be set for booting linux kernel .

Post by dozniak »

Apparently you need to follow Multiboot protocol to be able to boot multiboot-compliant kernel. Linux is no different.

There are probably some shortcuts if you want quick-n-dirty boot, but it will be not fully functional.
Learn to read.
Tomar
Posts: 4
Joined: Sat Mar 30, 2013 12:11 pm

Re: What register needs to be set for booting linux kernel .

Post by Tomar »

Thanks dozniak for your kind response,is it safe to say for any bootloader minimum required to boot linux/x86 is what you said

At entry, the CPU must be in 32-bit protected mode with paging
disabled; a GDT must be loaded with the descriptors for selectors
__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat
segment; __BOOS_CS must have execute/read permission, and __BOOT_DS
must have read/write permission; CS must be __BOOT_CS and DS, ES, SS
must be __BOOT_DS; interrupt must be disabled; %esi must hold the base
address of the struct boot_params; %ebp, %edi and %ebx must be zero.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: What register needs to be set for booting linux kernel .

Post by dozniak »

Just read the link I posted, it describes the full linux kernel boot protocol and what is needed to perform a successful kernel boot.
Learn to read.
Post Reply