From 0cd3ab3fdb2ec2894bba9b223e2f60f40601607c Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Mon, 24 Apr 2017 17:47:39 +0000 Subject: [PATCH] added a main routine --- kernel/CMakeLists.txt | 4 ++-- kernel/arch/x86/pc/start.cpp | 11 ++++++++--- kernel/src/include/base.hpp | 5 +++++ kernel/src/main.cpp | 14 ++++++++++++++ kernel/src/object_init.cpp | 12 ++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 kernel/src/include/base.hpp create mode 100644 kernel/src/main.cpp create mode 100644 kernel/src/object_init.cpp diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 6f69896..4b4d196 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -30,7 +30,7 @@ LOAD_PROFILE(${ARCH} ${SYSTEM}) ADD_EXECUTABLE(kernel ${PLATFORM_SRCS} ${ISA_SRCS} ${GENERIC_SRCS}) SET(CMAKE_ASM-ATT_COMPILE_OBJECT " -g -m32 -x assembler-with-cpp -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_ASM_FLAGS} ${PLATFORM_ASM_FLAGS} -c -o ") -SET(CMAKE_C_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -std=c11 -ffreestanding -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_C_FLAGS} ${PLATFORM_C_FLAGS}") -SET(CMAKE_CXX_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -ffreestanding -fno-rtti -fno-exceptions -std=gnu++17 -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -fno-use-cxa-atexit -std=c11 -ffreestanding -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_C_FLAGS} ${PLATFORM_C_FLAGS}") +SET(CMAKE_CXX_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -fno-use-cxa-atexit -ffreestanding -fno-rtti -fno-exceptions -std=gnu++17 -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}") SET_TARGET_PROPERTIES(kernel PROPERTIES LINK_FLAGS "-T ../../kernel/${PLATFORM_LAYOUT} -N ${ISA_LINKER_FLAGS} ${PLATFORM_LINKER_FLAGS} -nostdlib -nodefaultlibs -lgcc -Wl,--gc-sections") diff --git a/kernel/arch/x86/pc/start.cpp b/kernel/arch/x86/pc/start.cpp index 8960f02..333030d 100644 --- a/kernel/arch/x86/pc/start.cpp +++ b/kernel/arch/x86/pc/start.cpp @@ -1,6 +1,11 @@ -#include +#include #include "../../../hw/pc/cgaterm/cgaterm.hpp" +CGATerm term; +void main(); extern "C" void start() { - CGATerm x = CGATerm(); - x << "Hallo!\n"; + main(); +} +void drivers_init() { + setMainTTY(&term); + --term; } diff --git a/kernel/src/include/base.hpp b/kernel/src/include/base.hpp new file mode 100644 index 0000000..927ef40 --- /dev/null +++ b/kernel/src/include/base.hpp @@ -0,0 +1,5 @@ +#pragma once +#include +#include +extern TTY *out; +void setMainTTY(Kobject *obj); diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp new file mode 100644 index 0000000..5e963f4 --- /dev/null +++ b/kernel/src/main.cpp @@ -0,0 +1,14 @@ +#include +void drivers_init(); +extern "C" void(*start_ctors)(); +extern "C" void(*end_ctors)(); +extern "C" void(*start_dtors)(); +extern "C" void(*end_dtors)(); +void main() { + for(auto ctor=&start_ctors;ctor<&end_ctors;ctor++) + (**ctor)(); + drivers_init(); + *out << "Hallo!\n"; + for(auto dtor=&start_dtors;dtor!=&end_dtors;dtor++) + (**dtor)(); +} diff --git a/kernel/src/object_init.cpp b/kernel/src/object_init.cpp new file mode 100644 index 0000000..50bc367 --- /dev/null +++ b/kernel/src/object_init.cpp @@ -0,0 +1,12 @@ +#include +TTY *out; +bool tty_set = false; +void setMainTTY(Kobject *obj) { + if(obj->type == kobjectType::TTY) { + ++*obj; + if(tty_set) + --*out; + out=(TTY*)obj; + tty_set=true; + } +}