[kernel] move the top level kmain() out of kernel/ into top/
The kernel shouldn't really own most of the bringup of all the modules. Generally speaking the kernel can and should be treated like any other module in the system.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ reset:
|
||||
strlt r2, [r0], #4
|
||||
blt .L__bss_loop
|
||||
|
||||
bl kmain
|
||||
bl lk_main
|
||||
b .
|
||||
|
||||
.ltorg
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
42
kernel/init.c
Normal file
42
kernel/init.c
Normal file
@@ -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 <compiler.h>
|
||||
#include <debug.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/timer.h>
|
||||
#include <kernel/debug.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 <compiler.h>
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
@@ -32,8 +37,6 @@
|
||||
#include <lib/fs.h>
|
||||
#include <lib/bio.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/timer.h>
|
||||
#include <kernel/debug.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
15
top/rules.mk
Normal file
15
top/rules.mk
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user