Boot Assembly OS Using Grub

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
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Boot Assembly OS Using Grub

Post 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
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: Boot Assembly OS Using Grub

Post by StephanvanSchaik »

Hi,

This as well as this might be interesting.


Regards,
Stephan J.R. van Schaik.
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Boot Assembly OS Using Grub

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Boot Assembly OS Using Grub

Post 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 ;)
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Boot Assembly OS Using Grub

Post by Owen »

Also: Grub doesn't do real mode
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Boot Assembly OS Using Grub

Post 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?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Boot Assembly OS Using Grub

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Boot Assembly OS Using Grub

Post 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<
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Boot Assembly OS Using Grub

Post 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
If a trainstation is where trains stop, what is a workstation ?
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Boot Assembly OS Using Grub

Post by Nathan »

I've liked your way of thinking. I will try it, any problem I will post here. :)
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Boot Assembly OS Using Grub

Post by Nathan »

But there is any boot loader that could load real mode OSes and that are 16 Bits?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Boot Assembly OS Using Grub

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply