diff -ruN ../contrib/ref/hurd-l4/wortel/ia32-cmain.c wortel/ia32-cmain.c --- ../contrib/ref/hurd-l4/wortel/ia32-cmain.c 2005-02-14 16:32:45.000000000 +0100 +++ wortel/ia32-cmain.c 2005-02-18 14:07:24.000000000 +0100 @@ -24,11 +24,13 @@ #include #include +#include #include #include #include #include +#include #include "wortel-intern.h" #include "multiboot.h" @@ -44,22 +46,33 @@ void cmain (void) { - multiboot_info_t *mbi; + l4_generic_bootinfo_t bi; int argc = 0; char **argv = 0; l4_init (); l4_init_stubs (); - - mbi = (multiboot_info_t *) l4_boot_info (); - debug ("Multiboot Info: %p\n", mbi); - - if (CHECK_FLAG (mbi->flags, 3) && mbi->mods_count > 0) - { + + bi = (l4_generic_bootinfo_t) (l4_boot_info()); + + /* We are only interested in wortel cmdline */ + int nr; + l4_word_t br = (l4_word_t) l4_generic_bootinfo_first_entry (bi); + for (nr = (int) l4_generic_bootinfo_entries (bi); + nr > 0; + nr--, br += (l4_word_t) ((l4_generic_boot_rec_t) br)->offset_next) + { + if (((l4_generic_boot_rec_t) br)->type == _L4_BOOTINFO_MODULE + && strstr (((char*) l4_module_cmdline ((l4_generic_bootinfo_module_t) br)), "wortel")) + break; + } + + + if (nr) + { /* A command line is available. */ - module_t *mod = (module_t *) mbi->mods_addr; - char *str = (char *) mod[0].string; - int nr = 0; + char *str = (char *) l4_module_cmdline ((l4_generic_bootinfo_module_t) br); + nr = 0; /* First time around we count the number of arguments. */ argc = 1; @@ -77,7 +90,7 @@ argv = alloca (sizeof (char *) * (argc + 1)); /* Second time around we fill in the argv. */ - str = (char *) mod[0].string; + str = (char *) l4_module_cmdline ((l4_generic_bootinfo_module_t) br); while (*str && *str == ' ') str++; @@ -165,60 +178,91 @@ void find_components (void) { - multiboot_info_t *mbi = (multiboot_info_t *) l4_boot_info (); - - /* Load the module information. */ - if (CHECK_FLAG (mbi->flags, 3)) + l4_generic_bootinfo_t bi = (l4_generic_bootinfo_t) l4_boot_info(); + l4_generic_bootinfo_module_t mod; + multiboot_info_t *mbi = (multiboot_info_t*) (l4_MBI_address_from_bootinfo (bi)); + int nr, mod_count; + char* str; + l4_word_t br = (l4_word_t) l4_generic_bootinfo_first_entry (bi); + + /* Find all the modules after wortel (they should have been added with + * respect for their order). */ + for (nr = (int) l4_generic_bootinfo_entries (bi), mod_count = 0; + nr > 0; + nr--, br += (l4_word_t) ((l4_generic_boot_rec_t) br)->offset_next) + { + /* Do nothing for laden and sigma0. */ + if (((l4_generic_boot_rec_t) br)->type == _L4_BOOTINFO_MODULE + && (++mod_count > 2)) { - module_t *mod = (module_t *) mbi->mods_addr; - unsigned int i; + mod = (l4_generic_bootinfo_module_t) br; + str = (char*) l4_module_cmdline (mod); + + /* Wortel should be the third on the list. */ + if (mod_count == 3) + { + /* Add its command line args to the list of unused pages. */ + add_unused_area ((l4_word_t) str, strlen (str) + 1); + continue; + } + + unsigned int old_mods_args_len; + + /* Fill the mods structure with the relevant info */ + mods[mod_count-4].name = mod_names[mod_count-4]; + mods[mod_count-4].start = l4_module_start (mod); + mods[mod_count-4].end = l4_module_start (mod) + l4_module_size (mod); + + /* We copy over the argument lines, so that we don't depend + on the multiboot info structure anymore, and can reuse + that memory. */ + mods[mod_count-4].args = &mods_args[mods_args_len]; + old_mods_args_len = mods_args_len; + while (*str && mods_args_len < sizeof (mods_args)) + mods_args[mods_args_len++] = *(str++); + if (mods_args_len == sizeof (mods_args)) + panic ("No space to store the argument lines"); + mods_args[mods_args_len++] = '\0'; + + + /* Now we have to add the source string's area to the list + of unused pages, as we touched that memory. */ + add_unused_area ((l4_word_t) str, + mods_args_len - old_mods_args_len); + } - /* Add the argument string of the first module to the list of - unused pages. */ - add_unused_area ((l4_word_t) mod[0].string, - strlen ((char *) mod[0].string) + 1); - - mods_count = mbi->mods_count - 1; - if (mods_count > MOD_NUMBER) - mods_count = MOD_NUMBER; + /* Also add the generic bootinfo record to the list of unused pages. + FIXME: couldn't it be useful later ? */ + switch (l4_generic_boot_rec_type ((l4_generic_boot_rec_t) br)) + { + case _L4_BOOTINFO_MULTIBOOT: + add_unused_area ((l4_word_t) br, + sizeof (l4_generic_bootinfo_MBI)); + break; + case _L4_BOOTINFO_MODULE: + add_unused_area ((l4_word_t) br, + sizeof (l4_generic_bootinfo_module)); + break; + default: + panic ("Invalid generic bootinfo record type: 0x%x\n", + l4_generic_boot_rec_type ((l4_generic_boot_rec_t) br)); + } + } - /* Skip the entry for the rootserver. */ - mod++; + /* Add the MBI module info itself to the list of unused pages. */ + add_unused_area ((l4_word_t) mbi->mods_addr, + mbi->mods_count * sizeof (module_t)); - for (i = 0; i < mods_count; i++) - { - char *args; - unsigned int old_mods_args_len; + /* Add the multiboot info to the list of unused pages. */ + add_unused_area ((l4_word_t) mbi, sizeof (*mbi)); - mods[i].name = mod_names[i]; - mods[i].start = mod[i].mod_start; - mods[i].end = mod[i].mod_end; - - /* We copy over the argument lines, so that we don't depend - on the multiboot info structure anymore, and can reuse - that memory. */ - mods[i].args = &mods_args[mods_args_len]; - args = (char *) mod[i].string; - old_mods_args_len = mods_args_len; - while (*args && mods_args_len < sizeof (mods_args)) - mods_args[mods_args_len++] = *(args++); - if (mods_args_len == sizeof (mods_args)) - panic ("No space to store the argument lines"); - mods_args[mods_args_len++] = '\0'; - - /* Now we have to add the source string's area to the list - of unused pages, as we touched that memory. */ - add_unused_area ((l4_word_t) mod[i].string, - mods_args_len - old_mods_args_len); - } + /* Add the generic bootinfo to the list of unused pages. */ + add_unused_area ((l4_word_t) bi, sizeof (l4_generic_bootinfo)); - /* Add the module info itself to the list of unused pages. */ - add_unused_area ((l4_word_t) mbi->mods_addr, - mbi->mods_count * sizeof (module_t)); - } + if (mod_count != MOD_NUMBER + 3) + panic ("Bad number of modules: %d instead of required %d\n", mod_count, MOD_NUMBER + 3); + mods_count = MOD_NUMBER; - /* Add the multiboot info to the list of unused pages. */ - add_unused_area ((l4_word_t) mbi, sizeof (*mbi)); /* Finally initialize the wortel area variables. */ wortel_start = (l4_word_t) &_start;