OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 4:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Multibooting real-mode kernel.
PostPosted: Tue Feb 16, 2016 8:40 am 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
I want to build a real mode OS. I'm using Ubuntu and NASM. I'm using the real-mode example from the tutorials. I add the multiboot numbers at the beginning. I have a problem. Apparently I can't begin my real mode (NASM) program with a multiboot header - or maybe I can't multiboot a 16 bit program. Someone told me Grub switches into protected mode for multiboot compliant kernels. The code uses BIOS interrupts, so protected mode will be a problem.

QEMU (or grub) complains: error invalid arch-dependent ELF magic. I googled it. No help. If I remove the multiboot numbers at the beginning. It complains: no multiboot header.

I tried using NASM directive 'bits 32' for the first bytes which are the multiboot header (such as 0x1BADB002 ) and then use 'bits 16' for the rest of the code. That makes no difference.

File grub.cfg must have the following menu entry:
menuentry "myos" {
multiboot /boot/myos.kernel
}

File grub-mkrescue creates file myos.iso based on that menuentry

qemu-system-i386 -cdrom myos.iso says: invalid arch-dependent ELF magic. The only place magic is involved is in the multiboot header


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Tue Feb 16, 2016 8:49 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
GRUB can only boot multiboot-compliant kernels, which are 32-bit or (someone correct me if I'm wrong) 64-bit kernels. There's no point making your kernel multiboot-compliant if it's 16-bit.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Tue Feb 16, 2016 8:55 am 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
omarrx024 wrote:
GRUB can only boot multiboot-compliant kernels, which are 32-bit or (someone correct me if I'm wrong) 64-bit kernels. There's no point making your kernel multiboot-compliant if it's 16-bit.


It doesn't work if I remove the word 'multiboot' from:

menuentry "myos" {
multiboot /boot/myos.kernel
}

I have grub installed on the computer. There's no way to boot except using grub.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Tue Feb 16, 2016 9:22 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Grub can chain load another bootloader. So you put your 16-bit bootloader in the bootsector of the partition containing your OS and then chain load it from Grub.

http://www.gnu.org/software/grub/manual ... m-directly


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Fri Feb 19, 2016 9:22 am 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
I notice that the meaty skeleton tutorial is set up to boot using QEMU and no physical boot device. That method relies on GRUB, which I cant use for 16-bit kernel. Also I notice I can boot my simple 16-bit kernel from a flashdrive with only a MSDOS MBR in sector 1, with my kernel beginning in sector 2. I don't need an image of a DOS bootable floppy or a harddrive image. So apparently the only extra software needed is a MSDOS MBR. I believe I should be able to use that in an ISO file along with my simple 16-bit kernel to boot using the linux -cdrom (software) device that is used by meaty skeleton via QEMU. I concatenated the kernel onto the MBR and made an ISO from that. But QEMU says no bootable device.

There must be a simple method using the following 5 components:

DOS MBR in sector #1 (or el torito equivalent)
16-bit kernel following the MBR
Xorriso ISO creating program
-cdrom (software) device used in meaty skeleton
QEMU emulator

I tried some ideas using the above, but always QEMU seems to be looking for a bootable device (hardwae or bootable image?).

Thanks. Bill S.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Fri Feb 19, 2016 9:49 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 16, 2009 8:34 pm
Posts: 284
Location: Louisiana, USA
NOTE Before Reading: I have not actually tried this, it is all theory to me.

GRUB does allow you to boot a 16-bit kernel, in fact that is how memtest86+ is loaded:
Code:
menuentry 'Memory test (memtest86+)' {
   insmod part_msdos
   insmod ext2
   set root='hd3,msdos1'
   *CUT - ADVANCED SEARCH FOR UUID - CUT*
   linux16   /memtest86+.bin
}


Now, I have disassembled memtest86+.bin - it has no multiboot header and the first few lines are just segment fixes:
Code:
00000000  B8C007            mov ax,0x7c0
00000003  8ED8              mov ds,ax
00000005  B80090            mov ax,0x9000
00000008  8EC0              mov es,ax
0000000A  B90001            mov cx,0x100
0000000D  29F6              sub si,si
0000000F  29FF              sub di,di
00000011  FC                cld
00000012  F3A5              rep movsw
00000014  EA19000090        jmp word 0x9000:0x19


So, you can boot 16-bit, but without multiboot. And it seems Grub will load your binary to 0x7C00? which memtest86+ relocates to 0x90000.

But my recommendation would be to either use 32-bit multiboot complaint kernel OR roll your own boot sectors / loaders.

One more choice you do have - if you require multiboot - is to make a 32-bit multiboot complaint kernel and drop back down to 16-bit after grub loads you in.



Best Regards,

B!

_________________
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Sat Feb 20, 2016 8:42 am 
Offline
Member
Member

Joined: Wed Jan 08, 2014 8:41 am
Posts: 100
Location: Moscow, Russia
If all you want from GRUB is to load your file as a boot sector at 0x7C00 and transfer control to it in real mode, use the "chainloader" command.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Sat Feb 20, 2016 6:48 pm 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
OK. I got it. I made isolinux.cfg file that makes an ISO for my kernel then I use QEMU to boot the ISO - I just need to streamline it with a script. Thanks everybody for your input it is very instructive information. Bill S.


Top
 Profile  
 
 Post subject: Re: Multibooting real-mode kernel.
PostPosted: Mon Feb 22, 2016 2:32 am 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
iansjack wrote:
Grub can chain load another bootloader. So you put your 16-bit bootloader in the bootsector of the partition containing your OS and then chain load it from Grub.

http://www.gnu.org/software/grub/manual ... m-directly


I did a 16-bit bootloader and chainloading with grub. It works great. Thanks.

Bill S.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group