Page 1 of 2

Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 8:12 am
by animefreak1233

Code: Select all

MAGIC equ 0xE85250D6
ARCH equ 0
HEADER_LENGTH equ multiboot_end - multiboot_end
CHECKSUM equ -(MAGIC + ARCH + HEADER_LENGTH)
ALIGN 8, db 0
section .multiboot
multiboot_start:
	DD MAGIC
	DD ARCH
	DD HEADER_LENGTH
	DD CHECKSUM
multiboot_end:
ALIGN 16
section .bss
stack_top:
	resb 16384
stack_bottom:
section .text
ALIGN 16
GLOBAL _start
_start:
	mov eax, 0xBEEF
	mov ebx, 0xBEEF
	mov esp, stack_bottom
 	;mov ax, 0
;;;extern ksetup
;;; 	call ksetup
	cli
.hang:	hlt
	jmp .hang
.end:
	
That's boot.s. But the value in the register eax is 0x9020. In fact, _start never executes. Why?
My linker script:

Code: Select all

ENTRY(_start)

SECTIONS
{
	. = 1M;
	.multiboot BLOCK(4K):ALIGN(4K)
	{
		*(.multiboot)
		
	}
	.text BLOCK(4K):ALIGN(4K)
	{
		*(.text)
	}
	.rodata BLOCK(4K):ALIGN(4K)
	{
		*(.rodata)
	}
	.data BLOCK(4K):ALIGN(4K)
	{
		*(.data)
	}
	.bss BLOCK(4K):ALIGN(4K)
	{
		*(COMMON)
		*(.bss)
	}
}

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 8:58 am
by TheCool1Kevin
Are you using GRUB? If so, may I refer you to these:
http://wiki.osdev.org/Bare_Bones (GAS syntax)
http://wiki.osdev.org/Bare_Bones_with_NASM (NASM syntax for bootstrap code)

I think that you might need to specify the size of _start for you symbol :shrug:
Also, if you are using GRUB, which version is it? Because I see that your multiboot portion of the code is really messed up :D

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 9:00 am
by animefreak1233
Yes, I've read those. And my code isn't much different, just I'm using multiboot 2. And grub-file says that my file is indeed compatible. I'd like to know exactly what went wrong

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 9:03 am
by TheCool1Kevin
Oh? I thought GRUB2 had the same multiboot specs (because I use GRUB2 with the BareBones code, and it works fine)
If possible, double check the output binary:

Code: Select all

grub-file --is-x86-multiboot2 myos.bin
Edit: Run this instead

Code: Select all

grub-file --is-x86-multiboot2 myos.bin && echo File is multiboot

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 9:04 am
by animefreak1233
I did mention that I passed the grub-file test just fine

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 9:10 am
by TheCool1Kevin
I am an idot :)

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 9:38 am
by Kevin
animefreak1233 wrote:But the value in the register eax is 0x9020. In fact, _start never executes. Why?
So GRUB accepts your kernel binary, loads it and starts executing something, but not your kernel? If so, the next two question I would ask are: What does it execute? (Have a look at the eip register.) Did it load your binary correctly? (Have a look at the memory at 1M.)

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 11:27 am
by animefreak1233
Actually GRUB works, but I get the error - "can't find command multiboot". I usually run my OS directly through the '`-kernel`' to get around that.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 12:32 pm
by TheCool1Kevin
After fiddling around with the code, I got it to work:
In the beginning, replace your current header with:

Code: Select all

FLAGS equ 0 ;Change to fit your preference, preferably to 1<<0 | 1<<1
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
section .multiboot
align 4
multiboot_start:
   DD MAGIC
   DD FLAGS
   DD CHECKSUM
multiboot_end:
You were missing the FLAGS field, and there were a lot of random fields that I had no idea why you had them in there.
The magic, flags and checksum fields are marked as required according to the: GRUB Multiboot Specs Header Layout. Anyways, after the modification, the bootloader seemed to work without any errors.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 1:07 pm
by animefreak1233
That's because I'm using the newer multiboot spec. You can find it on the wiki.
Your multiboot header is the older one. The newer one is much nicer

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 1:22 pm
by Kevin
animefreak1233 wrote:Actually GRUB works, but I get the error - "can't find command multiboot".
Maybe you should have mentioned that error message. ;)

If GRUB doesn't have the multiboot module available, then the problem isn't with your kernel, but with your GRUB setup. You could try doing an "insmod multiboot" first. If that works, the "multiboot" command should be available afterwards.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 1:59 pm
by animefreak1233
I'm pretty sure I mentioned this before, but my current debugging setup DOES NOT need GRUB. I use the bin file straightly.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 2:30 pm
by Kevin
I thought you were asking how to make it work with GRUB. If this isn't what you're looking for, I don't seem to understand your question.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 7:58 pm
by TheCool1Kevin
animefreak1233 wrote:That's because I'm using the newer multiboot spec. You can find it on the wiki.
Your multiboot header is the older one. The newer one is much nicer
Oh ok. But GRUB2 should work with the Multiboot 1 specs nevertheless... But if you REALLY really want to stick with the Multiboot 2 specifications, then welp. :P
Kevin wrote:If GRUB doesn't have the multiboot module available, then the problem isn't with your kernel, but with your GRUB setup. You could try doing an "insmod multiboot" first. If that works, the "multiboot" command should be available afterwards.
I disagree. When I ran the original file, it gave me the same "multiboot header no found" message - and I assure you, my GRUB setup is perfectly fine :D
I'll look more into it.

Re: Custom bootstrap assembly file not workin.

Posted: Wed Dec 28, 2016 8:15 pm
by TheCool1Kevin
OOOHHHH HAHAHAHAHAHAHAHA LOL JOOOKKKKESSS
animefreak1233 wrote:

Code: Select all

HEADER_LENGTH equ multiboot_end - multiboot_end
Looks like someone needs to catch up on their ZZZZs.

Code: Select all

HEADER_LENGTH equ multiboot_start - multiboot_end
I also see some interesting align wackydoodles, so I rewrote the code again:

Code: Select all

MAGIC equ 0xE85250D6
ARCH equ 0
HEADER_LENGTH equ multiboot_start - multiboot_end
CHECKSUM equ -(MAGIC + ARCH + HEADER_LENGTH)
TAGS equ 0

section .multiboot
align 4
multiboot_start:
   DD MAGIC
   DD ARCH
   DD HEADER_LENGTH
   DD CHECKSUM
   DD TAGS
multiboot_end:
And them I run this and it doesn't work.

BUT WAIT, THERE'S MORE! (bugs)

You know the grub.cfg you use to generate the disk image? Yea, you'll need to change it from:

Code: Select all

menuentry "myos" {
	multiboot /boot/myos.bin
}
to

Code: Select all

menuentry "myos" {
	multiboot2 /boot/myos.bin
}
And, if this doesn't work, there's some example code at the end of http://nongnu.askapache.com/grub/phcoder/multiboot.pdf in GAS syntax.