summaryrefslogtreecommitdiffhomepage
path: root/Kernel/FirmwareKit/Handover.hxx
blob: 1a7d1da7c525d6f655dfbba06d7764696bb7122a (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* -------------------------------------------

	Copyright SoftwareLabs

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

/**
 * @file Handover.hxx
 * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
 * @brief The handover boot protocol.
 * @version 0.3
 * @date 2024-02-23
 *
 * @copyright Copyright (c) 2024, SoftwareLabs
 *
 */

#pragma once

#include <NewKit/Defines.hpp>

/* useful macros */

#define kHandoverMagic	 0xBADCC
#define kHandoverVersion 0x112

#define kHandoverStructSz sizeof(HEL::HandoverHeader)

namespace NewOS::HEL
{
	/**
	@brief the kind of executable we're loading.
*/
	enum
	{
		kTypeKernel		  = 100,
		kTypeKernelDriver = 101,
		kTypeRsrc		  = 102,
		kTypeCount		  = 3,
	};

	/**
	@brief The executable architecture.
*/

	enum
	{
		kArchAmd64 = 122,
		kArchCount = 2,
	};

	/**
@brief The first struct that we read when inspecting The executable
it tells us more about it and IS format independent.
*/
	typedef struct HandoverHeader final
	{
		UInt64	f_TargetMagic;
		Int32	f_TargetType;
		Int32	f_TargetArch;
		UIntPtr f_TargetStartAddress;
	} __attribute__((packed)) HandoverHeader, *HandoverHeaderPtr;

	struct HandoverInformationHeader
	{
		UInt64 f_Magic;
		UInt64 f_Version;

		voidPtr f_VirtualStart;
		SizeT	f_VirtualSize;
		voidPtr f_PhysicalStart;

		WideChar f_FirmwareVendorName[32];
		SizeT	 f_FirmwareVendorLen;

		struct
		{
			VoidPtr f_SmBios;
			VoidPtr f_RsdPtr;
		} f_HardwareTables;

		struct
		{
			UIntPtr f_The;
			SizeT	f_Size;
			UInt32	f_Width;
			UInt32	f_Height;
			UInt32	f_PixelFormat;
			UInt32	f_PixelPerLine;
		} f_GOP;

		UInt64 f_FirmwareSpecific[8];
	};

	enum
	{
		kHandoverSpecificKind,
		kHandoverSpecificAttrib,
		kHandoverSpecificMemoryEfi,
	};

	/// @brief Bootloader main type.
	typedef void (*BootMainKind)(NewOS::HEL::HandoverInformationHeader* handoverInfo);

	/// @brief Alias of bootloader main type.
	typedef void (*HandoverProc)(HandoverInformationHeader* handoverInfo);
} // namespace NewOS::HEL

/// @brief Bootloader global header.
inline NewOS::HEL::HandoverInformationHeader* kHandoverHeader = nullptr;