diff --git a/arch/arm/arm-m/start.c b/arch/arm/arm-m/start.c index b476801e..926aeb1f 100644 --- a/arch/arm/arm-m/start.c +++ b/arch/arm/arm-m/start.c @@ -28,7 +28,7 @@ extern unsigned int __data_start_rom, __data_start, __data_end; extern unsigned int __bss_start, __bss_end; -extern void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE; +extern void lk_main(void) __NO_RETURN __EXTERNALLY_VISIBLE; void _start(void) { @@ -46,5 +46,5 @@ void _start(void) while (bss != &__bss_end) *bss++ = 0; - kmain(); + lk_main(); } diff --git a/arch/arm/arm/start.S b/arch/arm/arm/start.S index de795bb1..c1b0d360 100644 --- a/arch/arm/arm/start.S +++ b/arch/arm/arm/start.S @@ -130,7 +130,7 @@ reset: strlt r2, [r0], #4 blt .L__bss_loop - bl kmain + bl lk_main b . .ltorg diff --git a/arch/x86/crt0.S b/arch/x86/crt0.S index 3eb0f077..53065a86 100644 --- a/arch/x86/crt0.S +++ b/arch/x86/crt0.S @@ -113,7 +113,7 @@ real_start: loop 2b /* call the main module */ - call kmain + call lk_main 0: /* just sit around waiting for interrupts */ hlt /* interrupts will unhalt the processor */ diff --git a/engine.mk b/engine.mk index 73803469..b5926beb 100644 --- a/engine.mk +++ b/engine.mk @@ -115,11 +115,7 @@ $(info PLATFORM = $(PLATFORM)) $(info TARGET = $(TARGET)) include arch/$(ARCH)/rules.mk -include platform/rules.mk -include target/rules.mk -include kernel/rules.mk -include dev/rules.mk -include app/rules.mk +include top/rules.mk # recursively include any modules in the MODULE variable, leaving a trail of included # modules in the ALLMODULES list diff --git a/kernel/init.c b/kernel/init.c new file mode 100644 index 00000000..2a990832 --- /dev/null +++ b/kernel/init.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 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 +#include +#include +#include +#include + +void kernel_init(void) +{ + // if enabled, configure the kernel's event log + kernel_evlog_init(); + + // initialize the threading system + dprintf(SPEW, "initializing threads\n"); + thread_init(); + + // initialize kernel timers + dprintf(SPEW, "initializing timers\n"); + timer_init(); +} + diff --git a/kernel/rules.mk b/kernel/rules.mk index b3a3256f..a6819c63 100644 --- a/kernel/rules.mk +++ b/kernel/rules.mk @@ -10,7 +10,7 @@ MODULE_DEPS := \ MODULE_SRCS := \ $(LOCAL_DIR)/debug.c \ $(LOCAL_DIR)/event.c \ - $(LOCAL_DIR)/main.c \ + $(LOCAL_DIR)/init.c \ $(LOCAL_DIR)/mutex.c \ $(LOCAL_DIR)/thread.c \ $(LOCAL_DIR)/timer.c \ diff --git a/kernel/main.c b/top/main.c similarity index 87% rename from kernel/main.c rename to top/main.c index 1c6295d0..7fcd060a 100644 --- a/kernel/main.c +++ b/top/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Travis Geiselbrecht + * Copyright (c) 2013 Travis Geiselbrecht * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files @@ -20,6 +20,11 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +/* + * Main entry point to the OS. Initializes modules in order and creates + * the default thread. + */ #include #include #include @@ -32,8 +37,6 @@ #include #include #include -#include -#include extern void *__ctor_list; extern void *__ctor_end; @@ -42,6 +45,8 @@ extern int _end; static int bootstrap2(void *arg); +extern void kernel_init(void); + static void call_constructors(void) { void **ctor; @@ -57,9 +62,9 @@ static void call_constructors(void) } } -/* called from crt0.S */ -void kmain(void) __NO_RETURN __EXTERNALLY_VISIBLE; -void kmain(void) +/* called from arch code */ +void lk_main(void) __NO_RETURN __EXTERNALLY_VISIBLE; +void lk_main(void) { inc_critical_section(); @@ -85,16 +90,8 @@ void kmain(void) dprintf(SPEW, "initializing heap\n"); heap_init(); - // if enabled, configure the kernel's event log - kernel_evlog_init(); - - // initialize the threading system - dprintf(SPEW, "initializing threads\n"); - thread_init(); - - // initialize kernel timers - dprintf(SPEW, "initializing timers\n"); - timer_init(); + // initialize the kernel + kernel_init(); // create a thread to complete system initialization dprintf(SPEW, "creating bootstrap completion thread\n"); @@ -141,3 +138,4 @@ static int bootstrap2(void *arg) return 0; } + diff --git a/top/rules.mk b/top/rules.mk new file mode 100644 index 00000000..697c4324 --- /dev/null +++ b/top/rules.mk @@ -0,0 +1,15 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) + +MODULE := $(LOCAL_DIR) + +MODULE_DEPS := \ + platform \ + target \ + app \ + dev \ + kernel + +MODULE_SRCS := \ + $(LOCAL_DIR)/main.c \ + +include make/module.mk