summaryrefslogtreecommitdiffhomepage
path: root/Boot
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
commit86e291120d124dec7244202b1766901a59dfb2e6 (patch)
tree1aa92d3b8a05216941986cf2724ff20ad01b3884 /Boot
parentf9579f444b1791d2b73d4d841569728fb203cb29 (diff)
[IMP] newoskrnl: Add symbol for cred_construct_token, reworked
ProcessHeap, new SCI.hxx for SCI and SCM. [IMP] newosldr: Loads the kernel correctly and can launch it, improved erorr handling. [META] newoskrnl, newosldr: Improved code and refactors. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Boot')
-rw-r--r--Boot/Sources/HEL/AMD64/BootJump.S6
-rw-r--r--Boot/Sources/HEL/AMD64/BootMain.cxx11
-rw-r--r--Boot/Sources/ProgramLoader.cxx48
3 files changed, 32 insertions, 33 deletions
diff --git a/Boot/Sources/HEL/AMD64/BootJump.S b/Boot/Sources/HEL/AMD64/BootJump.S
index fc7b3c68..7c2fcbc4 100644
--- a/Boot/Sources/HEL/AMD64/BootJump.S
+++ b/Boot/Sources/HEL/AMD64/BootJump.S
@@ -8,11 +8,13 @@
@brief this function setups a stack and then jumps to
a function */
rt_jump_to_address:
- mov r8, rsp
+ mov rsp, r8
push rax
push rdx
- jmp rcx
+ mov rbx, rcx
+ mov rcx, rdx
+ jmp rbx
pop rdx
pop rax
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx
index 5e0c8b05..56ef0457 100644
--- a/Boot/Sources/HEL/AMD64/BootMain.cxx
+++ b/Boot/Sources/HEL/AMD64/BootMain.cxx
@@ -243,16 +243,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
loader->SetName("\"newoskrnl.exe\" (64-bit MP)");
}
- if (!loader->IsValid())
- {
- writer.Write("newosldr: Invalid kernel image!\r");
-
- EFI::Stop();
-
- CANT_REACH();
- }
-
- writer.Write("newosldr: ").Write(loader->GetName()).Write("\r");
+ writer.Write("newosldr: Running: ").Write(loader->GetName()).Write("\r");
CopyMem(handoverHdrPtr->f_CommandLine[0], "/SMP", StrLen("/SMP"));
diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx
index 90e4b624..2103414a 100644
--- a/Boot/Sources/ProgramLoader.cxx
+++ b/Boot/Sources/ProgramLoader.cxx
@@ -18,6 +18,8 @@ EXTERN_C
#include <string.h>
}
+extern EfiBootServices* BS;
+
namespace Boot
{
EXTERN_C Int32 rt_jump_to_address(HEL::HandoverProc baseCode, HEL::HandoverInformationHeader* handover, Char* stackPointer);
@@ -63,14 +65,22 @@ namespace Boot
{
ExecSectionHeaderPtr sect = &sectPtr[sectIndex];
- // if this is a code header.
- if (sect->mCharacteristics & 0x00000020)
+ EfiPhysicalAddress address_to_alloc = sect->mVirtualAddress;
+
+ // if this is a code header, then we can look for the entrypoint.
+ if (sect->mCharacteristics & eUserSection)
{
- fStartAddress = (VoidPtr)(optHdr->mAddressOfEntryPoint + sect->mPointerToRawData +
- sect->mVirtualAddress);
- writer.Write("newosldr: Start Address: ").Write((UIntPtr)fStartAddress).Write("\r");
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderCode, 1, &address_to_alloc);
- break;
+ if (!fStartAddress)
+ {
+ fStartAddress = (VoidPtr)((UIntPtr)firstBytes + optHdr->mAddressOfEntryPoint);
+ writer.Write("newosldr: Start Address set: ").Write((UIntPtr)fStartAddress).Write("\r");
+ }
+ }
+ else
+ {
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderData, 1, &address_to_alloc);
}
}
}
@@ -97,32 +107,28 @@ namespace Boot
{
BTextWriter writer;
- if (!handover ||
- ((Char*)fStartAddress)[0] == 0x0)
+ if (!handover)
{
writer.Write("newosldr: Exec format error.\r");
return;
}
- writer.Write("newosldr: Trying to run: ").Write(fBlobName).Write("\r");
+ HEL::HandoverProc err_fn = [](HEL::HandoverInformationHeader* rcx) -> void {
+ BTextWriter writer;
+ writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
+
+ EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
+ };
if (!fStartAddress)
{
- HEL::HandoverProc fn = [](HEL::HandoverInformationHeader* rcx) -> void {
- BTextWriter writer;
- writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
-
- EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
- };
-
- rt_jump_to_address(fn, handover, fStackPtr);
-
- return;
+ err_fn(handover);
}
- HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
+ volatile HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
- rt_jump_to_address(start, handover, fStackPtr);
+ start(handover);
+ err_fn(handover);
}
const Char* ProgramLoader::GetName()