From: Vladimir 'phcoder' Serbinenko Date: Sat, 16 Jan 2010 14:38:00 +0000 (+0100) Subject: merge multiboot2 into mbtag-spec X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98b3579549fa38b2f9bad16aedc4d18e56d69acc;p=thirdparty%2Fgrub.git merge multiboot2 into mbtag-spec --- 98b3579549fa38b2f9bad16aedc4d18e56d69acc diff --cc doc/kernel.c index 9a1329ea1,1107ce69a..34e887bc0 --- a/doc/kernel.c +++ b/doc/kernel.c @@@ -19,9 -19,9 +19,6 @@@ /* Macros. */ --/* Check if the bit BIT in FLAGS is set. */ --#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit))) -- /* Some screen stuff. */ /* The number of columns. */ #define COLUMNS 80 @@@ -47,343 -47,109 +44,162 @@@ static void itoa (char *buf, int base, static void putchar (int c); void printf (const char *format, ...); - static void - tagged (unsigned long addr) - { + /* Check if MAGIC is valid and print the Multiboot information structure + pointed by ADDR. */ + void + cmain (unsigned long magic, unsigned long addr) -{ - multiboot_info_t *mbi; - ++{ + struct multiboot_tag *tag; + + /* Clear the screen. */ + cls (); + + /* Am I booted by a Multiboot-compliant boot loader? */ + if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) + { + printf ("Invalid magic number: 0x%x\n", (unsigned) magic); + return; + } + - /* Set MBI to the address of the Multiboot information structure. */ - mbi = (multiboot_info_t *) addr; - - /* Print out the flags. */ - printf ("flags = 0x%x\n", (unsigned) mbi->flags); - - /* Are mem_* valid? */ - if (CHECK_FLAG (mbi->flags, 0)) - printf ("mem_lower = %uKB, mem_upper = %uKB\n", - (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper); - - /* Is boot_device valid? */ - if (CHECK_FLAG (mbi->flags, 1)) - printf ("boot_device = 0x%x\n", (unsigned) mbi->boot_device); - - /* Is the command line passed? */ - if (CHECK_FLAG (mbi->flags, 2)) - printf ("cmdline = %s\n", (char *) mbi->cmdline); - - /* Are mods_* valid? */ - if (CHECK_FLAG (mbi->flags, 3)) - { - multiboot_module_t *mod; - int i; - - printf ("mods_count = %d, mods_addr = 0x%x\n", - (int) mbi->mods_count, (int) mbi->mods_addr); - for (i = 0, mod = (multiboot_module_t *) mbi->mods_addr; - i < mbi->mods_count; - i++, mod++) - printf (" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n", - (unsigned) mod->mod_start, - (unsigned) mod->mod_end, - (char *) mod->cmdline); - } - - /* Bits 4 and 5 are mutually exclusive! */ - if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5)) - { - printf ("Both bits 4 and 5 are set.\n"); - return; - } - - /* Is the symbol table of a.out valid? */ - if (CHECK_FLAG (mbi->flags, 4)) - { - multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym); - - printf ("multiboot_aout_symbol_table: tabsize = 0x%0x, " - "strsize = 0x%x, addr = 0x%x\n", - (unsigned) multiboot_aout_sym->tabsize, - (unsigned) multiboot_aout_sym->strsize, - (unsigned) multiboot_aout_sym->addr); - } - - /* Is the section header table of ELF valid? */ - if (CHECK_FLAG (mbi->flags, 5)) - { - multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec); - - printf ("multiboot_elf_sec: num = %u, size = 0x%x," - " addr = 0x%x, shndx = 0x%x\n", - (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size, - (unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx); - } - - /* Are mmap_* valid? */ - if (CHECK_FLAG (mbi->flags, 6)) + for (tag = (struct multiboot_tag *) addr; tag->type != MULTIBOOT_TAG_TYPE_END; + tag = (struct multiboot_tag *) ((multiboot_uint8_t *) tag + tag->size)) { - multiboot_memory_map_t *mmap; + printf ("Tag 0x%x, Size 0x%x\n", tag->type, tag->size); + switch (tag->type) + { + case MULTIBOOT_TAG_TYPE_CMDLINE: + printf ("Command line = %s\n", + ((struct multiboot_tag_string *) tag)->string); + break; + case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: + printf ("Boot loader name = %s\n", + ((struct multiboot_tag_string *) tag)->string); + break; + case MULTIBOOT_TAG_TYPE_MODULE: + printf ("Module at 0x%x-0x%x. Command line %s\n", + ((struct multiboot_tag_module *) tag)->mod_start, + ((struct multiboot_tag_module *) tag)->mod_end, + ((struct multiboot_tag_module *) tag)->cmdline); + break; + case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: + printf ("mem_lower = %uKB, mem_upper = %uKB\n", + ((struct multiboot_tag_basic_meminfo *) tag)->mem_lower, + ((struct multiboot_tag_basic_meminfo *) tag)->mem_upper); + break; + case MULTIBOOT_TAG_TYPE_BOOTDEV: + printf ("Boot device 0x%x,%u,%u\n", + ((struct multiboot_tag_bootdev *) tag)->biosdev, + ((struct multiboot_tag_bootdev *) tag)->slice, + ((struct multiboot_tag_bootdev *) tag)->part); + break; + case MULTIBOOT_TAG_TYPE_MMAP: + { + multiboot_memory_map_t *mmap; + + printf ("mmap\n"); - printf ("mmap_addr = 0x%x, mmap_length = 0x%x\n", - (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length); - for (mmap = (multiboot_memory_map_t *) mbi->mmap_addr; - (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (multiboot_memory_map_t *) ((unsigned long) mmap - + mmap->size + sizeof (mmap->size))) - printf (" size = 0x%x, base_addr = 0x%x%x," - " length = 0x%x%x, type = 0x%x\n", - (unsigned) mmap->size, - (unsigned) (mmap->addr >> 32), - (unsigned) (mmap->addr & 0xffffffff), - (unsigned) (mmap->len >> 32), - (unsigned) (mmap->len & 0xffffffff), - (unsigned) mmap->type); + for (mmap = ((struct multiboot_tag_mmap *) tag)->entries; + (multiboot_uint8_t *) mmap + < (multiboot_uint8_t *) tag + tag->size; + mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + + mmap->size + + sizeof (mmap->size))) + printf (" size = 0x%x, base_addr = 0x%x%x," + " length = 0x%x%x, type = 0x%x\n", + (unsigned) mmap->size, + (unsigned) (mmap->addr >> 32), + (unsigned) (mmap->addr & 0xffffffff), + (unsigned) (mmap->len >> 32), + (unsigned) (mmap->len & 0xffffffff), + (unsigned) mmap->type); + } + break; + case MULTIBOOT_TAG_TYPE_FRAMEBUFFER: + { + multiboot_uint32_t color; + unsigned i; + struct multiboot_tag_framebuffer *tagfb + = (struct multiboot_tag_framebuffer *) tag; + void *fb = (void *) (unsigned long) tagfb->common.framebuffer_addr; + + switch (tagfb->common.framebuffer_type) + { + case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED: + { + unsigned best_distance, distance; + struct multiboot_color *palette; + + palette = tagfb->framebuffer_palette; + + color = 0; + best_distance = 4*256*256; + + for (i = 0; i < tagfb->framebuffer_palette_num_colors; i++) + { + distance = (0xff - palette[i].blue) + * (0xff - palette[i].blue) + + palette[i].red * palette[i].red + + palette[i].green * palette[i].green; + if (distance < best_distance) + { + color = i; + best_distance = distance; + } + } + } + break; + + case MULTIBOOT_FRAMEBUFFER_TYPE_RGB: + color = ((1 << tagfb->framebuffer_blue_mask_size) - 1) + << tagfb->framebuffer_blue_field_position; + break; + + default: + color = 0xffffffff; + break; + } + + for (i = 0; i < tagfb->common.framebuffer_width + && i < tagfb->common.framebuffer_height; i++) + { + switch (tagfb->common.framebuffer_bpp) + { + case 8: + { + multiboot_uint8_t *pixel = fb + + tagfb->common.framebuffer_pitch * i + i; + *pixel = color; + } + break; + case 15: + case 16: + { + multiboot_uint16_t *pixel + = fb + tagfb->common.framebuffer_pitch * i + 2 * i; + *pixel = color; + } + break; + case 24: + { + multiboot_uint32_t *pixel + = fb + tagfb->common.framebuffer_pitch * i + 3 * i; + *pixel = (color & 0xffffff) | (*pixel & 0xff000000); + } + break; + + case 32: + { + multiboot_uint32_t *pixel + = fb + tagfb->common.framebuffer_pitch * i + 4 * i; + *pixel = color; + } + break; + } + } + break; + } + } } - } - - - /* Check if MAGIC is valid and print the Multiboot information structure - pointed by ADDR. */ - void - cmain (unsigned long magic, unsigned long addr) - { - multiboot_info_t *mbi; - - /* Clear the screen. */ - cls (); - - if (magic == MULTIBOOT_BOOTLOADER_MAGIC_TAGGED) - { - tagged (addr); - return; - } - - /* Am I booted by a Multiboot-compliant boot loader? */ - if (magic != MULTIBOOT_BOOTLOADER_MAGIC) - { - printf ("Invalid magic number: 0x%x\n", (unsigned) magic); - return; - } - - /* Set MBI to the address of the Multiboot information structure. */ - mbi = (multiboot_info_t *) addr; - - /* Print out the flags. */ - printf ("flags = 0x%x\n", (unsigned) mbi->flags); - - /* Are mem_* valid? */ - if (CHECK_FLAG (mbi->flags, 0)) - printf ("mem_lower = %uKB, mem_upper = %uKB\n", - (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper); - - /* Is boot_device valid? */ - if (CHECK_FLAG (mbi->flags, 1)) - printf ("boot_device = 0x%x\n", (unsigned) mbi->boot_device); - - /* Is the command line passed? */ - if (CHECK_FLAG (mbi->flags, 2)) - printf ("cmdline = %s\n", (char *) mbi->cmdline); - - /* Are mods_* valid? */ - if (CHECK_FLAG (mbi->flags, 3)) - { - multiboot_module_t *mod; - int i; - - printf ("mods_count = %d, mods_addr = 0x%x\n", - (int) mbi->mods_count, (int) mbi->mods_addr); - for (i = 0, mod = (multiboot_module_t *) mbi->mods_addr; - i < mbi->mods_count; - i++, mod++) - printf (" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n", - (unsigned) mod->mod_start, - (unsigned) mod->mod_end, - (char *) mod->cmdline); - } - - /* Bits 4 and 5 are mutually exclusive! */ - if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5)) - { - printf ("Both bits 4 and 5 are set.\n"); - return; - } - - /* Is the symbol table of a.out valid? */ - if (CHECK_FLAG (mbi->flags, 4)) - { - multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym); - - printf ("multiboot_aout_symbol_table: tabsize = 0x%0x, " - "strsize = 0x%x, addr = 0x%x\n", - (unsigned) multiboot_aout_sym->tabsize, - (unsigned) multiboot_aout_sym->strsize, - (unsigned) multiboot_aout_sym->addr); - } - - /* Is the section header table of ELF valid? */ - if (CHECK_FLAG (mbi->flags, 5)) - { - multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec); - - printf ("multiboot_elf_sec: num = %u, size = 0x%x," - " addr = 0x%x, shndx = 0x%x\n", - (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size, - (unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx); - } - - /* Are mmap_* valid? */ - if (CHECK_FLAG (mbi->flags, 6)) - { - multiboot_memory_map_t *mmap; - - printf ("mmap_addr = 0x%x, mmap_length = 0x%x\n", - (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length); - for (mmap = (multiboot_memory_map_t *) mbi->mmap_addr; - (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; - mmap = (multiboot_memory_map_t *) ((unsigned long) mmap - + mmap->size + sizeof (mmap->size))) - printf (" size = 0x%x, base_addr = 0x%x%x," - " length = 0x%x%x, type = 0x%x\n", - (unsigned) mmap->size, - mmap->addr >> 32, - mmap->addr & 0xffffffff, - mmap->len >> 32, - mmap->len & 0xffffffff, - (unsigned) mmap->type); - } - - /* Draw diagonal blue line. */ - if (CHECK_FLAG (mbi->flags, 12)) - { - multiboot_uint32_t color; - unsigned i; - void *fb = (void *) (unsigned long) mbi->framebuffer_addr; - - switch (mbi->framebuffer_type) - { - case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED: - { - unsigned best_distance, distance; - struct multiboot_color *palette; - - palette = (struct multiboot_color *) mbi->framebuffer_palette_addr; - - color = 0; - best_distance = 4*256*256; - - for (i = 0; i < mbi->framebuffer_palette_num_colors; i++) - { - distance = (0xff - palette[i].blue) * (0xff - palette[i].blue) - + palette[i].red * palette[i].red - + palette[i].green * palette[i].green; - if (distance < best_distance) - { - color = i; - best_distance = distance; - } - } - } - break; - - case MULTIBOOT_FRAMEBUFFER_TYPE_RGB: - color = ((1 << mbi->framebuffer_blue_mask_size) - 1) - << mbi->framebuffer_blue_field_position; - break; - - default: - color = 0xffffffff; - break; - } - for (i = 0; i < mbi->framebuffer_width - && i < mbi->framebuffer_height; i++) - { - switch (mbi->framebuffer_bpp) - { - case 8: - { - multiboot_uint8_t *pixel = fb + mbi->framebuffer_pitch * i + i; - *pixel = color; - } - break; - case 15: - case 16: - { - multiboot_uint16_t *pixel - = fb + mbi->framebuffer_pitch * i + 2 * i; - *pixel = color; - } - break; - case 24: - { - multiboot_uint32_t *pixel - = fb + mbi->framebuffer_pitch * i + 3 * i; - *pixel = (color & 0xffffff) | (*pixel & 0xff000000); - } - break; - - case 32: - { - multiboot_uint32_t *pixel - = fb + mbi->framebuffer_pitch * i + 4 * i; - *pixel = color; - } - break; - } - } - } - } /* Clear the screen and initialize VIDEO, XPOS and YPOS. */