From 1af53b431da6d3b5dcf7132f98f9eb2af88b57fa Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Tue, 5 Mar 2024 17:20:53 +0700 Subject: GDT rename procedure + edit .gitignore --- arch/x86/gdt/Gdt.cpp | 2 +- arch/x86/gdt/Gdt.h | 2 +- arch/x86/gdt/SwitchToGdt.s | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 arch/x86/gdt/SwitchToGdt.s (limited to 'arch/x86') diff --git a/arch/x86/gdt/Gdt.cpp b/arch/x86/gdt/Gdt.cpp index 88c7bbd..80fcd13 100755 --- a/arch/x86/gdt/Gdt.cpp +++ b/arch/x86/gdt/Gdt.cpp @@ -88,7 +88,7 @@ bool MngGdt::loadGdt() pointer <<= 16; pointer |= size; - GOTOGDTMEMSEG(pointer); + SWITCHTOGDT(pointer); isGdtLoaded = 1; return true; diff --git a/arch/x86/gdt/Gdt.h b/arch/x86/gdt/Gdt.h index a8d7dc2..6667d93 100755 --- a/arch/x86/gdt/Gdt.h +++ b/arch/x86/gdt/Gdt.h @@ -59,7 +59,7 @@ class DescSeg32 // Segment descriptor #ifdef __cplusplus extern "C" { #endif -extern void GOTOGDTMEMSEG(uint64 pointer); +extern void SWITCHTOGDT(uint64 pointer); #ifdef __cplusplus }; #endif diff --git a/arch/x86/gdt/SwitchToGdt.s b/arch/x86/gdt/SwitchToGdt.s new file mode 100644 index 0000000..52ebbc7 --- /dev/null +++ b/arch/x86/gdt/SwitchToGdt.s @@ -0,0 +1,13 @@ +global SWITCHTOGDT +SWITCHTOGDT: + 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: -- cgit v1.2.3 From 244a9154e42a49470bd28e3a95ebe9f4a5fe5ff7 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Wed, 6 Mar 2024 15:32:17 +0700 Subject: Initialization mechanism --- arch/SecondaryInit.cpp | 11 +++++++++++ arch/SecondaryInit.h | 9 +++++++++ arch/x86/PrimaryInit.cpp | 16 ++++++++++++++++ arch/x86/PrimaryInit.h | 12 ++++++++++++ arch/x86/gdt/Gdt.cpp | 2 ++ arch/x86/gdt/GlobalObj.cpp | 6 ------ arch/x86/gdt/GlobalObj.h | 11 ----------- arch/x86/gdt/GoToGdtMemSeg.s | 13 ------------- arch/x86/io/GlobalObj.cpp | 3 --- arch/x86/io/GlobalObj.h | 8 -------- arch/x86/io/VGADisplay.cpp | 2 ++ arch/x86/io/VGADisplay.h | 8 ++++++++ kernel/GlobalConstruct.cpp | 15 --------------- kernel/GlobalConstruct.h | 14 -------------- kernel/kernel.c | 13 +++++++------ makefile | 2 +- 16 files changed, 68 insertions(+), 77 deletions(-) create mode 100644 arch/SecondaryInit.cpp create mode 100644 arch/SecondaryInit.h create mode 100644 arch/x86/PrimaryInit.cpp create mode 100644 arch/x86/PrimaryInit.h delete mode 100644 arch/x86/gdt/GlobalObj.cpp delete mode 100644 arch/x86/gdt/GlobalObj.h delete mode 100644 arch/x86/gdt/GoToGdtMemSeg.s delete mode 100644 arch/x86/io/GlobalObj.cpp delete mode 100644 arch/x86/io/GlobalObj.h delete mode 100755 kernel/GlobalConstruct.cpp delete mode 100755 kernel/GlobalConstruct.h (limited to 'arch/x86') 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 -#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 -#include +#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"; }; diff --git a/makefile b/makefile index 5065549..d7bdcb2 100644 --- a/makefile +++ b/makefile @@ -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 \)) -- cgit v1.2.3