OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Sep 22, 2018 10:46 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: multiboot2 problems
PostPosted: Wed Sep 19, 2018 6:09 pm 
Offline

Joined: Fri Jun 16, 2017 1:51 am
Posts: 17
I've been having problems with my multiboot2 info request. I'm pretty sure I have my header right:
Code:
# Define the contnts of the Multiboot Header
.set MAGIC,      0xE85250D6
.set ARCH,      0
.set LENGTH,   (multiboot_header_end - multiboot_header)
.set CHECKSUM,   -(MAGIC + ARCH + LENGTH)

# Store the contents of the Multiboot header at the beginning of the file.
.section .multiboot
.align 8                        # Align the section on the 64-bit boundary.
multiboot_header:
.long MAGIC
.long ARCH
.long LENGTH
.long CHECKSUM
multiboot_info_req:
.short 1
.short 0
.long (multiboot_info_req_end - multiboot_info_req)
.long 4
.long 6
multiboot_info_req_end:
.short 0
.short 0
.long 8
multiboot_header_end:

Can anyone tell me if GRUB loads the multiboot info in the same order I requested it, and how to go about reading it in main()? Here is what I have for main():
Code:
#include <sys/sys.h>
#include <sys/multiboot2.h>
#include <kernel/tty.h>
#include <libc/stdio.h>

#include <stdint.h>

struct multiboot2_data {
    multiboot_uint32_t totalSize;
    multiboot_uint32_t reserved;
    struct multiboot_tag_basic_meminfo memInfo;
    struct multiboot_tag_mmap mmapInfo;
};

extern "C" void _main(struct multiboot2_data* mbd) {
    gdt_install();
    idt_install();
    terminal_initialize();
    terminal_writestring("Hello World! \n");
    struct multiboot_tag_basic_meminfo memInfo = mbd->memInfo;
    printf("Lower Memory: %x\n", memInfo.mem_lower);
    printf("Version: 0.0.0.1d\n");
    for(;;);
}


I know I'm having problems because when I test it, it tells me that I have 38GB of lower memory. And no, that is NOT a typo.

edit: And yes, I did remember to push %ebx.


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Wed Sep 19, 2018 6:31 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
MakaAlbarn001 wrote:
I know I'm having problems because when I test it, it tells me that I have 38GB of lower memory. And no, that is NOT a typo.


Something might be wrong with your printf() function... multiboot_uint32_t is a 32 bits unsigned integer. The biggest number that can be represented with a 32 bits unsigned integer is 4 GB.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 10:30 am 
Offline

Joined: Fri Jun 16, 2017 1:51 am
Posts: 17
You forgot that mem_lower is in Kilobytes.


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 12:17 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
Can you show us your boot code? Because without it, we can't look at it. Basically you should be pushing "ebx" on the stack before calling your main function.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 2:24 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 175
kzinti wrote:
Can you show us your boot code? Because without it, we can't look at it. Basically you should be pushing "ebx" on the stack before calling your main function.
In one of the OPs early edits they placed this at the bottom:
Quote:
edit: And yes, I did remember to push %ebx.
. I agree though that seeing all the code he's using would help identify the issue.


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 4:02 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
Well without seeing more code, there is no bug to be found here.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 4:59 pm 
Offline

Joined: Fri Jun 16, 2017 1:51 am
Posts: 17
You can take a look at my most recent commit. I have it set to print out the lower memory in decimal format.

git clone https://BringerOfShadows@bitbucket.org/ ... ststep.git


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 5:33 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
I know it's supposed to be preserved, but I wonder if EBX is getting trashed when you call "_init".

https://bitbucket.org/BringerOfShadows/ ... #boot.s-43

It might be worth pushing / poping it around the call to make sure its valid when you call "_main".

Have you tried tracing this with a debugger? It's probably easier than trying to guess what is happening.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 6:52 pm 
Offline

Joined: Fri Jun 16, 2017 1:51 am
Posts: 17
Okay, I need to update my glasses prescription. I forgot that I removed the "push %ebx" about 4-5 commits ago.
Now, when I try to run it. I get a lower memory of 5376KB.

edit: printing both lower and upper memory gives an upper memory of zero and a lower memory of 4Mil+ KB.

do you know what order GRUB will store the multiboot info?

edit2: Okay, I fixed the problem with my printf() function. Turns out that there was a buffer overrun issue when I was reversing the decimal string. Now I get a lower memory of 5376KB and an upper memory of 1510KB. So... still an issue in my multiboot structure.

edit3: Also, when I print other lines to screen, the contents of the structure get corrupted.


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 10:29 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
MakaAlbarn001 wrote:
do you know what order GRUB will store the multiboot info?


I don't understand what you mean by that. The muiltiboot info is a structure. What is there to "order"?

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Thu Sep 20, 2018 10:36 pm 
Offline

Joined: Fri Jun 16, 2017 1:51 am
Posts: 17
That's multiboot 1. In multiboot2, there is a series of different structures that follow a pattern. Look up the multiboot2 manual.


Top
 Profile  
 
 Post subject: Re: multiboot2 problems
PostPosted: Fri Sep 21, 2018 12:05 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 240
I see. You can look at the source code of grub to answer your question. But I don't understand why this would matter at all. Your code should not expect any specific ordering.

You should simply walk all the entries in a loop and handle the tags you care about.

Example:

https://github.com/kiznit/rainbow-os/bl ... #L302-L363

_________________
https://github.com/kiznit/rainbow-os


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 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