Required informations are not present in MBI

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.
Post Reply
StraykerPL
Posts: 8
Joined: Thu Mar 14, 2019 1:45 pm
Libera.chat IRC: straykerpl

Required informations are not present in MBI

Post by StraykerPL »

Hello!

For a few days I'm looking at my code of kernel. After fight with Multiboot 0.6 memory map I decided to update kernel to Multiboot 2.0. So I wrote header based on Multiboot 2.0 Specs and it starts on QEMU and VirtualBox.
The problem is that informations I requested from GRUB are not present in Multiboot Information Structure.

My Multiboot header:

Code: Select all

	; Multiboot 2:
	
	; Defining values:
	MAGIC equ 0xE85250D6
	ARCH equ 0x0
	LENGHT equ header_end - header_start
	CHECKSUM equ 0x100000000 - (MAGIC + ARCH + LENGHT)

; Defining header structure:
SECTION .multiboot
header_start:
	dd MAGIC
	dd ARCH
	dd LENGHT
	dd CHECKSUM

	; Tags for Multiboot bootloader:
	
	; Information request:
	ALIGN 8
request_tag_start:
	dw 1
	dw 0
	dd request_tag_end - request_tag_start
	dd 1 ; CMD line,
	dd 2 ; bootloader name,
	dd 4 ; basic memory amount,
	dd 6 ; memory map,
request_tag_end:

	ALIGN 8
	; End of tags, "NULL tag":
null_start:
	dw 0 ; Type
	dw 0 ; Flags
	dd 8 ; Size
null_end:
	
header_end: ; End of Multiboot header!
And here is for loop that checks for information's present:

Code: Select all

struct multiboot_tag *mbi = 0;

for (mbi = (struct multiboot_tag *) (mbi + 8); mbi->type != MULTIBOOT_TAG_TYPE_END; mbi = (struct multiboot_tag *) ((multiboot_uint8_t *) mbi + ((mbi->size + 7) & ~7)))
	{
		switch(mbi->type)
		{
			case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: ;
				kprintf("BOOTLOADER: OK\n");
			break;
			
			case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: ;
				kprintf("MEMINFO: OK\n");
			break;
			
			case MULTIBOOT_TAG_TYPE_CMDLINE: ;
				kprintf("CMDLINE: OK\n");
			break;
		}
	}
After booting, screen should show the informations but it doesn't:
https://drive.google.com/open?id=1rSoI3 ... UTtmoeYP1m

I would like to know what i'm doing wrong.
Could someone explain it to me please?

Resto of code of OS on my GitHub:
https://github.com/StraykerPL/StrayexOS
branan
Posts: 5
Joined: Sun Apr 24, 2011 6:05 pm

Re: Required informations are not present in MBI

Post by branan »

9 bytes at such a low address is VERY suspicious for multiboot info - many of the tags are inserted unconditionally, so it should be much larger than that. If I had to guess, I'd say that your compiler has generated code that is overwriting EBX before you can read it.

Instead of trying to read EAX and EBX with inline assembly, you should pass them as arguments to your C init function from assembly. How exactly you do this depends on your compiler and its calling conventions.
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Required informations are not present in MBI

Post by MichaelPetch »

I'd have to reiterate the comment about using inline assembly to get acccess to the magic number and MBI pointer. You should be pushing EAX and EBX onto the stack prior to calling kinit and then modifying kinit to take two parameters that are the magic number and the pointer. Nothing stops the compiler from generating code that clobbers EAX and EBX between the time your function is called and when you reach the inline assembly.You ar eprobably lucky that EAX and EBX gaven't been clobbered and your inline assembly appears to work.

More importantly: I notice you define mbi this way:

Code: Select all

struct multiboot_tag *mbi = 0;
then you do this:

Code: Select all

for (mbi = (struct multiboot_tag *) (mbi + 8); ...
If you add 8 to mbi that doesn't add 8 to the pointer. It adds 8*sizeof(multiboot_tag) which would be 8*8=64 bytes. I think you mean to use mbi+1 to skip past the first tag.
StraykerPL
Posts: 8
Joined: Thu Mar 14, 2019 1:45 pm
Libera.chat IRC: straykerpl

Re: Required informations are not present in MBI

Post by StraykerPL »

MichaelPetch wrote:I'd have to reiterate the comment about using inline assembly to get acccess to the magic number and MBI pointer. You should be pushing EAX and EBX onto the stack prior to calling kinit and then modifying kinit to take two parameters that are the magic number and the pointer. Nothing stops the compiler from generating code that clobbers EAX and EBX between the time your function is called and when you reach the inline assembly.You ar eprobably lucky that EAX and EBX gaven't been clobbered and your inline assembly appears to work.

More importantly: I notice you define mbi this way:

Code: Select all

struct multiboot_tag *mbi = 0;
then you do this:

Code: Select all

for (mbi = (struct multiboot_tag *) (mbi + 8); ...
If you add 8 to mbi that doesn't add 8 to the pointer. It adds 8*sizeof(multiboot_tag) which would be 8*8=64 bytes. I think you mean to use mbi+1 to skip past the first tag.
Thank you, this was the problem. I edited code to push magic values on stack and start initialisation with arguments described in Multiboot 2 specs from stack and it works. :)
Post Reply