Subversion Repositories HelenOS

Rev

Rev 4345 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4345 Rev 4347
1
/*
1
/*
2
 * Copyright (c) 2009 Jiri Svoboda
2
 * Copyright (c) 2009 Jiri Svoboda
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup genarch
29
/** @addtogroup genarch
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <genarch/multiboot/multiboot.h>
35
#include <genarch/multiboot/multiboot.h>
36
#include <arch/types.h>
36
#include <arch/types.h>
37
#include <typedefs.h>
37
#include <typedefs.h>
38
#include <config.h>
38
#include <config.h>
39
#include <string.h>
39
#include <string.h>
40
#include <macros.h>
40
#include <macros.h>
41
 
41
 
42
/** Extract command name from the multiboot module command line.
42
/** Extract command name from the multiboot module command line.
43
 *
43
 *
44
 * @param buf      Destination buffer (will always null-terminate).
44
 * @param buf      Destination buffer (will always null-terminate).
45
 * @param n        Size of destination buffer.
45
 * @param n        Size of destination buffer.
46
 * @param cmd_line Input string (the command line).
46
 * @param cmd_line Input string (the command line).
47
 *
47
 *
48
 */
48
 */
49
static void extract_command(char *buf, size_t n, const char *cmd_line)
49
static void extract_command(char *buf, size_t n, const char *cmd_line)
50
{
50
{
51
    const char *start, *end, *cp;
51
    const char *start, *end, *cp;
52
    size_t max_len;
52
    size_t max_len;
53
   
53
   
54
    /* Find the first space. */
54
    /* Find the first space. */
55
    end = strchr(cmd_line, ' ');
55
    end = strchr(cmd_line, ' ');
56
    if (end == NULL)
56
    if (end == NULL)
57
        end = cmd_line + strlen(cmd_line);
57
        end = cmd_line + strlen(cmd_line);
58
   
58
   
59
    /*
59
    /*
60
     * Find last occurence of '/' before 'end'. If found, place start at
60
     * Find last occurence of '/' before 'end'. If found, place start at
61
     * next character. Otherwise, place start at beginning of buffer.
61
     * next character. Otherwise, place start at beginning of buffer.
62
     */
62
     */
63
    cp = end;
63
    cp = end;
64
    start = buf;
64
    start = buf;
65
    while (cp != start) {
65
    while (cp != start) {
66
        if (*cp == '/') {
66
        if (*cp == '/') {
67
            start = cp + 1;
67
            start = cp + 1;
68
            break;
68
            break;
69
        }
69
        }
70
        --cp;
70
        --cp;
71
    }
71
    }
72
   
72
   
73
    /* Copy the command and null-terminate the string. */
73
    /* Copy the command and null-terminate the string. */
74
    max_len = min(n - 1, (size_t) (end - start));
74
    max_len = min(n - 1, (size_t) (end - start));
75
    strncpy(buf, start, max_len + 1);
75
    strncpy(buf, start, max_len + 1);
76
    buf[max_len] = '\0';
76
    buf[max_len] = '\0';
77
}
77
}
78
 
78
 
79
/** Parse multiboot information structure.
79
/** Parse multiboot information structure.
80
 *
80
 *
81
 * If @a signature does not contain a valid multiboot signature,
81
 * If @a signature does not contain a valid multiboot signature,
82
 * assumes no multiboot information is available.
82
 * assumes no multiboot information is available.
83
 *
83
 *
84
 * @param signature Should contain the multiboot signature.
84
 * @param signature Should contain the multiboot signature.
85
 * @param mi        Pointer to the multiboot information structure.
85
 * @param mi        Pointer to the multiboot information structure.
86
 */
86
 */
87
void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
87
void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
88
{
88
{
89
    uint32_t flags;
89
    uint32_t flags;
90
    multiboot_mod_t *mods;
90
    multiboot_mod_t *mods;
91
    uint32_t i;
91
    uint32_t i;
92
   
92
   
93
    if (signature == MULTIBOOT_LOADER_MAGIC)
93
    if (signature == MULTIBOOT_LOADER_MAGIC)
94
        flags = mi->flags;
94
        flags = mi->flags;
95
    else {
95
    else {
96
        /* No multiboot info available. */
96
        /* No multiboot info available. */
97
        flags = 0;
97
        flags = 0;
98
    }
98
    }
99
   
99
   
100
    /* Copy module information. */
100
    /* Copy module information. */
101
   
101
   
102
    if ((flags & MBINFO_FLAGS_MODS) != 0) {
102
    if ((flags & MBINFO_FLAGS_MODS) != 0) {
103
        init.cnt = mi->mods_count;
103
        init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS);
104
        mods = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
104
        mods = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
105
       
105
       
106
        for (i = 0; i < init.cnt; i++) {
106
        for (i = 0; i < init.cnt; i++) {
107
            init.tasks[i].addr = PA2KA(mods[i].start);
107
            init.tasks[i].addr = PA2KA(mods[i].start);
108
            init.tasks[i].size = mods[i].end - mods[i].start;
108
            init.tasks[i].size = mods[i].end - mods[i].start;
109
           
109
           
110
            /* Copy command line, if available. */
110
            /* Copy command line, if available. */
111
            if (mods[i].string) {
111
            if (mods[i].string) {
112
                extract_command(init.tasks[i].name,
112
                extract_command(init.tasks[i].name,
113
                    CONFIG_TASK_NAME_BUFLEN,
113
                    CONFIG_TASK_NAME_BUFLEN,
114
                    MULTIBOOT_PTR(mods[i].string));
114
                    MULTIBOOT_PTR(mods[i].string));
115
            } else
115
            } else
116
                init.tasks[i].name[0] = '\0';
116
                init.tasks[i].name[0] = '\0';
117
        }
117
        }
118
    } else
118
    } else
119
        init.cnt = 0;
119
        init.cnt = 0;
120
   
120
   
121
    /* Copy memory map. */
121
    /* Copy memory map. */
122
   
122
   
123
    int32_t mmap_length;
123
    int32_t mmap_length;
124
    multiboot_mmap_t *mme;
124
    multiboot_mmap_t *mme;
125
    uint32_t size;
125
    uint32_t size;
126
   
126
   
127
    if ((flags & MBINFO_FLAGS_MMAP) != 0) {
127
    if ((flags & MBINFO_FLAGS_MMAP) != 0) {
128
        mmap_length = mi->mmap_length;
128
        mmap_length = mi->mmap_length;
129
        mme = MULTIBOOT_PTR(mi->mmap_addr);
129
        mme = MULTIBOOT_PTR(mi->mmap_addr);
130
        e820counter = 0;
130
        e820counter = 0;
131
       
131
       
132
        i = 0;
132
        i = 0;
133
        while (mmap_length > 0) {
133
        while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) {
134
            e820table[i++] = mme->mm_info;
134
            e820table[i++] = mme->mm_info;
135
           
135
           
136
            /* Compute address of next structure. */
136
            /* Compute address of next structure. */
137
            size = sizeof(mme->size) + mme->size;
137
            size = sizeof(mme->size) + mme->size;
138
            mme = ((void *) mme) + size;
138
            mme = ((void *) mme) + size;
139
            mmap_length -= size;
139
            mmap_length -= size;
140
        }
140
        }
141
       
141
       
142
        e820counter = i;
142
        e820counter = i;
143
    } else
143
    } else
144
        e820counter = 0;
144
        e820counter = 0;
145
}
145
}
146
 
146
 
147
/** @}
147
/** @}
148
 */
148
 */
149
 
149