Custom bootstrap assembly file not workin.

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.
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Custom bootstrap assembly file not workin.

Post 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)
	}
}
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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
Last edited by TheCool1Kevin on Wed Dec 28, 2016 9:01 am, edited 1 time in total.
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Re: Custom bootstrap assembly file not workin.

Post 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
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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
Last edited by TheCool1Kevin on Wed Dec 28, 2016 9:11 am, edited 1 time in total.
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Re: Custom bootstrap assembly file not workin.

Post by animefreak1233 »

I did mention that I passed the grub-file test just fine
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post by TheCool1Kevin »

I am an idot :)
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.)
Developer of tyndur - community OS of Lowlevel (German)
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Re: Custom bootstrap assembly file not workin.

Post 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.
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Re: Custom bootstrap assembly file not workin.

Post 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
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
animefreak1233
Posts: 19
Joined: Sun Dec 20, 2015 1:18 pm

Re: Custom bootstrap assembly file not workin.

Post 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.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
User avatar
TheCool1Kevin
Posts: 24
Joined: Fri Oct 14, 2016 7:37 pm
Location: Canada
Contact:

Re: Custom bootstrap assembly file not workin.

Post 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.
LiquiDOS, my weird hobbyist OS.
"Strive for progress, not perfection" - Anonymous
Post Reply