blob: cfe39b23a491f22b14ce6105b3a960eba35f8098 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <compiler.h>
24#include <debug.h>
25#include <string.h>
26#include <arch.h>
27#include <platform.h>
28#include <target.h>
29#include <project.h>
30#include <lib/heap.h>
31#include <kernel/thread.h>
32#include <kernel/timer.h>
33#include <kernel/dpc.h>
34
35extern void *__ctor_list;
36extern void *__ctor_end;
37extern int __bss_start;
38extern int _end;
39
40static int bootstrap2(void *arg);
41
42static void call_constructors(void)
43{
44 void **ctor;
45
46 ctor = &__ctor_list;
47 while(ctor != &__ctor_end) {
48 void (*func)(void);
49
50 func = (void (*)())*ctor;
51
52 func();
53 ctor++;
54 }
55}
56
57/* called from crt0.S */
58void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
59void kmain(void)
60{
61 // early arch stuff
62 arch_early_init();
63
64 // do any super early platform initialization
65 platform_early_init();
66
67 // do any super early target initialization
68 target_early_init();
69
70 dprintf("welcome to lk\n\n");
71
72 // deal with any static constructors
73 dprintf("calling constructors\n");
74 call_constructors();
75
76 // bring up the kernel heap
77 dprintf("initializing heap\n");
78 heap_init();
79
80 // initialize the threading system
81 dprintf("initializing threads\n");
82 thread_init();
83
84 // initialize the dpc system
85 dprintf("initializing dpc\n");
86 dpc_init();
87
88 // initialize kernel timers
89 dprintf("initializing timers\n");
90 timer_init();
91
92 // create a thread to complete system initialization
93 dprintf("creating bootstrap completion thread\n");
94 thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
95
96 // enable interrupts
97 exit_critical_section();
98
99 // become the idle thread
100 thread_become_idle();
101}
102
103int main(void);
104
105static int bootstrap2(void *arg)
106{
107 dprintf("top of bootstrap2()\n");
108
109 arch_init();
110
111 // initialize the rest of the platform
112 dprintf("initializing rest of platform\n");
113 platform_init();
114
115 // initialize the rest of the target
116 dprintf("initializing rest of target\n");
117 target_init();
118
119 dprintf("calling project_init()\n");
120 project_init();
121
122 return 0;
123}
124