diff options
Diffstat (limited to 'Private/Source')
| -rw-r--r-- | Private/Source/AppMain.cxx | 10 | ||||
| -rw-r--r-- | Private/Source/DriveManager.cxx | 55 | ||||
| -rw-r--r-- | Private/Source/FS/NewFS.cxx | 213 | ||||
| -rw-r--r-- | Private/Source/KernelCheck.cxx | 4 | ||||
| -rw-r--r-- | Private/Source/KernelHeap.cxx | 9 | ||||
| -rw-r--r-- | Private/Source/NewFS+FileManager.cxx | 14 | ||||
| -rw-r--r-- | Private/Source/NewFS+IO.cxx | 22 | ||||
| -rw-r--r-- | Private/Source/PEFCodeManager.cxx | 29 | ||||
| -rw-r--r-- | Private/Source/PageAllocator.cxx | 9 | ||||
| -rw-r--r-- | Private/Source/PageManager.cxx | 18 | ||||
| -rw-r--r-- | Private/Source/Pmm.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/Storage/ATADeviceInterface.cxx | 22 | ||||
| -rw-r--r-- | Private/Source/Utils.cxx | 3 | ||||
| -rw-r--r-- | Private/Source/compile_flags.txt | 1 |
14 files changed, 273 insertions, 138 deletions
diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx index 87705393..8fa74459 100644 --- a/Private/Source/AppMain.cxx +++ b/Private/Source/AppMain.cxx @@ -20,12 +20,18 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) { ///! Mounts a NewFS block. NewOS::NewFilesystemManager* newFS = new NewOS::NewFilesystemManager(); - NewOS::ke_protect_ke_heap(newFS); NewOS::FilesystemManagerInterface::Mount(newFS); + if (newFS->GetImpl()) { + auto catalog = newFS->GetImpl()->GetCatalog("/Boot"); + if (catalog) { + NewOS::kcout << "Catalog-Path-Name: " << catalog->Name << NewOS::endl; + delete catalog; + } + } + while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0); - ///! we're done, unmount. delete newFS; } diff --git a/Private/Source/DriveManager.cxx b/Private/Source/DriveManager.cxx index 86478831..41f4f4ab 100644 --- a/Private/Source/DriveManager.cxx +++ b/Private/Source/DriveManager.cxx @@ -18,73 +18,82 @@ static UInt16 kATAIO = 0U; static UInt8 kATAMaster = 0U; /// @brief reads from an ATA drive. -/// @param pckt -/// @return +/// @param pckt +/// @return Void ke_drv_input(DriveTrait::DrivePacket* pckt) { if (!pckt) { return; } - + pckt->fPacketGood = false; #ifdef __AHCI__ - drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, 1, pckt->fPacketSize); + drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); #elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, 1, pckt->fPacketSize); + drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); #endif - pckt->fPacketGood = true; } /// @brief Writes to an ATA drive. -/// @param pckt -/// @return +/// @param pckt +/// @return Void ke_drv_output(DriveTrait::DrivePacket* pckt) { if (!pckt) { return; } - + pckt->fPacketGood = false; #ifdef __AHCI__ - drv_std_write(pckt->fLba,(Char*)pckt->fPacketContent, 1, pckt->fPacketSize); + drv_std_write(pckt->fLba,(Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); #elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, 1, pckt->fPacketSize); + drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); #endif pckt->fPacketGood = true; } /// @brief Executes a disk check on the ATA drive. -/// @param pckt -/// @return +/// @param pckt +/// @return Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) { if (!pckt) { return; } - + pckt->fPacketGood = false; + + +#if defined(__ATA_PIO__) || defined (__ATA_DMA__) + kATAMaster = true; + kATAIO = ATA_PRIMARY_IO; + + MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster)); +#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) + + pckt->fPacketGood = true; } /// @brief Gets the drive kind (ATA, SCSI, AHCI...) -/// @param -/// @return -#ifdef __ATA_PIO__ +/// @param +/// @return +#ifdef __ATA_PIO__ const Char* ke_drive_kind(Void) { return "ATA-PIO"; } #endif -#ifdef __ATA_DMA__ +#ifdef __ATA_DMA__ const Char* ke_drive_kind(Void) { return "ATA-DMA"; } #endif -#ifdef __AHCI__ +#ifdef __AHCI__ const Char* ke_drive_kind(Void) { return "AHCI"; } #endif /// @brief Unimplemented drive. -/// @param pckt -/// @return +/// @param pckt +/// @return Void ke_drv_unimplemented(DriveTrait::DrivePacket* pckt) {} /// @brief Makes a new drive. @@ -98,6 +107,7 @@ DriveTrait construct_drive() noexcept { trait.fInput = ke_drv_unimplemented; trait.fOutput = ke_drv_unimplemented; trait.fVerify = ke_drv_unimplemented; + trait.fDriveKind = ke_drive_kind; return trait; } @@ -107,12 +117,13 @@ DriveTrait construct_drive() noexcept { DriveTrait construct_main_drive() noexcept { DriveTrait trait; - rt_copy_memory((VoidPtr)"/Mount/Disk/0", trait.fName, rt_string_len("/Mount/Disk/0")); + rt_copy_memory((VoidPtr)"/Mount/MainDisk/", trait.fName, rt_string_len("/Mount/MainDisk/")); trait.fKind = kMassStorage | kEPMDrive; trait.fInput = ke_drv_input; trait.fOutput = ke_drv_output; trait.fVerify = ke_drv_check_disk; + trait.fDriveKind = ke_drive_kind; return trait; } diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx index 7eb79d10..a5dfe45b 100644 --- a/Private/Source/FS/NewFS.cxx +++ b/Private/Source/FS/NewFS.cxx @@ -10,12 +10,15 @@ #include <KernelKit/HError.hpp> #include <NewKit/Crc32.hpp> #include <NewKit/Utils.hpp> +#include <NewKit/String.hpp> +#include <Builtins/ATA/ATA.hxx> +#include <Builtins/AHCI/AHCI.hxx> using namespace NewOS; /// forward decl. -STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog); +STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog, Boolean isDataFork); STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv); STATIC MountpointInterface sMountpointInterface; @@ -30,28 +33,36 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, Lba whereFork = 0; theFork.DataOffset = - ke_find_free_fork(theFork.DataSize, this->fDriveIndex, catalog); + ke_find_free_fork(theFork.DataSize, this->fDriveIndex, catalog, theFork.Kind == kNewFSDataForkKind); theFork.Flags |= kNewFSFlagCreated; + Lba lba = theFork.Kind == kNewFSDataForkKind ? catalog->DataFork : catalog->ResourceFork; - if (catalog->FirstFork == 0) { - catalog->FirstFork = whereFork; + if (lba == 0) { + lba = whereFork; } else { - if (catalog->LastFork == 0) { - theFork.PreviousSibling = catalog->FirstFork; + if (lba == 0) { + theFork.PreviousSibling = lba; } } - if (catalog->LastFork == 0) { - catalog->LastFork = whereFork; + if (theFork.Kind == kNewFSDataForkKind) { + if (catalog->DataFork == 0) { + catalog->DataFork = whereFork; + } else { + theFork.PreviousSibling = catalog->DataFork; + } } else { - theFork.PreviousSibling = catalog->LastFork; + if (catalog->ResourceFork == 0) { + catalog->ResourceFork = whereFork; + } else { + theFork.PreviousSibling = catalog->ResourceFork; + } } - if (!sMountpointInterface.GetAddressOf(this->fDriveIndex) || - !*sMountpointInterface.GetAddressOf(this->fDriveIndex)) + if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; - auto drv = *sMountpointInterface.GetAddressOf(this->fDriveIndex); + auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex); drv->fPacket.fLba = whereFork; drv->fPacket.fPacketSize = theFork.DataSize; @@ -92,10 +103,10 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, /// @param name the fork name. /// @return the fork. _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, - _Input const Char* name) { - auto drv = *sMountpointInterface.GetAddressOf(this->fDriveIndex); + _Input const Char* name, Boolean isDataFork) { + auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex); NewFork* theFork = nullptr; - Lba lba = catalog->FirstFork; + Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; while (lba != 0) { drv->fPacket.fLba = lba; @@ -165,7 +176,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) { return false; } - Char sectorBuf[kNewFSMinimumSectorSz] = {0}; + UInt16 sectorBuf[kNewFSMinimumSectorSz] = {0}; drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; @@ -184,15 +195,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) { rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, kNewFSIdentLen); - rt_copy_memory((VoidPtr) "New OS\0", (VoidPtr)partBlock->PartitionName, - rt_string_len("New OS\0")); + rt_copy_memory((VoidPtr) "Untitled HD\0", (VoidPtr)partBlock->PartitionName, + rt_string_len("Untitled HD\0")); SizeT catalogCount = 0; - SizeT sectorCount = 0; - SizeT diskSize = 0; + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_drv_size(); partBlock->Kind = kNewFSPartitionTypeStandard; - partBlock->StartCatalog = sizeof(NewPartitionBlock) + kNewFSAddressAsLba; + partBlock->StartCatalog = kNewFSCatalogStartAddress;; partBlock->CatalogCount = catalogCount; partBlock->SectorCount = sectorCount; partBlock->DiskSize = diskSize; @@ -229,27 +240,90 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, /// @param catalogName /// @return _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName) { - return nullptr; + if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; + + Char* sectorBuf = new Char[sizeof(NewPartitionBlock)]; + auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); + + drive->fPacket.fPacketContent = sectorBuf; + drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); + drive->fPacket.fLba = kNewFSAddressAsLba; + + drive->fInput(&drive->fPacket); + + NewPartitionBlock* part = (NewPartitionBlock*)sectorBuf; + + kcout << "Drive-Kind: " << drive->fDriveKind() << endl; + + kcout << "Partition-Name: " << part->PartitionName << endl; + kcout << "Start-Catalog: " << number(part->StartCatalog) << endl; + kcout << "Catalog-Count: " << number(part->CatalogCount) << endl; + kcout << "Free-Catalog: " << number(part->FreeCatalog) << endl; + kcout << "Free-Sectors: " << number(part->FreeSectors) << endl; + kcout << "Sector-Size: " << number(part->SectorSize) << endl; + + auto start = part->StartCatalog; + + drive->fPacket.fLba = start; + drive->fPacket.fPacketContent = sectorBuf; + drive->fPacket.fPacketSize = sizeof(NewCatalog); + + drive->fInput(&drive->fPacket); + + while (drive->fPacket.fPacketGood) { + NewCatalog* catalog = (NewCatalog*)sectorBuf; + + if (StringBuilder::Equals(catalogName, catalog->Name)) { + NewCatalog* catalogPtr = new NewCatalog(); + rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); + + delete[] sectorBuf; + return catalogPtr; + } + + if (catalog->NextSibling == 0) + break; + + drive->fPacket.fLba = catalog->NextSibling; + drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; + drive->fInput(&drive->fPacket); + } + + delete[] sectorBuf; + + return nullptr; } /// @brief /// @param name /// @return _Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) { - return nullptr; + return this->FindCatalog(name); } /// @brief /// @param catalog /// @return Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) { - return true; + if (this->WriteCatalog(catalog, nullptr)) { + delete catalog; + catalog = nullptr; + + return true; + } + + return false; } /// @brief Mark catalog as removed. /// @param catalog The catalog structure. /// @return Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) { + if (!catalog) { + DbgLastError() = kErrorFileNotFound; + return false; + } + catalog->Flags |= kNewFSFlagDeleted; this->WriteCatalog(catalog, nullptr); @@ -260,54 +334,72 @@ Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) { /// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead. /// ***************************************************************** /// -/// @brief +/// @brief Read the catalog data fork. /// @param catalog /// @param dataSz /// @return VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, SizeT dataSz) { - return nullptr; + if (!catalog) { + DbgLastError() = kErrorFileNotFound; + return nullptr; + } + + return nullptr; } -/// @brief +/// @brief Seek in the data fork. /// @param catalog /// @param off /// @return bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) { - return false; + if (!catalog) { + DbgLastError() = kErrorFileNotFound; + return false; + } + + return false; } -/// @brief +/// @brief Tell where we are inside the data fork. /// @param catalog /// @return -SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { return 0; } +SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { + if (!catalog) { + DbgLastError() = kErrorFileNotFound; + return false; + } + + return 0; +} /// @brief Find a free fork inside the filesystem. /// @param sz the size of the fork to set. /// @return the valid lba. -STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog) { - auto drive = *sMountpointInterface.GetAddressOf(drv); +STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog, Boolean isDataFork) { + + if (sMountpointInterface.GetAddressOf(drv)) { + auto drive = *sMountpointInterface.GetAddressOf(drv); - if (drive) { /// prepare packet. bool done = false; bool error = false; - Lba lba = catalog->LastFork; + Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; while (!done) { - Char sectorBuf[kNewFSMinimumSectorSz] = {0}; + UInt16 sectorBuf[kNewFSMinimumSectorSz] = {0}; - drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; - drive->fPacket.fLba = lba; + drive.fPacket.fPacketContent = sectorBuf; + drive.fPacket.fPacketSize = kNewFSMinimumSectorSz; + drive.fPacket.fLba = lba; - drive->fInput(&drive->fPacket); + drive.fInput(&drive.fPacket); - if (!drive->fPacket.fPacketGood) { + if (!drive.fPacket.fPacketGood) { ///! not a lot of choices, disk has become unreliable. - if (ke_calculate_crc32(sectorBuf, kNewFSMinimumSectorSz) != - drive->fPacket.fPacketCRC32) { + if (ke_calculate_crc32((Char*)sectorBuf, kNewFSMinimumSectorSz) != + drive.fPacket.fPacketCRC32) { DbgLastError() = kErrorDiskIsCorrupted; } @@ -323,10 +415,10 @@ STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog) { fork->DataSize = sz; fork->Flags |= kNewFSFlagCreated; - drive->fOutput(&drive->fPacket); + drive.fOutput(&drive.fPacket); /// here it's either a read-only filesystem or something bad happened.' - if (!drive->fPacket.fPacketGood) { + if (!drive.fPacket.fPacketGood) { DbgLastError() = kErrorDiskReadOnly; return 0; @@ -351,18 +443,18 @@ STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog) { /// @param kind the catalog kind. /// @return the valid lba. STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv) { - auto drive = *sMountpointInterface.GetAddressOf(drv); - if (drive) { - Char sectorBuf[kNewFSMinimumSectorSz] = {0}; + if (sMountpointInterface.GetAddressOf(drv)) { + auto drive = *sMountpointInterface.GetAddressOf(drv); + UInt16 sectorBuf[kNewFSMinimumSectorSz] = {0}; /// prepare packet. - drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive.fPacket.fPacketContent = sectorBuf; + drive.fPacket.fPacketSize = kNewFSMinimumSectorSz; + drive.fPacket.fLba = kNewFSAddressAsLba; - drive->fInput(&drive->fPacket); + drive.fInput(&drive.fPacket); NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBuf; @@ -376,11 +468,11 @@ STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv) { return 1; } else { while (startLba != 0) { - drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; - drive->fPacket.fLba = startLba; + drive.fPacket.fPacketContent = sectorBuf; + drive.fPacket.fPacketSize = kNewFSMinimumSectorSz; + drive.fPacket.fLba = startLba; - drive->fInput(&drive->fPacket); + drive.fInput(&drive.fPacket); NewCatalog* catalog = (NewCatalog*)sectorBuf; @@ -404,7 +496,16 @@ STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv) { } namespace NewOS::Detail { -Boolean fs_init_newfs(Void) noexcept { return true; } +Boolean fs_init_newfs(Void) noexcept { + sMountpointInterface.A() = construct_main_drive(); + sMountpointInterface.B() = construct_drive(); + sMountpointInterface.C() = construct_drive(); + sMountpointInterface.D() = construct_drive(); + + sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); + + return true; +} } // namespace NewOS::Detail #endif // ifdef __FSKIT_NEWFS__ diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx index 5f617f06..d649ef35 100644 --- a/Private/Source/KernelCheck.cxx +++ b/Private/Source/KernelCheck.cxx @@ -91,8 +91,8 @@ void ke_stop(const NewOS::Int &id) { void ke_runtime_check(bool expr, const char *file, const char *line) { if (!expr) { #ifdef __DEBUG__ - kcout << "NewKernel: File: " << file << "\r\n"; - kcout << "NewKernel: Line: " << line << "\r\n"; + kcout << "New Kernel: File: " << file << "\r\n"; + kcout << "New Kernel: Line: " << line << "\r\n"; #endif // __DEBUG__ diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 3b77ebb6..52b9bafb 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -49,7 +49,7 @@ typedef HeapInformationBlock *HeapInformationBlockPtr; VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { if (sz == 0) ++sz; - auto wrapper = kHeapPageManager.Request(rw, user, false); + auto wrapper = kHeapPageManager.Request(rw, user, false, sz); Detail::HeapInformationBlockPtr heapInfo = reinterpret_cast<Detail::HeapInformationBlockPtr>( @@ -62,6 +62,9 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { ++kHeapCount; + NewOS::kcout << "New OS: Allocate: " << hex_number((IntPtr)wrapper.VirtualAddress() + + sizeof(Detail::HeapInformationBlock)) << endl; + return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() + sizeof(Detail::HeapInformationBlock)); } @@ -71,11 +74,15 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { /// @return Int32 ke_delete_ke_heap(VoidPtr heapPtr) { if (kHeapCount < 1) return -kErrorInternal; + if (((IntPtr)heapPtr - sizeof(Detail::HeapInformationBlock)) <= 0) return -kErrorInternal; + if (((IntPtr)heapPtr - kBadPtr) < 0) return -kErrorInternal; Detail::HeapInformationBlockPtr virtualAddress = reinterpret_cast<Detail::HeapInformationBlockPtr>( (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock)); + NewOS::kcout << "New OS: Freeing: " << hex_number((UIntPtr)virtualAddress) << endl; + if (virtualAddress && virtualAddress->fMagic == kKernelHeapMagic) { if (!virtualAddress->fPresent) { return -kErrorHeapNotPresent; diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx index 7227c2e2..910ec841 100644 --- a/Private/Source/NewFS+FileManager.cxx +++ b/Private/Source/NewFS+FileManager.cxx @@ -5,6 +5,7 @@ ------------------------------------------- */ #include <KernelKit/FileManager.hpp> +#include <KernelKit/KernelHeap.hpp> #ifdef __FSKIT_NEWFS__ @@ -15,9 +16,14 @@ namespace NewOS { /// @brief C++ constructor NewFilesystemManager::NewFilesystemManager() { MUST_PASS(Detail::fs_init_newfs()); + fImpl = new NewFSParser(); } -NewFilesystemManager::~NewFilesystemManager() = default; +NewFilesystemManager::~NewFilesystemManager() { + if (fImpl) { + delete fImpl; + } +} /// @brief Removes a node from the filesystem. /// @param fileName The filename @@ -53,15 +59,15 @@ NodePtr NewFilesystemManager::CreateAlias(const char* path) { } /// @brief Gets the root directory. -/// @return +/// @return const char* NewFilesystemHelper::Root() { return kNewFSRoot; } /// @brief Gets the up-dir directory. -/// @return +/// @return const char* NewFilesystemHelper::UpDir() { return kNewFSUpDir; } /// @brief Gets the separator character. -/// @return +/// @return const char NewFilesystemHelper::Separator() { return kNewFSSeparator; } } // namespace NewOS diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx index a7acb63b..c78a0793 100644 --- a/Private/Source/NewFS+IO.cxx +++ b/Private/Source/NewFS+IO.cxx @@ -8,13 +8,13 @@ #include <KernelKit/FileManager.hpp> /************************************************************* - * - * File: NewFS+IO.cxx + * + * File: NewFS+IO.cxx * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 - * + * * Copyright Mahrouss Logic, all rights reserved. - * + * *************************************************************/ @@ -24,8 +24,8 @@ /// Useful macros. -#define NEWFS_WRITE(DRV, TRAITS, MP) (*MP->DRV()).fOutput(&TRAITS) -#define NEWFS_READ(DRV, TRAITS, MP) (*MP->DRV()).fInput(&TRAITS) +#define NEWFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) +#define NEWFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) using namespace NewOS; @@ -33,12 +33,12 @@ using namespace NewOS; /// @param Mnt mounted interface. /// @param DrvTrait drive info /// @param DrvIndex drive index. -/// @return +/// @return Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { if (!Mnt) return -1; DrvTrait.fPacket.fPacketGood = false; - + switch (DrvIndex) { case kNewFSSubDriveA: { NEWFS_READ(A, DrvTrait.fPacket, Mnt); @@ -62,10 +62,10 @@ Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvInd } /// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info +/// @param Mnt mounted interface. +/// @param DrvTrait drive info /// @param DrvIndex drive index. -/// @return +/// @return Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { if (!Mnt) return -1; diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index 6ff5730d..cd1b301f 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -35,11 +35,9 @@ UInt32 rt_get_pef_platform(void) noexcept { /// @brief PEF loader constructor w/ blob. /// @param blob -PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) { - fCachedBlob = blob; - fBad = false; - +PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(blob) { MUST_PASS(fCachedBlob); + fBad = false; } /// @brief PEF loader constructor. @@ -155,10 +153,8 @@ ErrorOr<VoidPtr> PEFLoader::FindStart() { /// @return bool PEFLoader::IsLoaded() noexcept { return !fBad && fCachedBlob; } -#define kPefAppnameCommandHdr "PefAppName" - namespace Utils { -bool execute_from_image(PEFLoader &exec) noexcept { +bool execute_from_image(PEFLoader &exec, const Int32& procKind) noexcept { auto errOrStart = exec.FindStart(); if (errOrStart.Error() != 0) return false; @@ -166,10 +162,7 @@ bool execute_from_image(PEFLoader &exec) noexcept { ProcessHeader proc(errOrStart.Leak().Leak()); Ref<ProcessHeader> refProc = proc; - proc.Kind = ProcessHeader::kUserKind; - rt_copy_memory(exec.FindSymbol(kPefAppnameCommandHdr, kPefData), proc.Name, - rt_string_len((const Char *)exec.FindSymbol( - kPefAppnameCommandHdr, kPefData))); + proc.Kind = procKind; return ProcessScheduler::Shared().Leak().Add(refProc); } @@ -177,7 +170,19 @@ bool execute_from_image(PEFLoader &exec) noexcept { const char *PEFLoader::Path() { return fPath.Leak().CData(); } -const char *PEFLoader::Format() { return "PEF"; } +const char *PEFLoader::Format() { + #ifdef __32x0__ + return "32x0 PEF."; + #elif defined(__64x0__) + return "64x0 PEF."; + #elif defined(__x86_64__) + return "x86_64 PEF."; + #elif defined(__powerpc64__) + return "POWER PEF."; + #else + return "Unknonwn PEF."; + #endif // __32x0__ || __64x0__ || __x86_64__ +} const char *PEFLoader::MIME() { return kPefApplicationMime; } } // namespace NewOS diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx index 9b1e05f0..510fa0ee 100644 --- a/Private/Source/PageAllocator.cxx +++ b/Private/Source/PageAllocator.cxx @@ -10,8 +10,8 @@ /// @brief Internal namespace, used internally by kernel. namespace NewOS::Detail { -VoidPtr create_page_wrapper(Boolean rw, Boolean user) { - auto addr = HAL::hal_alloc_page(rw, user); +VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz) { + auto addr = HAL::hal_alloc_page(rw, user, pageSz); if (addr == kBadAddress) { kcout << "[create_page_wrapper] kBadAddress returned\n"; @@ -26,7 +26,7 @@ void exec_disable(UIntPtr VirtualAddr) { MUST_PASS(!VirtualAddrTable->Accessed); VirtualAddrTable->ExecDisable = true; - hal_flush_tlb(VirtualAddr); + hal_flush_tlb(); } bool page_disable(UIntPtr VirtualAddr) { @@ -34,10 +34,9 @@ bool page_disable(UIntPtr VirtualAddr) { auto VirtualAddrTable = (PTE *)(VirtualAddr); MUST_PASS(!VirtualAddrTable->Accessed); - if (VirtualAddrTable->Accessed) return false; VirtualAddrTable->Present = false; - hal_flush_tlb(VirtualAddr); + hal_flush_tlb(); return true; } diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx index 722df55e..0f7ae78a 100644 --- a/Private/Source/PageManager.cxx +++ b/Private/Source/PageManager.cxx @@ -30,15 +30,15 @@ PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, PTEWrapper::~PTEWrapper() {} /// @brief Flush virtual address. -/// @param VirtAddr +/// @param VirtAddr void PageManager::FlushTLB(UIntPtr VirtAddr) { if (VirtAddr == kBadAddress) return; - hal_flush_tlb(VirtAddr); + hal_flush_tlb(); } /// @brief Reclaim freed page. -/// @return +/// @return bool PTEWrapper::Reclaim() { if (!this->fPresent) { this->fPresent = true; @@ -52,17 +52,17 @@ bool PTEWrapper::Reclaim() { /// @param Rw r/w? /// @param User user mode? /// @param ExecDisable disable execution on page? -/// @return -PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable) { +/// @return +PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) { // Store PTE wrapper right after PTE. - VoidPtr ptr = NewOS::HAL::hal_alloc_page(Rw, User); + VoidPtr ptr = NewOS::HAL::hal_alloc_page(Rw, User, Sz); return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)}; } /// @brief Disable PTE. -/// @param wrapper the wrapper. -/// @return +/// @param wrapper the wrapper. +/// @return bool PageManager::Free(Ref<PTEWrapper *> &wrapper) { if (wrapper) { if (!Detail::page_disable(wrapper->VirtualAddress())) return false; @@ -73,7 +73,7 @@ bool PageManager::Free(Ref<PTEWrapper *> &wrapper) { } /// @brief Virtual PTE address. -/// @return +/// @return The virtual address of the page. const UIntPtr PTEWrapper::VirtualAddress() { return (fVirtAddr); } diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx index 7c331c65..bbd7e6f6 100644 --- a/Private/Source/Pmm.cxx +++ b/Private/Source/Pmm.cxx @@ -14,7 +14,7 @@ Pmm::~Pmm() = default; /* If this returns Null pointer, enter emergency mode */ Ref<PTEWrapper> Pmm::RequestPage(Boolean user, Boolean readWrite) { - PTEWrapper pt = fPageManager.Leak().Request(user, readWrite, false); + PTEWrapper pt = fPageManager.Leak().Request(user, readWrite, false, kPTESize); if (pt.fPresent) { kcout << "[PMM]: Allocation was successful."; diff --git a/Private/Source/Storage/ATADeviceInterface.cxx b/Private/Source/Storage/ATADeviceInterface.cxx index 89f11f5d..d70a03f0 100644 --- a/Private/Source/Storage/ATADeviceInterface.cxx +++ b/Private/Source/Storage/ATADeviceInterface.cxx @@ -28,17 +28,17 @@ ATADeviceInterface::~ATADeviceInterface() { const char* ATADeviceInterface::Name() const { return "ATADeviceInterface"; } /// @brief Output operator. -/// @param Data -/// @return +/// @param Data +/// @return ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) { if (!Data) return *this; for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); - if ((*interface) && rt_string_cmp((*interface)->fDriveKind(), "ATA-", 5) == 0) { + if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) { continue; - } else if ((*interface) && - rt_string_cmp((*interface)->fDriveKind(), "ATA-", 5) != 0) { + } else if ((interface) && + rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0) { return *this; } } @@ -48,21 +48,21 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) { } /// @brief Input operator. -/// @param Data -/// @return +/// @param Data +/// @return ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) { if (!Data) return *this; for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); - if ((*interface) && rt_string_cmp((*interface)->fDriveKind(), "ATA-", 5) == 0) { + if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) { continue; - } else if ((*interface) && - rt_string_cmp((*interface)->fDriveKind(), "ATA-", 5) != 0) { + } else if ((interface) && + rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0) { return *this; } } return (ATADeviceInterface&)DeviceInterface<MountpointInterface*>::operator>>( Data); -}
\ No newline at end of file +} diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx index fcdddc4a..11b7129a 100644 --- a/Private/Source/Utils.cxx +++ b/Private/Source/Utils.cxx @@ -94,8 +94,6 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { ++index; } - dstChar[index] = 0; - return index; } @@ -108,6 +106,7 @@ const Char *alloc_string(const Char *text) { voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char *>(text)); voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char *>(string)); rt_copy_memory(vText, vStr, rt_string_len(text)); + return string; } diff --git a/Private/Source/compile_flags.txt b/Private/Source/compile_flags.txt index b96cbe62..1f54e6fb 100644 --- a/Private/Source/compile_flags.txt +++ b/Private/Source/compile_flags.txt @@ -4,3 +4,4 @@ -I../ -I$(HOME)/ -D__FSKIT_NEWFS__ +-D__NEWOS_AMD64__ |
