source: mainline/kernel/genarch/src/multiboot/multiboot2.c@ 1f5c9c96

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1f5c9c96 was 1f5c9c96, checked in by Martin Decky <martin@…>, 14 years ago

implement multiboot v2 specification and use it in GRUB for UEFI

  • improve multiboot v1 code, move defines to a common location
  • rename VESA framebuffer stuff to generic "boot framebuffer"
  • small collateral changes
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup genarch
30 * @{
31 */
32/** @file
33 */
34
35#include <typedefs.h>
36#include <genarch/multiboot/multiboot.h>
37#include <genarch/multiboot/multiboot2.h>
38#include <genarch/fb/bfb.h>
39#include <config.h>
40#include <align.h>
41
42#define MULTIBOOT2_TAG_ALIGN 8
43
44static void multiboot2_module(const multiboot2_module_t *module)
45{
46 if (init.cnt < CONFIG_INIT_TASKS) {
47 init.tasks[init.cnt].addr = PA2KA(module->start);
48 init.tasks[init.cnt].size = module->end - module->start;
49 multiboot_extract_command(init.tasks[init.cnt].name,
50 CONFIG_TASK_NAME_BUFLEN, module->string);
51
52 init.cnt++;
53 }
54}
55
56static void multiboot2_memmap(uint32_t length, const multiboot2_memmap_t *memmap)
57{
58 multiboot2_memmap_entry_t *entry = (multiboot2_memmap_entry_t *)
59 ((uintptr_t) memmap + sizeof(*memmap));
60 uint32_t pos = sizeof(*memmap);
61
62 while ((pos < length) && (e820counter < MEMMAP_E820_MAX_RECORDS)) {
63 e820table[e820counter].base_address = entry->base_address;
64 e820table[e820counter].size = entry->size;
65 e820table[e820counter].type = entry->type;
66
67 /* Compute address of next entry. */
68 entry = (multiboot2_memmap_entry_t *)
69 ((uintptr_t) entry + memmap->entry_size);
70 pos += memmap->entry_size;
71
72 e820counter++;
73 }
74}
75
76static void multiboot2_fbinfo(const multiboot2_fbinfo_t *fbinfo)
77{
78 if (fbinfo->visual == MULTIBOOT2_VISUAL_RGB) {
79 bfb_addr = fbinfo->addr;
80 bfb_width = fbinfo->width;
81 bfb_height = fbinfo->height;
82 bfb_bpp = fbinfo->bpp;
83 bfb_scanline = fbinfo->scanline;
84
85 bfb_red_pos = fbinfo->rgb.red_pos;
86 bfb_red_size = fbinfo->rgb.red_size;
87
88 bfb_green_pos = fbinfo->rgb.green_pos;
89 bfb_green_size = fbinfo->rgb.green_size;
90
91 bfb_blue_pos = fbinfo->rgb.blue_pos;
92 bfb_blue_size = fbinfo->rgb.blue_size;
93 }
94}
95
96/** Parse multiboot2 information structure.
97 *
98 * If @a signature does not contain a valid multiboot2 signature,
99 * assumes no multiboot2 information is available.
100 *
101 * @param signature Should contain the multiboot2 signature.
102 * @param info Multiboot2 information structure.
103 *
104 */
105void multiboot2_info_parse(uint32_t signature, const multiboot2_info_t *info)
106{
107 if (signature != MULTIBOOT2_LOADER_MAGIC)
108 return;
109
110 const multiboot2_tag_t *tag = (const multiboot2_tag_t *)
111 ALIGN_UP((uintptr_t) info + sizeof(*info), MULTIBOOT2_TAG_ALIGN);
112
113 while (tag->type != MULTIBOOT2_TAG_TERMINATOR) {
114 switch (tag->type) {
115 case MULTIBOOT2_TAG_MODULE:
116 multiboot2_module(&tag->module);
117 break;
118 case MULTIBOOT2_TAG_MEMMAP:
119 multiboot2_memmap(tag->size, &tag->memmap);
120 break;
121 case MULTIBOOT2_TAG_FBINFO:
122 multiboot2_fbinfo(&tag->fbinfo);
123 break;
124 }
125
126 tag = (const multiboot2_tag_t *)
127 ALIGN_UP((uintptr_t) tag + tag->size, MULTIBOOT2_TAG_ALIGN);
128 }
129}
130
131/** @}
132 */
Note: See TracBrowser for help on using the repository browser.