summaryrefslogtreecommitdiffhomepage
path: root/Kernel
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-23 00:59:10 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-23 00:59:10 +0200
commit65e428a5a2b4eac24cccf5defe64d52faba8304d (patch)
treed23b304abce67455853d355ceb4d65f73d93ded9 /Kernel
parent9899e5d07f9010a874ed64c586508479f0a353c4 (diff)
Kernel: See below.
MHR-35: Implement it. Kernel: Write EPM header at sector 0. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FSKit/NewFS.hxx10
-rw-r--r--Kernel/FirmwareKit/EPM.hxx19
-rw-r--r--Kernel/HALKit/AMD64/HalInterruptAPI.asm4
-rw-r--r--Kernel/Sources/FS/NewFS.cxx50
4 files changed, 51 insertions, 32 deletions
diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx
index 47e42c88..8b2129da 100644
--- a/Kernel/FSKit/NewFS.hxx
+++ b/Kernel/FSKit/NewFS.hxx
@@ -80,8 +80,8 @@ default.
#define kNewFSLbaType (NewOS::Lba)
/// Start After the PM headers, pad 1024 bytes.
-#define kNewFSAddressAsLba (512)
-#define kNewFSCatalogStartAddress (1024 + sizeof(NewPartitionBlock) + sizeof(NewCatalog))
+#define kNewFSStartLba (1024)
+#define kNewFSCatalogStartAddress ((2048) + sizeof(NewPartitionBlock) + sizeof(NewCatalog))
#define kResourceTypeDialog (10)
#define kResourceTypeString (11)
@@ -106,7 +106,7 @@ enum
kNewFSOpticalDrive = 0x0C, // Blu-Ray/DVD
kNewFSMassStorageDevice = 0xCC, // USB
kNewFSScsi = 0xC4, // SCSI Hard Drive
- kNewFSFlashDrive = 0xC6,
+ kNewFSFlashDrive = 0xC6,
kNewFSUnknown = 0xFF, // Unknown device. (floppy)
kNewFSDriveCount = 5,
};
@@ -225,7 +225,7 @@ namespace NewOS
/// @param theFork the fork itself.
/// @return the fork
_Output NewFork* CreateFork(_Input NewCatalog* catalog,
- _Input NewFork& theFork);
+ _Input NewFork& theFork);
/// @brief Find fork inside New filesystem.
/// @param catalog the catalog.
@@ -243,7 +243,7 @@ namespace NewOS
_Output NewCatalog* GetCatalog(_Input const char* name);
- _Output NewCatalog* CreateCatalog(_Input const char* name,
+ _Output NewCatalog* CreateCatalog(_Input const char* name,
_Input const Int32& flags,
_Input const Int32& kind);
diff --git a/Kernel/FirmwareKit/EPM.hxx b/Kernel/FirmwareKit/EPM.hxx
index 47e3fbfb..b3f17889 100644
--- a/Kernel/FirmwareKit/EPM.hxx
+++ b/Kernel/FirmwareKit/EPM.hxx
@@ -41,22 +41,10 @@ struct PACKED BootBlock
NewOS::Int64 NumBlocks;
NewOS::Int64 SectorSz;
NewOS::Int64 LbaStart;
-};
-
-/**
- * @brief The EPM partition block.
- * used to describe a partition inside a media, doesn't exist on some platforms.
- */
-struct PACKED PartitionBlock
-{
- NewOS::Char Name[kEPMNameLength];
- NewOS::Int32 Version;
- NewOS::Int64 LbaEnd;
- NewOS::Int64 SectorSz;
- NewOS::Int64 LbaStart;
NewOS::Int16 Kind;
NewOS::Int32 FsVersion;
NewOS::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */
+ NewOS::Char Reserved[409]; // to fill a full sector.
};
/* @brief AMD64 magic for EPM */
@@ -102,8 +90,7 @@ enum kEPMKind
kEPMNewOS = 0x1f, // This kernel.
};
-typedef struct BootBlock BootBlockType;
-typedef struct PartitionBlock PartitionBlockType;
+typedef struct BootBlock BootBlockType;
#ifdef __NEWOS_AMD64__
#define kEPMMagic kEPMMagic86
@@ -123,6 +110,8 @@ typedef struct PartitionBlock PartitionBlockType;
#define kEPMRevision (0xAD)
///! @brief Current EPM revision
#define kEPMRevisionUEFI (0xAF)
+/// !@brief EPM base address
+#define kEpmBase (0U)
/// END OF SPECS
diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm
index 9c5b0d6a..016c9cd8 100644
--- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm
+++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm
@@ -122,6 +122,8 @@ IntNormal 31
[extern hal_apic_acknowledge]
__NEW_INT_32:
+;; make this active, SMP works again.
+%if 0
push rax
push rcx
push rdx
@@ -160,7 +162,7 @@ __NEW_INT_32:
;; tell there local apic that we're done.
mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI
-
+%endif
iretq
IntNormal 33
diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx
index 255511e3..541b7eef 100644
--- a/Kernel/Sources/FS/NewFS.cxx
+++ b/Kernel/Sources/FS/NewFS.cxx
@@ -15,6 +15,7 @@
#include <NewKit/KernelCheck.hpp>
#include <NewKit/String.hpp>
#include <NewKit/Utils.hpp>
+#include <FirmwareKit/EPM.hxx>
using namespace NewOS;
@@ -36,7 +37,7 @@ STATIC MountpointInterface sMountpointInterface;
/// @param theFork the fork itself.
/// @return the fork
_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
- _Input NewFork& theFork)
+ _Input NewFork& theFork)
{
if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
return nullptr;
@@ -205,7 +206,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name)
/// @param flags the flags of the catalog.
/// @param kind the catalog kind.
/// @return catalog pointer.
-_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
+_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
@@ -320,7 +321,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
{
nextSibling = (NewCatalog*)catalogBuf;
- if (startFree <= kNewFSAddressAsLba)
+ if (startFree <= kNewFSStartLba)
{
delete catalogChild;
delete catalog;
@@ -335,7 +336,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
drive->fPacket.fPacketContent = sectorBufPartBlock;
drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fInput(&drive->fPacket);
@@ -380,7 +381,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
drive->fPacket.fPacketContent = sectorBufPartBlock;
drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fInput(&drive->fPacket);
@@ -433,7 +434,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive)
drive->fPacket.fPacketContent = sectorBuf;
drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fInput(&drive->fPacket);
@@ -472,7 +473,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive)
drive->fPacket.fPacketContent = sectorBuf;
drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fOutput(&drive->fPacket);
@@ -488,6 +489,33 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive)
/// write the root catalog.
this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir);
+ if (partBlock->Flags & kNewFSPartitionTypeBoot)
+ {
+ /// make it bootable when needed.
+ Char bufEpmHdr[kNewFSSectorSz] = {0};
+
+ BootBlockType* epmBoot = (BootBlockType*)bufEpmHdr;
+
+ constexpr auto cFsName = "NewFS";
+
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, rt_string_len(cFsName));
+
+ epmBoot->FsVersion = kNewFSVersionInteger;
+ epmBoot->LbaStart = kNewFSStartLba;
+ epmBoot->SectorSz = partBlock->SectorSize;
+ epmBoot->NumBlocks = partBlock->CatalogCount;
+
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>("BOOT:")), epmBoot->Name, rt_string_len("BOOT:"));
+
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic));
+
+ drive->fPacket.fPacketContent = bufEpmHdr;
+ drive->fPacket.fPacketSize = (epmBoot->SectorSz);
+ drive->fPacket.fLba = kEpmBase;
+
+ drive->fOutput(&drive->fPacket);
+ }
+
return true;
}
@@ -604,7 +632,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName,
drive->fPacket.fPacketContent = sectorBuf;
drive->fPacket.fPacketSize = sizeof(NewPartitionBlock);
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fInput(&drive->fPacket);
@@ -688,7 +716,7 @@ _NewFSSearchThroughCatalogList:
_NewFSContinueSearch:
startCatalogList = catalog->NextSibling;
- if (startCatalogList <= kNewFSAddressAsLba)
+ if (startCatalogList <= kNewFSStartLba)
break;
drive->fPacket.fLba = startCatalogList;
@@ -769,7 +797,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName)
Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0};
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fLba = kNewFSStartLba;
drive->fPacket.fPacketContent = partitionBlockBuf;
drive->fPacket.fPacketSize = sizeof(NewPartitionBlock);
@@ -927,7 +955,7 @@ namespace NewOS::Detail
Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0};
- sMountpointInterface.A().fPacket.fLba = kNewFSAddressAsLba;
+ sMountpointInterface.A().fPacket.fLba = kNewFSStartLba;
sMountpointInterface.A().fPacket.fPacketContent = partitionBlockBuf;
sMountpointInterface.A().fPacket.fPacketSize = sizeof(NewPartitionBlock);