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.
I've got to the point where I'm detecting memory, I've decided to use multiboot.h and get my memory map from Grub following the tutorial I'm using this code
typedef struct multiboot_memory_map {
unsigned int size;
unsigned int base_addr_low,base_addr_high;
// You can also use: unsigned long long int base_addr; if supported.
unsigned int length_low,length_high;
// You can also use: unsigned long long int length; if supported.
unsigned int type;
} multiboot_memory_map_t;
int main(multiboot_info* mbt, unsigned int magic) {
...
multiboot_memory_map_t* mmap = mbt->mmap_addr;
while(mmap < mbt->mmap_addr + mbt->mmap_length) {
...
mmap = (multiboot_memory_map_t*) ( (unsigned int)mmap + mmap->size + sizeof(unsigned int) );
}
...
}
It works fine but takes over 5 minutes. I'm running my iso in VirtualBox. Now here's the odd part. I wrote to the screen the the loop at one point because I thought my OS had froze. If I write to the screen in that loop then the entire process takes less than 2 seconds. If I don't have anything in my loop by what is above it takes way, way to long. Is there something simple I might be overlooking here?
Also, I only have 128MB allocated for my virtual machine.
barkingtreefrog wrote:I've got to the point where I'm detecting memory, I've decided to use multiboot.h and get my memory map from Grub following the tutorial I'm using this code
typedef struct multiboot_memory_map {
unsigned int size;
unsigned int base_addr_low,base_addr_high;
// You can also use: unsigned long long int base_addr; if supported.
unsigned int length_low,length_high;
// You can also use: unsigned long long int length; if supported.
unsigned int type;
} multiboot_memory_map_t;
int main(multiboot_info* mbt, unsigned int magic) {
...
multiboot_memory_map_t* mmap = mbt->mmap_addr;
while(mmap < mbt->mmap_addr + mbt->mmap_length) {
...
mmap = (multiboot_memory_map_t*) ( (unsigned int)mmap + mmap->size + sizeof(unsigned int) );
}
...
}
It works fine but takes over 5 minutes. I'm running my iso in VirtualBox. Now here's the odd part. I wrote to the screen the the loop at one point because I thought my OS had froze. If I write to the screen in that loop then the entire process takes less than 2 seconds. If I don't have anything in my loop by what is above it takes way, way to long. Is there something simple I might be overlooking here?
Also, I only have 128MB allocated for my virtual machine.
This may seem a little off topic, and not sure if this helps or not, but I setup my VirtualBox with 256 MB ram and the video with 32 MB of RAM. They seemed to be the "sweet" spot for my projects.
Hm...
Did you make sure that it's the loop that is taking so long? Did you add output-statements directly before and after the loop?
Did you try it in another emulator?
Whats the complete code inside the loop?
Also I recommend that you use the structs defined in multiboot.h instead of creating your own.
The code you've showed us is not sufficient to reproduce the problem. Could you link us to your repository?
Until you do, you should still fix some unrelated problems with your code:
As C doesn't require that structures be packed, yours only works by sheer luck and can break as soon as you change the ABI. Either do proper serialization, using an array, or (sigh) use a compiler-specific extension, such as GCC's __attribute__((packed)).
Similarly, you should be using fixed-width integer types, as the ones you're using don't have fixed widths or sizes; they're ABI-dependent.
Finally, calling conventions also vary from ABI to ABI. It's safest to pass magic and mbt as external objects rather than as parameters.
Given that multiboot_memory_map_t is not an opaque type, why do you typedef it?
Why does your main function expect to have a return value?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, your not assigning anything to multiboot_memory_map_t and so nothing is being returned.
typedef struct multiboot_memory_map {
unsigned int size;
unsigned int base_addr_low,base_addr_high;
unsigned int length_low,length_high;
unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..
Kortath wrote:Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, you're not assigning anything to multiboot_memory_map_t and so nothing is being returned.
typedef struct multiboot_memory_map {
unsigned int size;
unsigned int base_addr_low,base_addr_high;
unsigned int length_low,length_high;
unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..
That is clearly *NOT* a function.
Either stop trolling, or go read up on C again.
There is no direct assignment, nothing to indicate a function call (); or anything of the sort.
Also:
I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between
Kortath wrote:Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, you're not assigning anything to multiboot_memory_map_t and so nothing is being returned.
typedef struct multiboot_memory_map {
unsigned int size;
unsigned int base_addr_low,base_addr_high;
unsigned int length_low,length_high;
unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..
That is clearly *NOT* a function.
Either stop trolling, or go read up on C again.
There is no direct assignment, nothing to indicate a function call (); or anything of the sort.
Also:
I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between
YOUR
and
YOU'RE
in english lesson.
Thanks for the info. I clearly misread it as a function.
requimrar wrote:I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between
requimrar wrote:I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between
YOUR
and
YOU'RE
in english lesson.
Five thumbs up. Your right!
Hmm? all I see is a wall, there's nothing on my right.
darkinsanity wrote:Hm...
Did you make sure that it's the loop that is taking so long? Did you add output-statements directly before and after the loop?
Did you try it in another emulator?
Whats the complete code inside the loop?
Also I recommend that you use the structs defined in multiboot.h instead of creating your own.
I did add output statements before, after, and in the loop. If I place an output statement inside of the loop then the mapping is near instant. Thanks for all of the replies everyone and sorry for the late response. I'll get back to all of you with some more code and/or updates after work tonight.