source: mainline/kernel/genarch/src/multiboot/multiboot.c@ 8781e9d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8781e9d was 8781e9d, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Remove realmode VESA code

This simply enables framebuffer setup via multiboot1
(multiboot2 already did it), and removes the obsolete code.

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[5d8d71e]1/*
2 * Copyright (c) 2009 Jiri Svoboda
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
[6404aca]29/** @addtogroup kernel_genarch
[5d8d71e]30 * @{
31 */
32/** @file
33 */
34
35#include <typedefs.h>
[1f5c9c96]36#include <genarch/multiboot/multiboot.h>
[8781e9d]37#include <genarch/fb/bfb.h>
[5d8d71e]38#include <config.h>
[e29e44bf]39#include <stddef.h>
[19f857a]40#include <str.h>
[5d8d71e]41
42/** Extract command name from the multiboot module command line.
43 *
[1f5c9c96]44 * @param buf Destination buffer (will be always NULL-terminated).
45 * @param size Size of destination buffer (in bytes).
[5d8d71e]46 * @param cmd_line Input string (the command line).
47 *
48 */
[1f5c9c96]49void multiboot_extract_command(char *buf, size_t size, const char *cmd_line)
[5d8d71e]50{
51 /* Find the first space. */
[b60c582]52 const char *end = str_chr(cmd_line, ' ');
[5d8d71e]53 if (end == NULL)
[06b785f]54 end = cmd_line + str_size(cmd_line);
[a35b458]55
[5d8d71e]56 /*
57 * Find last occurence of '/' before 'end'. If found, place start at
58 * next character. Otherwise, place start at beginning of buffer.
59 */
[b60c582]60 const char *cp = end;
61 const char *start = buf;
[a35b458]62
[5d8d71e]63 while (cp != start) {
64 if (*cp == '/') {
65 start = cp + 1;
66 break;
67 }
[b60c582]68 cp--;
[5d8d71e]69 }
[a35b458]70
[b60c582]71 /* Copy the command. */
[1f5c9c96]72 str_ncpy(buf, size, start, (size_t) (end - start));
73}
74
[c8cbd39]75/** Extract arguments from the multiboot module command line.
76 *
77 * @param buf Destination buffer (will be always NULL-terminated).
78 * @param size Size of destination buffer (in bytes).
79 * @param cmd_line Input string (the command line).
80 *
81 */
82void multiboot_extract_argument(char *buf, size_t size, const char *cmd_line)
83{
84 /* Start after first space. */
85 const char *start = str_chr(cmd_line, ' ');
86 if (start == NULL) {
87 str_cpy(buf, size, "");
88 return;
89 }
90
91 const char *end = cmd_line + str_size(cmd_line);
92
93 /* Skip the space(s). */
94 while (start != end) {
95 if (start[0] == ' ')
96 start++;
97 else
98 break;
99 }
100
101 str_ncpy(buf, size, start, (size_t) (end - start));
102}
103
[1f5c9c96]104static void multiboot_modules(uint32_t count, multiboot_module_t *mods)
105{
106 for (uint32_t i = 0; i < count; i++) {
107 if (init.cnt >= CONFIG_INIT_TASKS)
108 break;
[a35b458]109
[32817cc]110 init.tasks[init.cnt].paddr = mods[i].start;
[1f5c9c96]111 init.tasks[init.cnt].size = mods[i].end - mods[i].start;
[a35b458]112
[1f5c9c96]113 /* Copy command line, if available. */
114 if (mods[i].string) {
115 multiboot_extract_command(init.tasks[init.cnt].name,
116 CONFIG_TASK_NAME_BUFLEN, MULTIBOOT_PTR(mods[i].string));
[c8cbd39]117 multiboot_extract_argument(init.tasks[init.cnt].arguments,
118 CONFIG_TASK_ARGUMENTS_BUFLEN, MULTIBOOT_PTR(mods[i].string));
119 } else {
[1f5c9c96]120 init.tasks[init.cnt].name[0] = 0;
[c8cbd39]121 init.tasks[init.cnt].arguments[0] = 0;
122 }
[a35b458]123
[1f5c9c96]124 init.cnt++;
125 }
126}
127
128static void multiboot_memmap(uint32_t length, multiboot_memmap_t *memmap)
129{
130 uint32_t pos = 0;
[a35b458]131
[1f5c9c96]132 while ((pos < length) && (e820counter < MEMMAP_E820_MAX_RECORDS)) {
133 e820table[e820counter] = memmap->mm_info;
[a35b458]134
[1f5c9c96]135 /* Compute address of next structure. */
136 uint32_t size = sizeof(memmap->size) + memmap->size;
137 memmap = (multiboot_memmap_t *) ((uintptr_t) memmap + size);
138 pos += size;
[a35b458]139
[1f5c9c96]140 e820counter++;
141 }
[5d8d71e]142}
143
144/** Parse multiboot information structure.
145 *
146 * If @a signature does not contain a valid multiboot signature,
147 * assumes no multiboot information is available.
148 *
149 * @param signature Should contain the multiboot signature.
[1f5c9c96]150 * @param info Multiboot information structure.
151 *
[5d8d71e]152 */
[1f5c9c96]153void multiboot_info_parse(uint32_t signature, const multiboot_info_t *info)
[5d8d71e]154{
[1f5c9c96]155 if (signature != MULTIBOOT_LOADER_MAGIC)
156 return;
[ba1ea40]157
158 /* Copy command line. */
159 if ((info->flags & MULTIBOOT_INFO_FLAGS_CMDLINE) != 0)
160 multiboot_cmdline((char *) MULTIBOOT_PTR(info->cmd_line));
161
[1f5c9c96]162 /* Copy modules information. */
163 if ((info->flags & MULTIBOOT_INFO_FLAGS_MODS) != 0)
164 multiboot_modules(info->mods_count,
165 (multiboot_module_t *) MULTIBOOT_PTR(info->mods_addr));
[a35b458]166
[5d8d71e]167 /* Copy memory map. */
[1f5c9c96]168 if ((info->flags & MULTIBOOT_INFO_FLAGS_MMAP) != 0)
169 multiboot_memmap(info->mmap_length,
170 (multiboot_memmap_t *) MULTIBOOT_PTR(info->mmap_addr));
[8781e9d]171
172#ifdef CONFIG_FB
173
174 /* Initialize framebuffer. */
175 if ((info->flags & MULTIBOOT_INFO_FLAGS_FB) != 0) {
176 if (info->framebuffer_type != 1) {
177 /* Can't use this framebuffer. */
178 // FIXME: framebuffer_type == 2 is EGA mode, we should be able to use that.
179 return;
180 }
181
182 bfb_addr = info->framebuffer_addr;
183 bfb_width = info->framebuffer_width;
184 bfb_height = info->framebuffer_height;
185 bfb_bpp = info->framebuffer_bpp;
186 bfb_scanline = info->framebuffer_pitch;
187 bfb_red_pos = info->framebuffer_red_field_position;
188 bfb_red_size = info->framebuffer_red_mask_size;
189 bfb_green_pos = info->framebuffer_green_field_position;
190 bfb_green_size = info->framebuffer_green_mask_size;
191 bfb_blue_pos = info->framebuffer_blue_field_position;
192 bfb_blue_size = info->framebuffer_blue_mask_size;
193 }
194
195#endif
[5d8d71e]196}
197
198/** @}
199 */
Note: See TracBrowser for help on using the repository browser.