blob: cfe39b23a491f22b14ce6105b3a960eba35f8098 [file] [log] [blame]
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <compiler.h>
#include <debug.h>
#include <string.h>
#include <arch.h>
#include <platform.h>
#include <target.h>
#include <project.h>
#include <lib/heap.h>
#include <kernel/thread.h>
#include <kernel/timer.h>
#include <kernel/dpc.h>
extern void *__ctor_list;
extern void *__ctor_end;
extern int __bss_start;
extern int _end;
static int bootstrap2(void *arg);
static void call_constructors(void)
{
void **ctor;
ctor = &__ctor_list;
while(ctor != &__ctor_end) {
void (*func)(void);
func = (void (*)())*ctor;
func();
ctor++;
}
}
/* called from crt0.S */
void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE;
void kmain(void)
{
// early arch stuff
arch_early_init();
// do any super early platform initialization
platform_early_init();
// do any super early target initialization
target_early_init();
dprintf("welcome to lk\n\n");
// deal with any static constructors
dprintf("calling constructors\n");
call_constructors();
// bring up the kernel heap
dprintf("initializing heap\n");
heap_init();
// initialize the threading system
dprintf("initializing threads\n");
thread_init();
// initialize the dpc system
dprintf("initializing dpc\n");
dpc_init();
// initialize kernel timers
dprintf("initializing timers\n");
timer_init();
// create a thread to complete system initialization
dprintf("creating bootstrap completion thread\n");
thread_resume(thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
// enable interrupts
exit_critical_section();
// become the idle thread
thread_become_idle();
}
int main(void);
static int bootstrap2(void *arg)
{
dprintf("top of bootstrap2()\n");
arch_init();
// initialize the rest of the platform
dprintf("initializing rest of platform\n");
platform_init();
// initialize the rest of the target
dprintf("initializing rest of target\n");
target_init();
dprintf("calling project_init()\n");
project_init();
return 0;
}