Page 1 of 1

Multibooting real-mode kernel.

Posted: Tue Feb 16, 2016 8:40 am
by bilsch01
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

Re: Multibooting real-mode kernel.

Posted: Tue Feb 16, 2016 8:49 am
by BrightLight
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.

Re: Multibooting real-mode kernel.

Posted: Tue Feb 16, 2016 8:55 am
by bilsch01
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.

Re: Multibooting real-mode kernel.

Posted: Tue Feb 16, 2016 9:22 am
by iansjack
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

Re: Multibooting real-mode kernel.

Posted: Fri Feb 19, 2016 9:22 am
by bilsch01
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.

Re: Multibooting real-mode kernel.

Posted: Fri Feb 19, 2016 9:49 am
by BASICFreak
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: Select all

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: Select all

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!

Re: Multibooting real-mode kernel.

Posted: Sat Feb 20, 2016 8:42 am
by Icee
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.

Re: Multibooting real-mode kernel.

Posted: Sat Feb 20, 2016 6:48 pm
by bilsch01
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.

Re: Multibooting real-mode kernel.

Posted: Mon Feb 22, 2016 2:32 am
by bilsch01
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.