summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Private/EFIKit/EFILib.hxx15
-rw-r--r--Private/KernelKit/FileManager.hpp289
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx25
-rw-r--r--Private/NewBoot/BootKit/Platform.hxx (renamed from Private/NewBoot/BootKit/Processor.hxx)0
-rw-r--r--Private/NewBoot/BootKit/compile_flags.txt2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootKit.cxx12
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx6
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Platform.cxx2
-rw-r--r--Private/Source/PermissionSelector.cxx2
-rw-r--r--Private/Source/ThreadLocalStorage.cxx2
10 files changed, 182 insertions, 173 deletions
diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx
index eac2c618..3f441a76 100644
--- a/Private/EFIKit/EFILib.hxx
+++ b/Private/EFIKit/EFILib.hxx
@@ -12,6 +12,8 @@
#include <EFIKit/EFI.hxx>
+#include "NewKit/Defines.hpp"
+
inline EfiSystemTable* ST = nullptr;
inline EfiBootServices* BS = nullptr;
@@ -26,7 +28,16 @@ inline Void Stop(EfiSystemTable* SystemTable) noexcept {
rt_halt();
}
}
-} // namespace Detail
+
+/**
+@brief Exit EFI API to let the OS load correctly.
+Bascially frees everything we have in the EFI side.
+*/
+inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey,
+ EfiHandlePtr ImageHandle) noexcept {
+ SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey);
+}
+} // namespace EFI
inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept {
ST = SystemTable;
@@ -47,7 +58,7 @@ inline void KeRuntimeStop(const EfiCharType* File,
}
#ifdef __BOOTLOADER__
-#include <BootKit/Processor.hxx>
+#include <BootKit/Platform.hxx>
#endif // IF TARGET=BOOTLOADER
#endif /* ifndef __EFI_LIB__ */
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp
index ef508393..1d7c33b2 100644
--- a/Private/KernelKit/FileManager.hpp
+++ b/Private/KernelKit/FileManager.hpp
@@ -10,70 +10,65 @@
#pragma once
#include <FSKit/NewFS.hxx>
-#include <NewKit/Ref.hpp>
-#include <NewKit/Stream.hpp>
-
#include <NewKit/ErrorID.hpp>
#include <NewKit/Ref.hpp>
+#include <NewKit/Stream.hpp>
/// Main filesystem abstraction manager.
-#define kBootFolder "/boot"
-#define kBinFolder "/bin"
-#define kShLibsFolder "/lib"
+#define kBootFolder "/Boot"
+#define kBinFolder "/Programs"
+#define kShLibsFolder "/Library"
#define kSectorSz 512
/// refer to first enum.
#define kFileOpsCount 4
-namespace HCore
-{
-enum
-{
- kFileWriteAll = 100,
- kFileReadAll = 101,
- kFileReadChunk = 102,
- kFileWriteChunk = 103,
+namespace HCore {
+enum {
+ kFileWriteAll = 100,
+ kFileReadAll = 101,
+ kFileReadChunk = 102,
+ kFileWriteChunk = 103,
};
typedef VoidPtr NodePtr;
-class IFilesystemManager
-{
- public:
- IFilesystemManager() = default;
- virtual ~IFilesystemManager() = default;
+class IFilesystemManager {
+ public:
+ IFilesystemManager() = default;
+ virtual ~IFilesystemManager() = default;
- public:
- HCORE_COPY_DEFAULT(IFilesystemManager);
+ public:
+ HCORE_COPY_DEFAULT(IFilesystemManager);
- public:
- static bool Mount(IFilesystemManager *pMount);
- static IFilesystemManager *Unmount();
- static IFilesystemManager *GetMounted();
+ public:
+ static bool Mount(IFilesystemManager *pMount);
+ static IFilesystemManager *Unmount();
+ static IFilesystemManager *GetMounted();
- public:
- virtual NodePtr Create(const char *path) = 0;
- virtual NodePtr CreateAlias(const char *path) = 0;
- virtual NodePtr CreateDirectory(const char *path) = 0;
+ public:
+ virtual NodePtr Create(const char *path) = 0;
+ virtual NodePtr CreateAlias(const char *path) = 0;
+ virtual NodePtr CreateDirectory(const char *path) = 0;
- public:
- virtual bool Remove(const char *path) = 0;
+ public:
+ virtual bool Remove(const char *path) = 0;
- public:
- virtual NodePtr Open(const char *path, const char *r) = 0;
+ public:
+ virtual NodePtr Open(const char *path, const char *r) = 0;
- public:
- virtual void Write(NodePtr node, VoidPtr data, Int32 flags) = 0;
- virtual VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) = 0;
+ public:
+ virtual void Write(NodePtr node, VoidPtr data, Int32 flags) = 0;
+ virtual VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) = 0;
- public:
- virtual bool Seek(NodePtr node, SizeT off) = 0;
+ public:
+ virtual bool Seek(NodePtr node, SizeT off) = 0;
- public:
- virtual SizeT Tell(NodePtr node) = 0;
- virtual bool Rewind(NodePtr node) = 0;
+ public:
+ virtual SizeT Tell(NodePtr node) = 0;
+ virtual bool Rewind(NodePtr node) = 0;
};
#define kNPos (SizeT)0xFFFFFF;
@@ -81,74 +76,62 @@ class IFilesystemManager
/**
* @brief Child of IFilesystemManager, takes care of managing NewFS disks.
*/
-class NewFilesystemManager final : public IFilesystemManager
-{
- public:
- explicit NewFilesystemManager();
- ~NewFilesystemManager() override;
+class NewFilesystemManager final : public IFilesystemManager {
+ public:
+ explicit NewFilesystemManager();
+ ~NewFilesystemManager() override;
- public:
- HCORE_COPY_DEFAULT(NewFilesystemManager);
+ public:
+ HCORE_COPY_DEFAULT(NewFilesystemManager);
- public:
- NodePtr Create(const char *path) override;
- NodePtr CreateAlias(const char *path) override;
- NodePtr CreateDirectory(const char *path) override;
+ public:
+ NodePtr Create(const char *path) override;
+ NodePtr CreateAlias(const char *path) override;
+ NodePtr CreateDirectory(const char *path) override;
- public:
- bool Remove(const char *node) override;
+ public:
+ bool Remove(const char *node) override;
- public:
- NodePtr Open(const char *path, const char *r) override
- {
- if (!path || *path == 0)
- return nullptr;
+ public:
+ NodePtr Open(const char *path, const char *r) override {
+ if (!path || *path == 0) return nullptr;
- if (!r || *r == 0)
- return nullptr;
+ if (!r || *r == 0) return nullptr;
- return this->Open(path, r);
- }
+ return this->Open(path, r);
+ }
- public:
- Void Write(NodePtr node, VoidPtr data, Int32 flags) override
- {
- this->Write(node, data, flags);
- }
+ public:
+ Void Write(NodePtr node, VoidPtr data, Int32 flags) override {
+ this->Write(node, data, flags);
+ }
- VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override
- {
- return this->Read(node, flags, sz);
- }
+ VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override {
+ return this->Read(node, flags, sz);
+ }
- public:
- bool Seek(NodePtr node, SizeT off) override
- {
- if (!node || off == 0)
- return false;
+ public:
+ bool Seek(NodePtr node, SizeT off) override {
+ if (!node || off == 0) return false;
- return this->Seek(node, off);
- }
+ return this->Seek(node, off);
+ }
- public:
- SizeT Tell(NodePtr node) override
- {
- if (!node)
- return kNPos;
+ public:
+ SizeT Tell(NodePtr node) override {
+ if (!node) return kNPos;
- return this->Tell(node);
- }
+ return this->Tell(node);
+ }
- bool Rewind(NodePtr node) override
- {
- if (!node)
- return false;
+ bool Rewind(NodePtr node) override {
+ if (!node) return false;
- return this->Seek(node, 0);
- }
+ return this->Seek(node, 0);
+ }
- public:
- NewFSImpl *fIO{nullptr};
+ public:
+ NewFSImpl *fIO{nullptr};
};
/**
@@ -156,92 +139,80 @@ class NewFilesystemManager final : public IFilesystemManager
* @tparam Encoding file encoding (char, wchar_t...)
* @tparam FSClass Filesystem contract who takes care of it.
*/
-template <typename Encoding = char, typename FSClass = NewFilesystemManager> class FileStream final
-{
- public:
- explicit FileStream(const Encoding *path);
- ~FileStream();
-
- public:
- FileStream &operator=(const FileStream &);
- FileStream(const FileStream &);
-
- public:
- ErrorOr<Int64> WriteAll(const VoidPtr data) noexcept
- {
- if (data == nullptr)
- return ErrorOr<Int64>(H_INVALID_DATA);
-
- auto man = FSClass::GetMounted();
-
- if (man)
- {
- man->Write(fFile, data, kFileWriteAll);
- return ErrorOr<Int64>(0);
- }
-
- return ErrorOr<Int64>(H_INVALID_DATA);
+template <typename Encoding = char, typename FSClass = NewFilesystemManager>
+class FileStream final {
+ public:
+ explicit FileStream(const Encoding *path);
+ ~FileStream();
+
+ public:
+ FileStream &operator=(const FileStream &);
+ FileStream(const FileStream &);
+
+ public:
+ ErrorOr<Int64> WriteAll(const VoidPtr data) noexcept {
+ if (data == nullptr) return ErrorOr<Int64>(H_INVALID_DATA);
+
+ auto man = FSClass::GetMounted();
+
+ if (man) {
+ man->Write(fFile, data, kFileWriteAll);
+ return ErrorOr<Int64>(0);
}
- VoidPtr ReadAll() noexcept
- {
- auto man = FSClass::GetMounted();
+ return ErrorOr<Int64>(H_INVALID_DATA);
+ }
- if (man)
- {
- VoidPtr ret = man->Read(fFile, kFileReadAll, 0);
- return ret;
- }
+ VoidPtr ReadAll() noexcept {
+ auto man = FSClass::GetMounted();
- return nullptr;
+ if (man) {
+ VoidPtr ret = man->Read(fFile, kFileReadAll, 0);
+ return ret;
}
- voidPtr Read(SizeT offset, SizeT sz)
- {
- auto man = FSClass::GetMounted();
+ return nullptr;
+ }
- if (man)
- {
- man->Seek(fFile, offset);
- auto ret = man->Read(fFile, kFileReadChunk, sz);
+ voidPtr Read(SizeT offset, SizeT sz) {
+ auto man = FSClass::GetMounted();
- return ret;
- }
+ if (man) {
+ man->Seek(fFile, offset);
+ auto ret = man->Read(fFile, kFileReadChunk, sz);
- return nullptr;
+ return ret;
}
- void Write(SizeT offset, voidPtr data, SizeT sz)
- {
- auto man = FSClass::GetMounted();
+ return nullptr;
+ }
- if (man)
- {
- man->Seek(fFile, offset);
- man->Write(fFile, data, sz, kFileReadChunk);
- }
- }
+ void Write(SizeT offset, voidPtr data, SizeT sz) {
+ auto man = FSClass::GetMounted();
- public:
- char *MIME() noexcept
- {
- return const_cast<char *>(fMime);
+ if (man) {
+ man->Seek(fFile, offset);
+ man->Write(fFile, data, sz, kFileReadChunk);
}
+ }
- private:
- NodePtr fFile;
- const Char *fMime{"application-type/*"};
+ public:
+ char *MIME() noexcept { return const_cast<char *>(fMime); }
+
+ private:
+ NodePtr fFile;
+ const Char *fMime{"application-type/*"};
};
using FileStreamUTF8 = FileStream<char>;
using FileStreamUTF16 = FileStream<wchar_t>;
template <typename Encoding, typename Class>
-FileStream<Encoding, Class>::FileStream(const Encoding *path) : fFile(Class::GetMounted()->Open(path, "r+"))
-{
-}
+FileStream<Encoding, Class>::FileStream(const Encoding *path)
+ : fFile(Class::GetMounted()->Open(path, "r+")) {}
-template <typename Encoding, typename Class> FileStream<Encoding, Class>::~FileStream() = default;
-} // namespace HCore
+template <typename Encoding, typename Class>
+FileStream<Encoding, Class>::~FileStream() = default;
+} // namespace HCore
#define node_cast(PTR) reinterpret_cast<HCore::NodePtr>(PTR)
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 9c0ec863..e4c14d3a 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -31,16 +31,15 @@ typedef wchar_t CharacterType;
/**
* @brief BootKit Text Writer class
- * Writes to VGA.
+ * Writes to UEFI StdOut.
*/
class BTextWriter final {
public:
- void WriteString(const CharacterType *str);
-
- void WriteCharacter(CharacterType c);
+ BTextWriter &WriteString(const CharacterType *str);
+ BTextWriter &WriteCharacter(CharacterType c);
public:
- BTextWriter() = default;
+ explicit BTextWriter() = default;
~BTextWriter() = default;
public:
@@ -51,9 +50,23 @@ class BTextWriter final {
HCore::SizeT BStrLen(const char *ptr);
HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len);
+/**
+ * @brief BootKit File Reader class
+ * Reads using the UEFI Simple File protocol.
+ */
+class BFileReader final {
+ public:
+ explicit BFileReader() = default;
+ ~BFileReader() = default;
+
+ public:
+ BFileReader &operator=(const BFileReader &) = default;
+ BFileReader(const BFileReader &) = default;
+};
+
/***********************************************************************************/
/// Include other APIs.
/***********************************************************************************/
-#include <BootKit/Processor.hxx>
+#include <BootKit/Platform.hxx>
#include <BootKit/Protocol.hxx>
diff --git a/Private/NewBoot/BootKit/Processor.hxx b/Private/NewBoot/BootKit/Platform.hxx
index d4143094..d4143094 100644
--- a/Private/NewBoot/BootKit/Processor.hxx
+++ b/Private/NewBoot/BootKit/Platform.hxx
diff --git a/Private/NewBoot/BootKit/compile_flags.txt b/Private/NewBoot/BootKit/compile_flags.txt
new file mode 100644
index 00000000..45e268ea
--- /dev/null
+++ b/Private/NewBoot/BootKit/compile_flags.txt
@@ -0,0 +1,2 @@
+-std=c++20
+-I../
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx
index 19df55b0..b59c0140 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx
@@ -10,7 +10,7 @@
#include <BootKit/BootKit.hxx>
#include <EFIKit/EFILib.hxx>
-#include "EFIKit/EFI.hxx"
+/// bugs 0
HCore::SizeT BStrLen(const char *ptr) {
long long int cnt = 0;
@@ -41,18 +41,22 @@ HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len) {
/**
@brief puts wrapper over VGA.
*/
-void BTextWriter::WriteString(const CharacterType *str) {
- if (*str == 0 || !str) return;
+BTextWriter &BTextWriter::WriteString(const CharacterType *str) {
+ if (*str == 0 || !str) return *this;
ST->ConOut->OutputString(ST->ConOut, str);
+
+ return *this;
}
/**
@brief putc wrapper over VGA.
*/
-void BTextWriter::WriteCharacter(CharacterType c) {
+BTextWriter &BTextWriter::WriteCharacter(CharacterType c) {
EfiCharType str[2];
str[0] = c;
str[1] = 0;
ST->ConOut->OutputString(ST->ConOut, str);
+
+ return *this;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
index 89b3ece2..862226c2 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
@@ -19,10 +19,14 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
KeInitEFI(SystemTable);
BTextWriter writer;
- writer.WriteString(L"HCoreLdr: Booting from disk...\r\n");
+ writer.WriteString(L"HCoreLdr: Booting from disk...").WriteString(L"\r\n");
+
+ UInt64 mapKey = 0;
// TODO: Jump Code
+ EFI::ExitBootServices(SystemTable, mapKey, ImageHandle);
EFI::Stop(SystemTable);
+
return kEfiOk;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
index f72e0be1..729320b8 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
@@ -14,7 +14,7 @@
*
*/
-#include <BootKit/Processor.hxx>
+#include <BootKit/Platform.hxx>
extern "C" void rt_halt(void) { asm volatile("hlt"); }
diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx
index 299a35a6..a0d5fecf 100644
--- a/Private/Source/PermissionSelector.cxx
+++ b/Private/Source/PermissionSelector.cxx
@@ -13,6 +13,8 @@
#include <KernelKit/PermissionSelector.hxx>
#include <NewKit/RuntimeCheck.hpp>
+/// bugs 0
+
namespace HCore {
PermissionSelector::PermissionSelector(const Int32 &sel)
: fRing((RingKind)sel) {
diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx
index eee4f820..a9770590 100644
--- a/Private/Source/ThreadLocalStorage.cxx
+++ b/Private/Source/ThreadLocalStorage.cxx
@@ -10,6 +10,8 @@
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/ThreadLocalStorage.hxx>
+/// bugs 0
+
/***********************************************************************************/
/// @file ThreadLocalStorage.cxx
/// @brief TLS implementation in kernel.