diff options
| author | Alexey Gavrilov <rebovas@yahoo.com> | 2024-03-06 15:32:17 +0700 |
|---|---|---|
| committer | Alexey Gavrilov <rebovas@yahoo.com> | 2024-03-06 15:32:17 +0700 |
| commit | 244a9154e42a49470bd28e3a95ebe9f4a5fe5ff7 (patch) | |
| tree | 4999e8c789a036511a1b6bbaec594b712bb1f64a | |
| parent | 1af53b431da6d3b5dcf7132f98f9eb2af88b57fa (diff) | |
Initialization mechanism
| -rw-r--r-- | arch/SecondaryInit.cpp | 11 | ||||
| -rw-r--r-- | arch/SecondaryInit.h | 9 | ||||
| -rw-r--r-- | arch/x86/PrimaryInit.cpp | 16 | ||||
| -rw-r--r-- | arch/x86/PrimaryInit.h | 12 | ||||
| -rwxr-xr-x | arch/x86/gdt/Gdt.cpp | 2 | ||||
| -rw-r--r-- | arch/x86/gdt/GlobalObj.cpp | 6 | ||||
| -rw-r--r-- | arch/x86/gdt/GlobalObj.h | 11 | ||||
| -rw-r--r-- | arch/x86/gdt/GoToGdtMemSeg.s | 13 | ||||
| -rw-r--r-- | arch/x86/io/GlobalObj.cpp | 3 | ||||
| -rw-r--r-- | arch/x86/io/GlobalObj.h | 8 | ||||
| -rw-r--r-- | arch/x86/io/VGADisplay.cpp | 2 | ||||
| -rw-r--r-- | arch/x86/io/VGADisplay.h | 8 | ||||
| -rwxr-xr-x | kernel/GlobalConstruct.cpp | 15 | ||||
| -rwxr-xr-x | kernel/GlobalConstruct.h | 14 | ||||
| -rw-r--r-- | kernel/kernel.c | 13 | ||||
| -rw-r--r-- | makefile | 2 |
16 files changed, 68 insertions, 77 deletions
diff --git a/arch/SecondaryInit.cpp b/arch/SecondaryInit.cpp new file mode 100644 index 0000000..900f84b --- /dev/null +++ b/arch/SecondaryInit.cpp @@ -0,0 +1,11 @@ +#include "SecondaryInit.h" + +void SecondaryInitialization::processorInitialize() +{ + PrimaryInitialization::processorInitialize(); +}; + +void SecondaryInitialization::devicesInitialize() +{ + PrimaryInitialization::devicesInitialize(); +}; diff --git a/arch/SecondaryInit.h b/arch/SecondaryInit.h new file mode 100644 index 0000000..f9aa5be --- /dev/null +++ b/arch/SecondaryInit.h @@ -0,0 +1,9 @@ +#include "x86/PrimaryInit.h" + +class SecondaryInitialization : protected PrimaryInitialization +{ + public: + void processorInitialize() override final; + void devicesInitialize() override final; +}; + diff --git a/arch/x86/PrimaryInit.cpp b/arch/x86/PrimaryInit.cpp new file mode 100644 index 0000000..7de690e --- /dev/null +++ b/arch/x86/PrimaryInit.cpp @@ -0,0 +1,16 @@ +#include "PrimaryInit.h" + + +void PrimaryInitialization::processorInitialize() +{ + MngGdt mngGdt = MngGdt(); + + mngGdt.addDescriptor(DescSeg32::flatCodeKernel()); + mngGdt.addDescriptor(DescSeg32::flatDataKernel()); + mngGdt.loadGdt(); +}; + +void PrimaryInitialization::devicesInitialize() +{ + out::display = VGADisplay(); +}; diff --git a/arch/x86/PrimaryInit.h b/arch/x86/PrimaryInit.h new file mode 100644 index 0000000..8d16549 --- /dev/null +++ b/arch/x86/PrimaryInit.h @@ -0,0 +1,12 @@ +#include "gdt/Gdt.h" +#include "io/VGADisplay.h" + + +#define x86_ARCH + +class PrimaryInitialization +{ + protected: + virtual void processorInitialize(); + virtual void devicesInitialize(); +}; diff --git a/arch/x86/gdt/Gdt.cpp b/arch/x86/gdt/Gdt.cpp index 80fcd13..21941b4 100755 --- a/arch/x86/gdt/Gdt.cpp +++ b/arch/x86/gdt/Gdt.cpp @@ -1,6 +1,8 @@ #include "Gdt.h" +uint64 MngGdt::gdt[MngGdt::size]; + DescSeg32::DescSeg32(uint32 base, uint32 limit, uint8 access, uint8 flags) { this->baseLow = base & 0x0000FFFF; diff --git a/arch/x86/gdt/GlobalObj.cpp b/arch/x86/gdt/GlobalObj.cpp deleted file mode 100644 index fbceeef..0000000 --- a/arch/x86/gdt/GlobalObj.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "GlobalObj.h" - - -uint64 MngGdt::gdt[MngGdt::size]; - -MngGdt mngGdt; diff --git a/arch/x86/gdt/GlobalObj.h b/arch/x86/gdt/GlobalObj.h deleted file mode 100644 index 3c62847..0000000 --- a/arch/x86/gdt/GlobalObj.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef GDTGLOBALOBJ_H -#define GDTGLOBALOBJ_H - -#include <types.h> -#include "Gdt.h" - -extern MngGdt mngGdt; - -void mngGdtInit(); - -#endif diff --git a/arch/x86/gdt/GoToGdtMemSeg.s b/arch/x86/gdt/GoToGdtMemSeg.s deleted file mode 100644 index 2b5dd62..0000000 --- a/arch/x86/gdt/GoToGdtMemSeg.s +++ /dev/null @@ -1,13 +0,0 @@ -global GOTOGDTMEMSEG -GOTOGDTMEMSEG: - lgdt [esp + 4] - jmp 0x08:.reloadCS -.reloadCS: - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - ret -.end: diff --git a/arch/x86/io/GlobalObj.cpp b/arch/x86/io/GlobalObj.cpp deleted file mode 100644 index a1c4f03..0000000 --- a/arch/x86/io/GlobalObj.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "VGADisplay.h" - -VGADisplay display; diff --git a/arch/x86/io/GlobalObj.h b/arch/x86/io/GlobalObj.h deleted file mode 100644 index 72c6b06..0000000 --- a/arch/x86/io/GlobalObj.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef GLOBALOBJ_H -#define GLOBALOBJ_H - -#include "VGADisplay.h" - -extern VGADisplay display; - -#endif diff --git a/arch/x86/io/VGADisplay.cpp b/arch/x86/io/VGADisplay.cpp index 0cd0bed..ceb4862 100644 --- a/arch/x86/io/VGADisplay.cpp +++ b/arch/x86/io/VGADisplay.cpp @@ -1,5 +1,7 @@ #include "VGADisplay.h" +VGADisplay out::display; + VGADisplay::VGADisplay() { isBright = isBlink = shift = 0; diff --git a/arch/x86/io/VGADisplay.h b/arch/x86/io/VGADisplay.h index db4c4df..326ae95 100644 --- a/arch/x86/io/VGADisplay.h +++ b/arch/x86/io/VGADisplay.h @@ -36,4 +36,12 @@ class VGADisplay void setBlink(bool blinkAttr); void setBright(bool brigthAttr); }; + +// Global variables + +namespace out +{ + extern VGADisplay display; +}; + #endif diff --git a/kernel/GlobalConstruct.cpp b/kernel/GlobalConstruct.cpp deleted file mode 100755 index b16b6ae..0000000 --- a/kernel/GlobalConstruct.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "GlobalConstruct.h" - -void GlobalConstruct::terminalInit() -{ - display = VGADisplay(); -}; - -void GlobalConstruct::gdtInit() -{ - mngGdt = MngGdt(); - - mngGdt.addDescriptor(DescSeg32::flatCodeKernel()); - mngGdt.addDescriptor(DescSeg32::flatDataKernel()); - mngGdt.loadGdt(); -}; diff --git a/kernel/GlobalConstruct.h b/kernel/GlobalConstruct.h deleted file mode 100755 index 2b0a675..0000000 --- a/kernel/GlobalConstruct.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GLOBALCONSTRUCT_H -#define GLOBALCONSTRUCT_H - -#include "../arch/x86/io/GlobalObj.h" -#include "../arch/x86/gdt/GlobalObj.h" - -class GlobalConstruct -{ - public: - static void terminalInit(); - static void gdtInit(); -}; - -#endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 3d9a3cc..dfb03e4 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,12 +1,13 @@ -#include "GlobalConstruct.h" -#include <TypeConverter.h> -#include <types.h> +#include "../arch/SecondaryInit.h" #include "../arch/x86/cpuinfo/Cpuinfo.h" void main() { - GlobalConstruct::terminalInit(); - GlobalConstruct::gdtInit(); - Cpuinfo cpuinf; + SecondaryInitialization init; + + init.processorInitialize(); + init.devicesInitialize(); + + out::display << "Hello, World!\n"; }; @@ -4,7 +4,7 @@ ASM = nasm # test -O2 flag CFLAGS = -c -m32 -Wall -ffreestanding -nostdinc -nostdlib AFLAGS = -f elf32 -LDFLAGS = -m elf_i386 -L$(GCC_PATH) -lgcc +LDFLAGS = -m elf_i386 $(patsubst %,-L%,$(subst :, ,$(LIBS_PATH))) -lgcc -lstdc++ QEMUFLAGS = CFILES = $(shell find ./ -type f \( -name \*.cpp -o -name \*.c \)) |
