Subversion Repositories HelenOS

Rev

Rev 4201 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4201 Rev 4296
Line 39... Line 39...
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 sz       Size of destination buffer (in bytes).
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 sz, const char *cmd_line)
50
{
50
{
51
    const char *start, *end, *cp;
-
 
52
    size_t max_len;
-
 
53
   
-
 
54
    /* Find the first space. */
51
    /* Find the first space. */
55
    end = strchr(cmd_line, ' ');
52
    const char *end = str_chr(cmd_line, ' ');
56
    if (end == NULL)
53
    if (end == NULL)
57
        end = cmd_line + strlen(cmd_line);
54
        end = cmd_line + str_size(cmd_line);
58
   
55
   
59
    /*
56
    /*
60
     * Find last occurence of '/' before 'end'. If found, place start at
57
     * Find last occurence of '/' before 'end'. If found, place start at
61
     * next character. Otherwise, place start at beginning of buffer.
58
     * next character. Otherwise, place start at beginning of buffer.
62
     */
59
     */
63
    cp = end;
60
    const char *cp = end;
64
    start = buf;
61
    const char *start = buf;
-
 
62
   
65
    while (cp != start) {
63
    while (cp != start) {
66
        if (*cp == '/') {
64
        if (*cp == '/') {
67
            start = cp + 1;
65
            start = cp + 1;
68
            break;
66
            break;
69
        }
67
        }
70
        --cp;
68
        cp--;
71
    }
69
    }
72
   
70
   
73
    /* Copy the command and null-terminate the string. */
71
    /* Copy the command. */
74
    max_len = min(n - 1, (size_t) (end - start));
72
    str_ncpy(buf, sz, start, (size_t) (end - start));
75
    strncpy(buf, start, max_len + 1);
-
 
76
    buf[max_len] = '\0';
-
 
77
}
73
}
78
 
74
 
79
/** Parse multiboot information structure.
75
/** Parse multiboot information structure.
80
 *
76
 *
81
 * If @a signature does not contain a valid multiboot signature,
77
 * If @a signature does not contain a valid multiboot signature,
Line 85... Line 81...
85
 * @param mi        Pointer to the multiboot information structure.
81
 * @param mi        Pointer to the multiboot information structure.
86
 */
82
 */
87
void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
83
void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
88
{
84
{
89
    uint32_t flags;
85
    uint32_t flags;
90
    multiboot_mod_t *mods;
-
 
91
    uint32_t i;
-
 
92
   
86
   
93
    if (signature == MULTIBOOT_LOADER_MAGIC)
87
    if (signature == MULTIBOOT_LOADER_MAGIC)
94
        flags = mi->flags;
88
        flags = mi->flags;
95
    else {
89
    else {
96
        /* No multiboot info available. */
90
        /* No multiboot info available. */
97
        flags = 0;
91
        flags = 0;
98
    }
92
    }
99
   
93
   
100
    /* Copy module information. */
94
    /* Copy module information. */
101
   
95
    uint32_t i;
102
    if ((flags & MBINFO_FLAGS_MODS) != 0) {
96
    if ((flags & MBINFO_FLAGS_MODS) != 0) {
103
        init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS);
97
        init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS);
-
 
98
        multiboot_mod_t *mods
104
        mods = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
99
            = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
105
       
100
       
106
        for (i = 0; i < init.cnt; i++) {
101
        for (i = 0; i < init.cnt; i++) {
107
            init.tasks[i].addr = PA2KA(mods[i].start);
102
            init.tasks[i].addr = PA2KA(mods[i].start);
108
            init.tasks[i].size = mods[i].end - mods[i].start;
103
            init.tasks[i].size = mods[i].end - mods[i].start;
109
           
104
           
Line 111... Line 106...
111
            if (mods[i].string) {
106
            if (mods[i].string) {
112
                extract_command(init.tasks[i].name,
107
                extract_command(init.tasks[i].name,
113
                    CONFIG_TASK_NAME_BUFLEN,
108
                    CONFIG_TASK_NAME_BUFLEN,
114
                    MULTIBOOT_PTR(mods[i].string));
109
                    MULTIBOOT_PTR(mods[i].string));
115
            } else
110
            } else
116
                init.tasks[i].name[0] = '\0';
111
                init.tasks[i].name[0] = 0;
117
        }
112
        }
118
    } else
113
    } else
119
        init.cnt = 0;
114
        init.cnt = 0;
120
   
115
   
121
    /* Copy memory map. */
116
    /* Copy memory map. */
122
   
117
   
123
    int32_t mmap_length;
-
 
124
    multiboot_mmap_t *mme;
-
 
125
    uint32_t size;
-
 
126
   
-
 
127
    if ((flags & MBINFO_FLAGS_MMAP) != 0) {
118
    if ((flags & MBINFO_FLAGS_MMAP) != 0) {
128
        mmap_length = mi->mmap_length;
119
        int32_t mmap_length = mi->mmap_length;
129
        mme = MULTIBOOT_PTR(mi->mmap_addr);
120
        multiboot_mmap_t *mme = MULTIBOOT_PTR(mi->mmap_addr);
130
        e820counter = 0;
121
        e820counter = 0;
131
       
122
       
132
        i = 0;
123
        i = 0;
133
        while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) {
124
        while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) {
134
            e820table[i++] = mme->mm_info;
125
            e820table[i++] = mme->mm_info;
135
           
126
           
136
            /* Compute address of next structure. */
127
            /* Compute address of next structure. */
137
            size = sizeof(mme->size) + mme->size;
128
            uint32_t size = sizeof(mme->size) + mme->size;
138
            mme = ((void *) mme) + size;
129
            mme = ((void *) mme) + size;
139
            mmap_length -= size;
130
            mmap_length -= size;
140
        }
131
        }
141
       
132
       
142
        e820counter = i;
133
        e820counter = i;