diff -ruN ../contrib/ref/hurd-l4/laden/Makefile.am laden/Makefile.am --- ../contrib/ref/hurd-l4/laden/Makefile.am 2005-02-14 16:32:45.000000000 +0100 +++ laden/Makefile.am 2005-02-17 11:59:00.000000000 +0100 @@ -19,8 +19,9 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA if ARCH_IA32 - ARCH_SOURCES = multiboot.h ia32-crt0.S ia32-cmain.c \ - ia32-output.c output-vga.c output-serial.c ia32-shutdown.c + ARCH_SOURCES = multiboot.h ia32-crt0.S ia32-btinfo.c ia32-cmain.c \ + ia32-output.c output-vga.c output-serial.c \ + ia32-shutdown.c endif bootdir = $(prefix)/boot diff -ruN ../contrib/ref/hurd-l4/laden/ia32-btinfo.c laden/ia32-btinfo.c --- ../contrib/ref/hurd-l4/laden/ia32-btinfo.c 1970-01-01 01:00:00.000000000 +0100 +++ laden/ia32-btinfo.c 2005-02-19 22:14:14.000000000 +0100 @@ -0,0 +1,325 @@ +/* ia32-btinfo.c - Generic bootinfo support. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by Alexandre Buisse . + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "laden.h" +#include + +#include + +#include "multiboot.h" + +#define GENERIC_BTINFO_ADDR 0x30000 /* FIXME: should we place it here ? */ + + +static int num_entries = 1; +static l4_word_t next; +static l4_generic_bootinfo_t bootinfo = + (l4_generic_bootinfo_t) GENERIC_BTINFO_ADDR; +static multiboot_info_t *mbi; + + +/* This adds the module info in a new generic bootinfo record. + We choose to keep it simple and not add free space between two records. + Thus offset_next has the exact size of the record. */ +static void +add_generic_bootinfo_module (module_t *mod) +{ + l4_generic_bootinfo_module_t bootinfo_mod = + (l4_generic_bootinfo_module_t) next; + + bootinfo_mod->type = _L4_BOOTINFO_MODULE; + bootinfo_mod->version = _L4_BOOTINFO_VERSION; + bootinfo_mod->offset_next = sizeof (l4_generic_bootinfo_module); + bootinfo_mod->start = (l4_word_t) mod->mod_start; + bootinfo_mod->size = (l4_word_t) (mod->mod_end - mod->mod_start); + bootinfo_mod->cmdline_offset = (l4_word_t) ((l4_word_t) mod->string - (l4_word_t) bootinfo_mod); + debug ("Module at %x inserted at %x, with size %x, cmdline_offset %x and offset_next %x\n", + bootinfo_mod->start, (l4_word_t) bootinfo_mod, bootinfo_mod->size, + bootinfo_mod->cmdline_offset, bootinfo_mod->offset_next); + next += bootinfo_mod->offset_next; + num_entries++; +} + +/* Dump of multiboot info we retrieved from grub. */ +static void +debug_dump (void) +{ + if (CHECK_FLAG (mbi->flags, 9)) + debug ("Booted by %s\n", (char *) mbi->boot_loader_name); + + if (CHECK_FLAG (mbi->flags, 0)) + debug ("Memory: Lower %u KB, Upper %u KB\n", + mbi->mem_lower, mbi->mem_upper); + + if (CHECK_FLAG (mbi->flags, 3)) + { + module_t *mod = (module_t *) mbi->mods_addr; + int nr; + + for (nr = 0; nr < mbi->mods_count; nr++) + debug ("Module %i: Start 0x%x, End 0x%x, Cmd %s\n", + nr + 1, mod[nr].mod_start, mod[nr].mod_end, + (char *) mod[nr].string); + } + + if (CHECK_FLAG (mbi->flags, 6)) + { + memory_map_t *mmap; + int nr = 1; + + for (mmap = (memory_map_t *) mbi->mmap_addr; + (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; + mmap = (memory_map_t *) ((uint32_t) mmap + + mmap->size + sizeof (mmap->size))) + debug ("Memory Map %i: Type %i, Base 0x%llx, Length 0x%llx\n", + nr++, mmap->type, mmap->base_addr, mmap->length); + } +} + + +/* The following must be defined and are used to calculate the extents + of the laden binary itself. */ +extern char _start; +extern char _end; + + +/* Find the kernel, the initial servers and the other information + required for booting. */ +void +find_components (multiboot_info_t* mbi) +{ + l4_word_t start; + l4_word_t end; + + debug_dump (); + + /* Load the module information. */ + if (CHECK_FLAG (mbi->flags, 3)) + { + module_t *mod = (module_t *) mbi->mods_addr; + + if (mbi->mods_count > 0) + { + add_generic_bootinfo_module (mod); + kernel.low = mod->mod_start; + kernel.high = mod->mod_end; + mod++; + mbi->mods_count--; + } + if (mbi->mods_count > 0) + { + add_generic_bootinfo_module (mod); + sigma0.low = mod->mod_start; + sigma0.high = mod->mod_end; + mod++; + mbi->mods_count--; + } + /* Swallow the modules we used so far. This makes the + rootserver the first module in the list, regardless if + sigma1 is used or not. */ + mbi->mods_addr = (l4_word_t) mod; + if (mbi->mods_count > 0) + { + add_generic_bootinfo_module (mod); + rootserver.low = mod->mod_start; + rootserver.high = mod->mod_end; + } + + /* finish adding the modules in the generic bootinfo structure */ + int nr; + for (nr = 1, mod++; nr < mbi->mods_count; nr++, mod++) + add_generic_bootinfo_module (mod); + bootinfo->size = (l4_word_t) ((l4_word_t) next - (l4_word_t) bootinfo); + bootinfo->num_entries = (l4_word_t) num_entries; + } + + /* Now create the memory map. */ + + /* First, add the whole address space as shared memory by default to + allow arbitrary device access. */ + add_memory_map (0, -1, L4_MEMDESC_SHARED, 0); + + /* Now add what GRUB tells us. */ + if (CHECK_FLAG (mbi->flags, 6)) + { + /* mmap_* are valid. */ + memory_map_t *mmap; + + for (mmap = (memory_map_t *) mbi->mmap_addr; + (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; + mmap = (memory_map_t *) ((uint32_t) mmap + + mmap->size + sizeof (mmap->size))) + { + uint64_t end; + + if (mmap->base_addr >> 32) + panic ("L4 does not support more than 4 GB on ia32"); + + end = mmap->base_addr + mmap->length - 1; + + if (end >> 32) + panic ("L4 does not support more than 4 GB on ia32"); + + if (mmap->base_addr & ((1 << 10) - 1) + || mmap->length & ((1 << 10) - 1)) + panic ("Memory region (0x%llx - 0x%llx) is unaligned", + mmap->base_addr, end); + + add_memory_map ((uint32_t) mmap->base_addr, (uint32_t) end, + mmap->type == 1 + ? L4_MEMDESC_CONVENTIONAL : L4_MEMDESC_ARCH, + mmap->type == 1 ? 0 : mmap->type); + } + } + else if (CHECK_FLAG (mbi->flags, 0)) + { + /* mem_* are valid. */ + + add_memory_map (0, (mbi->mem_lower << 10) - 1, + L4_MEMDESC_CONVENTIONAL, 0); + add_memory_map (0x100000, (0x100000 + (mbi->mem_upper << 10)) - 1, + L4_MEMDESC_CONVENTIONAL, 0); + } + + /* The VGA memory, and ROM extension, is usually not included in the + BIOS map. We add it here. */ + add_memory_map (0xa0000, 0xf0000 - 1, L4_MEMDESC_SHARED, 0); + + /* The amount of conventional memory to be reserved for the kernel. */ +#define KMEM_SIZE (16 * 0x100000) + + /* The upper limit for the end of the kernel memory. */ +#define KMEM_MAX (240 * 0x100000) + + if (CHECK_FLAG (mbi->flags, 6)) + { + memory_map_t *mmap; + + for (mmap = (memory_map_t *) mbi->mmap_addr; + (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; + mmap = (memory_map_t *) ((uint32_t) mmap + + mmap->size + sizeof (mmap->size))) + { + if (mmap->type != 1) + continue; + + if (((uint32_t) mmap->length) >= KMEM_SIZE + && ((uint32_t) mmap->base_addr) <= KMEM_MAX - KMEM_SIZE) + { + uint32_t high = ((uint32_t) mmap->base_addr) + + ((uint32_t) mmap->length); + uint32_t low; + + if (high > KMEM_MAX) + high = KMEM_MAX; + low = high - KMEM_SIZE; + /* Round up to the next super page (4 MB). */ + low = (low + 0x3fffff) & ~0x3fffff; + + add_memory_map (low, high, L4_MEMDESC_RESERVED, 0); + } + } + } + else if (CHECK_FLAG (mbi->flags, 0)) + { + if ((mbi->mem_upper << 10) >= KMEM_SIZE) + { + uint32_t high = (mbi->mem_upper << 10) + 0x100000; + uint32_t low; + + if (high > KMEM_MAX) + high = KMEM_MAX; + + low = high - KMEM_SIZE; + /* Round up to the next super page (4 MB). */ + low = (low + 0x3fffff) & ~0x3fffff; + + add_memory_map (low, high, L4_MEMDESC_RESERVED, 0); + } + } + + /* Now protect ourselves, the multiboot info and the generic multiboot + info (at least the module configuration). */ + loader_add_region (program_name, (l4_word_t) &_start, (l4_word_t) &_end); + loader_add_region ("generic-btinfo", (l4_word_t) bootinfo, + (l4_word_t) (bootinfo + bootinfo->size)); + + start = (l4_word_t) mbi; + end = start + sizeof (*mbi); + loader_add_region ("grub-mbi", start, end); + + if (CHECK_FLAG (mbi->flags, 3) && mbi->mods_count) + { + module_t *mod = (module_t *) mbi->mods_addr; + int nr; + + start = (l4_word_t) mod; + end = ((l4_word_t) mod) + mbi->mods_count * sizeof (*mod); + loader_add_region ("grub-mods", start, end); + + start = (l4_word_t) mod[0].string; + end = start + 1; + for (nr = 0; nr < mbi->mods_count; nr++) + { + char *str = (char *) mod[nr].string; + + if (str) + { + if (((l4_word_t) str) < start) + start = (l4_word_t) str; + while (*str) + str++; + if (((l4_word_t) str) + 1 > end) + end = (l4_word_t) str + 1; + } + } + loader_add_region ("grub-mods-cmdlines", start, end); + } +} + + + + +/* Convert a multiboot info in a generic bootinfo structure */ +l4_word_t +mbi_to_generic_bootinfo (multiboot_info_t *multiboot_info) +{ + mbi = multiboot_info; + /* Initial values */ + bootinfo->magic = _L4_BOOTINFO_MAGIC; + bootinfo->version = _L4_BOOTINFO_VERSION; + bootinfo->first_entry = sizeof(l4_generic_bootinfo); + next = (l4_word_t) ((l4_word_t) bootinfo + bootinfo->first_entry); + + /* MBI structure */ + l4_generic_bootinfo_MBI_t bootinfo_mbi = (l4_generic_bootinfo_MBI_t) next; + bootinfo_mbi->type = _L4_BOOTINFO_MULTIBOOT; + bootinfo_mbi->version = _L4_BOOTINFO_VERSION; + bootinfo_mbi->offset_next = sizeof(l4_generic_bootinfo_MBI); + bootinfo_mbi->address = (l4_word_t) mbi; + debug ("mbi: %x, bootinfo_mbi: %x\n", (l4_word_t) mbi, (l4_word_t) bootinfo_mbi); + next += bootinfo_mbi->offset_next; + + find_components(mbi); + + return (l4_word_t) bootinfo; +} + + diff -ruN ../contrib/ref/hurd-l4/laden/ia32-cmain.c laden/ia32-cmain.c --- ../contrib/ref/hurd-l4/laden/ia32-cmain.c 2005-02-14 16:32:45.000000000 +0100 +++ laden/ia32-cmain.c 2005-02-17 11:59:00.000000000 +0100 @@ -25,6 +25,8 @@ #include "multiboot.h" +extern l4_word_t mbi_to_generic_bootinfo (multiboot_info_t*); + /* Return a help text for this architecture. */ const char * @@ -54,10 +56,6 @@ } -/* Check if the bit BIT in FLAGS is set. */ -#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit))) - - /* Setup the argument vector and pass control over to the main function. */ void @@ -125,10 +123,13 @@ argv[1] = 0; } + parse_args (argc, argv); + /* The boot info is set to the multiboot info on ia32. We use this also to get at the multiboot info from other functions called at a later time. */ - boot_info = (uint32_t) mbi; + boot_info = (uint32_t) mbi_to_generic_bootinfo (mbi); + /* Now invoke the main function. */ main (argc, argv); @@ -136,231 +137,3 @@ /* Never reached. */ } - -static void -debug_dump (void) -{ - multiboot_info_t *mbi = (multiboot_info_t *) boot_info; - - if (CHECK_FLAG (mbi->flags, 9)) - debug ("Booted by %s\n", (char *) mbi->boot_loader_name); - - if (CHECK_FLAG (mbi->flags, 0)) - debug ("Memory: Lower %u KB, Upper %u KB\n", - mbi->mem_lower, mbi->mem_upper); - - if (CHECK_FLAG (mbi->flags, 3)) - { - module_t *mod = (module_t *) mbi->mods_addr; - int nr; - - for (nr = 0; nr < mbi->mods_count; nr++) - debug ("Module %i: Start 0x%x, End 0x%x, Cmd %s\n", - nr + 1, mod[nr].mod_start, mod[nr].mod_end, - (char *) mod[nr].string); - } - - if (CHECK_FLAG (mbi->flags, 6)) - { - memory_map_t *mmap; - int nr = 1; - - for (mmap = (memory_map_t *) mbi->mmap_addr; - (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (memory_map_t *) ((uint32_t) mmap - + mmap->size + sizeof (mmap->size))) - debug ("Memory Map %i: Type %i, Base 0x%llx, Length 0x%llx\n", - nr++, mmap->type, mmap->base_addr, mmap->length); - } -} - - -/* The following must be defined and are used to calculate the extents - of the laden binary itself. */ -extern char _start; -extern char _end; - - -/* Find the kernel, the initial servers and the other information - required for booting. */ -void -find_components (void) -{ - multiboot_info_t *mbi = (multiboot_info_t *) boot_info; - l4_word_t start; - l4_word_t end; - - debug_dump (); - - /* Load the module information. */ - if (CHECK_FLAG (mbi->flags, 3)) - { - module_t *mod = (module_t *) mbi->mods_addr; - - if (mbi->mods_count > 0) - { - kernel.low = mod->mod_start; - kernel.high = mod->mod_end; - mod++; - mbi->mods_count--; - } - if (mbi->mods_count > 0) - { - sigma0.low = mod->mod_start; - sigma0.high = mod->mod_end; - mod++; - mbi->mods_count--; - } - /* Swallow the modules we used so far. This makes the - rootserver the first module in the list, regardless if - sigma1 is used or not. FIXME: The rootserver might need the - information about the other modules, though. */ - mbi->mods_addr = (l4_word_t) mod; - if (mbi->mods_count > 0) - { - rootserver.low = mod->mod_start; - rootserver.high = mod->mod_end; - } - } - - /* Now create the memory map. */ - - /* First, add the whole address space as shared memory by default to - allow arbitrary device access. */ - add_memory_map (0, -1, L4_MEMDESC_SHARED, 0); - - /* Now add what GRUB tells us. */ - if (CHECK_FLAG (mbi->flags, 6)) - { - /* mmap_* are valid. */ - memory_map_t *mmap; - - for (mmap = (memory_map_t *) mbi->mmap_addr; - (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (memory_map_t *) ((uint32_t) mmap - + mmap->size + sizeof (mmap->size))) - { - uint64_t end; - - if (mmap->base_addr >> 32) - panic ("L4 does not support more than 4 GB on ia32"); - - end = mmap->base_addr + mmap->length - 1; - - if (end >> 32) - panic ("L4 does not support more than 4 GB on ia32"); - - if (mmap->base_addr & ((1 << 10) - 1) - || mmap->length & ((1 << 10) - 1)) - panic ("Memory region (0x%llx - 0x%llx) is unaligned", - mmap->base_addr, end); - - add_memory_map ((uint32_t) mmap->base_addr, (uint32_t) end, - mmap->type == 1 - ? L4_MEMDESC_CONVENTIONAL : L4_MEMDESC_ARCH, - mmap->type == 1 ? 0 : mmap->type); - } - } - else if (CHECK_FLAG (mbi->flags, 0)) - { - /* mem_* are valid. */ - - add_memory_map (0, (mbi->mem_lower << 10) - 1, - L4_MEMDESC_CONVENTIONAL, 0); - add_memory_map (0x100000, (0x100000 + (mbi->mem_upper << 10)) - 1, - L4_MEMDESC_CONVENTIONAL, 0); - } - - /* The VGA memory, and ROM extension, is usually not included in the - BIOS map. We add it here. */ - add_memory_map (0xa0000, 0xf0000 - 1, L4_MEMDESC_SHARED, 0); - - /* The amount of conventional memory to be reserved for the kernel. */ -#define KMEM_SIZE (16 * 0x100000) - - /* The upper limit for the end of the kernel memory. */ -#define KMEM_MAX (240 * 0x100000) - - if (CHECK_FLAG (mbi->flags, 6)) - { - memory_map_t *mmap; - - for (mmap = (memory_map_t *) mbi->mmap_addr; - (uint32_t) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (memory_map_t *) ((uint32_t) mmap - + mmap->size + sizeof (mmap->size))) - { - if (mmap->type != 1) - continue; - - if (((uint32_t) mmap->length) >= KMEM_SIZE - && ((uint32_t) mmap->base_addr) <= KMEM_MAX - KMEM_SIZE) - { - uint32_t high = ((uint32_t) mmap->base_addr) - + ((uint32_t) mmap->length); - uint32_t low; - - if (high > KMEM_MAX) - high = KMEM_MAX; - low = high - KMEM_SIZE; - /* Round up to the next super page (4 MB). */ - low = (low + 0x3fffff) & ~0x3fffff; - - add_memory_map (low, high, L4_MEMDESC_RESERVED, 0); - } - } - } - else if (CHECK_FLAG (mbi->flags, 0)) - { - if ((mbi->mem_upper << 10) >= KMEM_SIZE) - { - uint32_t high = (mbi->mem_upper << 10) + 0x100000; - uint32_t low; - - if (high > KMEM_MAX) - high = KMEM_MAX; - - low = high - KMEM_SIZE; - /* Round up to the next super page (4 MB). */ - low = (low + 0x3fffff) & ~0x3fffff; - - add_memory_map (low, high, L4_MEMDESC_RESERVED, 0); - } - } - - /* Now protect ourselves and the mulitboot info (at least the module - configuration. */ - loader_add_region (program_name, (l4_word_t) &_start, (l4_word_t) &_end); - - start = (l4_word_t) mbi; - end = start + sizeof (*mbi); - loader_add_region ("grub-mbi", start, end); - - if (CHECK_FLAG (mbi->flags, 3) && mbi->mods_count) - { - module_t *mod = (module_t *) mbi->mods_addr; - int nr; - - start = (l4_word_t) mod; - end = ((l4_word_t) mod) + mbi->mods_count * sizeof (*mod); - loader_add_region ("grub-mods", start, end); - - start = (l4_word_t) mod[0].string; - end = start + 1; - for (nr = 0; nr < mbi->mods_count; nr++) - { - char *str = (char *) mod[nr].string; - - if (str) - { - if (((l4_word_t) str) < start) - start = (l4_word_t) str; - while (*str) - str++; - if (((l4_word_t) str) + 1 > end) - end = (l4_word_t) str + 1; - } - } - loader_add_region ("grub-mods-cmdlines", start, end); - } -} diff -ruN ../contrib/ref/hurd-l4/laden/laden.c laden/laden.c --- ../contrib/ref/hurd-l4/laden/laden.c 2005-02-14 16:32:45.000000000 +0100 +++ laden/laden.c 2005-02-21 15:43:19.000000000 +0100 @@ -102,7 +102,7 @@ } -static void +void parse_args (int argc, char *argv[]) { int i = 1; @@ -192,12 +192,8 @@ int main (int argc, char *argv[]) { - parse_args (argc, argv); - debug ("%s " PACKAGE_VERSION "\n", program_name); - find_components (); - load_components (); kip_fixup (); diff -ruN ../contrib/ref/hurd-l4/laden/laden.h laden/laden.h --- ../contrib/ref/hurd-l4/laden/laden.h 2005-02-14 16:32:45.000000000 +0100 +++ laden/laden.h 2005-02-21 15:43:51.000000000 +0100 @@ -30,6 +30,11 @@ #include "shutdown.h" #include "loader.h" + +/* Check if the bit BIT in FLAGS is set. */ +#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit))) + + /* The program name. */ extern char *program_name; @@ -37,10 +42,6 @@ #define BUG_ADDRESS "" -/* Find the kernel, the initial servers and the other information - required for booting. */ -void find_components (void); - /* Start kernel. IP is the entry point. */ void start_kernel (l4_word_t ip); @@ -85,8 +86,7 @@ descriptors to be loaded. */ int load_mem_info (l4_memory_desc_t memdesc, int nr); - -/* The generic code defines these functions. */ +void parse_args (int, char**); void kip_fixup (void);