GRUB: Multiboot Information Structure ?
Posted: Mon Nov 24, 2003 1:38 am
..
The Place to Start for Operating System Developers
http://f.osdev.org/
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));
}
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
That one's for me... ;DPerica wrote: Also, what is a union ??
Code: Select all
union x
{
double d;
int i;
}
Code: Select all
union y
{
int i[2];
double d;
}
Code: Select all
union record {
struct person_record person;
struct enterprise_record enterprise;
};
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).
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
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.