Subversion Repositories HelenOS

Rev

Rev 4012 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3984 svoboda 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 ia32
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
#include <main/main.h>
36
#include <arch/boot/boot.h>
37
#include <arch/boot/cboot.h>
38
#include <arch/boot/memmap.h>
39
#include <config.h>
40
#include <memstr.h>
4011 svoboda 41
#include <string.h>
4012 svoboda 42
#include <macros.h>
3984 svoboda 43
 
44
/* This is a symbol so the type is only dummy. Obtain the value using &. */
45
extern int _hardcoded_unmapped_size;
46
 
4012 svoboda 47
/** Extract command name from the multiboot module command line.
48
 *
4014 decky 49
 * @param buf      Destination buffer (will always null-terminate).
50
 * @param n        Size of destination buffer.
51
 * @param cmd_line Input string (the command line).
52
 *
4012 svoboda 53
 */
54
static void extract_command(char *buf, size_t n, const char *cmd_line)
55
{
56
    const char *start, *end, *cp;
57
    size_t max_len;
4014 decky 58
 
4012 svoboda 59
    /* Find the first space. */
60
    end = strchr(cmd_line, ' ');
4014 decky 61
    if (end == NULL)
62
        end = cmd_line + strlen(cmd_line);
63
 
4012 svoboda 64
    /*
65
     * Find last occurence of '/' before 'end'. If found, place start at
66
     * next character. Otherwise, place start at beginning of buffer.
67
     */
68
    cp = end;
69
    start = buf;
70
    while (cp != start) {
71
        if (*cp == '/') {
72
            start = cp + 1;
73
            break;
74
        }
75
        --cp;
76
    }
4014 decky 77
 
4012 svoboda 78
    /* Copy the command and null-terminate the string. */
79
    max_len = min(n - 1, (size_t) (end - start));
80
    strncpy(buf, start, max_len + 1);
81
    buf[max_len] = '\0';
82
}
83
 
3984 svoboda 84
/** C part of ia32 boot sequence.
4014 decky 85
 *
86
 * @param signature Should contain the multiboot signature.
87
 * @param mi        Pointer to the multiboot information structure.
3984 svoboda 88
 */
89
void ia32_cboot(uint32_t signature, const mb_info_t *mi)
90
{
91
    uint32_t flags;
92
    mb_mod_t *mods;
93
    uint32_t i;
4014 decky 94
 
95
    if (signature == MULTIBOOT_LOADER_MAGIC)
3985 svoboda 96
        flags = mi->flags;
4014 decky 97
    else {
3985 svoboda 98
        /* No multiboot info available. */
99
        flags = 0;
100
    }
4014 decky 101
 
3984 svoboda 102
    /* Copy module information. */
4014 decky 103
 
3984 svoboda 104
    if ((flags & MBINFO_FLAGS_MODS) != 0) {
105
        init.cnt = mi->mods_count;
106
        mods = mi->mods_addr;
4014 decky 107
 
3984 svoboda 108
        for (i = 0; i < init.cnt; i++) {
109
            init.tasks[i].addr = mods[i].start + 0x80000000;
110
            init.tasks[i].size = mods[i].end - mods[i].start;
4014 decky 111
 
3987 svoboda 112
            /* Copy command line, if available. */
113
            if (mods[i].string) {
4012 svoboda 114
                extract_command(init.tasks[i].name,
115
                    CONFIG_TASK_NAME_BUFLEN,
116
                    mods[i].string);
4014 decky 117
            } else
3987 svoboda 118
                init.tasks[i].name[0] = '\0';
3984 svoboda 119
        }
4014 decky 120
    } else
3984 svoboda 121
        init.cnt = 0;
4014 decky 122
 
3984 svoboda 123
    /* Copy memory map. */
4014 decky 124
 
3984 svoboda 125
    int32_t mmap_length;
126
    mb_mmap_t *mme;
127
    uint32_t size;
4014 decky 128
 
3984 svoboda 129
    if ((flags & MBINFO_FLAGS_MMAP) != 0) {
130
        mmap_length = mi->mmap_length;
131
        mme = mi->mmap_addr;
132
        e820counter = 0;
4014 decky 133
 
3984 svoboda 134
        i = 0;
135
        while (mmap_length > 0) {
136
            e820table[i++] = mme->mm_info;
4014 decky 137
 
3984 svoboda 138
            /* Compute address of next structure. */
139
            size = sizeof(mme->size) + mme->size;
140
            mme = ((void *) mme) + size;
141
            mmap_length -= size;
142
        }
4014 decky 143
 
3984 svoboda 144
        e820counter = i;
4014 decky 145
    } else
3984 svoboda 146
        e820counter = 0;
4014 decky 147
 
3984 svoboda 148
#ifdef CONFIG_SMP
149
    /* Copy AP bootstrap routines below 1 MB. */
150
    memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
151
        (size_t) &_hardcoded_unmapped_size);
152
#endif
4014 decky 153
 
3984 svoboda 154
    main_bsp();
155
}
156
 
157
/** @}
158
 */