Page 1 of 1

Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 4:31 pm
by Nathan
Hello,
I'm developing a OS using Assembly, but it's one of those bootloader OSes, and I'm needing more than just 512 bytes(the boot sector) to use, then I want to remove the boot part of my OS, and use Grub to load it. Here is how my code is right now(it's very big, then I've suppressed it):

Code: Select all

[BITS 16]
[ORG 0x7C00]

; Lots of code...

times 510-($-$$) db 0
dw 0xAA55
Then my questions are:
  • What I need to change on my code to make it boot with Grub?
  • I need to change anything on how I compile my code?
Remember that I already have a Grub image(because I already tried to develop my OS in C)

Best Regards,
Nathan Paulino Campos

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 4:46 pm
by StephanvanSchaik
Hi,

This as well as this might be interesting.


Regards,
Stephan J.R. van Schaik.

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 4:57 pm
by Nathan
When I tried to do it, like this:

Code: Select all

%define MBOOT_MAGIC 0x1badb002
%define MBOOT_FLAGS 0x00010002

[BITS 16]
[ORG 7C00h]

align 4, db 0
header:
   dd MBOOT_MAGIC
   dd MBOOT_FLAGS
   dd 0 - MBOOT_MAGIC - MBOOT_FLAGS
   dd header
   dd main
   dd end_of_file
   dd end_of_file
   dd main
align 0, db 0
; More code...
I got this error:

Code: Select all

gker.asm:17: error: division by zero
What I need to do?

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 5:16 pm
by pcmattman
Your code attempts to align on a 0-byte boundary. I'll leave it up to you to figure out why that's wrong ;)

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 5:26 pm
by Owen
Also: Grub doesn't do real mode

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 6:04 pm
by Nathan
I've changed that line to this:

Code: Select all

align 4, db 0
But when I booted Grub and selected my OS, I got this error:

Code: Select all

  Booting 'MyOS'

root    (fd0)
 Filesystem type is fat, using whole disk
kernel  /boot/kernel.bin

Error 7: Loading below 1MB is not supported

Press any key to continue...
What is wrong now?

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 7:05 pm
by neon
If main is a function inside of your bootloader (loaded at 0x7c00) its not going to work. Grub only supports loading to 1MB or above. Also, as mentioned above, Grub and the MultiBoot standard says that the system must be running in protected mode on entry: It wont work if you are trying to boot using real mode code.

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 7:22 pm
by Nathan
Oh! But there is any way to do boot my OS, that is on real mode? Don't matter the boot loader. [-o<

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 7:52 pm
by gerryg400
Many have written a 32bit loader that loads a 64bit kernel and switches to long mode to execute it. You could do a similar thing. i.e, Write a 32bit loader that loads your kernel, switches to real mode and executes it.

i.e.
Grub loads 32bit loader
Loader loads kernel below 1M
Loader switches to real mode
Loader jumps to rmode kernel

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 7:59 pm
by Nathan
I've liked your way of thinking. I will try it, any problem I will post here. :)

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 8:14 pm
by Nathan
But there is any boot loader that could load real mode OSes and that are 16 Bits?

Re: Boot Assembly OS Using Grub

Posted: Sat Jun 19, 2010 9:54 pm
by neon
If you are just looking for boot code (boot sector) to boot your OS in real mode, just search Google. There are tons of them. Dont copy and paste however; some might have licensing restrictions and you wont learn anything that way.

If you are looking for a larger boot loader (Like the one that you tried using, Grub) then I personally dont know of any, sorry.