OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:24 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Required informations are not present in MBI
PostPosted: Tue Mar 26, 2019 4:02 am 
Offline

Joined: Thu Mar 14, 2019 1:45 pm
Posts: 8
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:
   ; 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:
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=1rSoI3pDlCdh6o_lnzkxyFHUTtmoeYP1m

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

_________________
My GitHub: https://github.com/StraykerPL


Top
 Profile  
 
 Post subject: Re: Required informations are not present in MBI
PostPosted: Tue Mar 26, 2019 7:11 am 
Offline

Joined: Sun Apr 24, 2011 6:05 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: Required informations are not present in MBI
PostPosted: Tue Mar 26, 2019 7:37 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
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:
struct multiboot_tag *mbi = 0;
then you do this:
Code:
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.


Top
 Profile  
 
 Post subject: Re: Required informations are not present in MBI
PostPosted: Tue Mar 26, 2019 12:37 pm 
Offline

Joined: Thu Mar 14, 2019 1:45 pm
Posts: 8
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:
struct multiboot_tag *mbi = 0;
then you do this:
Code:
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. :)

_________________
My GitHub: https://github.com/StraykerPL


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 116 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group