+NTSTATUS
+OslPrepareTarget (
+ _Out_ PULONG ReturnFlags,
+ _Out_ PBOOLEAN Jump
+ )
+{
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+OslExecuteTransition (
+ VOID
+ )
+{
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+OslpMain (
+ _Out_ PULONG ReturnFlags
+ )
+{
+ INT CpuInfo[4];
+ BOOLEAN NxDisabled;
+ NTSTATUS Status;
+ BOOLEAN ExecuteJump;
+
+ /* Check if the CPU supports NX */
+ BlArchCpuId(0x80000001, 0, CpuInfo);
+ if (!(CpuInfo[3] & 0x10000))
+ {
+ /* It doesn't, check if this is Intel */
+ EfiPrintf(L"NX disabled: %d\r\n");
+ if (BlArchGetCpuVendor() == CPU_INTEL)
+ {
+ /* Then turn off the MSR feature for it */
+ EfiPrintf(L"NX being turned off\r\n");
+ __writemsr(MSR_IA32_MISC_ENABLE,
+ __readmsr(MSR_IA32_MISC_ENABLE) & MSR_XD_ENABLE_MASK);
+ NxDisabled = TRUE;
+ }
+ }
+
+ /* Turn on NX support with the CPU-generic MSR */
+ __writemsr(MSR_EFER, __readmsr(MSR_EFER) | MSR_NXE);
+
+ /* Load the kernel */
+ Status = OslPrepareTarget(ReturnFlags, &ExecuteJump);
+ if (NT_SUCCESS(Status) && (ExecuteJump))
+ {
+ /* Jump to the kernel */
+ Status = OslExecuteTransition();
+ }
+
+ /* Retore NX support */
+ __writemsr(MSR_EFER, __readmsr(MSR_EFER) ^ MSR_NXE);
+
+ /* Did we disable NX? */
+ if (NxDisabled)
+ {
+ /* Turn it back on */
+ __writemsr(MSR_IA32_MISC_ENABLE,
+ __readmsr(MSR_IA32_MISC_ENABLE) | ~MSR_XD_ENABLE_MASK);
+ }
+
+ /* Go back */
+ return Status;
+}
+