From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/CodeManager.hpp | 33 ++++ Kernel/KernelKit/DebugOutput.hpp | 184 +++++++++++++++++++ Kernel/KernelKit/Defines.hpp | 12 ++ Kernel/KernelKit/DeviceManager.hpp | 131 ++++++++++++++ Kernel/KernelKit/DriveManager.hxx | 146 ++++++++++++++++ Kernel/KernelKit/FileManager.hpp | 258 +++++++++++++++++++++++++++ Kernel/KernelKit/Framebuffer.hpp | 90 ++++++++++ Kernel/KernelKit/HError.hpp | 49 ++++++ Kernel/KernelKit/KernelHeap.hpp | 39 +++++ Kernel/KernelKit/LoaderInterface.hpp | 33 ++++ Kernel/KernelKit/LockDelegate.hpp | 64 +++++++ Kernel/KernelKit/MSDOS.hpp | 68 ++++++++ Kernel/KernelKit/PCI/Database.hpp | 38 ++++ Kernel/KernelKit/PCI/Device.hpp | 79 +++++++++ Kernel/KernelKit/PCI/Dma.hpp | 81 +++++++++ Kernel/KernelKit/PCI/Dma.inl | 20 +++ Kernel/KernelKit/PCI/Express.hpp | 11 ++ Kernel/KernelKit/PCI/IO-Impl-AMD64.inl | 47 +++++ Kernel/KernelKit/PCI/IO.hpp | 59 +++++++ Kernel/KernelKit/PCI/Iterator.hpp | 38 ++++ Kernel/KernelKit/PCI/PCI.hpp | 58 ++++++ Kernel/KernelKit/PE.hxx | 123 +++++++++++++ Kernel/KernelKit/PECodeManager.hxx | 24 +++ Kernel/KernelKit/PEF.hpp | 114 ++++++++++++ Kernel/KernelKit/PEFCodeManager.hxx | 60 +++++++ Kernel/KernelKit/PEFSharedObject.hxx | 112 ++++++++++++ Kernel/KernelKit/PermissionSelector.hxx | 57 ++++++ Kernel/KernelKit/ProcessScheduler.hpp | 301 ++++++++++++++++++++++++++++++++ Kernel/KernelKit/SMPManager.hpp | 129 ++++++++++++++ Kernel/KernelKit/Semaphore.hpp | 42 +++++ Kernel/KernelKit/ThreadLocalStorage.hxx | 53 ++++++ Kernel/KernelKit/ThreadLocalStorage.inl | 55 ++++++ Kernel/KernelKit/Timer.hpp | 64 +++++++ Kernel/KernelKit/UserHeap.hpp | 46 +++++ Kernel/KernelKit/XCOFF.hxx | 38 ++++ Kernel/KernelKit/compile_flags.txt | 5 + 36 files changed, 2761 insertions(+) create mode 100644 Kernel/KernelKit/CodeManager.hpp create mode 100644 Kernel/KernelKit/DebugOutput.hpp create mode 100644 Kernel/KernelKit/Defines.hpp create mode 100644 Kernel/KernelKit/DeviceManager.hpp create mode 100644 Kernel/KernelKit/DriveManager.hxx create mode 100644 Kernel/KernelKit/FileManager.hpp create mode 100644 Kernel/KernelKit/Framebuffer.hpp create mode 100644 Kernel/KernelKit/HError.hpp create mode 100644 Kernel/KernelKit/KernelHeap.hpp create mode 100644 Kernel/KernelKit/LoaderInterface.hpp create mode 100644 Kernel/KernelKit/LockDelegate.hpp create mode 100644 Kernel/KernelKit/MSDOS.hpp create mode 100644 Kernel/KernelKit/PCI/Database.hpp create mode 100644 Kernel/KernelKit/PCI/Device.hpp create mode 100644 Kernel/KernelKit/PCI/Dma.hpp create mode 100644 Kernel/KernelKit/PCI/Dma.inl create mode 100644 Kernel/KernelKit/PCI/Express.hpp create mode 100644 Kernel/KernelKit/PCI/IO-Impl-AMD64.inl create mode 100644 Kernel/KernelKit/PCI/IO.hpp create mode 100644 Kernel/KernelKit/PCI/Iterator.hpp create mode 100644 Kernel/KernelKit/PCI/PCI.hpp create mode 100644 Kernel/KernelKit/PE.hxx create mode 100644 Kernel/KernelKit/PECodeManager.hxx create mode 100644 Kernel/KernelKit/PEF.hpp create mode 100644 Kernel/KernelKit/PEFCodeManager.hxx create mode 100644 Kernel/KernelKit/PEFSharedObject.hxx create mode 100644 Kernel/KernelKit/PermissionSelector.hxx create mode 100644 Kernel/KernelKit/ProcessScheduler.hpp create mode 100644 Kernel/KernelKit/SMPManager.hpp create mode 100644 Kernel/KernelKit/Semaphore.hpp create mode 100644 Kernel/KernelKit/ThreadLocalStorage.hxx create mode 100644 Kernel/KernelKit/ThreadLocalStorage.inl create mode 100644 Kernel/KernelKit/Timer.hpp create mode 100644 Kernel/KernelKit/UserHeap.hpp create mode 100644 Kernel/KernelKit/XCOFF.hxx create mode 100644 Kernel/KernelKit/compile_flags.txt (limited to 'Kernel/KernelKit') diff --git a/Kernel/KernelKit/CodeManager.hpp b/Kernel/KernelKit/CodeManager.hpp new file mode 100644 index 00000000..176efcfd --- /dev/null +++ b/Kernel/KernelKit/CodeManager.hpp @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: CodeManager.hpp + Purpose: Code Manager and Shared Objects. + + Revision History: + + 30/01/24: Added file (amlel) + 3/8/24: Add UPP struct. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +#define kUPPNameLen 64 + +namespace NewOS +{ + /// @brief Main process entrypoint. + typedef void (*MainKind)(void); + + /// @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/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp new file mode 100644 index 00000000..7fde69aa --- /dev/null +++ b/Kernel/KernelKit/DebugOutput.hpp @@ -0,0 +1,184 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +#define kDebugMaxPorts 16 + +#define kDebugUnboundPort 0x0FEED + +#define kDebugMag0 'H' +#define kDebugMag1 'D' +#define kDebugMag2 'B' +#define kDebugMag3 'G' + +#define kDebugSourceFile 0 +#define kDebugLine 33 +#define kDebugTeam 43 +#define kDebugEOP 49 + +namespace NewOS +{ + // @brief Emulates a VT100 terminal. + class TerminalDevice final : public DeviceInterface + { + public: + TerminalDevice(void (*print)(const Char*), void (*get)(const Char*)) + : DeviceInterface(print, get) + { + } + + virtual ~TerminalDevice() + { + } + + /// @brief returns device name (terminal name) + /// @return string type (const char*) + virtual const char* Name() const override + { + return ("TerminalDevice"); + } + + NEWOS_COPY_DEFAULT(TerminalDevice); + + static TerminalDevice& Shared() noexcept; + }; + + inline TerminalDevice& end_line() + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + selfTerm << "\r"; + return selfTerm; + } + + inline TerminalDevice& carriage_return() + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + selfTerm << "\r"; + return selfTerm; + } + + inline TerminalDevice& tabulate() + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + selfTerm << "\t"; + return selfTerm; + } + + /// @brief emulate a terminal bell, like the VT100 does. + inline TerminalDevice& bell() + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + selfTerm << "\a"; + return selfTerm; + } + + namespace Detail + { + inline TerminalDevice _write_number(const Long& x, TerminalDevice& term) + { + UInt64 y = (x > 0 ? x : -x) / 10; + UInt64 h = (x > 0 ? x : -x) % 10; + + if (y) + _write_number(y, term); + + /* fail if the number is not base-10 */ + if (h > 9) + { + _write_number('?', term); + return term; + } + + if (y < 0) + y = -y; + + const char NUMBERS[11] = "0123456789"; + + Char buf[2]; + buf[0] = NUMBERS[h]; + buf[1] = 0; + + term << buf; + return term; + } + + inline TerminalDevice _write_number_hex(const Long& x, TerminalDevice& term) + { + UInt64 y = (x > 0 ? x : -x) / 16; + UInt64 h = (x > 0 ? x : -x) % 16; + + if (y) + _write_number_hex(y, term); + + /* fail if the hex number is not base-16 */ + if (h > 15) + { + _write_number_hex('?', term); + return term; + } + + if (y < 0) + y = -y; + + const char NUMBERS[17] = "0123456789ABCDEF"; + + Char buf[2]; + buf[0] = NUMBERS[h]; + buf[1] = 0; + + term << buf; + return term; + } + } // namespace Detail + + inline TerminalDevice& hex_number(const Long& x) + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + + selfTerm << "0x"; + Detail::_write_number_hex(x, selfTerm); + + return selfTerm; + } + + inline TerminalDevice& number(const Long& x) + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + + Detail::_write_number(x, selfTerm); + + return selfTerm; + } + + inline TerminalDevice& get_console_in(Char* buf) + { + TerminalDevice& selfTerm = TerminalDevice::Shared(); + selfTerm >> buf; + return selfTerm; + } + + typedef Char rt_debug_type[255]; + + class DebuggerPortHeader final + { + public: + Int16 fPort[kDebugMaxPorts]; + Int16 fBoundCnt; + }; +} // namespace NewOS + +#ifdef kcout +#undef kcout +#endif // ifdef kcout + +#define kcout TerminalDevice::Shared() +#define endl end_line() diff --git a/Kernel/KernelKit/Defines.hpp b/Kernel/KernelKit/Defines.hpp new file mode 100644 index 00000000..b40c5a54 --- /dev/null +++ b/Kernel/KernelKit/Defines.hpp @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define KERNELKIT_VERSION "1.01" +#define KERNELKIT_RELEASE "Cairo" diff --git a/Kernel/KernelKit/DeviceManager.hpp b/Kernel/KernelKit/DeviceManager.hpp new file mode 100644 index 00000000..d6a2849d --- /dev/null +++ b/Kernel/KernelKit/DeviceManager.hpp @@ -0,0 +1,131 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* NewOS device interface manager. */ +/* @file KernelKit/DeviceManager.hpp */ +/* @brief Device abstraction and I/O buffer. */ + +#include +#include + +#define kDriveManagerCount 4U + +// Last Rev +// Wed, Apr 3, 2024 9:09:41 AM + +namespace NewOS +{ + template + class DeviceInterface; + + template + class DeviceInterface + { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : fOut(Out), fIn(In) + { + } + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; + + public: + virtual DeviceInterface& operator<<(T Data) + { + fOut(Data); + return *this; + } + + virtual DeviceInterface& operator>>(T Data) + { + fIn(Data); + return *this; + } + + virtual const char* Name() const + { + return "DeviceInterface"; + } + + operator bool() + { + return fOut && fIn; + } + bool operator!() + { + return !fOut && !fIn; + } + + private: + void (*fOut)(T Data); + void (*fIn)(T Data); + }; + + /// + /// @brief Input Output Buffer + /// Used mainly to communicate between hardware. + /// + template + class IOBuf final + { + public: + explicit IOBuf(T Dat) + : fData(Dat) + { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } + + IOBuf& operator=(const IOBuf&) = default; + IOBuf(const IOBuf&) = default; + + ~IOBuf() = default; + + public: + template + R operator->() const + { + return fData; + } + + template + R& operator[](Size index) const + { + return fData[index]; + } + + private: + T fData; + }; + + ///! @brief Device enum types. + enum + { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeMedia, + kDeviceTypeCount, + }; +} // namespace NewOS diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx new file mode 100644 index 00000000..ad77958e --- /dev/null +++ b/Kernel/KernelKit/DriveManager.hxx @@ -0,0 +1,146 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef __DRIVE_MANAGER__ +#define __DRIVE_MANAGER__ + +#include +#include +#include +#include +#include +#include + +#define kDriveInvalidID -1 +#define kDriveNameLen 32 + +namespace NewOS +{ + enum + { + kInvalidDrive = -1, + kBlockDevice = 0xAD, + kMassStorage = 0xDA, + kFloppyDisc = 0xCD, + kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray + /// combine with below. + kReadOnly = 0x10, // Read only drive + kEPMDrive = 0x11, // Explicit Partition Map. + kEPTDrive = 0x12, // ESP w/ EPM partition. + kMBRDrive = 0x13, // IBM PC classic partition scheme + kDriveCnt = 9, + }; + + typedef Int64 rt_drive_id_type; + + /// @brief Media drive trait type. + struct DriveTrait final + { + Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... + Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. + rt_drive_id_type fId; // Drive id. + Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive + + /// @brief Packet drive (StorageKit compilant.) + struct DrivePacket final + { + VoidPtr fPacketContent; //! packet body. + Char fPacketMime[kDriveNameLen]; //! identify what we're sending. + SizeT fPacketSize; //! packet size + UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false + Boolean fPacketGood; + Lba fLba; + } fPacket; + + Void (*fInput)(DrivePacket* packetPtr); + Void (*fOutput)(DrivePacket* packetPtr); + Void (*fVerify)(DrivePacket* packetPtr); + const Char* (*fDriveKind)(Void); + }; + + ///! drive as a device. + typedef DriveTrait* DriveTraitPtr; + + /** + * @brief Mounted drives interface. + * @note This class has all of it's drive set to nullptr, allocate them using + * GetAddressOf(index). + */ + class MountpointInterface final + { + public: + explicit MountpointInterface() = default; + ~MountpointInterface() = default; + + NEWOS_COPY_DEFAULT(MountpointInterface); + + public: + DriveTrait& A() + { + return mA; + } + DriveTrait& B() + { + return mB; + } + DriveTrait& C() + { + return mC; + } + DriveTrait& D() + { + return mD; + } + + DriveTraitPtr GetAddressOf(Int32 index) + { + DbgLastError() = kErrorSuccess; + + switch (index) + { + case 0: + return &mA; + case 1: + return &mB; + case 2: + return &mC; + case 3: + return &mD; + default: { + DbgLastError() = kErrorNoSuchDisk; + kcout << "New OS: No such disk.\n"; + + break; + } + } + + return nullptr; + } + + private: + DriveTrait mA, mB, mC, mD; + }; + + /// @brief Unimplemented drive. + /// @param pckt + /// @return + Void ke_drv_unimplemented(DriveTrait::DrivePacket* pckt); + + /// @brief Gets the drive kind (ATA, SCSI, AHCI...) + /// @param + /// @return + const Char* ke_drive_kind(Void); + + /// @brief Makes a new drive. + /// @return the new drive. + DriveTrait construct_drive(void) noexcept; + + /// @brief Fetches the main drive. + /// @return the new drive. + DriveTrait construct_main_drive(void) noexcept; +} // namespace NewOS + +#endif /* ifndef __DRIVE_MANAGER__ */ diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp new file mode 100644 index 00000000..d0843a5e --- /dev/null +++ b/Kernel/KernelKit/FileManager.hpp @@ -0,0 +1,258 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Update documentation (amlel) + + ------------------------------------------- */ + +#pragma once + +#ifdef __FSKIT_NEWFS__ +#include +#endif // __FSKIT_NEWFS__ + +#include +#include +#include +#include + +/// @brief Filesystem abstraction manager. +/// Works like the VFS or IFS. + +#define kBootFolder "/Boot" +#define kBinFolder "/Applications" +#define kShLibsFolder "/Library" +#define kMountFolder "/Mount" + +/// refer to first enum. +#define kFileOpsCount 4 +#define kFileMimeGeneric "application-type/*" + +namespace NewOS +{ + enum + { + kFileWriteAll = 100, + kFileReadAll = 101, + kFileReadChunk = 102, + kFileWriteChunk = 103, + kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, + }; + + typedef VoidPtr NodePtr; + + /** + @brief Filesystem Manager Interface class + @brief Used to provide common I/O for a specific filesystem. +*/ + class FilesystemManagerInterface + { + public: + FilesystemManagerInterface() = default; + virtual ~FilesystemManagerInterface() = default; + + public: + NEWOS_COPY_DEFAULT(FilesystemManagerInterface); + + public: + /// @brief Mounts a new filesystem into an active state. + /// @param interface the filesystem interface + /// @return + static bool Mount(FilesystemManagerInterface* interface); + + /// @brief Unmounts the active filesystem + /// @return + static FilesystemManagerInterface* Unmount(); + + /// @brief Getter, gets the active filesystem. + /// @return + static FilesystemManagerInterface* GetMounted(); + + public: + virtual NodePtr Create(_Input const char* path) = 0; + virtual NodePtr CreateAlias(_Input const char* path) = 0; + virtual NodePtr CreateDirectory(_Input const char* path) = 0; + + public: + virtual bool Remove(_Input const char* path) = 0; + + public: + virtual NodePtr Open(_Input const char* path, _Input const char* r) = 0; + + public: + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; + virtual _Output VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) = 0; + + public: + virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; + + public: + virtual SizeT Tell(_Input NodePtr node) = 0; + virtual bool Rewind(_Input NodePtr node) = 0; + }; + +/** @brief invalid position. (n-pos) */ +#define kNPos (SizeT)(-1); + +#ifdef __FSKIT_NEWFS__ + /** + * @brief Based of FilesystemManagerInterface, takes care of managing NewFS + * disks. + */ + class NewFilesystemManager final : public FilesystemManagerInterface + { + public: + explicit NewFilesystemManager(); + ~NewFilesystemManager() override; + + public: + NEWOS_COPY_DEFAULT(NewFilesystemManager); + + public: + NodePtr Create(const char* path) override; + NodePtr CreateAlias(const char* path) override; + NodePtr CreateDirectory(const char* path) override; + + public: + bool Remove(const char* path) override; + NodePtr Open(const char* path, const char* r) override; + Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; + VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; + bool Seek(NodePtr node, SizeT off); + SizeT Tell(NodePtr node) override; + bool Rewind(NodePtr node) override; + + public: + void SetResourceFork(const char* forkName); + void SetDataFork(const char* forkName); + + NewFSParser* GetImpl() noexcept; + + private: + Char fDataFork[kNewFSForkNameLen] = {0}; + Char fRsrcFork[kNewFSForkNameLen] = {0}; + NewFSParser* fImpl{nullptr}; + }; + +#endif // ifdef __FSKIT_NEWFS__ + + /** + * Usable FileStream + * @tparam Encoding file encoding (char, wchar_t...) + * @tparam FSClass Filesystem contract who takes care of it. + */ + template + class FileStream final + { + public: + explicit FileStream(const Encoding* path, const Encoding* restrict_type); + ~FileStream(); + + public: + FileStream& operator=(const FileStream&); + FileStream(const FileStream&); + + public: + ErrorOr WriteAll(const VoidPtr data) noexcept + { + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fFile, data, kFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr Read() noexcept + { + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fFile, kFileReadAll, 0); + return ret; + } + + return nullptr; + } + + voidPtr Read(SizeT offset, SizeT sz) + { + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + auto ret = man->Read(fFile, kFileReadChunk, sz); + + return ret; + } + + return nullptr; + } + + Void Write(SizeT offset, voidPtr data, SizeT sz) + { + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + man->Write(fFile, data, sz, kFileReadChunk); + } + } + + /// @brief Leak node pointer. + /// @return The node pointer. + NodePtr Leak() + { + return fFile; + } + + public: + char* MIME() noexcept + { + return const_cast(fMime); + } + + private: + NodePtr fFile; + const Char* fMime{kFileMimeGeneric}; + }; + +#define kRestrictR "r" +#define kRestrictRB "rb" +#define kRestrictW "w" +#define kRestrictRW "rw" + + using FileStreamUTF8 = FileStream; + using FileStreamUTF16 = FileStream; + + typedef UInt64 CursorType; + + template + FileStream::FileStream(const Encoding* path, + const Encoding* restrict_type) + : fFile(Class::GetMounted()->Open(path, restrict_type)) + { + } + + template + FileStream::~FileStream() = default; +} // namespace NewOS + +#define node_cast(PTR) reinterpret_cast(PTR) diff --git a/Kernel/KernelKit/Framebuffer.hpp b/Kernel/KernelKit/Framebuffer.hpp new file mode 100644 index 00000000..903a1fa8 --- /dev/null +++ b/Kernel/KernelKit/Framebuffer.hpp @@ -0,0 +1,90 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: Framebuffer.hpp + Purpose: Framebuffer object. + +------------------------------------------- */ + +#ifndef __INC_FB_HPP__ +#define __INC_FB_HPP__ + +#include +#include + +namespace NewOS +{ + enum class FramebufferColorKind : UChar + { + RGB32, + RGB16, + RGB8, + INVALID, + }; + + class FramebufferContext final + { + public: + UIntPtr fBase; + UIntPtr fBpp; + UInt fWidth; + UInt fHeight; + }; + + class Framebuffer final + { + public: + explicit Framebuffer(Ref& addr) + : fFrameBufferAddr(addr) + { + } + ~Framebuffer() + { + } + + Framebuffer& operator=(const Framebuffer&) = delete; + Framebuffer(const Framebuffer&) = default; + + volatile UIntPtr* operator[](const UIntPtr& pos); + + operator bool(); + + const FramebufferColorKind& Color( + const FramebufferColorKind& colour = FramebufferColorKind::INVALID); + + Ref& Leak(); + + /// @brief Draws a rectangle inside the fb. + /// @param width the width of it + /// @param height the height of it + /// @param x its x coord. + /// @param y its y coord. + /// @param color the color of it. + /// @return the framebuffer object. + Framebuffer& DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color); + + /// @brief Puts a pixel on the screen. + /// @param x where in X + /// @param y where in Y + /// @param color the color of it. + /// @return the framebuffer object. + Framebuffer& PutPixel(SizeT x, SizeT y, UInt32 color); + + private: + Ref fFrameBufferAddr; + FramebufferColorKind fColour; + }; + + /***********************************************************************************/ + /// Some common colors. + /***********************************************************************************/ + + extern const UInt32 kRgbRed; + extern const UInt32 kRgbGreen; + extern const UInt32 kRgbBlue; + extern const UInt32 kRgbBlack; + extern const UInt32 kRgbWhite; +} // namespace NewOS + +#endif /* ifndef __INC_FB_HPP__ */ diff --git a/Kernel/KernelKit/HError.hpp b/Kernel/KernelKit/HError.hpp new file mode 100644 index 00000000..f4285afb --- /dev/null +++ b/Kernel/KernelKit/HError.hpp @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +namespace NewOS +{ + typedef Int32 HError; + + inline constexpr HError kErrorSuccess = 0; + inline constexpr HError kErrorExecutable = 33; + inline constexpr HError kErrorExecutableLib = 34; // no such library!!! + inline constexpr HError kErrorFileNotFound = 35; + inline constexpr HError kErrorDirectoryNotFound = 36; + inline constexpr HError kErrorDiskReadOnly = 37; + inline constexpr HError kErrorDiskIsFull = 38; + inline constexpr HError kErrorProcessFault = 39; + inline constexpr HError kErrorSocketHangUp = 40; + inline constexpr HError kErrorThreadLocalStorage = 41; + inline constexpr HError kErrorMath = 42; + inline constexpr HError kErrorNoNetwork = 43; + inline constexpr HError kErrorHeapOutOfMemory = 44; + inline constexpr HError kErrorNoSuchDisk = 45; + inline constexpr HError kErrorFileExists = 46; + inline constexpr HError kErrorFormatFailed = 47; + inline constexpr HError kErrorNetworkTimeout = 48; + inline constexpr HError kErrorInternal = 49; + inline constexpr HError kErrorForkAlreadyExists = 50; + inline constexpr HError kErrorOutOfTeamSlot = 51; + inline constexpr HError kErrorHeapNotPresent = 52; + inline constexpr HError kErrorNoEntrypoint = 53; + inline constexpr HError kErrorDiskIsCorrupted = 54; + inline constexpr HError kErrorDisk = 55; + inline constexpr HError kErrorInvalidData = 56; + inline constexpr HError kErrorUnimplemented = 0; + + Boolean ke_bug_check(void) noexcept; +} // namespace NewOS + +#define DbgOk() (kLastError == NewOS::kErrorSuccess) +#define DbgFailed() (kLastError != NewOS::kErrorSuccess) +#define DbgLastError() kLastError + +inline NewOS::HError kLastError = 0; diff --git a/Kernel/KernelKit/KernelHeap.hpp b/Kernel/KernelKit/KernelHeap.hpp new file mode 100644 index 00000000..bb21e981 --- /dev/null +++ b/Kernel/KernelKit/KernelHeap.hpp @@ -0,0 +1,39 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +// last-rev 30/01/24 +// file: KernelHeap.hpp +// description: heap allocation for the kernel. + +#include + +namespace NewOS +{ + + /// @brief Declare pointer as free. + /// @param heapPtr the pointer. + /// @return + Int32 ke_delete_ke_heap(voidPtr allocatedPtr); + + /// @brief Check if pointer is a valid kernel pointer. + /// @param heapPtr the pointer + /// @return if it exists. + Boolean ke_is_valid_heap(VoidPtr ptr); + + /// @brief allocate chunk of memory. + /// @param sz size of pointer + /// @param rw read write (true to enable it) + /// @param user is it accesible by user processes? + /// @return the pointer + voidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user); + + /// @brief Protect the heap with a CRC value. + /// @param heapPtr HIB pointer. + /// @return if it valid: point has crc now., otherwise fail. + Boolean ke_protect_ke_heap(VoidPtr heapPtr); +} // namespace NewOS diff --git a/Kernel/KernelKit/LoaderInterface.hpp b/Kernel/KernelKit/LoaderInterface.hpp new file mode 100644 index 00000000..71c90e0c --- /dev/null +++ b/Kernel/KernelKit/LoaderInterface.hpp @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +namespace NewOS +{ + /// @brief This interface is used to make loader contracts (MSCOFF, PEF). + /// @author @Amlal-El-Mahrouss + class LoaderInterface + { + public: + explicit LoaderInterface() = default; + virtual ~LoaderInterface() = default; + + NEWOS_COPY_DEFAULT(LoaderInterface); + + public: + virtual _Output const char* FormatAsString() = 0; + virtual _Output const char* MIME() = 0; + virtual _Output const char* Path() = 0; + virtual _Output ErrorOr FindStart() = 0; + virtual _Output VoidPtr FindSymbol(_Input const char* name, _Input Int32 kind) = 0; + }; +} // namespace NewOS diff --git a/Kernel/KernelKit/LockDelegate.hpp b/Kernel/KernelKit/LockDelegate.hpp new file mode 100644 index 00000000..56a2e17f --- /dev/null +++ b/Kernel/KernelKit/LockDelegate.hpp @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include + +#define kLockDone (200U) /* job is done */ +#define kLockTimedOut (100U) /* job has timed out */ + +namespace NewOS +{ + /// @brief Lock condition pointer. + typedef Boolean* LockPtr; + + /// @brief Locking delegate class, hangs until limit. + /// @tparam N the amount of cycles to wait. + template + class LockDelegate final + { + public: + LockDelegate() = delete; + + public: + explicit LockDelegate(LockPtr expr) + { + auto spin = 0U; + + while (spin != N) + { + if (*expr) + { + fLockStatus | kLockDone; + break; + } + } + + if (spin == N) + fLockStatus | kLockTimedOut; + } + + ~LockDelegate() = default; + + LockDelegate& operator=(const LockDelegate&) = delete; + LockDelegate(const LockDelegate&) = delete; + + bool Done() + { + return fLockStatus[kLockDone] == kLockDone; + } + + bool HasTimedOut() + { + return fLockStatus[kLockTimedOut] != kLockTimedOut; + } + + private: + Atom fLockStatus; + }; +} // namespace NewOS diff --git a/Kernel/KernelKit/MSDOS.hpp b/Kernel/KernelKit/MSDOS.hpp new file mode 100644 index 00000000..8b27ca58 --- /dev/null +++ b/Kernel/KernelKit/MSDOS.hpp @@ -0,0 +1,68 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: MSDOS.hpp + Purpose: MS-DOS header for NewOS. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#ifndef __MSDOS_EXEC__ +#define __MSDOS_EXEC__ + +#include +#include + +// Last Rev +// Sat Feb 24 CET 2024 + +#define kMagMz0 'M' +#define kMagMz1 'Z' + +typedef NewOS::UInt32 DosWord; +typedef NewOS::Long DosLong; + +typedef struct _DosHeader +{ + NewOS::UInt8 eMagic[2]; + DosWord eMagLen; + DosWord ePagesCount; + DosWord eCrlc; + DosWord eCParHdr; + DosWord eMinAlloc; + DosWord eMaxAlloc; + DosWord eStackSeg; + DosWord eStackPtr; + DosWord eChksum; + DosWord eIp; + DosWord eCs; + DosWord eLfarlc; + DosWord eOvno; + DosWord eRes[4]; + DosWord eOemid; + DosWord eOeminfo; + DosWord eRes2[10]; + DosLong eLfanew; +} DosHeader, *DosHeaderPtr; + +namespace NewOS +{ + /// @brief Find the PE header inside the the blob. + inline auto rt_find_exec_header(DosHeaderPtr ptrDos) -> VoidPtr + { + if (!ptrDos) + return nullptr; + if (ptrDos->eMagic[0] != kMagMz0) + return nullptr; + if (ptrDos->eMagic[1] != kMagMz1) + return nullptr; + + return (VoidPtr)(&ptrDos->eLfanew + 1); + } +} // namespace NewOS + +#endif /* ifndef __MSDOS_EXEC__ */ diff --git a/Kernel/KernelKit/PCI/Database.hpp b/Kernel/KernelKit/PCI/Database.hpp new file mode 100644 index 00000000..002e572a --- /dev/null +++ b/Kernel/KernelKit/PCI/Database.hpp @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ +#pragma once + +#include +#include + +namespace NewOS +{ + namespace Types + { + // https://wiki.osdev.org/PCI + enum class PciDeviceKind : UChar + { + MassStorageController = 0x1, + NetworkController = 0x2, + DisplayController = 0x3, + MultimediaController = 0x4, + MemoryController = 0x5, + Bridge = 0x6, + CommunicationController = 0x7, + GenericSystemPeripheral = 0x8, + InputDeviceController = 0x9, + DockingStation = 0xa, + Processor = 0xb, + SerialBusController = 0xc, + WirelessController = 0xd, + IntelligentController = 0xe, + SatelliteCommunicationsController = 0xf, + CoProcessor = 0x40, + Unassgined = 0xf, + Invalid = Unassgined, + }; + } // namespace Types +} // namespace NewOS diff --git a/Kernel/KernelKit/PCI/Device.hpp b/Kernel/KernelKit/PCI/Device.hpp new file mode 100644 index 00000000..69a99494 --- /dev/null +++ b/Kernel/KernelKit/PCI/Device.hpp @@ -0,0 +1,79 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ +#pragma once + +#include + +namespace NewOS::PCI +{ + enum class PciConfigKind : UShort + { + ConfigAddress = 0xCF8, + ConfigData = 0xCFC, + Invalid = 0xFFF + }; + + class Device final + { + public: + Device() = default; + + public: + explicit Device(UShort bus, UShort device, UShort function, UShort bar); + + Device& operator=(const Device&) = default; + + Device(const Device&) = default; + + ~Device(); + + public: + UInt Read(UInt bar, Size szData); + void Write(UInt bar, UIntPtr data, Size szData); + + public: + operator bool(); + + public: + template + UInt Read(UInt bar) + { + static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); + return Read(bar, sizeof(T)); + } + + template + void Write(UInt bar, UIntPtr data) + { + static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); + Write(bar, data, sizeof(T)); + } + + public: + UShort DeviceId(); + UShort VendorId(); + UShort InterfaceId(); + UChar Class(); + UChar Subclass(); + UChar ProgIf(); + UChar HeaderType(); + + public: + void EnableMmio(); + void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that. + + UShort Vendor(); + + private: + UShort fBus; + UShort fDevice; + UShort fFunction; + UShort fBar; + }; +} // namespace NewOS::PCI + +EXTERN_C void NewOSPCISetCfgTarget(NewOS::UInt bar); +EXTERN_C NewOS::UInt NewOSPCIReadRaw(NewOS::UInt bar); diff --git a/Kernel/KernelKit/PCI/Dma.hpp b/Kernel/KernelKit/PCI/Dma.hpp new file mode 100644 index 00000000..dc7b8601 --- /dev/null +++ b/Kernel/KernelKit/PCI/Dma.hpp @@ -0,0 +1,81 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace NewOS +{ + enum class DmaKind + { + PCI, // Bus mastering is required to be turned on. Basiaclly a request + // control system. 64-Bit access depends on the PAE bit and the device + // (if Double Address Cycle is available) + ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. + Invalid, + }; + + class DMAWrapper final + { + public: + explicit DMAWrapper() = delete; + + public: + explicit DMAWrapper(nullPtr) = delete; + explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) + : fAddress(Ptr), fKind(Kind) + { + } + + public: + DMAWrapper& operator=(voidPtr Ptr); + + public: + DMAWrapper& operator=(const DMAWrapper&) = default; + DMAWrapper(const DMAWrapper&) = default; + + public: + ~DMAWrapper() = default; + + template + T* operator->(); + + template + T* Get(const UIntPtr off = 0); + + public: + operator bool(); + bool operator!(); + + public: + bool Write(const UIntPtr& bit, const UIntPtr& offset); + UIntPtr Read(const UIntPtr& offset); + Boolean Check(UIntPtr offset) const; + + public: + UIntPtr operator[](const UIntPtr& offset); + + private: + voidPtr fAddress{nullptr}; + DmaKind fKind{DmaKind::Invalid}; + + private: + friend class DMAFactory; + }; + + class DMAFactory final + { + public: + static OwnPtr> Construct(OwnPtr& dma); + }; +} // namespace NewOS + +#include diff --git a/Kernel/KernelKit/PCI/Dma.inl b/Kernel/KernelKit/PCI/Dma.inl new file mode 100644 index 00000000..53c52802 --- /dev/null +++ b/Kernel/KernelKit/PCI/Dma.inl @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +namespace NewOS +{ + template + T* DMAWrapper::operator->() + { + return fAddress; + } + + template + T* DMAWrapper::Get(const UIntPtr offset) + { + return reinterpret_cast((UIntPtr) fAddress + offset); + } +} diff --git a/Kernel/KernelKit/PCI/Express.hpp b/Kernel/KernelKit/PCI/Express.hpp new file mode 100644 index 00000000..d6266ad2 --- /dev/null +++ b/Kernel/KernelKit/PCI/Express.hpp @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl b/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl new file mode 100644 index 00000000..92a15b8b --- /dev/null +++ b/Kernel/KernelKit/PCI/IO-Impl-AMD64.inl @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: IO-Impl-AMD64.hpp + Purpose: I/O for AMD64. + + Revision History: + + 30/01/24: Add file. (amlel) + 02/02/24: Update I/O routines. (amlel) + +------------------------------------------- */ + +namespace NewOS { +template +template +T IOArray::In(SizeT index) { + switch (sizeof(T)) { + case 4: + return HAL::In32(fPorts[index].Leak()); + case 2: + return HAL::In16(fPorts[index].Leak()); + case 1: + return HAL::In8(fPorts[index].Leak()); + default: + return 0xFFFF; + } +} + +template +template +void IOArray::Out(SizeT index, T value) { + switch (sizeof(T)) { +#ifdef __x86_64__ + case 4: + HAL::Out32(fPorts[index].Leak(), value); + case 2: + HAL::Out16(fPorts[index].Leak(), value); + case 1: + HAL::Out8(fPorts[index].Leak(), value); +#endif + default: + break; + } +} +} // namespace NewOS diff --git a/Kernel/KernelKit/PCI/IO.hpp b/Kernel/KernelKit/PCI/IO.hpp new file mode 100644 index 00000000..0b10f5d0 --- /dev/null +++ b/Kernel/KernelKit/PCI/IO.hpp @@ -0,0 +1,59 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +namespace NewOS +{ + template + class IOArray final + { + public: + IOArray() = delete; + + IOArray(nullPtr) = delete; + + explicit IOArray(Array& ports) + : fPorts(ports) + { + } + ~IOArray() + { + } + + IOArray& operator=(const IOArray&) = default; + + IOArray(const IOArray&) = default; + + operator bool() + { + return !fPorts.Empty(); + } + + public: + template + T In(SizeT index); + + template + void Out(SizeT index, T value); + + private: + Array fPorts; + }; + + using IOArray16 = IOArray<16>; +} // namespace NewOS + +#ifdef __x86_64__ +#include +#else +#error Please provide platform specific code for the I/O +#endif // ifdef __x86_64__ diff --git a/Kernel/KernelKit/PCI/Iterator.hpp b/Kernel/KernelKit/PCI/Iterator.hpp new file mode 100644 index 00000000..278711a7 --- /dev/null +++ b/Kernel/KernelKit/PCI/Iterator.hpp @@ -0,0 +1,38 @@ +#ifndef __PCI_ITERATOR_HPP__ +#define __PCI_ITERATOR_HPP__ + +#include +#include +#include +#include +#include + +#define NEWOS_BUS_COUNT (256) +#define NEWOS_DEVICE_COUNT (33) +#define NEWOS_FUNCTION_COUNT (8) + +namespace NewOS::PCI +{ + class Iterator final + { + public: + Iterator() = delete; + + public: + explicit Iterator(const Types::PciDeviceKind& deviceType); + + Iterator& operator=(const Iterator&) = default; + + Iterator(const Iterator&) = default; + + ~Iterator(); + + public: + Ref operator[](const Size& sz); + + private: + Array fDevices; + }; +} // namespace NewOS::PCI + +#endif // __PCI_ITERATOR_HPP__ diff --git a/Kernel/KernelKit/PCI/PCI.hpp b/Kernel/KernelKit/PCI/PCI.hpp new file mode 100644 index 00000000..2e523d4a --- /dev/null +++ b/Kernel/KernelKit/PCI/PCI.hpp @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ +#pragma once + +#include + +#define PCI_CONFIG_ADDRESS (0xCF8) +#define PCI_CONFIG_DATA (0xCFC) + +#define PCI_DEVICE_COUNT (32) +#define PCI_FUNC_COUNT (8) +#define PCI_BUS_COUNT (255) + +namespace NewOS::PCI +{ + // model + struct DeviceHeader + { + UInt16 VendorId; + UInt16 DeviceId; + UInt8 Command; + UInt8 Status; + UInt8 RevisionId; + UInt8 ProgIf; + UInt8 SubClass; + UInt8 Class; + UInt8 CacheLineSz; + UInt8 LatencyTimer; + UInt8 HeaderType; + UInt8 Bist; + UInt8 Bus; + UInt8 Device; + UInt8 Function; + }; + + namespace Detail + { + class BAR + { + public: + UIntPtr BAR; + SizeT Size; + }; + } // namespace Detail + + class BAR + { + public: + Detail::BAR BAR1; + Detail::BAR BAR2; + Detail::BAR BAR3; + Detail::BAR BAR4; + Detail::BAR BAR5; + }; +} // namespace NewOS::PCI diff --git a/Kernel/KernelKit/PE.hxx b/Kernel/KernelKit/PE.hxx new file mode 100644 index 00000000..5ab40b70 --- /dev/null +++ b/Kernel/KernelKit/PE.hxx @@ -0,0 +1,123 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: PE.hxx + Purpose: Portable Executable for NewOS. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#ifndef __PE__ +#define __PE__ + +#include + +#define kPeMagic 0x00004550 + +typedef struct ExecHeader final +{ + NewOS::UInt32 mMagic; // PE\0\0 or 0x00004550 + NewOS::UInt16 mMachine; + NewOS::UInt16 mNumberOfSections; + NewOS::UInt32 mTimeDateStamp; + NewOS::UInt32 mPointerToSymbolTable; + NewOS::UInt32 mNumberOfSymbols; + NewOS::UInt16 mSizeOfOptionalHeader; + NewOS::UInt16 mCharacteristics; +} ALIGN(8) ExecHeader, *ExecHeaderPtr; + +#define kMagPE32 0x010b +#define kMagPE64 0x020b + +#define kPEMachineAMD64 0x8664 +#define kPEMachineARM64 0xaa64 + +typedef struct ExecOptionalHeader final +{ + NewOS::UInt16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) + NewOS::UChar mMajorLinkerVersion; + NewOS::UChar mMinorLinkerVersion; + NewOS::UIntPtr mSizeOfCode; + NewOS::UIntPtr mSizeOfInitializedData; + NewOS::UIntPtr mSizeOfUninitializedData; + NewOS::UInt32 mAddressOfEntryPoint; + NewOS::UInt32 mBaseOfCode; + NewOS::UIntPtr mImageBase; + NewOS::UInt32 mSectionAlignment; + NewOS::UInt32 mFileAlignment; + NewOS::UInt16 mMajorOperatingSystemVersion; + NewOS::UInt16 mMinorOperatingSystemVersion; + NewOS::UInt16 mMajorImageVersion; + NewOS::UInt16 mMinorImageVersion; + NewOS::UInt16 mMajorSubsystemVersion; + NewOS::UInt16 mMinorSubsystemVersion; + NewOS::UInt32 mWin32VersionValue; + NewOS::UIntPtr mSizeOfImage; + NewOS::UIntPtr mSizeOfHeaders; + NewOS::UInt32 mCheckSum; + NewOS::UInt16 mSubsystem; + NewOS::UInt16 mDllCharacteristics; + NewOS::UIntPtr mSizeOfStackReserve; + NewOS::UIntPtr mSizeOfStackCommit; + NewOS::UIntPtr mSizeOfHeapReserve; + NewOS::UIntPtr mSizeOfHeapCommit; + NewOS::UInt32 mLoaderFlags; + NewOS::UInt32 mNumberOfRvaAndSizes; +} ExecOptionalHeader, *ExecOptionalHeaderPtr; + +typedef struct ExecSectionHeader final +{ + CONST NewOS::UChar mName[8]; + NewOS::UInt32 mVirtualSize; + NewOS::UInt32 mVirtualAddress; + NewOS::UInt32 mSizeOfRawData; + NewOS::UInt32 mPointerToRawData; + NewOS::UInt32 mPointerToRelocations; + NewOS::UInt32 mPointerToLinenumbers; + NewOS::UInt16 mNumberOfRelocations; + NewOS::UInt16 mNumberOfLinenumbers; + NewOS::UInt32 mCharacteristics; +} ExecSectionHeader, *ExecSectionHeaderPtr; + +enum kExecDataDirParams +{ + kExecExport, + kExecImport, + kExecInvalid, + kExecCount, +}; + +typedef struct ExecExportDirectory +{ + NewOS::UInt32 mCharacteristics; + NewOS::UInt32 mTimeDateStamp; + NewOS::UInt16 mMajorVersion; + NewOS::UInt16 mMinorVersion; + NewOS::UInt32 mName; + NewOS::UInt32 mBase; + NewOS::UInt32 mNumberOfFunctions; + NewOS::UInt32 mNumberOfNames; + NewOS::UInt32 mAddressOfFunctions; // export table rva + NewOS::UInt32 mAddressOfNames; + NewOS::UInt32 mAddressOfNameOrdinal; // ordinal table rva +} ExecExportDirectory, *ExecExportDirectoryPtr; + +typedef struct ExecImportDirectory +{ + union { + NewOS::UInt32 mCharacteristics; + NewOS::UInt32 mOriginalFirstThunk; + }; + NewOS::UInt32 mTimeDateStamp; + NewOS::UInt32 mForwarderChain; + NewOS::UInt32 mNameRva; + NewOS::UInt32 mThunkTableRva; +} ExecImportDirectory, *ExecImportDirectoryPtr; + +#define kPeStart "__hcore_subsys_start" + +#endif /* ifndef __PE__ */ diff --git a/Kernel/KernelKit/PECodeManager.hxx b/Kernel/KernelKit/PECodeManager.hxx new file mode 100644 index 00000000..0627617c --- /dev/null +++ b/Kernel/KernelKit/PECodeManager.hxx @@ -0,0 +1,24 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: PECodeManager.hxx + Purpose: PE32+ Code Manager and Shared Objects. + + Revision History: + + 12/02/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +//////////////////////////////////////////////////// + +// LAST REV: Mon Feb 12 13:52:01 CET 2024 + +//////////////////////////////////////////////////// + +#include +#include +#include diff --git a/Kernel/KernelKit/PEF.hpp b/Kernel/KernelKit/PEF.hpp new file mode 100644 index 00000000..77fa4f62 --- /dev/null +++ b/Kernel/KernelKit/PEF.hpp @@ -0,0 +1,114 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: PEF.hpp + Purpose: Preferred Executable Format for NewOS. + + Revision History: + + ?/?/23: Added file (amlel) + +------------------------------------------- */ + +#ifndef __PEF__ +#define __PEF__ + +#include +#include +#include + +#define kPefMagic "Joy!" +#define kPefMagicFat "yoJ!" + +#define kPefMagicLen 5 + +#define kPefVersion 1 +#define kPefNameLen 255 + +namespace NewOS +{ + enum + { + kPefArchIntel86S, + kPefArchAMD64, + kPefArchRISCV, + kPefArch64x0, /* 64x0. ISA */ + kPefArch32x0, /* 32x0. ISA */ + kPefArchPowerPC, + kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1, + kPefArchInvalid = 0xFF, + }; + + enum + { + kPefSubArchAMD, + kPefSubArchIntel, + kPefSubArchARM, + kPefSubArchIBM, + }; + + enum + { + kPefKindExec = 1, /* .exe */ + kPefKindSharedObject = 2, /* .lib */ + kPefKindObject = 4, /* .obj */ + kPefKindDebug = 5, /* .dbg */ + kPefKindDriver = 6, + kPefKindCount, + }; + + typedef struct PEFContainer final + { + Char Magic[kPefMagicLen]; + UInt32 Linker; + UInt32 Version; + UInt32 Kind; + UInt32 Abi; + UInt32 Cpu; + UInt32 SubCpu; /* Cpu specific information */ + UIntPtr Start; + SizeT HdrSz; /* Size of header */ + SizeT Count; /* container header count */ + } PACKED PEFContainer; + + /* First PEFCommandHeader starts after PEFContainer */ + /* Last container is __exec_end */ + + /* PEF executable section and commands. */ + + typedef struct PEFCommandHeader final + { + Char Name[kPefNameLen]; /* container name */ + UInt32 Cpu; /* container cpu */ + UInt32 SubCpu; /* container sub-cpu */ + UInt32 Flags; /* container flags */ + UInt16 Kind; /* container kind */ + UIntPtr Offset; /* content offset */ + SizeT Size; /* content Size */ + } PACKED PEFCommandHeader; + + enum + { + kPefCode = 0xC, + kPefData = 0xD, + kPefZero = 0xE, + kPefLinkerID = 0x1, + }; +} // namespace NewOS + +#define kPefExt ".exec" +#define kPefDylibExt ".lib" +#define kPefLibExt ".slib" +#define kPefObjectExt ".obj" +#define kPefDebugExt ".dbg" + +// NewOS System Binary Interface. +#define kPefAbi (0x5046) + +#define kPefStart "__ImageStart" + +#define kPefForkKind kPefMagic +#define kPefForkKindFAT kPefMagicFat + +#endif /* ifndef __PEF__ */ diff --git a/Kernel/KernelKit/PEFCodeManager.hxx b/Kernel/KernelKit/PEFCodeManager.hxx new file mode 100644 index 00000000..1dc7c3ac --- /dev/null +++ b/Kernel/KernelKit/PEFCodeManager.hxx @@ -0,0 +1,60 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef _INC_CODE_MANAGER_PEF_ +#define _INC_CODE_MANAGER_PEF_ + +#include +#include +#include + +#define kPefApplicationMime "application/x-newos-exec" + +namespace NewOS +{ + /// + /// \name PEFLoader + /// \brief PEF loader class. + /// + class PEFLoader : public LoaderInterface + { + private: + explicit PEFLoader() = delete; + + public: + explicit PEFLoader(const VoidPtr blob); + explicit PEFLoader(const Char* path); + ~PEFLoader() override; + + public: + NEWOS_COPY_DEFAULT(PEFLoader); + + public: + const char* Path() override; + const char* FormatAsString() override; + const char* MIME() override; + + public: + ErrorOr FindStart() override; + VoidPtr FindSymbol(const char* name, Int32 kind) override; + + public: + bool IsLoaded() noexcept; + + private: + Ref fPath; + VoidPtr fCachedBlob; + bool fFatBinary; + bool fBad; + }; + + namespace Utils + { + bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept; + } // namespace Utils +} // namespace NewOS + +#endif // ifndef _INC_CODE_MANAGER_PEF_ diff --git a/Kernel/KernelKit/PEFSharedObject.hxx b/Kernel/KernelKit/PEFSharedObject.hxx new file mode 100644 index 00000000..436145df --- /dev/null +++ b/Kernel/KernelKit/PEFSharedObject.hxx @@ -0,0 +1,112 @@ +/* + * ======================================================== + * + * NewOS + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#ifndef __KERNELKIT_SHARED_OBJECT_HXX__ +#define __KERNELKIT_SHARED_OBJECT_HXX__ + +#include +#include +#include +#include + +namespace NewOS +{ + /// @brief Pure implementation, missing method/function handler. + extern "C" void __mh_purecall(void); + + /** + * @brief Shared Library class + * Load library from this class + */ + class SharedObject final + { + public: + struct SharedObjectTrait final + { + VoidPtr fImageObject; + VoidPtr fImageEntrypointOffset; + }; + + public: + explicit SharedObject() = default; + ~SharedObject() = default; + + public: + NEWOS_COPY_DEFAULT(SharedObject); + + private: + SharedObjectTrait* fMounted{nullptr}; + + public: + SharedObjectTrait** GetAddressOf() + { + return &fMounted; + } + + SharedObjectTrait* Get() + { + return fMounted; + } + + public: + void Mount(SharedObjectTrait* to_mount) + { + if (!to_mount || !to_mount->fImageObject) + return; + + fMounted = to_mount; + + if (fLoader && to_mount) + { + delete fLoader; + fLoader = nullptr; + } + + if (!fLoader) + { + fLoader = new PEFLoader(fMounted->fImageObject); + } + } + + void Unmount() + { + if (fMounted) + fMounted = nullptr; + }; + + template + SymbolType Load(const char* symbol_name, SizeT len, Int32 kind) + { + if (symbol_name == nullptr || *symbol_name == 0) + return nullptr; + if (len > kPathLen || len < 1) + return nullptr; + + auto ret = + reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); + + if (!ret) + { + if (kind == kPefCode) + return (VoidPtr)__mh_purecall; + + return nullptr; + } + + return ret; + } + + private: + PEFLoader* fLoader{nullptr}; + }; + + typedef SharedObject* SharedObjectPtr; +} // namespace NewOS + +#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */ diff --git a/Kernel/KernelKit/PermissionSelector.hxx b/Kernel/KernelKit/PermissionSelector.hxx new file mode 100644 index 00000000..22771bdd --- /dev/null +++ b/Kernel/KernelKit/PermissionSelector.hxx @@ -0,0 +1,57 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef _INC_PERMISSION_SEL_HPP +#define _INC_PERMISSION_SEL_HPP + +#include +#include + +// kernel mode user. +#define kMachineUser "Machine" + +// user mode users. +#define kSuperUser "Admin" +#define kGuestUser "Guest" + +// hash 'user@host:password' -> base64 encoded data +// use this data to then fetch specific data. + +namespace NewOS +{ + enum class RingKind + { + kRingUser = 3, + kRingDriver = 2, + kRingKernel = 0, + kRingUnknown = -1, + kRingCount = 4, + }; + + class PermissionSelector final + { + private: + explicit PermissionSelector(const Int32& sel); + explicit PermissionSelector(const RingKind& kind); + + ~PermissionSelector(); + + public: + NEWOS_COPY_DEFAULT(PermissionSelector) + + public: + bool operator==(const PermissionSelector& lhs); + bool operator!=(const PermissionSelector& lhs); + + public: + const RingKind& Ring() noexcept; + + private: + RingKind fRing; + }; +} // namespace NewOS + +#endif /* ifndef _INC_PERMISSION_SEL_HPP */ diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp new file mode 100644 index 00000000..ba34f9cb --- /dev/null +++ b/Kernel/KernelKit/ProcessScheduler.hpp @@ -0,0 +1,301 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef __PROCESS_SCHEDULER__ +#define __PROCESS_SCHEDULER__ + +#include +#include +#include +#include +#include +#include + +#define kSchedMinMicroTime AffinityKind::kHartStandard +#define kSchedInvalidPID (-1) + +#define kSchedProcessLimitPerTeam (100U) + +//////////////////////////////////////////////////// + +// LAST REV: Mon Feb 12 13:52:01 CET 2024 + +//////////////////////////////////////////////////// + +namespace NewOS +{ + class ProcessHeader; + class ProcessTeam; + class ProcessScheduler; + + //! @brief Process identifier. + typedef Int64 ProcessID; + + //! @brief Process name length. + inline constexpr SizeT kProcessLen = 256U; + + //! @brief Forward declaration. + class ProcessHeader; + class ProcessScheduler; + class ProcessHelper; + + //! @brief Process status enum. + enum class ProcessStatus : Int32 + { + kStarting, + kRunning, + kKilled, + kFrozen, + kDead + }; + + //! @brief Affinity is the amount of nano-seconds this process is going + //! to run. + enum class AffinityKind : Int32 + { + kInvalid = 300, + kVeryHigh = 250, + kHigh = 200, + kHartStandard = 150, + kLowUsage = 100, + kVeryLowUsage = 50, + }; + + // operator overloading. + + inline bool operator<(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int < rhs_int; + } + + inline bool operator>(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int > rhs_int; + } + + inline bool operator<=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int <= rhs_int; + } + + inline bool operator>=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int >= rhs_int; + } + + // end of operator overloading. + + enum ProcessSubsystemEnum + { + eProcessSubsystemLogin, + eProcessSubsystemNative, + eProcessSubsystemInvalid, + eProcessSubsystemCount, + }; + + using ProcessSubsystem = ProcessSubsystemEnum; + using ProcessTime = UInt64; + using PID = Int64; + + // for permission manager, tells where we run the code. + enum class ProcessSelector : Int + { + kRingUser, /* user ring (or ring 3 in x86) */ + kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ + kRingKernel, /* machine privileges */ + }; + + // Helper types. + using ImagePtr = VoidPtr; + using HeapPtr = VoidPtr; + + // @name ProcessHeader + // @brief Process Header (PH) + // Holds information about the running process. + // Thread execution is being abstracted away. + class ProcessHeader final + { + public: + explicit ProcessHeader(VoidPtr startImage = nullptr) + : Image(startImage) + { + MUST_PASS(startImage); + } + + ~ProcessHeader() = default; + + NEWOS_COPY_DEFAULT(ProcessHeader) + + public: + void SetEntrypoint(UIntPtr& imageStart) noexcept; + + public: + Char Name[kProcessLen] = {"NewOS Process"}; + ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid}; + ProcessSelector Selector{ProcessSelector::kRingUser}; + HAL::StackFramePtr StackFrame{nullptr}; + AffinityKind Affinity; + ProcessStatus Status; + + // Memory, images. + HeapPtr HeapCursor{nullptr}; + ImagePtr Image{nullptr}; + HeapPtr HeapPtr{nullptr}; + + // memory usage + SizeT UsedMemory{0}; + SizeT FreeMemory{0}; + + enum + { + kUserKind = 3, + kLibKind = 3, + kDriverKind = 0, + kKindCount, + }; + + enum + { + kRingUserKind = 3, + kRingDriverKind = 0, + }; + + ProcessTime PTime; + PID ProcessId{kSchedInvalidPID}; + Int32 Ring{kRingDriverKind}; + Int32 Kind{kUserKind}; + + public: + //! @brief boolean operator, check status. + operator bool() + { + return Status != ProcessStatus::kDead; + } + + //! @brief Crash the app, exits with code ~0. + void Crash(); + + //! @brief Exits app. + void Exit(Int32 exitCode = 0); + + //! @brief TLS Allocate + VoidPtr New(const SizeT& sz); + + //! @brief TLS Free. + Boolean Delete(VoidPtr ptr, const SizeT& sz); + + //! @brief Wakes up threads. + void Wake(const bool wakeup = false); + + // ProcessHeader getters. + public: + //! @brief ProcessHeader name getter, example: "C RunTime" + const Char* GetName(); + + const ProcessSelector& GetSelector(); + const ProcessStatus& GetStatus(); + const AffinityKind& GetAffinity(); + + private: + friend ProcessScheduler; + friend ProcessHelper; + }; + + /// \brief Processs Team (contains multiple processes inside it.) + /// Equivalent to a process batch + class ProcessTeam final + { + public: + explicit ProcessTeam() = default; + ~ProcessTeam() = default; + + NEWOS_COPY_DEFAULT(ProcessTeam); + + MutableArray>& AsArray(); + Ref& AsRef(); + + public: + MutableArray> mProcessList; + Ref mCurrentProcess; + }; + + using ProcessHeaderRef = ProcessHeader*; + + /// @brief ProcessHeader manager class. + /// The main class which you call to schedule an app. + class ProcessScheduler final + { + private: + explicit ProcessScheduler() = default; + + public: + ~ProcessScheduler() = default; + + NEWOS_COPY_DEFAULT(ProcessScheduler) + + operator bool() + { + return mTeam.AsArray().Count() > 0; + } + bool operator!() + { + return mTeam.AsArray().Count() == 0; + } + + ProcessTeam& CurrentTeam() + { + return mTeam; + } + + SizeT Add(Ref& headerRef); + bool Remove(SizeT headerIndex); + + Ref& GetCurrent(); + SizeT Run() noexcept; + + static Ref Shared(); + + private: + ProcessTeam mTeam; + }; + + /* + * Just a helper class, which contains some utilities for the scheduler. + */ + + class ProcessHelper final + { + public: + static bool Switch(HAL::StackFrame* newStack, const PID& newPid); + static bool CanBeScheduled(Ref& process); + static PID& GetCurrentPID(); + static bool StartScheduling(); + }; + + const Int32& rt_get_exit_code() noexcept; +} // namespace NewOS + +#include + +//////////////////////////////////////////////////// + +// END + +//////////////////////////////////////////////////// + +#endif /* ifndef __PROCESS_SCHEDULER__ */ diff --git a/Kernel/KernelKit/SMPManager.hpp b/Kernel/KernelKit/SMPManager.hpp new file mode 100644 index 00000000..3d7a4189 --- /dev/null +++ b/Kernel/KernelKit/SMPManager.hpp @@ -0,0 +1,129 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef __SMP_MANAGER__ +#define __SMP_MANAGER__ + +#include +#include +#include + +// Last Rev +// Sat Feb 24 CET 2024 + +#define kMaxHarts 8 + +namespace NewOS +{ + using ThreadID = UInt32; + + enum ThreadKind + { + kHartSystemReserved, // System reserved thread, well user can't use it + kHartStandard, // user thread, cannot be used by kernel + kHartFallback, // fallback thread, cannot be used by user if not clear or + // used by kernel. + kHartBoot, // The core we booted from, the mama. + kInvalidHart, + kHartCount, + }; + + typedef enum ThreadKind SmThreadKind; + typedef ThreadID SmThreadID; + + /// + /// \name HardwareThread + /// @brief CPU Hardware Thread (POWER, x64, or 64x0) + /// + + class HardwareThread final + { + public: + explicit HardwareThread(); + ~HardwareThread(); + + public: + NEWOS_COPY_DEFAULT(HardwareThread) + + public: + operator bool(); + + public: + void Wake(const bool wakeup = false) noexcept; + void Busy(const bool busy = false) noexcept; + + public: + bool Switch(HAL::StackFrame* stack); + bool IsWakeup() noexcept; + + public: + HAL::StackFrame* StackFrame() noexcept; + const ThreadKind& Kind() noexcept; + bool IsBusy() noexcept; + const ThreadID& ID() noexcept; + + private: + HAL::StackFrame* fStack; + ThreadKind fKind; + ThreadID fID; + bool fWakeup; + bool fBusy; + Int64 fPID; + + private: + friend class SMPManager; + }; + + /// + /// \name SMPManager + /// @brief Multi processor manager to manage other cores and dispatch tasks. + /// + + class SMPManager final + { + private: + explicit SMPManager(); + + public: + ~SMPManager(); + + public: + NEWOS_COPY_DEFAULT(SMPManager); + + public: + bool Switch(HAL::StackFrame* the); + HAL::StackFramePtr GetStackFrame() noexcept; + + public: + Ref operator[](const SizeT& idx); + bool operator!() noexcept; + operator bool() noexcept; + + public: + /// @brief Shared instance of the SMP Manager. + /// @return the reference to the smp manager. + static Ref Shared(); + + public: + /// @brief Returns the amount of threads present in the system. + /// @returns SizeT the amount of cores present. + SizeT Count() noexcept; + + private: + Array fThreadList; + ThreadID fCurrentThread{0}; + }; + + /// @brief wakes up thread. + /// wakes up thread from hang. + Void rt_wakeup_thread(HAL::StackFramePtr stack); + + /// @brief makes thread sleep. + /// hooks and hangs thread to prevent code from executing. + Void rt_hang_thread(HAL::StackFramePtr stack); +} // namespace NewOS + +#endif // !__SMP_MANAGER__ diff --git a/Kernel/KernelKit/Semaphore.hpp b/Kernel/KernelKit/Semaphore.hpp new file mode 100644 index 00000000..f12e1282 --- /dev/null +++ b/Kernel/KernelKit/Semaphore.hpp @@ -0,0 +1,42 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace NewOS +{ + class ProcessHeader; + + typedef ProcessHeader* ProcessHeaderRef; + + /// @brief Access control class, which locks a task until one is done. + class Semaphore final + { + public: + explicit Semaphore() = default; + ~Semaphore() = default; + + public: + bool IsLocked() const; + bool Unlock() noexcept; + + public: + void Sync() noexcept; + + public: + bool Lock(ProcessHeader* process); + bool LockOrWait(ProcessHeader* process, const Int64& seconds); + + public: + NEWOS_COPY_DEFAULT(Semaphore); + + private: + ProcessHeaderRef fLockingProcess{nullptr}; + }; +} // namespace NewOS diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx new file mode 100644 index 00000000..eece3cbc --- /dev/null +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -0,0 +1,53 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef _KERNELKIT_TLS_HPP +#define _KERNELKIT_TLS_HPP + +#include + +//! @brief TLS implementation in C++ + +#define kCookieMag0 'H' +#define kCookieMag1 'C' +#define kCookieMag2 'R' + +template +T* tls_new_ptr(void); + +template +bool tls_delete_ptr(T* ptr); + +template +T* tls_new_class(Args&&... args); + +#define kTLSCookieLen 3 + +/// @brief Thread Information Block for Local Storage. +/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) +struct PACKED ThreadInformationBlock final +{ + NewOS::Char Cookie[kTLSCookieLen]; + NewOS::UIntPtr StartCode; // Start Address + NewOS::UIntPtr StartData; // Allocation Heap + NewOS::UIntPtr StartStack; // Stack Pointer. + NewOS::Int32 ThreadID; // Thread execution ID. +}; + +/// @brief TLS install TIB and PIB. +EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, NewOS::VoidPtr PIB); + +///! @brief Cookie Sanity check. +NewOS::Boolean tls_check_tib(ThreadInformationBlock* Ptr); + +/// @brief TLS check system call +EXTERN_C NewOS::Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr StackPtr) noexcept; + +#include + +// last rev 1/29/24 + +#endif /* ifndef _KERNELKIT_TLS_HPP */ diff --git a/Kernel/KernelKit/ThreadLocalStorage.inl b/Kernel/KernelKit/ThreadLocalStorage.inl new file mode 100644 index 00000000..ae3277eb --- /dev/null +++ b/Kernel/KernelKit/ThreadLocalStorage.inl @@ -0,0 +1,55 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +//! @brief Allocates a pointer from the process's tls. + +#ifndef __PROCESS_MANAGER__ +#include +#endif + +template +inline T* tls_new_ptr(void) +{ + using namespace NewOS; + + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); + + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); + + T* pointer = (T*)ref_process.Leak().New(sizeof(T)); + return pointer; +} + +//! @brief TLS delete implementation. +template +inline bool tls_delete_ptr(T* ptr) +{ + if (!ptr) + return false; + + using namespace NewOS; + + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); + + ptr->~T(); + + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); + return ref_process.Leak().Delete(ptr, sizeof(T)); +} + +template +T* tls_new_class(Args&&... args) +{ + T* ptr = tls_new_ptr(); + + if (ptr) + { + *ptr = T(NewOS::forward(args)...); + return ptr; + } + + return nullptr; +} diff --git a/Kernel/KernelKit/Timer.hpp b/Kernel/KernelKit/Timer.hpp new file mode 100644 index 00000000..8b0642c7 --- /dev/null +++ b/Kernel/KernelKit/Timer.hpp @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace NewOS +{ + class HardwareTimer; + class HardwareTimerInterface; + + class HardwareTimerInterface + { + public: + /// @brief Default constructor + explicit HardwareTimerInterface() = default; + virtual ~HardwareTimerInterface() = default; + + public: + NEWOS_COPY_DEFAULT(HardwareTimerInterface); + + public: + virtual Int32 Wait() noexcept; + }; + + class HardwareTimer final : public HardwareTimerInterface + { + public: + explicit HardwareTimer(Int64 seconds); + ~HardwareTimer() override; + + public: + NEWOS_COPY_DEFAULT(HardwareTimer); + + public: + Int32 Wait() noexcept override; + + public: + IntPtr* fDigitalTimer{nullptr}; + Int64 fWaitFor{0}; + }; + + inline Int64 Seconds(Int64 time) + { + if (time < 0) + return 0; + + return 1000 / time; + } + + inline Int64 Milliseconds(Int64 time) + { + if (time < 0) + return 0; + + return 1000 / Seconds(time); + } +} // namespace NewOS diff --git a/Kernel/KernelKit/UserHeap.hpp b/Kernel/KernelKit/UserHeap.hpp new file mode 100644 index 00000000..6197e30d --- /dev/null +++ b/Kernel/KernelKit/UserHeap.hpp @@ -0,0 +1,46 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +/// @version 5/11/23 +/// @file UserHeap.hpp +/// @brief memory heap for user programs. + +#define kUserHeapMaxSz (4096) +#define kUserHeapMag (0xFAF0FEF0) + +namespace NewOS +{ + typedef enum + { + /// @brief Driver only heap. + kUserHeapDriver = 0x2, + /// @brief Shared heap. + kUserHeapShared = 0x4, + /// @brief User and private heap. + kUserHeapUser = 0x6, + /// @brief Read and Write heap. + kUserHeapRw = 0x8, + } kUserHeapFlags; + + /// @brief Allocate a process heap, no zero out is done here. + /// @param flags + /// @return The process's heap. + VoidPtr rt_new_heap(Int32 flags); + + /// @brief Frees the process heap. + /// @param pointer The process heap pointer. + /// @return + Int32 rt_free_heap(voidPtr pointer); +} // namespace NewOS diff --git a/Kernel/KernelKit/XCOFF.hxx b/Kernel/KernelKit/XCOFF.hxx new file mode 100644 index 00000000..2b153918 --- /dev/null +++ b/Kernel/KernelKit/XCOFF.hxx @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + File: XCOFF.hpp + Purpose: XCOFF for NewOS. + + Revision History: + + 04/07/24: Added file (amlel) + +------------------------------------------- */ + +#ifndef __XCOFF__ +#define __XCOFF__ + +#include + +#define kXCOFF64Magic 0x01F7 + +#define kXCOFFRelFlg 0x0001 +#define kXCOFFExecutable 0x0002 +#define kXCOFFLnno 0x0004 +#define kXCOFFLSyms 0x0008 + +/// @brief XCoff file header, meant for POWER apps. +typedef struct XCoffFileHeader +{ + NewOS::UInt16 fMagic; + NewOS::UInt16 fTarget; + NewOS::UInt16 fNumSecs; + NewOS::UInt32 fTimeDat; + NewOS::UIntPtr fSymPtr; + NewOS::UInt32 fNumSyms; + NewOS::UInt16 fOptHdr; // ?: Number of bytes in optional header +} XCoffFileHeader; + +#endif // ifndef __XCOFF__ diff --git a/Kernel/KernelKit/compile_flags.txt b/Kernel/KernelKit/compile_flags.txt new file mode 100644 index 00000000..a37ae6bf --- /dev/null +++ b/Kernel/KernelKit/compile_flags.txt @@ -0,0 +1,5 @@ +-nostdlib +-ffreestanding +-std=c++20 +-I./ +-I../ -- cgit v1.2.3 From 915c14eb3b717bbd168d069e296a4246c6aef117 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 19:23:04 +0200 Subject: MHR-23: Starting to implement SMP for AMD64. Signed-off-by: Amlal El Mahrouss --- Boot/Source/HEL/AMD64/BootMain.cxx | 3 +- Kernel/HALKit/64x0/ReadMe.md | 4 +++ Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 11 ++++--- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 33 ++++++++++--------- Kernel/HALKit/AMD64/HalHardwareMP.cpp | 4 +-- Kernel/HALKit/AMD64/HalInterruptAPI.asm | 20 ++++++------ Kernel/HALKit/AMD64/ReadMe.md | 4 +++ Kernel/HALKit/ARM64/ReadMe.md | 4 +++ Kernel/HALKit/POWER/ReadMe.md | 4 +++ Kernel/HALKit/RISCV/ReadMe.md | 4 +++ Kernel/KernelKit/DebugOutput.hpp | 28 +++++++++++++++- Kernel/Source/AppMain.cxx | 10 ++++++ Kernel/Source/CodeManager.cxx | 37 +++++++++++----------- 13 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 Kernel/HALKit/64x0/ReadMe.md create mode 100644 Kernel/HALKit/AMD64/ReadMe.md create mode 100644 Kernel/HALKit/ARM64/ReadMe.md create mode 100644 Kernel/HALKit/POWER/ReadMe.md create mode 100644 Kernel/HALKit/RISCV/ReadMe.md (limited to 'Kernel/KernelKit') diff --git a/Boot/Source/HEL/AMD64/BootMain.cxx b/Boot/Source/HEL/AMD64/BootMain.cxx index f422b661..649596b4 100644 --- a/Boot/Source/HEL/AMD64/BootMain.cxx +++ b/Boot/Source/HEL/AMD64/BootMain.cxx @@ -90,7 +90,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries; ++indexVT) { - volatile Char* vendorTable = reinterpret_cast( + Char* vendorTable = reinterpret_cast( SystemTable->ConfigurationTable[indexVT].VendorTable); /// ACPI's 'RSD PTR', which contains hardware tables (MADT, FACP...) @@ -99,6 +99,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, vendorTable[4] == 'P' && vendorTable[5] == 'T' && vendorTable[6] == 'R' && vendorTable[7] == ' ') { + writer.Write(L"New Boot: Found ACPI RSD PTR!\r"); handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable; break; diff --git a/Kernel/HALKit/64x0/ReadMe.md b/Kernel/HALKit/64x0/ReadMe.md new file mode 100644 index 00000000..6744f602 --- /dev/null +++ b/Kernel/HALKit/64x0/ReadMe.md @@ -0,0 +1,4 @@ +64x0 Hardware Abstraction Layer + +- Supported CPU: SoftwareLabs 64x0 +- Supported Firmware: CoreBoot \ No newline at end of file diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index 3609165f..f4c9226e 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -75,7 +75,7 @@ namespace NewOS SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); - SizeT num = xsdt->Length + sizeof(SDT) / 8; + SizeT num = (xsdt->Length + sizeof(SDT)) / 8; this->fEntries = num; @@ -83,10 +83,11 @@ namespace NewOS kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; constexpr short ACPI_SIGNATURE_LENGTH = 4; + SizeT offsetToAdd = 0UL; for (Size index = 0; index < num; ++index) { - SDT* sdt = (SDT*)*((UInt64*)(UInt64)xsdt + sizeof(SDT) + (index * 8)); + SDT* sdt = &(xsdt[index]) + offsetToAdd; for (int signature_index = 0; signature_index < 4; signature_index++) { @@ -94,11 +95,13 @@ namespace NewOS break; if (signature_index == 3) - return ErrorOr(reinterpret_cast((SDT*)sdt)); + return ErrorOr(reinterpret_cast(sdt)); } + + offsetToAdd = sdt->Length; } - return ErrorOr{-1}; + return ErrorOr{nullptr}; } /*** diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 2129d790..ec6d47da 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -23,12 +23,12 @@ namespace NewOS::HAL constexpr Int32 kThreadBoot = 4; /* - * - * this is used to store info about the current running thread - * we use this struct to determine if we can use it, or mark it as used or on - * sleep. - * - */ + * + * this is used to store info about the current running thread + * we use this struct to determine if we can use it, or mark it as used or on + * sleep. + * + */ struct ProcessorInfoAMD64 final { @@ -51,12 +51,12 @@ namespace NewOS::HAL { struct MadtAddress final { + UInt32 fAddress; UInt32 fFlags; // 1 = Dual Legacy PICs installed - UInt32 fPhysicalAddress; Char fType; Char fRecLen; // record length - } Madt[]; + } fMadt[]; }; struct MadtProcessorLocalApic final @@ -104,20 +104,23 @@ namespace NewOS::HAL void hal_system_get_cores(voidPtr rsdPtr) { - kcout << "New OS: Constructing ACPIFactoryInterface...\r"; - auto acpi = ACPIFactoryInterface(rsdPtr); kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); if (kApicMadt) { - kcout << "New OS: Successfuly fetched the MADT!\r"; + kcout << "New OS: Successfuly fetched the cores!\r"; kApicInfoBlock = (MadtType*)kApicMadt; + + kcout << "New OS: Revision: "; + kcout.HexNumber(kApicInfoBlock->Revision).EndLine(); + + ke_stop(RUNTIME_CHECK_BOOTSTRAP); } - else - { - MUST_PASS(false); - } + else + { + ke_stop(RUNTIME_CHECK_BOOTSTRAP); + } } } // namespace NewOS::HAL diff --git a/Kernel/HALKit/AMD64/HalHardwareMP.cpp b/Kernel/HALKit/AMD64/HalHardwareMP.cpp index 2ebf45fd..83e99ef8 100644 --- a/Kernel/HALKit/AMD64/HalHardwareMP.cpp +++ b/Kernel/HALKit/AMD64/HalHardwareMP.cpp @@ -16,7 +16,7 @@ namespace NewOS { HAL::rt_cli(); - stack->Rcx = 0; + HAL::rt_sti(); } @@ -27,7 +27,7 @@ namespace NewOS { HAL::rt_cli(); - stack->Rcx = 1; + HAL::rt_sti(); } diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index e4063388..875a1abc 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -14,16 +14,16 @@ %define kInterruptId 0x21 %macro IntExp 1 -global __HCR_INT_%1 -__HCR_INT_%1: +global __NEW_INT_%1 +__NEW_INT_%1: cld iretq %endmacro %macro IntNormal 1 -global __HCR_INT_%1 -__HCR_INT_%1: +global __NEW_INT_%1 +__NEW_INT_%1: cld iretq @@ -54,7 +54,7 @@ IntNormal 4 IntNormal 5 ;; Invalid opcode interrupt -__HCR_INT_6: +__NEW_INT_6: cli push rax @@ -75,7 +75,7 @@ IntExp 11 IntExp 12 -__HCR_INT_13: +__NEW_INT_13: cli push rax @@ -88,7 +88,7 @@ __HCR_INT_13: sti iretq -__HCR_INT_14: +__NEW_INT_14: cli push rax @@ -135,7 +135,7 @@ IntNormal 41 IntNormal 42 IntNormal 43 -__HCR_INT_44: +__NEW_INT_44: cli ;; TODO: CoreEvents dispatch routine. @@ -153,7 +153,7 @@ IntNormal 47 IntNormal 48 IntNormal 49 -__HCR_INT_50: +__NEW_INT_50: cli ;; todo handle system calls. @@ -217,6 +217,6 @@ section .data kInterruptVectorTable: %assign i 0 %rep 256 - dq __HCR_INT_%+i + dq __NEW_INT_%+i %assign i i+1 %endrep diff --git a/Kernel/HALKit/AMD64/ReadMe.md b/Kernel/HALKit/AMD64/ReadMe.md new file mode 100644 index 00000000..0be48c77 --- /dev/null +++ b/Kernel/HALKit/AMD64/ReadMe.md @@ -0,0 +1,4 @@ +AMD64 Hardware Abstraction Layer + +- Supported CPU: AMD64 CPU +- Supported Firmware: EDK 2 \ No newline at end of file diff --git a/Kernel/HALKit/ARM64/ReadMe.md b/Kernel/HALKit/ARM64/ReadMe.md new file mode 100644 index 00000000..89679e18 --- /dev/null +++ b/Kernel/HALKit/ARM64/ReadMe.md @@ -0,0 +1,4 @@ +ARM64 Hardware Abstraction Layer + +- Supported CPU: Qualcomm CPU +- Supported Firmware: EDK 2 \ No newline at end of file diff --git a/Kernel/HALKit/POWER/ReadMe.md b/Kernel/HALKit/POWER/ReadMe.md new file mode 100644 index 00000000..a9751581 --- /dev/null +++ b/Kernel/HALKit/POWER/ReadMe.md @@ -0,0 +1,4 @@ +POWER Hardware Abstraction Layer + +- Supported CPU: POWER +- Supported Firmware: CoreBoot \ No newline at end of file diff --git a/Kernel/HALKit/RISCV/ReadMe.md b/Kernel/HALKit/RISCV/ReadMe.md new file mode 100644 index 00000000..b099aa31 --- /dev/null +++ b/Kernel/HALKit/RISCV/ReadMe.md @@ -0,0 +1,4 @@ +RISCV64 Hardware Abstraction Layer + +- Supported CPU: RISCV64 +- Supported Firmware: CoreBoot \ No newline at end of file diff --git a/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp index 7fde69aa..656fe7a9 100644 --- a/Kernel/KernelKit/DebugOutput.hpp +++ b/Kernel/KernelKit/DebugOutput.hpp @@ -15,7 +15,7 @@ #define kDebugUnboundPort 0x0FEED -#define kDebugMag0 'H' +#define kDebugMag0 'N' #define kDebugMag1 'D' #define kDebugMag2 'B' #define kDebugMag3 'G' @@ -27,6 +27,12 @@ namespace NewOS { + class TerminalDevice; + + inline TerminalDevice& end_line(); + inline TerminalDevice& number(const Long& x); + inline TerminalDevice& hex_number(const Long& x); + // @brief Emulates a VT100 terminal. class TerminalDevice final : public DeviceInterface { @@ -34,10 +40,30 @@ namespace NewOS TerminalDevice(void (*print)(const Char*), void (*get)(const Char*)) : DeviceInterface(print, get) { + } virtual ~TerminalDevice() { + + } + + TerminalDevice& Number(const Long Data) noexcept + { + number(Data); + return *this; + } + + TerminalDevice& HexNumber(const Long Data) noexcept + { + number(Data); + return *this; + } + + TerminalDevice& EndLine() noexcept + { + end_line(); + return *this; } /// @brief returns device name (terminal name) diff --git a/Kernel/Source/AppMain.cxx b/Kernel/Source/AppMain.cxx index b91d6082..4f5de11f 100644 --- a/Kernel/Source/AppMain.cxx +++ b/Kernel/Source/AppMain.cxx @@ -22,6 +22,7 @@ #include #include #include +#include namespace Detail { @@ -177,6 +178,12 @@ namespace Detail return fNewFS; } }; + + STATIC NewOS::Void AppWatchdogThread(NewOS::Void) + { + NewOS::kcout << "SystemSanityThread: Exiting process..."; + NewOS::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Exit(0); + } } // namespace Detail /// @file Main microkernel entrypoint. @@ -186,6 +193,9 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) /// Now run kernel loop, until no process are running. Detail::FilesystemWizard wizard; // automatic. + auto cWatchdogThreadName = "SystemSanityThread"; + NewOS::execute_from_image((NewOS::MainKind)Detail::AppWatchdogThread, cWatchdogThreadName); + while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0) { ; diff --git a/Kernel/Source/CodeManager.cxx b/Kernel/Source/CodeManager.cxx index 39917163..001795ce 100644 --- a/Kernel/Source/CodeManager.cxx +++ b/Kernel/Source/CodeManager.cxx @@ -8,22 +8,23 @@ #include #include -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 if the process was started or not. -bool execute_from_image(MainKind main, const char* processName) noexcept +namespace NewOS { - if (!main) - return false; - - ProcessHeader proc((VoidPtr)main); - proc.Kind = ProcessHeader::kDriverKind; - rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(proc.Name)); - - Ref refProc = proc; - - return ProcessScheduler::Shared().Leak().Add(refProc); -} \ No newline at end of file + /// @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) noexcept + { + if (!main) + return false; + + ProcessHeader proc((VoidPtr)main); + proc.Kind = ProcessHeader::kDriverKind; + rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(proc.Name)); + + Ref refProc = proc; + + return ProcessScheduler::Shared().Leak().Add(refProc); + } +} // namespace NewOS \ No newline at end of file -- cgit v1.2.3 From 84b0e780dfd9272b177c32cc3bb99f37bb88304d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 10 May 2024 07:06:43 +0200 Subject: MHR-23: Getting SMP to work... Signed-off-by: Amlal El Mahrouss --- Boot/NetBoot/Module.cxx | 5 +- Boot/NetBoot/NetBoot.hxx | 12 +++ Boot/Source/BootloaderRsrc.rsrc | 2 +- Boot/Source/makefile | 106 -------------------- Boot/makefile | 110 +++++++++++++++++++++ Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 19 ++-- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 58 +++++------ Kernel/HALKit/AXP/README.TXT | 2 +- Kernel/KernelKit/DebugOutput.hpp | 2 +- Kernel/KernelKit/FileManager.hpp | 2 - Kernel/KernelKit/ProcessScheduler.hpp | 4 +- Kernel/KernelRsrc.rsrc | 2 +- Kernel/Linker/16x0.json | 2 +- Kernel/Linker/32x0.json | 2 +- Kernel/Linker/64x0.json | 2 +- Kernel/NewKit/Application.hxx | 31 ------ Kernel/NewKit/ApplicationInterface.hxx | 31 ++++++ Kernel/Source/AppMain.cxx | 39 ++++++-- Kernel/Source/FileManager.cxx | 22 +---- Kernel/Source/KernelCheck.cxx | 2 +- Kernel/Source/ProcessScheduler.cxx | 2 +- Kernel/Source/Variant.cxx | 5 - Kernel/makefile | 5 +- 23 files changed, 240 insertions(+), 227 deletions(-) create mode 100644 Boot/NetBoot/NetBoot.hxx delete mode 100644 Boot/Source/makefile create mode 100644 Boot/makefile delete mode 100644 Kernel/NewKit/Application.hxx create mode 100644 Kernel/NewKit/ApplicationInterface.hxx (limited to 'Kernel/KernelKit') diff --git a/Boot/NetBoot/Module.cxx b/Boot/NetBoot/Module.cxx index c296903b..57841904 100644 --- a/Boot/NetBoot/Module.cxx +++ b/Boot/NetBoot/Module.cxx @@ -8,10 +8,11 @@ */ #include +#include -EXTERN_C Int32 EfiMain(Void) +EXTERN_C Int32 ModuleMain(Void) { - /// - Find a network drive called "/OnlineBoot" + /// - Find a network drive called "/Remote/NewOSKrnl" /// - Download our image /// - Boot from it. diff --git a/Boot/NetBoot/NetBoot.hxx b/Boot/NetBoot/NetBoot.hxx new file mode 100644 index 00000000..d45f1de1 --- /dev/null +++ b/Boot/NetBoot/NetBoot.hxx @@ -0,0 +1,12 @@ +/* + * ======================================================== + * + * NetBoot + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include diff --git a/Boot/Source/BootloaderRsrc.rsrc b/Boot/Source/BootloaderRsrc.rsrc index d79211e7..0282192b 100644 --- a/Boot/Source/BootloaderRsrc.rsrc +++ b/Boot/Source/BootloaderRsrc.rsrc @@ -15,7 +15,7 @@ BEGIN VALUE "FileVersion", BOOTLOADER_VERSION VALUE "InternalName", "NewBoot" VALUE "LegalCopyright", "Copyright SoftwareLabs, all rights reserved." - VALUE "OriginalFilename", "NewBoot.exe" + VALUE "OriginalFilename", "NewOSLdr.exe" VALUE "ProductName", "NewBoot" VALUE "ProductVersion", BOOTLOADER_VERSION END diff --git a/Boot/Source/makefile b/Boot/Source/makefile deleted file mode 100644 index 70fa7232..00000000 --- a/Boot/Source/makefile +++ /dev/null @@ -1,106 +0,0 @@ -################################################## -# (C) SoftwareLabs, all rights reserved. -# This is the bootloader makefile. -################################################## - -CC_GNU=x86_64-w64-mingw32-g++ -LD_GNU=x86_64-w64-mingw32-ld - -WINDRES=x86_64-w64-mingw32-windres - -ADD_FILE=touch -COPY=cp -HTTP_GET=wget - -ifeq ($(shell uname), Windows_NT) -EMU=qemu-system-x86_64w -else -EMU=qemu-system-x86_64 -endif - -ifeq ($(NEWS_MODEL), ) -NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" -endif - -IMG=epm.img -IMG_2=epm-slave.img - -EMU_FLAGS=-net none -smp 4 -m 8G -M q35 \ - -bios OVMF.fd -device piix3-ide,id=ide \ - -drive id=disk,file=$(IMG),format=raw,if=none \ - -device ide-hd,drive=disk,bus=ide.0 -drive \ - file=fat:rw:Root,index=2,format=raw -d int -hdd epm-slave.img - -LD_FLAGS=-e Main --subsystem=10 - -ifeq ($(NEWS_STANDLONE), ) -OBJ=*.o ../../Kernel/Objects/*.obj -else -RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o -STANDALONE_MACRO=-D__STANDALONE__ -OBJ=*.o -endif - -REM=rm -REM_FLAG=-f - -FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ - -DEFI_FUNCTION_WRAPPER -I../ -I../../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ - -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ - -BOOT_LOADER=NewBoot.exe -KERNEL=NewKernel.exe - -.PHONY: invalid-recipe -invalid-recipe: - @echo "invalid-recipe: Use make compile- instead." - -.PHONY: all -all: compile-amd64 - mkdir -p Root/EFI/BOOT - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(BOOT_LOADER) - $(COPY) $(BOOT_LOADER) Root/EFI/BOOT/BOOTX64.EFI - $(COPY) $(BOOT_LOADER) Root/EFI/BOOT/NEWBOOT.EFI - $(COPY) ../../Kernel/$(KERNEL) Root/$(KERNEL) - -ifneq ($(DEBUG_SUPPORT), ) -DEBUG = -D__DEBUG__ -endif - -.PHONY: compile-amd64 -compile-amd64: - $(RESCMD) - $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx) - -.PHONY: run-efi-amd64 -run-efi-amd64: - $(EMU) $(EMU_FLAGS) - -# img_2 is the rescue disk. img is the bootable disk, as provided by the NeWS. -.PHONY: epm-img -epm-img: - qemu-img create -f raw $(IMG) 10G - qemu-img create -f raw $(IMG_2) 512M - -.PHONY: download-edk -download-edk: - $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - -BINS=*.bin -EXECUTABLES=NewBoot.exe NewKernel.exe OVMF.fd - -TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) - -.PHONY: clean -clean: - $(REM) $(TARGETS) - -.PHONY: help -help: - @echo "=== HELP ===" - @echo "epm-img: Format a disk using the Explicit Partition Map." - @echo "gpt-img: Format a disk using the Explicit Partition Map." - @echo "clean: clean bootloader." - @echo "bootloader-amd64: Build bootloader. (PC AMD64)" - @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Boot/makefile b/Boot/makefile new file mode 100644 index 00000000..878cee2a --- /dev/null +++ b/Boot/makefile @@ -0,0 +1,110 @@ +################################################## +# (C) SoftwareLabs, all rights reserved. +# This is the bootloader makefile. +################################################## + +CC_GNU=x86_64-w64-mingw32-g++ +LD_GNU=x86_64-w64-mingw32-ld + +WINDRES=x86_64-w64-mingw32-windres + +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + +ifeq ($(shell uname), Windows_NT) +EMU=qemu-system-x86_64w +else +EMU=qemu-system-x86_64 +endif + +ifeq ($(NEWS_MODEL), ) +NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" +endif + +BIOS=OVMF.fd +IMG=epm.img +IMG_2=epm-slave.img + +EMU_FLAGS=-net none -smp 4,sockets=1,cores=4,threads=1 -m 8G -M q35 \ + -bios Source/$(BIOS) -device piix3-ide,id=ide \ + -drive id=disk,file=Source/$(IMG),format=raw,if=none \ + -device ide-hd,drive=disk,bus=ide.0 -drive \ + file=fat:rw:Source/Root,index=2,format=raw -d int -hdd Source/$(IMG_2) + +LD_FLAGS=-e Main --subsystem=10 + +ifeq ($(NEWS_STANDLONE), ) +OBJ=*.o ../Kernel/Objects/*.obj +else +RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o +STANDALONE_MACRO=-D__STANDALONE__ +OBJ=*.o +endif + +REM=rm +REM_FLAG=-f + +FLAG_ASM=-f win64 +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ + -DEFI_FUNCTION_WRAPPER -I./ -I../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ + -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ + +BOOT_LOADER=NewOSLdr.exe +KERNEL=NewOSKrnl.exe + +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make compile- instead." + +.PHONY: all +all: compile-amd64 + mkdir -p Root/EFI/BOOT + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Source/$(BOOT_LOADER) + $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/BOOTX64.EFI + $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/NEWBOOT.EFI + $(COPY) ../Kernel/$(KERNEL) Source/Root/$(KERNEL) + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +.PHONY: compile-amd64 +compile-amd64: + $(RESCMD) + $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) \ + $(wildcard Source/HEL/AMD64/*.cxx) \ + $(wildcard Source/HEL/AMD64/*.S) + $(wildcard Source/*.cxx) + +.PHONY: run-efi-amd64 +run-efi-amd64: + $(EMU) $(EMU_FLAGS) + +# img_2 is the rescue disk. img is the bootable disk, as provided by the NeWS. +.PHONY: epm-img +epm-img: + qemu-img create -f raw $(IMG) 10G + qemu-img create -f raw $(IMG_2) 512M + +.PHONY: download-edk +download-edk: + $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd + +BINS=*.bin +EXECUTABLES=NewOSLdr.exe NewOSKrnl.exe OVMF.fd + +TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) + +.PHONY: clean +clean: + $(REM) $(TARGETS) + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "epm-img: Format a disk using the Explicit Partition Map." + @echo "gpt-img: Format a disk using the Explicit Partition Map." + @echo "clean: clean bootloader." + @echo "bootloader-amd64: Build bootloader. (PC AMD64)" + @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index f4c9226e..db82616e 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -75,7 +75,7 @@ namespace NewOS SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); - SizeT num = (xsdt->Length + sizeof(SDT)) / 8; + SizeT num = -(xsdt->Length - sizeof(SDT)) / 8; this->fEntries = num; @@ -83,22 +83,19 @@ namespace NewOS kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; constexpr short ACPI_SIGNATURE_LENGTH = 4; - SizeT offsetToAdd = 0UL; - - for (Size index = 0; index < num; ++index) + + for (Size index = 0; index < this->fEntries; ++index) { - SDT* sdt = &(xsdt[index]) + offsetToAdd; + SDT &sdt = xsdt[index]; - for (int signature_index = 0; signature_index < 4; signature_index++) + for (short signature_index = 0; signature_index < ACPI_SIGNATURE_LENGTH; ++signature_index) { - if (sdt->Signature[signature_index] != signature[signature_index]) + if (sdt.Signature[signature_index] != signature[signature_index]) break; - if (signature_index == 3) - return ErrorOr(reinterpret_cast(sdt)); + if (signature_index == 4) + return ErrorOr(reinterpret_cast(&sdt)); } - - offsetToAdd = sdt->Length; } return ErrorOr{nullptr}; diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index ec6d47da..470a3286 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -46,54 +46,54 @@ namespace NewOS::HAL STATIC voidPtr kApicMadt = nullptr; STATIC const char* kApicSignature = "APIC"; - /// @brief Multiple APIC descriptor table. + /// @brief Multiple APIC Descriptor Table. struct MadtType final : public SDT { struct MadtAddress final { - UInt32 fAddress; - UInt32 fFlags; // 1 = Dual Legacy PICs installed - - Char fType; - Char fRecLen; // record length - } fMadt[]; + Char RecordType; + Char RecordLen; // record length + + UInt32 Address; + UInt32 Flags; // 1 = Dual Legacy PICs installed + } MadtRecords[]; }; struct MadtProcessorLocalApic final { - Char fProcessorId; - Char fApicId; - UInt32 fFlags; + Char AcpiProcessorId; + Char Reserved; + UInt32 Flags; }; struct MadtIOApic final { - Char fApicId; - Char fReserved; - UInt32 fAddress; - UInt32 fSystemInterruptBase; + Char ApicId; + Char Reserved; + UInt32 Address; + UInt32 SystemInterruptBase; }; struct MadtInterruptSource final { - Char fBusSource; - Char fIrqSource; - UInt32 fGSI; - UInt16 fFlags; + Char BusSource; + Char IrqSource; + UInt32 GSI; + UInt16 Flags; }; struct MadtInterruptNmi final { - Char fNmiSource; - Char fReserved; - UInt16 fFlags; - UInt32 fGSI; + Char NmiSource; + Char Reserved; + UInt16 Flags; + UInt32 GSI; }; struct MadtLocalApicAddressOverride final { - UInt16 fResvered; - UIntPtr fAddress; + UInt16 Resvered; + UIntPtr Address; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -109,17 +109,13 @@ namespace NewOS::HAL if (kApicMadt) { - kcout << "New OS: Successfuly fetched the cores!\r"; + kcout << "New OS: APIC is present...\r"; kApicInfoBlock = (MadtType*)kApicMadt; - - kcout << "New OS: Revision: "; - kcout.HexNumber(kApicInfoBlock->Revision).EndLine(); - - ke_stop(RUNTIME_CHECK_BOOTSTRAP); } else { - ke_stop(RUNTIME_CHECK_BOOTSTRAP); + kcout << "New OS: APIC is not present! it is a vital component.\r"; + ke_stop(RUNTIME_CHECK_FAILED); } } } // namespace NewOS::HAL diff --git a/Kernel/HALKit/AXP/README.TXT b/Kernel/HALKit/AXP/README.TXT index 03c2b816..d4ef257d 100644 --- a/Kernel/HALKit/AXP/README.TXT +++ b/Kernel/HALKit/AXP/README.TXT @@ -1 +1 @@ -A Toy HAL to test the Kernel portability. +An toy HAL to test the kernel portability. diff --git a/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp index 656fe7a9..c6eb4485 100644 --- a/Kernel/KernelKit/DebugOutput.hpp +++ b/Kernel/KernelKit/DebugOutput.hpp @@ -56,7 +56,7 @@ namespace NewOS TerminalDevice& HexNumber(const Long Data) noexcept { - number(Data); + hex_number(Data); return *this; } diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index d0843a5e..a5ac6a93 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -136,8 +136,6 @@ namespace NewOS NewFSParser* GetImpl() noexcept; private: - Char fDataFork[kNewFSForkNameLen] = {0}; - Char fRsrcFork[kNewFSForkNameLen] = {0}; NewFSParser* fImpl{nullptr}; }; diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp index ba34f9cb..243857ae 100644 --- a/Kernel/KernelKit/ProcessScheduler.hpp +++ b/Kernel/KernelKit/ProcessScheduler.hpp @@ -163,7 +163,7 @@ namespace NewOS enum { - kUserKind = 3, + kAppKind = 3, kLibKind = 3, kDriverKind = 0, kKindCount, @@ -178,7 +178,7 @@ namespace NewOS ProcessTime PTime; PID ProcessId{kSchedInvalidPID}; Int32 Ring{kRingDriverKind}; - Int32 Kind{kUserKind}; + Int32 Kind{kAppKind}; public: //! @brief boolean operator, check status. diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index d8fc6473..6689d10c 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -15,7 +15,7 @@ BEGIN VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "NewKernel" VALUE "LegalCopyright", "SoftwareLabs" - VALUE "OriginalFilename", "NewKernel.exe" + VALUE "OriginalFilename", "NewOSKrnl.exe" VALUE "ProductName", "NewKernel" VALUE "ProductVersion", KERNEL_VERSION END diff --git a/Kernel/Linker/16x0.json b/Kernel/Linker/16x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/16x0.json +++ b/Kernel/Linker/16x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/32x0.json b/Kernel/Linker/32x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/32x0.json +++ b/Kernel/Linker/32x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/64x0.json b/Kernel/Linker/64x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/64x0.json +++ b/Kernel/Linker/64x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/NewKit/Application.hxx b/Kernel/NewKit/Application.hxx deleted file mode 100644 index 19a892d6..00000000 --- a/Kernel/NewKit/Application.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -/// -/// @brief Application object, given by the OS to the process. interact with the OS. -/// @file Application.hxx -/// @author Amlal EL Mahrouss -/// - -#include -#include - -/// \brief Application Interface. -/// \author Amlal El Mahrouss -typedef struct _ApplicationInterface final -{ - /// @brief Releases the object exit the process on main object. - NewOS::Void (*Release)(struct _Application* Self, NewOS::Int32 ExitCode); - /// @brief Invoke a function from the application object. - NewOS::IntPtr (*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...); - /// @brief Query a new application object from a GUID. - /// @note this doesn't query a process, it query a registered object withtin that app. - NewOS::Void (*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); -} ApplicationInterface, *ApplicationInterfaceRef; - -#define app_cast reinterpret_cast diff --git a/Kernel/NewKit/ApplicationInterface.hxx b/Kernel/NewKit/ApplicationInterface.hxx new file mode 100644 index 00000000..09d2c901 --- /dev/null +++ b/Kernel/NewKit/ApplicationInterface.hxx @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +/// +/// @brief Application object, given by the OS to the process. interact with the OS. +/// @file ApplicationInterface.hxx +/// @author Amlal EL Mahrouss +/// + +#include +#include + +/// \brief Application Interface. +/// \author Amlal El Mahrouss +typedef struct _ApplicationInterface final +{ + /// @brief Releases the object exit the process on main object. + NewOS::Void (*Release)(struct _Application* Self, NewOS::Int32 ExitCode); + /// @brief Invoke a function from the application object. + NewOS::IntPtr (*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...); + /// @brief Query a new application object from a GUID. + /// @note this doesn't query a process, it query a registered object withtin that app. + NewOS::Void (*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); +} ApplicationInterface, *ApplicationInterfaceRef; + +#define app_cast reinterpret_cast diff --git a/Kernel/Source/AppMain.cxx b/Kernel/Source/AppMain.cxx index 4f5de11f..028e70e5 100644 --- a/Kernel/Source/AppMain.cxx +++ b/Kernel/Source/AppMain.cxx @@ -179,25 +179,50 @@ namespace Detail } }; - STATIC NewOS::Void AppWatchdogThread(NewOS::Void) + /// @brief System loader entrypoint. + /// @param void no parameters. + /// @return void no return value. + STATIC NewOS::Void AppSystemLoader(NewOS::Void) { - NewOS::kcout << "SystemSanityThread: Exiting process..."; + NewOS::PEFLoader coreGraphicsShLib("/System/CoreGraphics"); + + if (!coreGraphicsShLib.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(coreGraphicsShLib, + NewOS::ProcessHeader::kLibKind); + + NewOS::PEFLoader logonService("/System/Login"); + + if (!logonService.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(logonService, + NewOS::ProcessHeader::kAppKind); + + NewOS::kcout << "SystemLoader: Exiting process, we're done initializing stuff..."; + NewOS::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Exit(0); } } // namespace Detail -/// @file Main microkernel entrypoint. - +/// @brief Application entrypoint. +/// @param Void +/// @return Void EXTERN_C NewOS::Void AppMain(NewOS::Void) { /// Now run kernel loop, until no process are running. Detail::FilesystemWizard wizard; // automatic. - auto cWatchdogThreadName = "SystemSanityThread"; - NewOS::execute_from_image((NewOS::MainKind)Detail::AppWatchdogThread, cWatchdogThreadName); + auto cLoaderName = "SystemLoader"; + NewOS::execute_from_image(Detail::AppSystemLoader, cLoaderName); while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0) { - ; + NewOS::kcout << "New OS: sleeping...\r"; } } diff --git a/Kernel/Source/FileManager.cxx b/Kernel/Source/FileManager.cxx index 72ea15a1..ed90dab8 100644 --- a/Kernel/Source/FileManager.cxx +++ b/Kernel/Source/FileManager.cxx @@ -90,11 +90,11 @@ namespace NewOS NEWOS_UNUSED(flags); - const char* cReadAllFork = fDataFork; - + auto dataForkName = "FileData"; + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast(node), data, size, - cReadAllFork); + dataForkName); } /// @brief Read from filesystem fork. @@ -112,11 +112,11 @@ namespace NewOS NEWOS_UNUSED(flags); - const char* cReadAllFork = fDataFork; + auto dataForkName = "FileData"; if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast(node), sz, - cReadAllFork); + dataForkName); return nullptr; } @@ -167,17 +167,5 @@ namespace NewOS { return fImpl; } - - void NewFilesystemManager::SetResourceFork(const char* forkName) - { - if (!forkName) return; - rt_copy_memory((VoidPtr)forkName, (VoidPtr)fRsrcFork, rt_string_len(forkName)); - } - - void NewFilesystemManager::SetDataFork(const char* forkName) - { - if (!forkName) return; - rt_copy_memory((VoidPtr)forkName, (VoidPtr)fDataFork, rt_string_len(forkName)); - } #endif // __FSKIT_NEWFS__ } // namespace NewOS diff --git a/Kernel/Source/KernelCheck.cxx b/Kernel/Source/KernelCheck.cxx index e7c43650..5df52248 100644 --- a/Kernel/Source/KernelCheck.cxx +++ b/Kernel/Source/KernelCheck.cxx @@ -26,7 +26,7 @@ namespace NewOS void ke_stop(const NewOS::Int& id) { kcout << "*** STOP *** \r"; - kcout << "*** NewKernel.exe has trigerred a runtime stop. *** \r"; + kcout << "*** Kernel has trigerred a runtime stop. *** \r"; switch (id) { diff --git a/Kernel/Source/ProcessScheduler.cxx b/Kernel/Source/ProcessScheduler.cxx index 859ce657..555dfe07 100644 --- a/Kernel/Source/ProcessScheduler.cxx +++ b/Kernel/Source/ProcessScheduler.cxx @@ -218,7 +218,7 @@ namespace NewOS kcout << "ProcessScheduler::Add(Ref& process)\r"; /// Create heap according to type of process. - if (process.Leak().Kind == ProcessHeader::kUserKind) + if (process.Leak().Kind == ProcessHeader::kAppKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); else if (process.Leak().Kind == ProcessHeader::kLibKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared); diff --git a/Kernel/Source/Variant.cxx b/Kernel/Source/Variant.cxx index afe66624..1a09718b 100644 --- a/Kernel/Source/Variant.cxx +++ b/Kernel/Source/Variant.cxx @@ -10,11 +10,6 @@ namespace NewOS { const Char* Variant::ToString() { - if (fPtr == nullptr) - { - return ("Memory:{Nullptr}"); - } - switch (fKind) { case VariantKind::kString: diff --git a/Kernel/makefile b/Kernel/makefile index 61eb9dfe..74365a60 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -37,10 +37,7 @@ LDFLAGS = -e __ImageStart --subsystem=17 LDOBJ = Objects/*.obj # This file is the kernel, responsible of task management and memory. -KERNEL = NewKernel.exe - -# The kernel entrypoint -SCRIPT = --script=Linker/Platforms/PC.lds +KERNEL = NewOSKrnl.exe .PHONY: error error: -- cgit v1.2.3 From bc57a29a24b98b00ba17710ba84ec2188ab73504 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 10 May 2024 18:08:31 +0200 Subject: MHR-23: Improve code, remove outdated comments. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/PEF.hpp | 3 --- Kernel/KernelKit/XCOFF.hxx | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'Kernel/KernelKit') diff --git a/Kernel/KernelKit/PEF.hpp b/Kernel/KernelKit/PEF.hpp index 77fa4f62..6dbc5270 100644 --- a/Kernel/KernelKit/PEF.hpp +++ b/Kernel/KernelKit/PEF.hpp @@ -73,9 +73,6 @@ namespace NewOS } PACKED PEFContainer; /* First PEFCommandHeader starts after PEFContainer */ - /* Last container is __exec_end */ - - /* PEF executable section and commands. */ typedef struct PEFCommandHeader final { diff --git a/Kernel/KernelKit/XCOFF.hxx b/Kernel/KernelKit/XCOFF.hxx index 2b153918..50efdf0d 100644 --- a/Kernel/KernelKit/XCOFF.hxx +++ b/Kernel/KernelKit/XCOFF.hxx @@ -16,12 +16,12 @@ #include -#define kXCOFF64Magic 0x01F7 +#define kXCOFF64Magic (0x01F7) -#define kXCOFFRelFlg 0x0001 -#define kXCOFFExecutable 0x0002 -#define kXCOFFLnno 0x0004 -#define kXCOFFLSyms 0x0008 +#define kXCOFFRelFlg (0x0001) +#define kXCOFFExecutable (0x0002) +#define kXCOFFLnno (0x0004) +#define kXCOFFLSyms (0x0008) /// @brief XCoff file header, meant for POWER apps. typedef struct XCoffFileHeader -- cgit v1.2.3