Page 1 of 1

Boot NetBSD with custom bootloader via multiboot

Posted: Thu Feb 28, 2013 3:21 pm
by Mackerel
Hi all,

My first post, so apologies in advance if this is the wrong forum!

Anyway, here is my situation. I have a standard NetBSD kernel (stripped down to about 4MB) and a custom bootloader (similar to BSDs but ending up in good ol' C and long mode).

At the end of my boot2 routine, I create the MIS structure for NetBSD and push the location into EBX. The magic number 0xBAD2B002 is being pushed into EAX. When I release control to the OS, I can see the first few assembler instructions being executed. An objdump -D netbsd | less tells me:

netbsd: file format elf64-x86-64


Disassembly of section .text:

ffffffff80100000 <start>:
ffffffff80100000: 66 c7 05 72 04 00 00 movw $0x1234,0x472(%rip) # ffffffff8010047b <cpu_switchto+0x7b>
ffffffff80100007: 34 12
ffffffff80100009: 8b 44 24 04 mov 0x4(%rsp),%eax
ffffffff8010000d: a3 18 66 4c 00 8b 44 movabs %eax,0xc24448b004c6618
ffffffff80100014: 24 0c
ffffffff80100016: 85 c0 test %eax,%eax
ffffffff80100018: 74 64 je ffffffff8010007e <start+0x7e>

The first few steps, as I said, are being executed. However, the movabs instruction fails and Bochs tells me that the operand is not a valid canonical address. That is correct, it is not. But the BSD bootloader must do something to avoid this?

What is this instruction being used for? Does anyone have an idea?

Thanks for any ideas/pointers.

Re: Boot NetBSD with custom bootloader via multiboot

Posted: Thu Feb 28, 2013 3:54 pm
by iansjack
Just a thought, but are you sure that the NetBSD loader puts the system into long mode before executing those instructions? What do they look like if you disassemble them at 32-bit rather than 64?

Re: Boot NetBSD with custom bootloader via multiboot

Posted: Thu Feb 28, 2013 4:58 pm
by Mackerel
Indeed, that seems to be the problem. My BL proceeds all the way into long mode whereas the BSD entry point is 32 bit. After a few executions, the kernel jumps to long mode.

Seems like I've got to modify my BL to only go to protected mode.

Re: Boot NetBSD with custom bootloader via multiboot

Posted: Sat Mar 02, 2013 12:38 am
by palk
Multiboot requires that the machine be in a 32-bit state.

http://www.gnu.org/software/grub/manual ... hine-state