source: mainline/kernel/genarch/src/multiboot/multiboot2.c@ 9d504072

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9d504072 was c8cbd39, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Hack: copy kernel arguments to sysinfo

  • Property mode set to 100644
File size: 4.2 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].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 multiboot_extract_argument(init.tasks[init.cnt].arguments,
52 CONFIG_TASK_ARGUMENTS_BUFLEN, module->string);
53
54 init.cnt++;
55 }
56}
57
58static void multiboot2_memmap(uint32_t length, const multiboot2_memmap_t *memmap)
59{
60 multiboot2_memmap_entry_t *entry = (multiboot2_memmap_entry_t *)
61 ((uintptr_t) memmap + sizeof(*memmap));
62 uint32_t pos = sizeof(*memmap);
63
64 while ((pos < length) && (e820counter < MEMMAP_E820_MAX_RECORDS)) {
65 e820table[e820counter].base_address = entry->base_address;
66 e820table[e820counter].size = entry->size;
67 e820table[e820counter].type = entry->type;
68
69 /* Compute address of next entry. */
70 entry = (multiboot2_memmap_entry_t *)
71 ((uintptr_t) entry + memmap->entry_size);
72 pos += memmap->entry_size;
73
74 e820counter++;
75 }
76}
77
78static void multiboot2_fbinfo(const multiboot2_fbinfo_t *fbinfo)
79{
80#ifdef CONFIG_FB
81 if (fbinfo->visual == MULTIBOOT2_VISUAL_RGB) {
82 bfb_addr = fbinfo->addr;
83 bfb_width = fbinfo->width;
84 bfb_height = fbinfo->height;
85 bfb_bpp = fbinfo->bpp;
86 bfb_scanline = fbinfo->scanline;
87
88 bfb_red_pos = fbinfo->rgb.red_pos;
89 bfb_red_size = fbinfo->rgb.red_size;
90
91 bfb_green_pos = fbinfo->rgb.green_pos;
92 bfb_green_size = fbinfo->rgb.green_size;
93
94 bfb_blue_pos = fbinfo->rgb.blue_pos;
95 bfb_blue_size = fbinfo->rgb.blue_size;
96 }
97#endif
98}
99
100/** Parse multiboot2 information structure.
101 *
102 * If @a signature does not contain a valid multiboot2 signature,
103 * assumes no multiboot2 information is available.
104 *
105 * @param signature Should contain the multiboot2 signature.
106 * @param info Multiboot2 information structure.
107 *
108 */
109void multiboot2_info_parse(uint32_t signature, const multiboot2_info_t *info)
110{
111 if (signature != MULTIBOOT2_LOADER_MAGIC)
112 return;
113
114 const multiboot2_tag_t *tag = (const multiboot2_tag_t *)
115 ALIGN_UP((uintptr_t) info + sizeof(*info), MULTIBOOT2_TAG_ALIGN);
116
117 while (tag->type != MULTIBOOT2_TAG_TERMINATOR) {
118 switch (tag->type) {
119 case MULTIBOOT2_TAG_MODULE:
120 multiboot2_module(&tag->module);
121 break;
122 case MULTIBOOT2_TAG_MEMMAP:
123 multiboot2_memmap(tag->size, &tag->memmap);
124 break;
125 case MULTIBOOT2_TAG_FBINFO:
126 multiboot2_fbinfo(&tag->fbinfo);
127 break;
128 }
129
130 tag = (const multiboot2_tag_t *)
131 ALIGN_UP((uintptr_t) tag + tag->size, MULTIBOOT2_TAG_ALIGN);
132 }
133}
134
135/** @}
136 */
Note: See TracBrowser for help on using the repository browser.