Subversion Repositories HelenOS

Rev

Rev 3386 | Rev 4263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3386 Rev 4153
Line 79... Line 79...
79
#include <ipc/ipc.h>
79
#include <ipc/ipc.h>
80
#include <macros.h>
80
#include <macros.h>
81
#include <adt/btree.h>
81
#include <adt/btree.h>
82
#include <smp/smp.h>
82
#include <smp/smp.h>
83
#include <ddi/ddi.h>
83
#include <ddi/ddi.h>
84
 
-
 
-
 
84
#include <main/main.h>
85
 
85
 
86
/** Global configuration structure. */
86
/** Global configuration structure. */
87
config_t config;
87
config_t config;
88
 
88
 
89
/** Initial user-space tasks */
89
/** Initial user-space tasks */
Line 103... Line 103...
103
 * These 'hardcoded' variables will be intialized by
103
 * These 'hardcoded' variables will be intialized by
104
 * the linker or the low level assembler code with
104
 * the linker or the low level assembler code with
105
 * appropriate sizes and addresses.
105
 * appropriate sizes and addresses.
106
 */
106
 */
107
 
107
 
108
/**< Virtual address of where the kernel is loaded. */
108
/** Virtual address of where the kernel is loaded. */
109
uintptr_t hardcoded_load_address = 0;
109
uintptr_t hardcoded_load_address = 0;
110
/**< Size of the kernel code in bytes. */
110
/** Size of the kernel code in bytes. */
111
size_t hardcoded_ktext_size = 0;
111
size_t hardcoded_ktext_size = 0;
112
/**< Size of the kernel data in bytes. */
112
/** Size of the kernel data in bytes. */
113
size_t hardcoded_kdata_size = 0;
113
size_t hardcoded_kdata_size = 0;
114
/**< Lowest safe stack virtual address. */
114
/** Lowest safe stack virtual address. */
115
uintptr_t stack_safe = 0;      
115
uintptr_t stack_safe = 0;      
116
 
116
 
117
void main_bsp(void);
-
 
118
void main_ap(void);
-
 
119
 
-
 
120
/*
117
/*
121
 * These two functions prevent stack from underflowing during the
118
 * These two functions prevent stack from underflowing during the
122
 * kernel boot phase when SP is set to the very top of the reserved
119
 * kernel boot phase when SP is set to the very top of the reserved
123
 * space. The stack could get corrupted by a fooled compiler-generated
120
 * space. The stack could get corrupted by a fooled compiler-generated
124
 * pop sequence otherwise.
121
 * pop sequence otherwise.
Line 189... Line 186...
189
 */
186
 */
190
void main_bsp_separated_stack(void)
187
void main_bsp_separated_stack(void)
191
{
188
{
192
    /* Keep this the first thing. */
189
    /* Keep this the first thing. */
193
    the_initialize(THE);
190
    the_initialize(THE);
194
 
-
 
195
    LOG();
-
 
196
   
191
   
197
    version_print();
192
    version_print();
198
   
193
   
199
    LOG("\nconfig.base=%#" PRIp " config.kernel_size=%" PRIs
194
    LOG("\nconfig.base=%#" PRIp " config.kernel_size=%" PRIs
200
        "\nconfig.stack_base=%#" PRIp " config.stack_size=%" PRIs,
195
        "\nconfig.stack_base=%#" PRIp " config.stack_size=%" PRIs,
201
        config.base, config.kernel_size, config.stack_base,
196
        config.base, config.kernel_size, config.stack_base,
202
        config.stack_size);
197
        config.stack_size);
203
   
198
   
204
 
-
 
-
 
199
#ifdef CONFIG_KCONSOLE
205
    /*
200
    /*
206
     * kconsole data structures must be initialized very early
201
     * kconsole data structures must be initialized very early
207
     * because other subsystems will register their respective
202
     * because other subsystems will register their respective
208
     * commands.
203
     * commands.
209
     */
204
     */
210
    LOG_EXEC(kconsole_init());
205
    LOG_EXEC(kconsole_init());
-
 
206
#endif
211
   
207
   
212
    /*
208
    /*
213
     * Exception handler initialization, before architecture
209
     * Exception handler initialization, before architecture
214
     * starts adding its own handlers
210
     * starts adding its own handlers
215
     */
211
     */
216
    LOG_EXEC(exc_init());
212
    LOG_EXEC(exc_init());
217
 
213
   
218
    /*
214
    /*
219
     * Memory management subsystems initialization.
215
     * Memory management subsystems initialization.
220
     */
216
     */
221
    LOG_EXEC(arch_pre_mm_init());
217
    LOG_EXEC(arch_pre_mm_init());
222
    LOG_EXEC(frame_init());
218
    LOG_EXEC(frame_init());
Line 250... Line 246...
250
    LOG_EXEC(futex_init());
246
    LOG_EXEC(futex_init());
251
   
247
   
252
    if (init.cnt > 0) {
248
    if (init.cnt > 0) {
253
        count_t i;
249
        count_t i;
254
        for (i = 0; i < init.cnt; i++)
250
        for (i = 0; i < init.cnt; i++)
255
            printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
251
            LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
256
                "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
252
                "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
257
                init.tasks[i].size);
253
                init.tasks[i].size);
258
    } else
254
    } else
259
        printf("No init binaries found\n");
255
        printf("No init binaries found\n");
260
   
256
   
261
    LOG_EXEC(ipc_init());
257
    LOG_EXEC(ipc_init());
262
    LOG_EXEC(klog_init());
258
    LOG_EXEC(klog_init());
-
 
259
   
-
 
260
#ifdef CONFIG_KCONSOLE
-
 
261
    LOG_EXEC(kconsole_notify_init());
-
 
262
#endif
263
 
263
   
264
    /*
264
    /*
265
     * Create kernel task.
265
     * Create kernel task.
266
     */
266
     */
267
    task_t *kernel = task_create(AS_KERNEL, "kernel");
267
    task_t *kernel = task_create(AS_KERNEL, "kernel");
268
    if (!kernel)
268
    if (!kernel)
269
        panic("Can't create kernel task\n");
269
        panic("Cannot create kernel task.");
270
   
270
   
271
    /*
271
    /*
272
     * Create the first thread.
272
     * Create the first thread.
273
     */
273
     */
-
 
274
    thread_t *kinit_thread
274
    thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit",
275
        = thread_create(kinit, NULL, kernel, 0, "kinit", true);
275
        true);
-
 
276
    if (!kinit_thread)
276
    if (!kinit_thread)
277
        panic("Can't create kinit thread\n");
277
        panic("Cannot create kinit thread.");
278
    LOG_EXEC(thread_ready(kinit_thread));
278
    LOG_EXEC(thread_ready(kinit_thread));
279
   
279
   
280
    /*
280
    /*
281
     * This call to scheduler() will return to kinit,
281
     * This call to scheduler() will return to kinit,
282
     * starting the thread of kernel threads.
282
     * starting the thread of kernel threads.
Line 326... Line 326...
326
    /*
326
    /*
327
     * If we woke kmp up before we left the kernel stack, we could
327
     * If we woke kmp up before we left the kernel stack, we could
328
     * collide with another CPU coming up. To prevent this, we
328
     * collide with another CPU coming up. To prevent this, we
329
     * switch to this cpu's private stack prior to waking kmp up.
329
     * switch to this cpu's private stack prior to waking kmp up.
330
     */
330
     */
-
 
331
    context_save(&CPU->saved_context);
331
    context_set(&CPU->saved_context, FADDR(main_ap_separated_stack),
332
    context_set(&CPU->saved_context, FADDR(main_ap_separated_stack),
332
        (uintptr_t) CPU->stack, CPU_STACK_SIZE);
333
        (uintptr_t) CPU->stack, CPU_STACK_SIZE);
333
    context_restore(&CPU->saved_context);
334
    context_restore(&CPU->saved_context);
334
    /* not reached */
335
    /* not reached */
335
}
336
}