source: mainline/kernel/genarch/src/multiboot/multiboot.c@ c69209d

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

use [u]int{8|16|32|64}_t type definitions as detected by the autotool
replace direct usage of arch/types.h with typedefs.h

  • Property mode set to 100644
File size: 4.0 KB
Line 
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
29/** @addtogroup genarch
30 * @{
31 */
32/** @file
33 */
34
35#include <genarch/multiboot/multiboot.h>
36#include <typedefs.h>
37#include <config.h>
38#include <str.h>
39#include <macros.h>
40
41/** Extract command name from the multiboot module command line.
42 *
43 * @param buf Destination buffer (will always NULL-terminate).
44 * @param sz Size of destination buffer (in bytes).
45 * @param cmd_line Input string (the command line).
46 *
47 */
48static void extract_command(char *buf, size_t sz, const char *cmd_line)
49{
50 /* Find the first space. */
51 const char *end = str_chr(cmd_line, ' ');
52 if (end == NULL)
53 end = cmd_line + str_size(cmd_line);
54
55 /*
56 * Find last occurence of '/' before 'end'. If found, place start at
57 * next character. Otherwise, place start at beginning of buffer.
58 */
59 const char *cp = end;
60 const char *start = buf;
61
62 while (cp != start) {
63 if (*cp == '/') {
64 start = cp + 1;
65 break;
66 }
67 cp--;
68 }
69
70 /* Copy the command. */
71 str_ncpy(buf, sz, start, (size_t) (end - start));
72}
73
74/** Parse multiboot information structure.
75 *
76 * If @a signature does not contain a valid multiboot signature,
77 * assumes no multiboot information is available.
78 *
79 * @param signature Should contain the multiboot signature.
80 * @param mi Pointer to the multiboot information structure.
81 */
82void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
83{
84 uint32_t flags;
85
86 if (signature == MULTIBOOT_LOADER_MAGIC)
87 flags = mi->flags;
88 else {
89 /* No multiboot info available. */
90 flags = 0;
91 }
92
93 /* Copy module information. */
94 uint32_t i;
95 if ((flags & MBINFO_FLAGS_MODS) != 0) {
96 init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS);
97 multiboot_mod_t *mods
98 = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
99
100 for (i = 0; i < init.cnt; i++) {
101 init.tasks[i].addr = PA2KA(mods[i].start);
102 init.tasks[i].size = mods[i].end - mods[i].start;
103
104 /* Copy command line, if available. */
105 if (mods[i].string) {
106 extract_command(init.tasks[i].name,
107 CONFIG_TASK_NAME_BUFLEN,
108 MULTIBOOT_PTR(mods[i].string));
109 } else
110 init.tasks[i].name[0] = 0;
111 }
112 } else
113 init.cnt = 0;
114
115 /* Copy memory map. */
116
117 if ((flags & MBINFO_FLAGS_MMAP) != 0) {
118 int32_t mmap_length = mi->mmap_length;
119 multiboot_mmap_t *mme = MULTIBOOT_PTR(mi->mmap_addr);
120 e820counter = 0;
121
122 i = 0;
123 while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) {
124 e820table[i++] = mme->mm_info;
125
126 /* Compute address of next structure. */
127 uint32_t size = sizeof(mme->size) + mme->size;
128 mme = ((void *) mme) + size;
129 mmap_length -= size;
130 }
131
132 e820counter = i;
133 } else
134 e820counter = 0;
135}
136
137/** @}
138 */
Note: See TracBrowser for help on using the repository browser.