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 |
|
---|
44 | static void multiboot2_module(const multiboot2_module_t *module)
|
---|
45 | {
|
---|
46 | if (init.cnt < CONFIG_INIT_TASKS) {
|
---|
47 | init.tasks[init.cnt].paddr = 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 |
|
---|
56 | static 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 |
|
---|
76 | static void multiboot2_fbinfo(const multiboot2_fbinfo_t *fbinfo)
|
---|
77 | {
|
---|
78 | #ifdef CONFIG_FB
|
---|
79 | if (fbinfo->visual == MULTIBOOT2_VISUAL_RGB) {
|
---|
80 | bfb_addr = fbinfo->addr;
|
---|
81 | bfb_width = fbinfo->width;
|
---|
82 | bfb_height = fbinfo->height;
|
---|
83 | bfb_bpp = fbinfo->bpp;
|
---|
84 | bfb_scanline = fbinfo->scanline;
|
---|
85 |
|
---|
86 | bfb_red_pos = fbinfo->rgb.red_pos;
|
---|
87 | bfb_red_size = fbinfo->rgb.red_size;
|
---|
88 |
|
---|
89 | bfb_green_pos = fbinfo->rgb.green_pos;
|
---|
90 | bfb_green_size = fbinfo->rgb.green_size;
|
---|
91 |
|
---|
92 | bfb_blue_pos = fbinfo->rgb.blue_pos;
|
---|
93 | bfb_blue_size = fbinfo->rgb.blue_size;
|
---|
94 | }
|
---|
95 | #endif
|
---|
96 | }
|
---|
97 |
|
---|
98 | /** Parse multiboot2 information structure.
|
---|
99 | *
|
---|
100 | * If @a signature does not contain a valid multiboot2 signature,
|
---|
101 | * assumes no multiboot2 information is available.
|
---|
102 | *
|
---|
103 | * @param signature Should contain the multiboot2 signature.
|
---|
104 | * @param info Multiboot2 information structure.
|
---|
105 | *
|
---|
106 | */
|
---|
107 | void multiboot2_info_parse(uint32_t signature, const multiboot2_info_t *info)
|
---|
108 | {
|
---|
109 | if (signature != MULTIBOOT2_LOADER_MAGIC)
|
---|
110 | return;
|
---|
111 |
|
---|
112 | const multiboot2_tag_t *tag = (const multiboot2_tag_t *)
|
---|
113 | ALIGN_UP((uintptr_t) info + sizeof(*info), MULTIBOOT2_TAG_ALIGN);
|
---|
114 |
|
---|
115 | while (tag->type != MULTIBOOT2_TAG_TERMINATOR) {
|
---|
116 | switch (tag->type) {
|
---|
117 | case MULTIBOOT2_TAG_MODULE:
|
---|
118 | multiboot2_module(&tag->module);
|
---|
119 | break;
|
---|
120 | case MULTIBOOT2_TAG_MEMMAP:
|
---|
121 | multiboot2_memmap(tag->size, &tag->memmap);
|
---|
122 | break;
|
---|
123 | case MULTIBOOT2_TAG_FBINFO:
|
---|
124 | multiboot2_fbinfo(&tag->fbinfo);
|
---|
125 | break;
|
---|
126 | }
|
---|
127 |
|
---|
128 | tag = (const multiboot2_tag_t *)
|
---|
129 | ALIGN_UP((uintptr_t) tag + tag->size, MULTIBOOT2_TAG_ALIGN);
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /** @}
|
---|
134 | */
|
---|