summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-28 09:08:00 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-28 09:08:00 +0200
commitb608517c047f7e4f7d7d70af7db76b0e9b0873b0 (patch)
tree2ffd9ee4e202692d873f53f41520cde960b1ddef /Private/NewBoot
parentdd6568c64e440fe9d8c75539165377ddbbca3e2c (diff)
MHR-18: Big set of patches regarding the New Filesystem.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx23
-rw-r--r--Private/NewBoot/BootKit/Vendor/Support.hxx6
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx20
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Support.cxx14
-rw-r--r--Private/NewBoot/Source/compile_flags.txt1
-rw-r--r--Private/NewBoot/Source/makefile4
7 files changed, 42 insertions, 28 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 4b9eecfd..14609e77 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -211,7 +211,7 @@ public:
Boolean Format(const char* partName, BFileDescriptor* fileBlobs, SizeT blobCount);
/// @brief check if partition is good.
- operator bool() noexcept {
+ Bool IsPartitionValid() noexcept {
fDiskDev.Leak().mBase = (kNewFSAddressAsLba);
fDiskDev.Leak().mSize = BootDev::kSectorSize;
@@ -221,12 +221,13 @@ public:
NewPartitionBlock* blockPart = reinterpret_cast<NewPartitionBlock*>(buf);
+ BTextWriter writer;
+
for (SizeT indexMag = 0UL; indexMag < kNewFSIdentLen; ++indexMag) {
if (blockPart->Ident[indexMag] != kNewFSIdent[indexMag])
return false;
}
- BTextWriter writer;
writer.Write(L"Device Size: ").Write(this->fDiskDev.GetDiskSize()).Write(L"\r\n");
if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() ||
@@ -255,16 +256,11 @@ private:
Lba startLba = partBlock.StartCatalog;
BTextWriter writer;
- SizeT blobCounter = 0UL;
+ Char bufCatalog[sizeof(NewCatalog)] = { 0 };
+ Char bufFork[sizeof(NewFork)] = { 0 };
while (blob) {
- if (blobCounter > blobCount) break;
- ++blobCounter;
-
- Char bufCatalog[sizeof(NewCatalog)] = { 0 };
- Char bufFork[sizeof(NewFork)] = { 0 };
-
- NewCatalog* catalogKind = (NewCatalog*)bufFork;
+ NewCatalog* catalogKind = (NewCatalog*)bufCatalog;
catalogKind->PrevSibling = startLba;
@@ -306,7 +302,7 @@ private:
fDiskDev.Leak().mBase = startLba + sizeof(NewCatalog);
fDiskDev.Leak().mSize = sizeof(NewFork);
- fDiskDev.Write((Char*)forkKind, sizeof(NewFork));
+ fDiskDev.Write((Char*)bufFork, sizeof(NewFork));
do {
this->fDiskDev.Leak().mSize = BootDev::kSectorSize;
@@ -338,13 +334,16 @@ private:
fDiskDev.Leak().mBase = startLba;
fDiskDev.Leak().mSize = sizeof(NewCatalog);
- fDiskDev.Write((Char*)catalogKind, sizeof(NewCatalog));
+ fDiskDev.Write((Char*)bufCatalog, sizeof(NewCatalog));
startLba += (sizeof(NewCatalog) + sizeof(NewFork) + blob->fBlobSz);
--partBlock.FreeCatalog;
--partBlock.FreeSectors;
+ memset(bufFork, 0, sizeof(NewFork));
+ memset(bufCatalog, 0, sizeof(NewCatalog));
+
blob = blob->fNext;
}
diff --git a/Private/NewBoot/BootKit/Vendor/Support.hxx b/Private/NewBoot/BootKit/Vendor/Support.hxx
index 4d35b4cb..b4ba4f68 100644
--- a/Private/NewBoot/BootKit/Vendor/Support.hxx
+++ b/Private/NewBoot/BootKit/Vendor/Support.hxx
@@ -13,9 +13,9 @@
#define LONG_MAX ((long)(~0UL>>1))
#define LONG_MIN (~LONG_MAX)
-#define SetMem(dst, c, sz) BSetMem((CharacterTypeUTF16 *)dst, c, sz)
-#define MoveMem(dst, src, sz) BCopyMem((CharacterTypeUTF16 *)dst, (CharacterTypeUTF16 *)src, sz)
-#define CopyMem(dst, src, sz) BCopyMem((CharacterTypeUTF16 *)dst, (CharacterTypeUTF16 *)src, sz)
+#define SetMem(dst, c, sz) memset(dst, c, sz)
+#define MoveMem(dst, src, sz) memcpy(dst, src, sz)
+#define CopyMem(dst, src, sz) memcpy(dst,src, sz)
inline int isspace(int c) { return c == ' '; }
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
index 5be1e977..d6b5542c 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
@@ -107,18 +107,22 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
boot_ata_select(IO);
Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
- Out8(IO + ATA_REG_SEC_COUNT0, 1);
+
+ Out8(IO + ATA_REG_SEC_COUNT0, 2);
Out8(IO + ATA_REG_LBA0, (Lba));
Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
- Out8(IO + ATA_REG_LBA4, (Lba) >> 24);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
+ boot_ata_wait_io(IO);
+
for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
boot_ata_wait_io(IO);
Buf[IndexOff] = In16(IO + ATA_REG_DATA);
+ boot_ata_wait_io(IO);
}
}
@@ -130,18 +134,22 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
boot_ata_select(IO);
Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
- Out8(IO + ATA_REG_SEC_COUNT0, 1);
+
+ Out8(IO + ATA_REG_SEC_COUNT0, 2);
Out8(IO + ATA_REG_LBA0, (Lba));
Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
- Out8(IO + ATA_REG_LBA4, (Lba) >> 24);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
+ boot_ata_wait_io(IO);
+
for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
boot_ata_wait_io(IO);
Out16(IO + ATA_REG_DATA, Buf[IndexOff]);
+ boot_ata_wait_io(IO);
}
}
@@ -188,7 +196,7 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz
if (!Buf || SectorSz < 1) return *this;
- auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize;
+ auto lba = this->Leak().mBase / SectorSz;
boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster,
Buf, SectorSz, this->Leak().mSize);
@@ -211,7 +219,7 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS
if (!Buf || SectorSz < 1) return *this;
- auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize;
+ auto lba = this->Leak().mBase / SectorSz;
boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster,
Buf, SectorSz, this->Leak().mSize);
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 36dc47d3..12d34232 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -165,7 +165,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
/// if not formated yet, then format it with the following folders:
/// /, /Boot, /Applications.
- if (!diskFormatter) {
+ if (!diskFormatter.IsPartitionValid()) {
BDiskFormatFactory<BootDeviceATA>::BFileDescriptor rootDesc{0};
memcpy(rootDesc.fFileName, "/", strlen("/"));
diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
index 686f4811..3a6974bb 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Support.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
@@ -16,8 +16,11 @@
/// @param len length of of src.
EXTERN_C VoidPtr memset(void *dst, int byte,
long long unsigned int len) {
- SetMem(dst, byte, len);
- return dst;
+ for (size_t i = 0UL; i < len; ++i) {
+ ((int*)dst)[i] = byte;
+ }
+
+ return dst;
}
/// @brief memcpy definition in C++.
@@ -26,8 +29,11 @@ EXTERN_C VoidPtr memset(void *dst, int byte,
/// @param len length of of src.
EXTERN_C VoidPtr memcpy(void *dst, const void *src,
long long unsigned int len) {
- CopyMem(dst, src, len);
- return dst;
+ for (size_t i = 0UL; i < len; ++i){
+ ((int*)dst)[i] = ((int*)src)[i];
+ }
+
+ return dst;
}
/// @brief strlen definition in C++.
diff --git a/Private/NewBoot/Source/compile_flags.txt b/Private/NewBoot/Source/compile_flags.txt
index e58d7ab9..c74d22b2 100644
--- a/Private/NewBoot/Source/compile_flags.txt
+++ b/Private/NewBoot/Source/compile_flags.txt
@@ -1,3 +1,4 @@
-std=c++20
-I../
-I../../
+-D__NEWOS_AMD64__
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index f3a292c5..9f70d903 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -75,8 +75,8 @@ run-efi-amd64:
.PHONY: epm-img
epm-img:
- qemu-img create -f qcow2 $(IMG) 512M
- qemu-img create -f qcow2 $(IMG_2) 512M
+ qemu-img create -f raw $(IMG) 512M
+ qemu-img create -f raw $(IMG_2) 512M
.PHONY: download-edk
download-edk: