You are not logged in.

#1 2009-10-07 19:25:59

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

[solved] Booting a "Multiboot" OS only works with high amounts of mem

edit: ok, I hate when it happens, but I've just found the solution: raising the memory reserved for the virtual machine. It's funny, however, that such simple kernel won't boot with less than 128MB of RAM.

I'm not sure if this is the right place to post this question, but as it's at least indirectly related to programming, I'll post it here.

Recently I've read Tenenbaum's book about Minix and now I'm feeling like hacking a simple OS if only for saying "I can do it". The problem is I got stuck right at the first step: booting. I wasn't willing to implement a bootloader so I decided to use Grub and implement a Multiboot compatible kernel.

Running 'info multiboot' you can see a example showing how to implement a "multiboot" kernel. I used exactly the same code and compiled it with:

gcc -nostartfiles -nodefaultlibs -o kernel boot.S kernel.c

The code compiles with two warnings about redefinitions of printf, but it gives no errors. The 'kernel' file is less than 3KB big and running 'objdump -d kernel' seems to be fine.

Satisfied with it, I've tried to create an ISO image so I could test it in a virtual machine (VirtualBox). I followed the instructions from Grub manual of how to install it in a CD (create a iso/boot/grub/ folder, put stage2_eltorito there, etc). I also created a menu.lst like this:

default 0
timeout 30
fallback 1

title Test
root (cd)
kernel /boot/kernel

and created the ISO image with: 'mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso' .

I've tried to run it in a virtual machine and it boots, but when I press enter to run 'Test', which should run the kernel from the 'multiboot' example, grub gives me an error:

Booting 'Test'

root (cd)
 Filesystem type is iso9660, using whole disk.
kernel /boot/kernel
  [Multiboot-elf, <0x8048000:0x803:0x0> 

Error 28: Selected item cannot fit into memory.

Press any key to continue...

And then it fallsback to the menu. (The menu shows [639k lower / 64448k upper memory])

Last edited by andre.ramaciotti (2009-10-12 19:54:04)


(lambda ())

Offline

#2 2009-10-12 19:41:07

sdkmvx
Member
From: South Carolina
Registered: 2008-06-26
Posts: 6

Re: [solved] Booting a "Multiboot" OS only works with high amounts of mem

The linker is compiling your binary to the default location of 0x8000000. This is fine for Linux to load as an application (even with less than 128MB memory, Linux can use the MMU on the CPU to map anything to 0x8000000). However with ring0 code you are dealing with real physical memory locations. You would need either a linker script (which you can look up, also see: http://wiki.osdev.org/Linker_Scripts) or to specify the options on the command line with

ld -Ttext 0x100000 etc.

0x100000 is at 1MB, so that leaves BIOS memory unaffected. For memory management past that you should read a memory map, which is beyond the scope of this.

Edit: Fix formatting issues.

Last edited by sdkmvx (2009-10-12 19:41:52)

Offline

#3 2009-10-12 19:53:18

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [solved] Booting a "Multiboot" OS only works with high amounts of mem

Thanks. I've read Tenenbaum's book about Minix, and though I have a slight idea of how to implement memory management, I had no idea of how to compile an OS.


(lambda ())

Offline

Board footer

Powered by FluxBB