summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 08:48:01 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 08:48:01 +0200
commit2d11ddee665e8425708bbda876060b2958de5d07 (patch)
treebaeb55c221705e1c84ccd89644204bb17d40c365
parent5dc33d9a22207b8b664ea83f88280911a22d0c52 (diff)
[newosldr] Running kernel as separate image instead.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--.vscode/c_cpp_properties.json6
-rw-r--r--Boot/BootKit/ProgramLoader.hxx1
-rw-r--r--Boot/Sources/HEL/AMD64/BootMain.cxx29
-rw-r--r--Boot/Sources/HEL/AMD64/New+Delete.cxx2
-rw-r--r--Boot/Sources/ProgramLoader.cxx9
-rw-r--r--Boot/amd64-efi.make7
-rw-r--r--Kernel/KernelKit/DebugOutput.hpp8
-rw-r--r--Kernel/KernelKit/Defines.hpp1
-rw-r--r--Kernel/NewKit/Macros.hpp2
-rw-r--r--Kernel/Sources/FS/NewFS.cxx32
-rw-r--r--Kernel/Sources/User.cxx2
11 files changed, 51 insertions, 48 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 6c57511e..2cb9e3a7 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -16,8 +16,7 @@
"__EFI_x86_64__",
"__ATA_PIO__",
"__NEWOS_AMD64__",
- "__DEBUG__",
- "__NEWOS_OTA__"
+ "__DEBUG__"
],
"cStandard": "c17",
"cppStandard": "c++20",
@@ -40,8 +39,7 @@
"__EFI_x86_64__",
"__ATA_PIO__",
"__NEWOS_AMD64__",
- "__DEBUG__",
- "__NEWOS_OTA__"
+ "__DEBUG__"
],
"cStandard": "c17",
"cppStandard": "c++20",
diff --git a/Boot/BootKit/ProgramLoader.hxx b/Boot/BootKit/ProgramLoader.hxx
index 90f8996f..09fff89b 100644
--- a/Boot/BootKit/ProgramLoader.hxx
+++ b/Boot/BootKit/ProgramLoader.hxx
@@ -32,6 +32,7 @@ namespace Boot
void Start(HEL::HandoverInformationHeader* handover);
const char* GetName();
void SetName(const char* name);
+ bool IsValid();
private:
Char fBlobName[255];
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx
index 8705f4a8..5e0c8b05 100644
--- a/Boot/Sources/HEL/AMD64/BootMain.cxx
+++ b/Boot/Sources/HEL/AMD64/BootMain.cxx
@@ -227,8 +227,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
diskFormatter.Format(kMachineModel, &rootDesc, 1);
}
-#ifdef __NEWOS_OTA__
-
BFileReader readerKernel(L"newoskrnl.exe", ImageHandle);
readerKernel.ReadAll(0);
@@ -236,30 +234,35 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
Boot::ProgramLoader* loader = nullptr;
// ------------------------------------------ //
- // If we succeed in reading the blob, then execute it.
+ // If we succeed in reading the blob, then execute it.
// ------------------------------------------ //
if (readerKernel.Blob())
{
loader = new Boot::ProgramLoader(readerKernel.Blob());
- loader->SetName("\"newoskrnl.exe\" (ZKA 64-bit MP)");
+ loader->SetName("\"newoskrnl.exe\" (64-bit MP)");
}
- writer.Write("Running: ").Write(loader->GetName()).Write("\r");
+ if (!loader->IsValid())
+ {
+ writer.Write("newosldr: Invalid kernel image!\r");
+
+ EFI::Stop();
-#endif // ifdef __NEWOS_OTA__
+ CANT_REACH();
+ }
+
+ writer.Write("newosldr: ").Write(loader->GetName()).Write("\r");
+
+ CopyMem(handoverHdrPtr->f_CommandLine[0], "/SMP", StrLen("/SMP"));
EFI::ExitBootServices(*MapKey, ImageHandle);
// ---------------------------------------------------- //
- // Call OTA kernel or fallback to builtin.
+ // Call kernel.
// ---------------------------------------------------- //
-#ifdef __NEWOS_OTA__
- if (loader)
- loader->Start(handoverHdrPtr);
-#else
- hal_init_platform(handoverHdrPtr);
-#endif // ifdef __NEWOS_OTA__
+
+ loader->Start(handoverHdrPtr);
EFI::Stop();
diff --git a/Boot/Sources/HEL/AMD64/New+Delete.cxx b/Boot/Sources/HEL/AMD64/New+Delete.cxx
index 15903bb4..62dcda35 100644
--- a/Boot/Sources/HEL/AMD64/New+Delete.cxx
+++ b/Boot/Sources/HEL/AMD64/New+Delete.cxx
@@ -11,6 +11,8 @@
#ifdef __STANDALONE__
#include <cstddef> /* Since we're using GCC for this EFI program. */
+EXTERN EfiBootServices* BS;
+
/// @brief Allocates a new object.
/// @param sz the size.
/// @return
diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx
index 4ea0d4c6..fabd1c63 100644
--- a/Boot/Sources/ProgramLoader.cxx
+++ b/Boot/Sources/ProgramLoader.cxx
@@ -39,13 +39,13 @@ namespace Boot
if (firstBytes[0] == kMagMz0 &&
firstBytes[1] == kMagMz1)
{
- writer.Write("newosldr: MZ executable detected.\r");
+ writer.Write("newosldr: Windows executable detected.\r");
ExecHeaderPtr hdrPtr = (ldr_find_exec_header(firstBytes));
ExecOptionalHeaderPtr optHdr = (ldr_find_opt_exec_header(firstBytes));
// Parse PE32+
- fStartAddress = (VoidPtr)((UIntPtr)optHdr->mImageBase + optHdr->mBaseOfCode + optHdr->mAddressOfEntryPoint);
+ fStartAddress = (VoidPtr)(optHdr->mAddressOfEntryPoint);
fStackPtr = new Char[optHdr->mSizeOfStackReserve];
writer.Write("newosldr: Major Linker: ").Write(optHdr->mMajorLinkerVersion).Write("\r");
@@ -112,4 +112,9 @@ namespace Boot
{
CopyMem(fBlobName, name, StrLen(name));
}
+
+ bool ProgramLoader::IsValid()
+ {
+ return fStartAddress != nullptr;
+ }
} // namespace Boot
diff --git a/Boot/amd64-efi.make b/Boot/amd64-efi.make
index f1e40d7a..49d2ae59 100644
--- a/Boot/amd64-efi.make
+++ b/Boot/amd64-efi.make
@@ -38,19 +38,14 @@ EMU_FLAGS=-net none -smp 2 -m 4G -M q35 \
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__ \
+FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -D__NEWOS_OTA__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \
-DEFI_FUNCTION_WRAPPER -I./ -I../Vendor -I../Kernel -c -nostdlib -fno-rtti -fno-exceptions \
-std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__NEWOS_AMD64__ -D__MAHROUSS__ -D__BOOTLOADER__
diff --git a/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp
index 02b73fc9..498b7972 100644
--- a/Kernel/KernelKit/DebugOutput.hpp
+++ b/Kernel/KernelKit/DebugOutput.hpp
@@ -107,14 +107,14 @@ namespace Kernel
{
inline TerminalDevice _write_number(const Long& x, TerminalDevice& term)
{
- UInt64 y = (x > 0 ? x : -x) / 9;
- UInt64 h = (x > 0 ? x : -x) % 9;
+ 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)
+ if (h > 10)
{
_write_number('?', term);
return term;
@@ -123,7 +123,7 @@ namespace Kernel
if (y < 0)
y = -y;
- const char cNumbers[17] = "0123456789";
+ const char cNumbers[11] = "0123456789";
Char buf[2];
buf[0] = cNumbers[h];
diff --git a/Kernel/KernelKit/Defines.hpp b/Kernel/KernelKit/Defines.hpp
index 191d1098..d69f4d1b 100644
--- a/Kernel/KernelKit/Defines.hpp
+++ b/Kernel/KernelKit/Defines.hpp
@@ -9,4 +9,3 @@
#include <NewKit/Defines.hpp>
#define KERNELKIT_VERSION "1.02"
-#define KERNELKIT_RELEASE "Alexandria"
diff --git a/Kernel/NewKit/Macros.hpp b/Kernel/NewKit/Macros.hpp
index aecd6d89..a9492f3a 100644
--- a/Kernel/NewKit/Macros.hpp
+++ b/Kernel/NewKit/Macros.hpp
@@ -53,7 +53,7 @@
#endif // #ifndef ATTRIBUTE
#ifndef __MAHROUSS_VER__
-#define __MAHROUSS_VER__ (202404)
+#define __MAHROUSS_VER__ (2024)
#endif // !__MAHROUSS_VER__
#ifndef EXTERN_C
diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx
index 05833c0e..ae2013cb 100644
--- a/Kernel/Sources/FS/NewFS.cxx
+++ b/Kernel/Sources/FS/NewFS.cxx
@@ -303,15 +303,13 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name,
Int32 flagsList = flags;
- if (name[0] == kNewFSMetaFilePrefix)
+ if (flagsList & kNewFSCatalogKindMetaFile)
{
if (UserView::The()->Current() != UserView::The()->fRootUser)
{
delete catalogChild;
return nullptr;
}
-
- flagsList |= kNewFSCatalogKindMetaFile;
}
catalogChild->ResourceForkSize = cDefaultForkSize;
@@ -351,7 +349,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name,
while (drive->fPacket.fPacketGood)
{
- nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf;
+ nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf);
if (startFree <= kNewFSStartLba)
{
@@ -361,7 +359,9 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name,
return nullptr;
}
- /// allocation or reallocation or catalog...
+ // ========================== //
+ // allocate catalog now...
+ // ========================== //
if (nextSibling->Flags != kNewFSFlagCreated)
{
Char sectorBufPartBlock[kNewFSSectorSz] = {0};
@@ -449,13 +449,13 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name,
/// @return If it was sucessful, see ErrLocal().
bool NewFSParser::Format(_Input _Output DriveTrait* drive)
{
- /// verify disk.
+ // verify disk.
drive->fVerify(&drive->fPacket);
rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
- /// if disk isn't good, then error out.
+ // if disk isn't good, then error out.
if (false == drive->fPacket.fPacketGood)
{
ErrLocal() = kErrorDiskIsCorrupted;
@@ -470,12 +470,12 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive)
drive->fInput(&drive->fPacket);
- /// disk isnt faulty and data has been fetched.
+ // disk isnt faulty and data has been fetched.
if (drive->fPacket.fPacketGood)
{
NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf;
- /// check for an empty partition here.
+ // check for an empty partition here.
if (partBlock->PartitionName[0] == 0 &&
rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen))
{
@@ -483,7 +483,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive)
partBlock->Version = kNewFSVersionInteger;
- const auto cUntitledHD = "newoskrnl HD\0";
+ const auto cUntitledHD = "Untitled HD\0";
rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident,
kNewFSIdentLen);
@@ -733,7 +733,7 @@ _NewFSSearchThroughCatalogList:
/// ignore unallocated catalog, break
if (catalog->Flags != kNewFSFlagCreated)
{
- goto _NewFSContinueSearch;
+ goto NewFSContinueSearch;
}
NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT();
@@ -746,7 +746,7 @@ _NewFSSearchThroughCatalogList:
return catalogPtr;
}
- _NewFSContinueSearch:
+ NewFSContinueSearch:
startCatalogList = catalog->NextSibling;
if (startCatalogList <= kNewFSStartLba)
@@ -773,8 +773,8 @@ _NewFSSearchThroughCatalogList:
return nullptr;
}
-/// @brief
-/// @param name
+/// @brief Get catalog from filesystem.
+/// @param name the catalog's name/
/// @return
_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const char* name)
{
@@ -782,8 +782,8 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const char* name)
return this->FindCatalog(name, unused);
}
-/// @brief
-/// @param catalog
+/// @brief Closes a catalog, (frees it).
+/// @param catalog the catalog to close.
/// @return
Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog)
{
diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx
index 7d496a69..dda3d016 100644
--- a/Kernel/Sources/User.cxx
+++ b/Kernel/Sources/User.cxx
@@ -97,7 +97,7 @@ namespace Kernel
// Retrieve token from a specific file fork.
// ------------------------------------------ //
- auto token = file.Read(password);
+ auto token = file.Read(user->fUserName.CData());
if (!token)
{