/* There are a number of constraints that must be followed before calling this function: 1) Interrupts must be disabled. 2) The caller must be in 32-bit paged mode. 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode. 4) CR3 must point to valid page tables that guarantee that the pages for this function and the stack are identity mapped. */
__declspec(naked)
/* There are a number of constraints that must be followed before calling this function: 1) Interrupts must be disabled. 2) The caller must be in 32-bit paged mode. 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode. 4) CR3 must point to valid page tables that guarantee that the pages for this function and the stack are identity mapped. */
__declspec(naked)
{
  _asm {
    push    ebp
    mov     ebp, esp
    mov     ebx, EntryPoint
    mov     ecx, Context1
    mov     edx, Context2
    pushfd
    pop     edi
    cli
    mov     eax, cr0
    btr     eax, 31
    mov     esp, NewStack
    mov     cr0, eax
    push    edi
    popfd
    push    edx
    push    ecx
    call    ebx
    jmp     $
  }
}