aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt268
-rw-r--r--arch/CMakeLists.txt17
-rw-r--r--arch/include/arch/io.hpp9
-rw-r--r--arch/include/arch/memory.hpp9
-rw-r--r--arch/include/arch/system.hpp9
-rw-r--r--cmake/Platforms/x86_64.cmake1
-rw-r--r--kern/CMakeLists.txt16
-rw-r--r--kern/include/kern/error.hpp13
-rw-r--r--kern/include/kern/print.hpp26
-rw-r--r--kern/src/abort.cpp3
-rw-r--r--kern/src/error.cpp19
-rw-r--r--kern/src/main.cpp11
-rw-r--r--kern/src/print.cpp76
-rw-r--r--libs/CMakeLists.txt2
-rw-r--r--src/kernel/main.cpp9
15 files changed, 352 insertions, 136 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 75ac1b5..e10da55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,138 +22,154 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
#[============================================================================[
-# Documentation
-#]============================================================================]
-
-find_package("Doxygen")
-
-set(DOXYGEN_GENERATE_HTML YES)
-set(DOXYGEN_GENERATE_XML YES)
-set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp")
-set(DOXYGEN_OUTPUT_DIRECTORY "doxygen")
-set(DOXYGEN_QUIET YES)
-
-file(GLOB_RECURSE DOXYGEN_SOURCES CONFIGURE_DEPENDS "*.hpp")
-
-message(STATUS "${SPHINX_SOURCES}")
-
-doxygen_add_docs("docs_xml"
- ${DOXYGEN_SOURCES}
- ALL
- USE_STAMP_FILE
- COMMENT "Generating developer documentation sources"
-)
-
-set_target_properties("docs_xml" PROPERTIES
- ADDITIONAL_CLEAN_FILES
- "${PROJECT_BINARY_DIR}/doxygen"
-)
-
-file(GLOB_RECURSE SPHINX_SOURCES CONFIGURE_DEPENDS "../docs/**.rst")
-
-add_custom_target("docs" ALL
- COMMAND "${SPHINX_BUILD_EXE}"
- "../docs"
- "docs"
- "-q"
- DEPENDS "docs_xml"
- SOURCES ${SPHINX_SOURCES}
- COMMENT "Generating developer documentation html"
-)
-
-set_target_properties("docs" PROPERTIES
- ADDITIONAL_CLEAN_FILES
- "${PROJECT_BINARY_DIR}/docs"
-)
-
-#[============================================================================[
-# Global Compiler Configuration
-#]============================================================================]
-
-add_compile_options(
- "$<$<CXX_COMPILER_ID:GNU>:-Wall>"
- "$<$<CXX_COMPILER_ID:GNU>:-Wextra>"
- "$<$<CXX_COMPILER_ID:GNU>:-Werror>"
- "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>"
-)
-
-#[============================================================================[
-# Global Libraries
+# Global Build System Configuration
#]============================================================================]
-add_subdirectory("libs/kstd" EXCLUDE_FROM_ALL SYSTEM)
-add_subdirectory("libs/multiboot2" EXCLUDE_FROM_ALL SYSTEM)
+add_subdirectory("libs")
+add_subdirectory("kern")
+add_subdirectory("arch")
-#[============================================================================[
-# Global Directories
-#]============================================================================]
+add_executable("kernel")
-include_directories(
- "include"
- "arch/${CMAKE_SYSTEM_PROCESSOR}/include"
+target_link_libraries("kernel" PRIVATE
+ "kern"
+ "arch::all"
+ # "arch-${CMAKE_SYSTEM_PROCESSOR}"
)
-#[============================================================================[
-# The Bootstrap Library
-#]============================================================================]
+# #[============================================================================[
+# # Documentation
+# #]============================================================================]
-add_library("_boot" OBJECT)
-add_library("teachos::boot" ALIAS "_boot")
+# find_package("Doxygen")
-#[============================================================================[
-# The Video Library
-#]============================================================================]
-
-add_library("_video" OBJECT)
-add_library("teachos::video" ALIAS "_video")
-
-#[============================================================================[
-# THE Memory Library
-#]============================================================================]
-
-add_library("_memory" OBJECT)
-add_library("teachos::memory" ALIAS "_memory")
-
-#[============================================================================[
-# The Exception handling Library
-#]============================================================================]
-
-add_library("_exception" OBJECT)
-add_library("teachos::exception" ALIAS "_exception")
-
-#[============================================================================[
-# The Context switching Library
-#]============================================================================]
-
-add_library("_context" OBJECT)
-add_library("teachos::context_switching" ALIAS "_context")
-
-add_library("_interrupt_handling" OBJECT)
-add_library("teachos::interrupt_handling" ALIAS "_interrupt_handling")
-# https://forum.osdev.org/viewtopic.php?f=1&t=36712
-# https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-interrupt-function-attribute_002c-x86
-target_compile_options("_interrupt_handling" PRIVATE "-mgeneral-regs-only")
-
-#[============================================================================[
-# The Kernel
-#]============================================================================]
-
-add_executable("_kernel"
- "src/kernel/main.cpp"
-)
-add_executable("teachos::kernel" ALIAS "_kernel")
-
-target_link_libraries("_kernel" PRIVATE
- "teachos::boot"
- "teachos::video"
- "teachos::memory"
- "teachos::exception"
- "teachos::context_switching"
- "teachos::interrupt_handling"
-)
-
-#[============================================================================[
-# Platform Specific Components
-#]============================================================================]
+# set(DOXYGEN_GENERATE_HTML YES)
+# set(DOXYGEN_GENERATE_XML YES)
+# set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp")
+# set(DOXYGEN_OUTPUT_DIRECTORY "doxygen")
+# set(DOXYGEN_QUIET YES)
+
+# file(GLOB_RECURSE DOXYGEN_SOURCES CONFIGURE_DEPENDS "*.hpp")
-add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}")
+# message(STATUS "${SPHINX_SOURCES}")
+
+# doxygen_add_docs("docs_xml"
+# ${DOXYGEN_SOURCES}
+# ALL
+# USE_STAMP_FILE
+# COMMENT "Generating developer documentation sources"
+# )
+
+# set_target_properties("docs_xml" PROPERTIES
+# ADDITIONAL_CLEAN_FILES
+# "${PROJECT_BINARY_DIR}/doxygen"
+# )
+
+# file(GLOB_RECURSE SPHINX_SOURCES CONFIGURE_DEPENDS "../docs/**.rst")
+
+# add_custom_target("docs" ALL
+# COMMAND "${SPHINX_BUILD_EXE}"
+# "../docs"
+# "docs"
+# "-q"
+# DEPENDS "docs_xml"
+# SOURCES ${SPHINX_SOURCES}
+# COMMENT "Generating developer documentation html"
+# )
+
+# set_target_properties("docs" PROPERTIES
+# ADDITIONAL_CLEAN_FILES
+# "${PROJECT_BINARY_DIR}/docs"
+# )
+
+# #[============================================================================[
+# # Global Compiler Configuration
+# #]============================================================================]
+
+# add_compile_options(
+# "$<$<CXX_COMPILER_ID:GNU>:-Wall>"
+# "$<$<CXX_COMPILER_ID:GNU>:-Wextra>"
+# "$<$<CXX_COMPILER_ID:GNU>:-Werror>"
+# "$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>"
+# )
+
+# #[============================================================================[
+# # Global Libraries
+# #]============================================================================]
+
+# add_subdirectory("libs/kstd" EXCLUDE_FROM_ALL SYSTEM)
+# add_subdirectory("libs/multiboot2" EXCLUDE_FROM_ALL SYSTEM)
+
+# #[============================================================================[
+# # Global Directories
+# #]============================================================================]
+
+# include_directories(
+# "include"
+# "arch/${CMAKE_SYSTEM_PROCESSOR}/include"
+# )
+
+# #[============================================================================[
+# # The Bootstrap Library
+# #]============================================================================]
+
+# add_library("_boot" OBJECT)
+# add_library("teachos::boot" ALIAS "_boot")
+
+# #[============================================================================[
+# # The Video Library
+# #]============================================================================]
+
+# add_library("_video" OBJECT)
+# add_library("teachos::video" ALIAS "_video")
+
+# #[============================================================================[
+# # THE Memory Library
+# #]============================================================================]
+
+# add_library("_memory" OBJECT)
+# add_library("teachos::memory" ALIAS "_memory")
+
+# #[============================================================================[
+# # The Exception handling Library
+# #]============================================================================]
+
+# add_library("_exception" OBJECT)
+# add_library("teachos::exception" ALIAS "_exception")
+
+# #[============================================================================[
+# # The Context switching Library
+# #]============================================================================]
+
+# add_library("_context" OBJECT)
+# add_library("teachos::context_switching" ALIAS "_context")
+
+# add_library("_interrupt_handling" OBJECT)
+# add_library("teachos::interrupt_handling" ALIAS "_interrupt_handling")
+# # https://forum.osdev.org/viewtopic.php?f=1&t=36712
+# # https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-interrupt-function-attribute_002c-x86
+# target_compile_options("_interrupt_handling" PRIVATE "-mgeneral-regs-only")
+
+# #[============================================================================[
+# # The Kernel
+# #]============================================================================]
+
+# add_executable("_kernel"
+# "src/kernel/main.cpp"
+# )
+# add_executable("teachos::kernel" ALIAS "_kernel")
+
+# target_link_libraries("_kernel" PRIVATE
+# "teachos::boot"
+# "teachos::video"
+# "teachos::memory"
+# "teachos::exception"
+# "teachos::context_switching"
+# "teachos::interrupt_handling"
+# )
+
+# #[============================================================================[
+# # Platform Specific Components
+# #]============================================================================]
+
+# add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}")
diff --git a/arch/CMakeLists.txt b/arch/CMakeLists.txt
new file mode 100644
index 0000000..3bdc3c2
--- /dev/null
+++ b/arch/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_library("arch-all" INTERFACE)
+add_library("arch::all" ALIAS "arch-all")
+
+target_sources("arch-all" INTERFACE
+ FILE_SET HEADERS
+ BASE_DIRS "include"
+ FILES
+ "include/arch/io.hpp"
+ "include/arch/memory.hpp"
+ "include/arch/system.hpp"
+)
+
+target_include_directories("arch-all" INTERFACE
+ "include"
+)
+
+# add_subdirectory("${CMAKE_SYSTEM_PROCESSOR}")
diff --git a/arch/include/arch/io.hpp b/arch/include/arch/io.hpp
new file mode 100644
index 0000000..8986b9c
--- /dev/null
+++ b/arch/include/arch/io.hpp
@@ -0,0 +1,9 @@
+#ifndef TEACHOS_ARCH_IO_HPP
+#define TEACHOS_ARCH_IO_HPP
+
+namespace teachos::arch::io
+{
+ auto init() -> void;
+}
+
+#endif
diff --git a/arch/include/arch/memory.hpp b/arch/include/arch/memory.hpp
new file mode 100644
index 0000000..33f7fdd
--- /dev/null
+++ b/arch/include/arch/memory.hpp
@@ -0,0 +1,9 @@
+#ifndef TEACHOS_ARCH_MEMORY_HPP
+#define TEACHOS_ARCH_MEMORY_HPP
+
+namespace teachos::arch::memory
+{
+ auto init() -> void;
+}
+
+#endif
diff --git a/arch/include/arch/system.hpp b/arch/include/arch/system.hpp
new file mode 100644
index 0000000..73e2463
--- /dev/null
+++ b/arch/include/arch/system.hpp
@@ -0,0 +1,9 @@
+#ifndef TEACHOS_ARCH_SYSTEM_HPP
+#define TEACHOS_ARCH_SYSTEM_HPP
+
+namespace teachos::arch::system
+{
+ [[noreturn]] auto halt() -> void;
+}
+
+#endif
diff --git a/cmake/Platforms/x86_64.cmake b/cmake/Platforms/x86_64.cmake
index 29af020..c84d9ba 100644
--- a/cmake/Platforms/x86_64.cmake
+++ b/cmake/Platforms/x86_64.cmake
@@ -60,6 +60,5 @@ ${CRT_BEGIN_PATH} \
<OBJECTS> \
-o <TARGET> \
<LINK_LIBRARIES> \
--lgcc \
${CRT_END_PATH}"
)
diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt
new file mode 100644
index 0000000..b2c7e2f
--- /dev/null
+++ b/kern/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_library("kern" OBJECT
+ "src/abort.cpp"
+ "src/error.cpp"
+ "src/main.cpp"
+ "src/print.cpp"
+)
+
+target_include_directories("kern" PUBLIC
+ "include"
+)
+
+target_link_libraries("kern" PUBLIC
+ "arch::all"
+
+ "gcc"
+)
diff --git a/kern/include/kern/error.hpp b/kern/include/kern/error.hpp
new file mode 100644
index 0000000..e58b9f1
--- /dev/null
+++ b/kern/include/kern/error.hpp
@@ -0,0 +1,13 @@
+#ifndef TEACHOS_KERN_ERROR_HPP
+#define TEACHOS_KERN_ERROR_HPP
+
+#include <source_location>
+#include <string_view>
+
+namespace teachos
+{
+ [[noreturn]]
+ auto panic(std::string_view message, std::source_location = std::source_location::current()) -> void;
+}
+
+#endif
diff --git a/kern/include/kern/print.hpp b/kern/include/kern/print.hpp
new file mode 100644
index 0000000..fc9b5d6
--- /dev/null
+++ b/kern/include/kern/print.hpp
@@ -0,0 +1,26 @@
+
+#ifndef TEACHOS_KERN_PRINT_HPP
+#define TEACHOS_KERN_PRINT_HPP
+
+#include <string_view>
+
+namespace teachos
+{
+
+ using print_handler = auto(std::string_view) -> void;
+ using println_handler = auto(std::string_view) -> void;
+
+ auto print(std::string_view text) -> void;
+ auto println(std::string_view text) -> void;
+
+ auto print_error(std::string_view text) -> void;
+ auto println_error(std::string_view text) -> void;
+
+ auto set_print_handler(print_handler handler) -> print_handler *;
+ auto set_println_handler(println_handler handler) -> print_handler *;
+ auto set_print_error_handler(print_handler handler) -> print_handler *;
+ auto set_println_error_handler(println_handler handler) -> print_handler *;
+
+} // namespace teachos
+
+#endif
diff --git a/kern/src/abort.cpp b/kern/src/abort.cpp
new file mode 100644
index 0000000..6db0b74
--- /dev/null
+++ b/kern/src/abort.cpp
@@ -0,0 +1,3 @@
+#include "kern/error.hpp"
+
+extern "C" [[noreturn]] auto abort() -> void { teachos::panic("Abort called"); }
diff --git a/kern/src/error.cpp b/kern/src/error.cpp
new file mode 100644
index 0000000..a5229fd
--- /dev/null
+++ b/kern/src/error.cpp
@@ -0,0 +1,19 @@
+#include "kern/error.hpp"
+
+#include "arch/system.hpp"
+#include "kern/print.hpp"
+
+namespace teachos
+{
+
+ auto panic(std::string_view message, std::source_location location) -> void
+ {
+ println_error("!!!Kernel Panic!!! ");
+ println_error(message);
+ println_error(location.file_name());
+ println_error(location.function_name());
+
+ arch::system::halt();
+ }
+
+} // namespace teachos
diff --git a/kern/src/main.cpp b/kern/src/main.cpp
new file mode 100644
index 0000000..5e1b6ea
--- /dev/null
+++ b/kern/src/main.cpp
@@ -0,0 +1,11 @@
+#include "arch/io.hpp"
+#include "arch/memory.hpp"
+#include "kern/error.hpp"
+
+auto main() -> int
+{
+ teachos::arch::io::init();
+ teachos::arch::memory::init();
+
+ teachos::panic("Architecture specific main returned!");
+}
diff --git a/kern/src/print.cpp b/kern/src/print.cpp
new file mode 100644
index 0000000..64e2c65
--- /dev/null
+++ b/kern/src/print.cpp
@@ -0,0 +1,76 @@
+
+#include "kern/print.hpp"
+
+#include <string_view>
+
+namespace teachos
+{
+ namespace
+ {
+ print_handler * current_print_handler{};
+ println_handler * current_println_handler{};
+ print_handler * current_print_error_handler{};
+ println_handler * current_println_error_handler{};
+ } // namespace
+
+ auto print(std::string_view text) -> void
+ {
+ if (current_print_handler)
+ {
+ current_print_handler(text);
+ }
+ }
+
+ auto println(std::string_view text) -> void
+ {
+ if (current_println_handler)
+ {
+ current_println_handler(text);
+ }
+ }
+
+ auto print_error(std::string_view text) -> void
+ {
+ if (current_print_error_handler)
+ {
+ current_print_error_handler(text);
+ }
+ }
+
+ auto println_error(std::string_view text) -> void
+ {
+ if (current_println_error_handler)
+ {
+ current_println_error_handler(text);
+ }
+ }
+
+ auto set_print_handler(print_handler handler) -> print_handler *
+ {
+ auto old = current_print_handler;
+ current_print_handler = handler;
+ return old;
+ }
+
+ auto set_println_handler(println_handler handler) -> print_handler *
+ {
+ auto old = current_println_handler;
+ current_println_handler = handler;
+ return old;
+ }
+
+ auto set_print_error_handler(print_handler handler) -> print_handler *
+ {
+ auto old = current_print_error_handler;
+ current_print_error_handler = handler;
+ return old;
+ }
+
+ auto set_println_error_handler(println_handler handler) -> print_handler *
+ {
+ auto old = current_println_error_handler;
+ current_println_error_handler = handler;
+ return old;
+ }
+
+} // namespace teachos
diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt
new file mode 100644
index 0000000..b2dbf86
--- /dev/null
+++ b/libs/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory("kstd" EXCLUDE_FROM_ALL SYSTEM)
+add_subdirectory("multiboot2" EXCLUDE_FROM_ALL SYSTEM) \ No newline at end of file
diff --git a/src/kernel/main.cpp b/src/kernel/main.cpp
deleted file mode 100644
index 36c6d92..0000000
--- a/src/kernel/main.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "arch/kernel/main.hpp"
-
-#include "arch/exception_handling/panic.hpp"
-
-extern "C" auto kernel_main() -> void
-{
- teachos::arch::kernel::main();
- teachos::arch::exception_handling::panic("Architecture specific main returned!");
-}