summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-02 07:04:53 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-02 07:04:53 +0200
commitf0811b1e200293c5ccc387d866d0ad49a41bba17 (patch)
treea31adbc1d14465e08088a98f1b4b8ebd0936db16
parentd445096b8403ad0bdbf0095c50f66ba01fde9f33 (diff)
Kernel: New commit, see below.
- Implement FileManager's NewFilesystemManager. - Add ATA-DMA and ATA-PIO APIs. - Add the two raw call (fs_newfs_read_raw, fs_newfs_write_raw) to the NewFS API. - Add kPRDTTransferStatus to tell if PRD is in use. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--Private/FSKit/NewFS.hxx40
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-DMA.cxx37
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-PIO.cxx4
l---------Private/HALKit/PC1
-rw-r--r--Private/KernelKit/CodeManager.hpp8
-rw-r--r--Private/KernelKit/FileManager.hpp35
-rw-r--r--Private/KernelKit/ProcessScheduler.hpp8
-rw-r--r--Private/KernelKit/Semaphore.hpp4
-rw-r--r--Private/Source/CodeManager.cxx3
-rw-r--r--Private/Source/FileManager.cxx85
-rw-r--r--Private/Source/NewFS+IO.cxx13
-rw-r--r--Private/Source/ProcessTeam.cxx2
-rw-r--r--Private/StorageKit/PRDT.hpp5
-rw-r--r--Private/makefile22
14 files changed, 202 insertions, 65 deletions
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx
index 6b852f73..10e5e1e7 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -171,9 +171,9 @@ class NewFSParser {
HCORE_COPY_DEFAULT(NewFSParser);
public:
- virtual _Output NewFork* CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) = 0;
+ virtual _Output NewFork* CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) = 0;
- virtual _Output NewFork* FindFork(_Input NewCatalog* catalog, _Input const Char* name) = 0;
+ virtual _Output NewFork* FindFork(_Input NewCatalog* catalog, _Input const Char* name) = 0;
virtual _Output Void RemoveFork(_Input NewFork* fork) = 0;
@@ -198,8 +198,18 @@ class NewFSParser {
virtual bool WriteCatalog(_Input _Output NewCatalog* catalog,
voidPtr data) = 0;
+ virtual VoidPtr ReadCatalog(_Input _Output NewCatalog* catalog,
+ SizeT dataSz) = 0;
+
+ virtual bool Seek(_Input _Output NewCatalog* catalog,
+ SizeT off) = 0;
+
+ virtual SizeT Tell(_Input _Output NewCatalog* catalog) = 0;
+
virtual bool RemoveCatalog(_Input _Output NewCatalog* catalog) = 0;
+ virtual bool CloseCatalog(_InOut NewCatalog* catalog) = 0;
+
/// @brief Make a EPM+NewFS drive out of the disk.
/// @param drive The drive to write on.
/// @return If it was sucessful, see DbgLastError().
@@ -217,11 +227,27 @@ class NewFilesystemHelper final {
static const char* UpDir();
static const char Separator();
};
-} // namespace NewOS
enum {
- kNewFSPartGPT,
- kNewFSPartEPM,
- kNewFSPartUDF,
- kNewFSPartCount,
+ kHCFSSubDriveA,
+ kHCFSSubDriveB,
+ kHCFSSubDriveC,
+ kHCFSSubDriveD,
+ kHCFSSubDriveInvalid,
+ kHCFSSubDriveCount,
};
+
+/// @brief Write to newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Int32 fs_newfs_write_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
+
+/// @brief Read from newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Int32 fs_newfs_read_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
+} // namespace NewOS
diff --git a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
index e69de29b..4189e467 100644
--- a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
+++ b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx
@@ -0,0 +1,37 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+/**
+ * @file ATA-DMA.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief ATA driver (DMA mode).
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) Mahrouss Logic
+ *
+ */
+
+#include <StorageKit/PRDT.hpp>
+
+#include <Builtins/ATA/Defines.hxx>
+#include <ArchKit/ArchKit.hpp>
+
+using namespace NewOS;
+
+EXTERN_C Int32 kPRDTTransferStatus;
+
+#ifdef __ATA_DMA__
+
+#ifdef __ATA_PIO__
+# error You can't have both PIO and DMA enabled!
+#endif /* ifdef __ATA_PIO__ */
+
+#ifdef __AHCI__
+# error You can't have both ATA and AHCI enabled!
+#endif /* ifdef __AHCI__ */
+
+#endif /* ifdef __ATA_DMA__ */
diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
index 0f8a0d75..2344cd86 100644
--- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
+++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
@@ -18,6 +18,8 @@
#include <Builtins/ATA/Defines.hxx>
#include <ArchKit/ArchKit.hpp>
+#ifdef __ATA_PIO__
+
using namespace NewOS;
using namespace NewOS::HAL;
@@ -175,3 +177,5 @@ Void drv_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
/// @check is ATA detected?
Boolean drv_ata_detected(Void) { return kATADetected; }
+
+#endif /* ifdef __ATA_PIO__ */ \ No newline at end of file
diff --git a/Private/HALKit/PC b/Private/HALKit/PC
deleted file mode 120000
index 4af647a3..00000000
--- a/Private/HALKit/PC
+++ /dev/null
@@ -1 +0,0 @@
-AMD64/ \ No newline at end of file
diff --git a/Private/KernelKit/CodeManager.hpp b/Private/KernelKit/CodeManager.hpp
index adb37ff0..a6984cfc 100644
--- a/Private/KernelKit/CodeManager.hpp
+++ b/Private/KernelKit/CodeManager.hpp
@@ -24,9 +24,9 @@ namespace NewOS {
/// @brief Main process entrypoint.
typedef void (*MainKind)(void);
-/// @brief Executes a new process from memory.
-/// @param main
-/// @param processName
-/// @return
+/// @brief Executes a new process from a function. kernel code only.
+/// @note This sets up a new stack, anything on the main function that calls the kernel will not be accessible.
+/// @param main the start of the process.
+/// @return if the process was started or not.
bool execute_from_image(MainKind main, const char* processName);
} // namespace NewOS \ No newline at end of file
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp
index 9f7249cd..2eabd4b3 100644
--- a/Private/KernelKit/FileManager.hpp
+++ b/Private/KernelKit/FileManager.hpp
@@ -127,18 +127,10 @@ class NewFilesystemManager final : public FilesystemManagerInterface {
bool Remove(const char *node) override;
public:
- NodePtr Open(const char *path, const char *r) override {
- if (!path || *path == 0) return nullptr;
-
- if (!r || *r == 0) return nullptr;
-
- return this->Open(path, r);
- }
+ NodePtr Open(const char *path, const char *r) override;
public:
- Void Write(NodePtr node, VoidPtr data, Int32 flags) override {
- this->Write(node, data, flags);
- }
+ Void Write(NodePtr node, VoidPtr data, Int32 flags) override;
public:
/**
@@ -146,29 +138,16 @@ class NewFilesystemManager final : public FilesystemManagerInterface {
* using OpenFork.
*/
- VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override {
- return this->Read(node, flags, sz);
- }
+ VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override;
public:
- bool Seek(NodePtr node, SizeT off) override {
- if (!node || off == 0) return false;
-
- return this->Seek(node, off);
- }
-
+ bool Seek(NodePtr node, SizeT off);
public:
- SizeT Tell(NodePtr node) override {
- if (!node) return kNPos;
- return this->Tell(node);
- }
+ SizeT Tell(NodePtr node) override;
+ bool Rewind(NodePtr node) override;
- bool Rewind(NodePtr node) override {
- if (!node) return false;
-
- return this->Seek(node, 0);
- }
+ NewFSParser* GetImpl() noexcept;
public:
NewFSParser *fImpl{nullptr};
diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp
index c9e3b379..97ba92e3 100644
--- a/Private/KernelKit/ProcessScheduler.hpp
+++ b/Private/KernelKit/ProcessScheduler.hpp
@@ -30,10 +30,10 @@ class ProcessHeader;
class ProcessTeam;
class ProcessScheduler;
-//! @brief ProcessHeader identifier.
+//! @brief Process identifier.
typedef Int64 ProcessID;
-//! @brief ProcessHeader name length.
+//! @brief Process name length.
inline constexpr SizeT kProcessLen = 256U;
//! @brief Forward declaration.
@@ -41,7 +41,7 @@ class ProcessHeader;
class ProcessScheduler;
class ProcessHelper;
-//! @brief ProcessHeader status enum.
+//! @brief Process status enum.
enum class ProcessStatus : Int32 {
kStarting,
kRunning,
@@ -209,7 +209,7 @@ class ProcessTeam final {
Ref<ProcessHeader> mCurrentProcess;
};
-using ProcessPtr = ProcessHeader *;
+using ProcessHeaderRef = ProcessHeader *;
/// @brief ProcessHeader manager class.
/// The main class which you call to schedule an app.
diff --git a/Private/KernelKit/Semaphore.hpp b/Private/KernelKit/Semaphore.hpp
index 0e41aa49..7324093e 100644
--- a/Private/KernelKit/Semaphore.hpp
+++ b/Private/KernelKit/Semaphore.hpp
@@ -13,7 +13,7 @@ namespace NewOS
{
class ProcessHeader;
- typedef ProcessHeader* ProcessPtr;
+ typedef ProcessHeader* ProcessHeaderRef;
/// @brief Access control class, which locks a task until one is done.
class Semaphore final
@@ -37,7 +37,7 @@ namespace NewOS
HCORE_COPY_DEFAULT(Semaphore);
private:
- ProcessPtr fLockingProcess{ nullptr };
+ ProcessHeaderRef fLockingProcess{ nullptr };
};
}
diff --git a/Private/Source/CodeManager.cxx b/Private/Source/CodeManager.cxx
index db2a7017..b8725b98 100644
--- a/Private/Source/CodeManager.cxx
+++ b/Private/Source/CodeManager.cxx
@@ -11,8 +11,9 @@
using namespace NewOS;
/// @brief Executes a new process from a function. kernel code only.
+/// @note This sets up a new stack, anything on the main function that calls the kernel will not be accessible.
/// @param main the start of the process.
-/// @return
+/// @return if the process was started or not.
bool execute_from_image(MainKind main, const char* processName) noexcept {
if (!main) return false;
diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx
index bbe7d30b..4d3c7d32 100644
--- a/Private/Source/FileManager.cxx
+++ b/Private/Source/FileManager.cxx
@@ -16,7 +16,9 @@ static FilesystemManagerInterface* kMounted = nullptr;
/// @brief FilesystemManager getter.
/// @return The mounted filesystem.
-FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() { return kMounted; }
+FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() {
+ return kMounted;
+}
/// @brief Unmount filesystem.
/// @return the unmounted filesystem.
@@ -42,4 +44,85 @@ bool FilesystemManagerInterface::Mount(FilesystemManagerInterface* mountPtr) {
return false;
}
+
+#ifdef __FSKIT_NEWFS__
+/// @brief Opens a new file.
+/// @param path
+/// @param r
+/// @return
+NodePtr NewFilesystemManager::Open(const char* path, const char* r) {
+ if (!path || *path == 0) return nullptr;
+
+ if (!r || *r == 0) return nullptr;
+
+ auto catalog = fImpl->GetCatalog(path);
+
+ if (catalog->Kind != kNewFSCatalogKindFile) {
+ fImpl->CloseCatalog(catalog);
+ return nullptr;
+ }
+
+ return node_cast(catalog);
+}
+
+/// @brief Writes to a catalog
+/// @param node
+/// @param data
+/// @param flags
+/// @return
+Void NewFilesystemManager::Write(NodePtr node, VoidPtr data,
+ Int32 flags) {
+ if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile)
+ fImpl->WriteCatalog(reinterpret_cast<NewCatalog*>(node), data);
+}
+
+/**
+ * NOTE: Write and Read are implemented using a custom NodePtr, retrieved
+ * using OpenFork.
+ */
+
+/// @brief Reads from filesystem.
+/// @param node
+/// @param flags
+/// @param sz
+/// @return
+VoidPtr NewFilesystemManager::Read(NodePtr node, Int32 flags, SizeT sz) {
+ if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile)
+ return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz);
+
+ return nullptr;
+}
+
+/// @brief Seek from Catalog.
+/// @param node
+/// @param off
+/// @return
+bool NewFilesystemManager::Seek(NodePtr node, SizeT off) {
+ if (!node || off == 0) return false;
+
+ return fImpl->Seek(reinterpret_cast<NewCatalog*>(node), off);
+}
+
+/// @brief Tell where the catalog is/
+/// @param node
+/// @return
+SizeT NewFilesystemManager::Tell(NodePtr node) {
+ if (!node) return kNPos;
+
+ return fImpl->Tell(reinterpret_cast<NewCatalog*>(node));
+}
+
+/// @brief Rewind the catalog.
+/// @param node
+/// @return
+bool NewFilesystemManager::Rewind(NodePtr node) {
+ if (!node) return false;
+
+ return this->Seek(node, 0);
+}
+
+/// @brief The filesystem implementation.
+/// @return
+NewFSParser* NewFilesystemManager::GetImpl() noexcept { return fImpl; }
+#endif // __FSKIT_NEWFS__
} // namespace NewOS
diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx
index fb13362e..8264f7fa 100644
--- a/Private/Source/NewFS+IO.cxx
+++ b/Private/Source/NewFS+IO.cxx
@@ -29,21 +29,12 @@
using namespace NewOS;
-enum {
- kHCFSSubDriveA,
- kHCFSSubDriveB,
- kHCFSSubDriveC,
- kHCFSSubDriveD,
- kHCFSSubDriveInvalid,
- kHCFSSubDriveCount,
-};
-
/// @brief Read from newfs disk.
/// @param Mnt mounted interface.
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_newfs_read_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return -1;
DrvTrait.fPacket.fPacketGood = false;
@@ -75,7 +66,7 @@ Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvInd
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_newfs_write_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return -1;
DrvTrait.fPacket.fPacketGood = false;
diff --git a/Private/Source/ProcessTeam.cxx b/Private/Source/ProcessTeam.cxx
index dbbcab24..df4cd55d 100644
--- a/Private/Source/ProcessTeam.cxx
+++ b/Private/Source/ProcessTeam.cxx
@@ -6,7 +6,7 @@
/***********************************************************************************/
/// @file ProcessTeam.cxx
-/// @brief ProcessHeader Team API.
+/// @brief Process Team API.
/***********************************************************************************/
#include <KernelKit/ProcessScheduler.hpp>
diff --git a/Private/StorageKit/PRDT.hpp b/Private/StorageKit/PRDT.hpp
index 48886db6..9163a8bf 100644
--- a/Private/StorageKit/PRDT.hpp
+++ b/Private/StorageKit/PRDT.hpp
@@ -12,7 +12,8 @@
#define kPrdtTransferSize (sizeof(NewOS::UShort))
namespace NewOS {
-enum {
+/// @brief Tranfer information about PRD.
+enum kPRDTTransfer {
kPRDTTransferInProgress,
kPRDTTransferIsDone,
kPRDTTransferCount,
@@ -47,5 +48,5 @@ class PRDT final {
UIntPtr m_PrdtAddr;
};
-using PhysicalAddress = PRDT; // here
+EXTERN_C Int32 kPRDTTransferStatus;
} // namespace NewOS
diff --git a/Private/makefile b/Private/makefile
index a1661bb6..af311d44 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -8,6 +8,22 @@ LD = x86_64-w64-mingw32-ld
CCFLAGS = -c -ffreestanding -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./
ASM = nasm
+ifneq ($(NEWOS_PIO_ATA), )
+DISKDRIVER = -D__ATA_PIO__
+endif
+
+ifneq ($(NEWOS_DMA_ATA), )
+DISKDRIVER = -D__ATA_DMA__
+endif
+
+ifneq ($(NEWOS_AHCI), )
+DISKDRIVER = -D__AHCI__
+endif
+
+ifneq ($(DEBUG), )
+DEBUG = -D__DEBUG__
+endif
+
# Add assembler, linker, and object files variables.
ASMFLAGS = -f win64
LDFLAGS = -e Main --subsystem=17
@@ -27,7 +43,7 @@ MOVEALL=./MoveAll.sh
.PHONY: h-core-amd64-epm
h-core-amd64-epm: clean
- $(CC) $(CCFLAGS) $(DEBUG) $(wildcard Source/*.cxx HALKit/AMD64/Storage/*.cxx) $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Source/Network/*.cxx) $(wildcard Source/Storage/*.cxx) $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) $(wildcard HALKit/AMD64/*.s)
+ $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Source/*.cxx HALKit/AMD64/Storage/*.cxx) $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Source/Network/*.cxx) $(wildcard Source/Storage/*.cxx) $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) $(wildcard HALKit/AMD64/*.s)
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm
@@ -49,8 +65,8 @@ all: h-core-amd64-epm link-amd64-epm
help:
@echo "=== HELP ==="
@echo "all: Build kernel and link it."
- @echo "link-amd64-epm: Link kernel. (PC AMD64)"
- @echo "h-core-amd64-epm: Build kernel. (PC AMD64)"
+ @echo "link-amd64-epm: Link kernel. (EPM AMD64)"
+ @echo "h-core-amd64-epm: Build kernel. (EPM AMD64)"
.PHONY: clean
clean: