GRUB: Multiboot Information Structure ?
GRUB: Multiboot Information Structure ?
..
Last edited by Perica on Sun Dec 03, 2006 9:23 pm, edited 1 time in total.
Re:GRUB: Multiboot Information Structure ?
unless the multiboot header changed, mine is way way differernt to your structure.
also adding "} __attribute__((packed)) ;" to the end of the struct definition WONT WORK.
either have the attribute on EVERY line ni the struct, or use #pragma pack(1) at the top of your structure and #pragma pack() underneath it.
try this test and see what results you get...
also adding "} __attribute__((packed)) ;" to the end of the struct definition WONT WORK.
either have the attribute on EVERY line ni the struct, or use #pragma pack(1) at the top of your structure and #pragma pack() underneath it.
try this test and see what results you get...
Code: Select all
#include <stdio.h>
#include <stdlib.h>
typedef struct A
{
char a;
int b;
char c;
} A;
typedef struct B
{
char a __attribute__ ((packed));
int b __attribute__ ((packed));
char c __attribute__ ((packed));
} B;
typedef struct C
{
char a;
int b;
char c;
} C __attribute__ ((packed));
#pragma pack(1)
typedef struct D
{
char a;
int b;
char c;
} D;
#pragma pack()
int main(int argc, char *agrv[])
{
printf("A=%i\n", sizeof(A));
printf("B=%i\n", sizeof(B));
printf("C=%i\n", sizeof(C));
printf("D=%i\n", sizeof(D));
}
-- Stu --
Re:GRUB: Multiboot Information Structure ?
..
Last edited by Perica on Sun Dec 03, 2006 9:23 pm, edited 1 time in total.
Re:GRUB: Multiboot Information Structure ?
why wouldnt it work? dunno but i can tell you it doesnt work.
as for the MIS, my cvs last night of grub reads
also, if your curious, here is the output of the test code i posted.
clearly, B and D work, A is unpacked and C doesnt work.
as for the MIS, my cvs last night of grub reads
Code: Select all
/* The Multiboot information. */
typedef struct multiboot_info
{
unsigned long flags;
unsigned long mem_lower;
unsigned long mem_upper;
unsigned long boot_device;
unsigned long cmdline;
unsigned long mods_count;
unsigned long mods_addr;
union
{
aout_symbol_table_t aout_sym;
elf_section_header_table_t elf_sec;
} u;
unsigned long mmap_length;
unsigned long mmap_addr;
} multiboot_info_t;
Code: Select all
sgeorge@yakumo ~/source
$ gcc -O2 structs.c -o structs.exe
sgeorge@yakumo ~/source
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld --with-gnu-
as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexe
cdir=/usr/sbin --mandir=/usr/share/man --infodir=/usr/share/info --enable-langua
ges=c,ada,c++,f77,pascal,java,objc --enable-libgcj --enable-threads=posix --with
-system-zlib --enable-nls --without-included-gettext --enable-interpreter --enab
le-sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --dis
able-win32-registry --enable-java-gc=boehm --disable-hash-synchronization --verb
ose --target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin
Thread model: posix
gcc version 3.3.1 (cygming special)
sgeorge@yakumo ~/source
$ ./structs
A=12
B=6
C=12
D=6
-- Stu --
Re:GRUB: Multiboot Information Structure ?
..
Last edited by Perica on Sun Dec 03, 2006 9:23 pm, edited 1 time in total.
Re:GRUB: Multiboot Information Structure ?
That one's for me... ;DPerica wrote: Also, what is a union ??
A union is a special datatype, usually used in system programming only because it's error prone. Consider:
Code: Select all
union x
{
double d;
int i;
}
But x isn't a struct, it's a union, and that means that sizeof(x) == sizeof(double).
Huh?
Well, x holds either a double or an int, depending on what you last wrote to it. Therefore, the size of a union is the largest of its elements, and at any given time, it holds only one element.
The elements "share" the same memory.
unions are very popular among those delighting in truly ugly code, like this:
Code: Select all
union y
{
int i[2];
double d;
}
:puke:
Well, that's a union for you. I hope the explanation was understandable.
Every good solution is obvious once you've found it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GRUB: Multiboot Information Structure ?
unions were often used in binary file reading because you get a "record" and it could either be person_record or enterprise_record, then you encode the stuff as
If you look at COFF or ELF header files, you'll see they're full of unions.
Code: Select all
union record {
struct person_record person;
struct enterprise_record enterprise;
};
Re:GRUB: Multiboot Information Structure ?
..
Last edited by Perica on Sun Dec 03, 2006 9:24 pm, edited 1 time in total.
Re:GRUB: Multiboot Information Structure ?
The GRUB download package has a sample kernel, in the docs directory, which does just that.
Re:GRUB: Multiboot Information Structure ?
well for one thing, test the code i pasted at the top of this thread and see what results you get back. that will etll you if the struct packing works on your gcc or not.Perica wrote: Thanks for the explanation on unions, i guess you learn something new every day.
Anyway, does anybody have anything to say about putting __attribute__((packed)) after a structure definition being legal or not??
Also, does anybody see anything wrong with my Multiboot Information Structure..... because i don't know what i'm doing wrong, i keep getting faulty values ??? Does anybody know of a kernel that boots using GRUB and sucessfully extracts values from the Multiboot Information Structure?? (I would like to see how other people are doing this and maybe figure out what i'm doing wrong).
and second, open up the docs/multiboot.h file and look for the header struct, you will find the correct multiboot_info header in there
-- Stu --
Re:GRUB: Multiboot Information Structure ?
..
Last edited by Perica on Sun Dec 03, 2006 9:24 pm, edited 1 time in total.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GRUB: Multiboot Information Structure ?
That's speaking wisely! we should put that between <h1> tags on the "post a new thread for unregistered users" form ;-pPerica wrote: i don't regret starting off OS development with writing a boot loader at all, it's taught me alot of low-level things that are necessary for kernel development. Later on i plan on writing a boot loader, but i first need something worth booting
Re:GRUB: Multiboot Information Structure ?
Perica, you've summed up the arguments to and for bootloaders better than anyone I've seen. I think that paragraph should be mandatory advice for anyone starting in OS development.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GRUB: Multiboot Information Structure ?
perica: would you mind posting that in the ".:QuickLinkz:." thread aswell ?
Re:GRUB: Multiboot Information Structure ?
hmm what version of GCC is that? i had 3.3.1 and it didnt work..Perica wrote: I tested (under MinGW, i'm not sure if it works on all distributions of GCC..... but it should) if putting __attribute__((__packed__)) after a structure definition truly worked, and it does; just like the manuals have stated.
my cvs last night header file still does not have all those extra fields.. so i still dont know where you got that from...I visited the GRUB CVS respository and had a look at the example kernel and multiboot structures and i've figured out what i was doing wrong. I didn't insert one field in the multiboot information strucutre (a field before the mmap_* fields), so when acessing the mmap_* variables.... i've been reading the the values of something else.
multiboot.h
none of the structs in there match yours.
(aah i found it in stage2, not the docs directory.. shame on grub for having two differnet versions!!)
mb_info.h
my bad!
-- Stu --