summaryrefslogtreecommitdiffhomepage
path: root/dev/Boot/src/HEL/ARM64/BootMain.cc
blob: 1cf72d4b503177546cce53aeefb7f9eff0d34fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -------------------------------------------

	Copyright (C) 2024, Theater Quality Corp, all rights reserved.

------------------------------------------- */

#include <FirmwareKit/EFI/API.h>
#include <FirmwareKit/EFI.h>
#include <BootKit/Thread.h>
#include <BootKit/BootKit.h>

#ifndef kExpectedWidth
#define kExpectedWidth (1280)
#endif

#ifndef kExpectedHeight
#define kExpectedHeight (720)
#endif

EXTERN EfiBootServices* BS;

STATIC EfiGraphicsOutputProtocol* kGop		 = nullptr;
STATIC UInt16					  kGopStride = 0U;
STATIC EfiGUID					  kGopGuid;

/// @brief Main EFI entrypoint.
/// @param ImageHandle Handle of this image.
/// @param SystemTable The system table of it.
/// @return nothing, never returns.
EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr	ImageHandle,
								EfiSystemTable* SystemTable)
{
	InitEFI(SystemTable);

	kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
	kGop	 = nullptr;

	BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop);

	kGopStride = 4;

	Boot::BTextWriter writer;

	for (SizeT i = 0; i < kGop->Mode->MaxMode; ++i)
	{
		EfiGraphicsOutputProtocolModeInformation* infoPtr = nullptr;
		UInt32									  sz	  = 0U;

		kGop->QueryMode(kGop, i, &sz, &infoPtr);

		writer.Write(infoPtr->HorizontalResolution);
		writer.Write(infoPtr->VerticalResolution);
		writer.Write("\r");

		if (infoPtr->HorizontalResolution == kExpectedWidth &&
			infoPtr->VerticalResolution == kExpectedHeight)
		{
			kGop->SetMode(kGop, i);
			break;
		}
	}

	Boot::BFileReader reader_kernel(L"minoskrnl.exe", ImageHandle);

	reader_kernel.ReadAll(0);

	if (reader_kernel.Blob())
	{
		auto kernel_thread = Boot::BThread(reader_kernel.Blob());

		if (kernel_thread.IsValid())
			kernel_thread.Start(nullptr, YES);
	}

	CANT_REACH();
}