From 39415bb759f7eb67fb393385c28c3d2e5d7f6857 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 2 Jun 2024 09:25:18 +0200 Subject: MHR-23: Porting to ARM64 now. Signed-off-by: Amlal El Mahrouss --- Kernel/Sources/CxxAbi.cxx | 2 +- Kernel/Sources/FS/NewFS.cxx | 53 +++++++++-------- Kernel/Sources/IndexableProperty.cxx | 2 +- Kernel/Sources/KernelCheck.cxx | 4 +- Kernel/Sources/PEFSharedObject.cxx | 106 +++++++++++++++++++++++++++++++++ Kernel/Sources/PEFSharedObjectRT.cxx | 107 ---------------------------------- Kernel/Sources/ThreadLocalStorage.cxx | 6 +- 7 files changed, 141 insertions(+), 139 deletions(-) create mode 100644 Kernel/Sources/PEFSharedObject.cxx delete mode 100644 Kernel/Sources/PEFSharedObjectRT.cxx (limited to 'Kernel/Sources') diff --git a/Kernel/Sources/CxxAbi.cxx b/Kernel/Sources/CxxAbi.cxx index 9aea8db7..0b01928a 100644 --- a/Kernel/Sources/CxxAbi.cxx +++ b/Kernel/Sources/CxxAbi.cxx @@ -14,7 +14,7 @@ uarch_t __atexit_func_count; extern "C" void __cxa_pure_virtual() { - NewOS::kcout << "New OS: C++ placeholder method.\n"; + NewOS::kcout << "newoskrnl: C++ placeholder method.\n"; } extern "C" void ___chkstk_ms() diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 6f19c8ed..5e07fef8 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -73,11 +73,11 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, drv->fInput(&drv->fPacket); - kcout << "New OS: Next-Fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "newoskrnl: Next-Fork: " << hex_number(curFork.NextSibling) << endl; if (curFork.Flags == kNewFSFlagCreated) { - kcout << "New OS: Fork already exists.\r"; + kcout << "newoskrnl: Fork already exists.\r"; /// sanity check. if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && @@ -126,10 +126,10 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, drv->fOutput(&drv->fPacket); /// log what we have now. - kcout << "New OS: Wrote fork data at: " << hex_number(theFork.DataOffset) + kcout << "newoskrnl: Wrote fork data at: " << hex_number(theFork.DataOffset) << endl; - kcout << "New OS: Wrote fork at: " << hex_number(lba) << endl; + kcout << "newoskrnl: Wrote fork at: " << hex_number(lba) << endl; return &theFork; } @@ -372,9 +372,9 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fOutput(&drive->fPacket); - kcout << "New OS: Create new catalog, status: " + kcout << "newoskrnl: Create new catalog, status: " << hex_number(catalogChild->Flags) << endl; - kcout << "New OS: Create new catalog, status: " << catalogChild->Name + kcout << "newoskrnl: Create new catalog, status: " << catalogChild->Name << endl; drive->fPacket.fPacketContent = sectorBufPartBlock; @@ -449,7 +449,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) partBlock->Version = kNewFSVersionInteger; - const auto cUntitledHD = "New OS HD\0"; + const auto cUntitledHD = "newoskrnl HD\0"; rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, kNewFSIdentLen); @@ -475,14 +475,14 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) drive->fOutput(&drive->fPacket); - kcout << "Drive-Kind: " << drive->fDriveKind() << endl; + kcout << "newoskrnl: drive kind: " << drive->fDriveKind() << endl; - kcout << "Partition-Name: " << partBlock->PartitionName << endl; - kcout << "Start-Catalog: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "Catalog-Count: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "Free-Catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "Free-Sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "Sector-Size: " << hex_number(partBlock->SectorSize) << endl; + kcout << "newoskrnl: partition name: " << partBlock->PartitionName << endl; + kcout << "newoskrnl: start: " << hex_number(partBlock->StartCatalog) << endl; + kcout << "newoskrnl: number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; + kcout << "newoskrnl: free catalog: " << hex_number(partBlock->FreeCatalog) << endl; + kcout << "newoskrnl: free sectors: " << hex_number(partBlock->FreeSectors) << endl; + kcout << "newoskrnl: sector size: " << hex_number(partBlock->SectorSize) << endl; /// write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); @@ -490,7 +490,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) return true; } - kcout << "New OS: PartitionBlock already exists.\r"; + kcout << "newoskrnl: PartitionBlock already exists.\r"; /// return success as well, do not ignore that partition. return true; @@ -531,14 +531,14 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, drive->fInput(&drive->fPacket); - kcout << "Fork-Name: " << forkData->ForkName << endl; + kcout << "newoskrnl: forkName: " << forkData->ForkName << endl; /// sanity check the fork. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { DbgLastError() = kErrorDiskIsCorrupted; - kcout << "New OS: Invalid fork offset.\r"; + kcout << "newoskrnl: Invalid fork offset.\r"; delete forkData; return false; @@ -552,7 +552,8 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, drive->fPacket.fPacketContent = data; drive->fPacket.fPacketSize = sizeOfData; drive->fPacket.fLba = forkData->DataOffset; - kcout << "Fork-Offset: " << hex_number(forkData->DataOffset) << endl; + + kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl; drive->fOutput(&drive->fPacket); @@ -563,10 +564,12 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, catalog == nullptr) { delete catalog; + drive->fPacket.fPacketContent = data; drive->fPacket.fPacketSize = sizeOfData; drive->fPacket.fLba = forkData->DataOffset; - kcout << "Fork-Offset: " << hex_number(forkData->DataOffset) << endl; + + kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl; drive->fOutput(&drive->fPacket); @@ -670,7 +673,7 @@ _NewFSSearchThroughCatalogList: NewCatalog* catalogPtr = new NewCatalog(); rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); - kcout << "New OS: Found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "newoskrnl: found catalog at: " << hex_number(startCatalogList) << endl; outLba = startCatalogList; delete[] sectorBuf; @@ -809,8 +812,8 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, Lba dataForkLba = catalog->DataFork; Size dataForkSize = catalog->DataForkSize; - kcout << "Found-Catalog: " << catalog->Name - << ", Data-Fork: " << hex_number(dataForkLba) << endl; + kcout << "newoskrnl: catalog " << catalog->Name + << ", fork: " << hex_number(dataForkLba) << endl; Char* sectorBuf = new Char[sizeof(NewFork)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); @@ -830,7 +833,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, forkData = (NewFork*)sectorBuf; - kcout << "Fork-Name: " << forkData->ForkName << endl; + kcout << "newoskrnl: name: " << forkData->ForkName << endl; if (forkData->DataOffset <= kNewFSCatalogStartAddress) { @@ -930,11 +933,11 @@ namespace NewOS::Detail if (!StringBuilder::Equals(partBlock->Ident, kNewFSIdent)) { - kcout << "New OS: New FS Partition is corrupt.\r"; + kcout << "newoskrnl: New FS Partition is corrupt.\r"; return false; } - kcout << "New OS: Read partition: " << partBlock->PartitionName << ", with success!\r"; + kcout << "newoskrnl: Read partition: " << partBlock->PartitionName << ", with success!\r"; return true; } diff --git a/Kernel/Sources/IndexableProperty.cxx b/Kernel/Sources/IndexableProperty.cxx index 16694f52..6c773b9a 100644 --- a/Kernel/Sources/IndexableProperty.cxx +++ b/Kernel/Sources/IndexableProperty.cxx @@ -50,7 +50,7 @@ namespace NewOS indexer.AddFlag(kIndexerClaimed); rt_copy_memory((VoidPtr)indexer.LeakProperty().Path, (VoidPtr)filename, filenameLen); - kcout << "New OS: FSKit: index new file: " << filename << endl; + kcout << "newoskrnl: FSKit: index new file: " << filename << endl; } } } // namespace Indexer diff --git a/Kernel/Sources/KernelCheck.cxx b/Kernel/Sources/KernelCheck.cxx index b59417d4..6b355011 100644 --- a/Kernel/Sources/KernelCheck.cxx +++ b/Kernel/Sources/KernelCheck.cxx @@ -98,8 +98,8 @@ namespace NewOS if (!expr) { #ifdef __DEBUG__ - kcout << "New Kernel: File: " << file << "\r"; - kcout << "New Kernel: Line: " << line << "\r"; + kcout << "newoskrnl: File: " << file << "\r"; + kcout << "newoskrnl: Line: " << line << "\r"; #endif // __DEBUG__ diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx new file mode 100644 index 00000000..06825a3c --- /dev/null +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -0,0 +1,106 @@ +/* + * ======================================================== + * + * NewOS + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include +#include + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared library ABI, except a rt_library_init and + rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the + routines. (amlel) + + ------------------------------------------- */ + +using namespace NewOS; + +/***********************************************************************************/ +/// @file SharedObjectRT.cxx +/// @brief Shared Object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Library runtime initializer. */ +/***********************************************************************************/ + +EXTERN_C SharedObjectPtr rt_library_init(void) +{ + SharedObjectPtr library = tls_new_class(); + + if (!library) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(tls_new_class()); + + if (!library->Get()) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageObject = + ProcessScheduler::The().Leak().GetCurrent().Leak().Image; + + if (!library->Get()->fImageObject) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageEntrypointOffset = + library->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + + return library; +} + +/***********************************************************************************/ +/* @brief Ends the library. */ +/* @note Please check if the lib got freed! */ +/* @param SharedObjectPtr the library to free. */ +/***********************************************************************************/ + +EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) +{ + MUST_PASS(successful); + + // sanity check (will also trigger a bug check if this fails) + if (lib == nullptr) + { + *successful = false; + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} + +/***********************************************************************************/ + +/// @brief Unimplemented function (crashes by default) +/// @param +EXTERN_C void __mh_purecall(void) +{ + kcout << "newoskrnl: unimplemented symbol!\r"; +} diff --git a/Kernel/Sources/PEFSharedObjectRT.cxx b/Kernel/Sources/PEFSharedObjectRT.cxx deleted file mode 100644 index 3ddef245..00000000 --- a/Kernel/Sources/PEFSharedObjectRT.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ======================================================== - * - * NewOS - * Copyright SoftwareLabs, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------- - - Revision History: - - 01/02/24: Rework shared library ABI, except a rt_library_init and - rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the - routines. (amlel) - - ------------------------------------------- */ - -using namespace NewOS; - -/***********************************************************************************/ -/// @file SharedObjectRT.cxx -/// @brief Shared Object runtime. -/***********************************************************************************/ - -/***********************************************************************************/ -/* @brief Library runtime initializer. */ -/***********************************************************************************/ - -EXTERN_C SharedObjectPtr rt_library_init(void) -{ - SharedObjectPtr library = tls_new_class(); - - if (!library) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Mount(tls_new_class()); - - if (!library->Get()) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageObject = - ProcessScheduler::The().Leak().GetCurrent().Leak().Image; - - if (!library->Get()->fImageObject) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageEntrypointOffset = - library->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - - return library; -} - -/***********************************************************************************/ -/* @brief Ends the library. */ -/* @note Please check if the lib got freed! */ -/* @param SharedObjectPtr the library to free. */ -/***********************************************************************************/ - -EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) -{ - MUST_PASS(successful); - - // sanity check (will also trigger a bug check if this fails) - if (lib == nullptr) - { - *successful = false; - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - } - - delete lib->Get(); - delete lib; - - lib = nullptr; - - *successful = true; -} - -/***********************************************************************************/ - -/// @brief Unimplemented function (crashes by default) -/// @param -EXTERN_C void __mh_purecall(void) -{ - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - return; -} diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 00305006..f72bab67 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -33,7 +33,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "New OS: Checking for a valid cookie...\r"; + kcout << "newoskrnl: Checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -50,9 +50,9 @@ EXTERN_C Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr stackPtr) noexcep if (!tls_check_tib(tib)) { - kcout << "New OS: Verification failed, Crashing...\r"; + kcout << "newoskrnl: Verification failed, Crashing...\r"; ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); } - kcout << "New OS: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; } -- cgit v1.2.3