+++ /dev/null
-#------------------------------------------------------------------------------\r
-#\r
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-# Module Name:\r
-#\r
-# Thunk16.S\r
-#\r
-# Abstract:\r
-#\r
-# Real mode thunk\r
-#\r
-#------------------------------------------------------------------------------\r
-\r
-#include <EdkIIGlueBase.h>\r
-\r
-.globl ASM_PFX(m16Start), ASM_PFX(m16Size), ASM_PFX(mThunk16Attr), ASM_PFX(m16Gdt), ASM_PFX(m16GdtrBase), ASM_PFX(mTransition)\r
-.globl ASM_PFX(InternalAsmThunk16)\r
-\r
-ASM_PFX(m16Start):\r
-\r
-SavedGdt: .space 6\r
-\r
-ASM_PFX(BackFromUserCode):\r
- push %ss\r
- push %cs\r
- .byte 0x66\r
- call L_Base1 # push eip\r
-L_Base1:\r
- pushfw # pushfd actually\r
- cli # disable interrupts\r
- push %gs\r
- push %fs\r
- push %es\r
- push %ds\r
- pushaw # pushad actually\r
- .byte 0x66, 0xba # mov edx, imm32\r
-ASM_PFX(ThunkAttr): .space 4\r
- testb $THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15, %dl\r
- jz 1f\r
- movl $0x15cd2401, %eax # mov ax, 2401h & int 15h\r
- cli # disable interrupts\r
- jnc 2f\r
-1:\r
- testb $THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL, %dl\r
- jz 2f\r
- inb $0x92, %al\r
- orb $2, %al\r
- outb %al, $0x92 # deactivate A20M#\r
-2:\r
- xorw %ax, %ax # xor eax, eax\r
- movl %ss, %eax # mov ax, ss\r
- .byte 0x67, 0x66, 0x8d, 0x6c, 0x24, 0x34, 0x66\r
- mov %ebp, 0xffffffd8(%esi)\r
- mov 0xfffffff8(%esi), %ebx\r
- shlw $4, %ax # shl eax, 4\r
- addw %ax, %bp # add ebp, eax\r
- .byte 0x66, 0xb8 # mov eax, imm32\r
-SavedCr4: .space 4\r
- movl %eax, %cr4\r
- lgdtw %cs:0xfffffff2(%edi)\r
- .byte 0x66, 0xb8 # mov eax, imm32\r
-SavedCr0: .space 4\r
- movl %eax, %cr0\r
- .byte 0xb8 # mov ax, imm16\r
-SavedSs: .space 2\r
- movl %eax, %ss\r
- .byte 0x66, 0xbc # mov esp, imm32\r
-SavedEsp: .space 4\r
- .byte 0x66\r
- lret # return to protected mode\r
-\r
-_EntryPoint: .long ASM_PFX(ToUserCode) - ASM_PFX(m16Start)\r
- .word 0x8\r
-_16Idtr: .word 0x3ff\r
- .long 0\r
-_16Gdtr: .word GdtEnd - _NullSegDesc - 1\r
-_16GdtrBase: .long _NullSegDesc\r
-\r
-ASM_PFX(ToUserCode):\r
- movl %ss, %edx\r
- movl %ecx, %ss # set new segment selectors\r
- movl %ecx, %ds\r
- movl %ecx, %es\r
- movl %ecx, %fs\r
- movl %ecx, %gs\r
- movl %eax, %cr0\r
- movl %ebp, %cr4 # real mode starts at next instruction\r
- movl %esi, %ss # set up 16-bit stack segment\r
- xchgw %bx, %sp # set up 16-bit stack pointer\r
- .byte 0x66\r
- call L_Base # push eip\r
-L_Base:\r
- popw %bp # ebp <- offset L_Base\r
- .byte 0x67; # address size override\r
- push 54(%esp)\r
- lea 0xc(%esi), %eax\r
- push %eax\r
- lret\r
-\r
-L_RealMode:\r
- mov %edx, %cs:0xffffffc5(%esi)\r
- mov %bx, %cs:0xffffffcb(%esi)\r
- lidtw %cs:0xffffffd7(%esi)\r
- popaw # popad actually\r
- pop %ds\r
- pop %es\r
- pop %fs\r
- pop %gs\r
- popfw # popfd\r
- lretw # transfer control to user code\r
-\r
-_NullSegDesc: .quad 0\r
-_16CsDesc:\r
- .word -1\r
- .word 0\r
- .byte 0\r
- .byte 0x9b\r
- .byte 0x8f # 16-bit segment, 4GB limit\r
- .byte 0\r
-_16DsDesc:\r
- .word -1\r
- .word 0\r
- .byte 0\r
- .byte 0x93\r
- .byte 0x8f # 16-bit segment, 4GB limit\r
- .byte 0\r
-GdtEnd:\r
-\r
-#\r
-# @param RegSet The pointer to a IA32_DWORD_REGS structure\r
-# @param Transition The pointer to the transition code\r
-# @return The address of the 16-bit stack after returning from user code\r
-#\r
-ASM_PFX(InternalAsmThunk16):\r
- push %ebp\r
- push %ebx\r
- push %esi\r
- push %edi\r
- push %ds\r
- push %es\r
- push %fs\r
- push %gs\r
- movl 36(%esp), %esi # esi <- RegSet\r
- movzwl 0x32(%esi), %edx\r
- mov 0xc(%esi), %edi\r
- add $0xffffffc8, %edi\r
- movl %edi, %ebx # ebx <- stack offset\r
- imul $0x10, %edx, %eax\r
- push $0xd\r
- addl %eax, %edi # edi <- linear address of 16-bit stack\r
- pop %ecx\r
- rep\r
- movsl # copy RegSet\r
- movl 40(%esp), %eax # eax <- address of transition code\r
- movl %edx, %esi # esi <- 16-bit stack segment\r
- lea 0x61(%eax), %edx\r
- movl %eax, %ecx\r
- andl $0xf, %ecx\r
- shll $12, %eax\r
- lea 0x6(%ecx), %ecx\r
- movw %cx, %ax\r
- stosl # [edi] <- return address of user code\r
- sgdtl 0xffffff9f(%edx)\r
- sidtl 0x24(%esp)\r
- movl %cr0, %eax\r
- movl %eax, (%edx) # save CR0 in SavedCr0\r
- andl $0x7ffffffe, %eax # clear PE, PG bits\r
- movl %cr4, %ebp\r
- mov %ebp, 0xfffffff1(%edx)\r
- andl $0x300, %ebp # clear all but PCE and OSFXSR bits\r
- pushl $0x10\r
- pop %ecx # ecx <- selector for data segments\r
- lgdtl 0x20(%edx)\r
- pushfl\r
- lcall *0x14(%edx)\r
- popfl\r
- lidtl 0x24(%esp)\r
- lea 0xffffffcc(%ebp), %eax\r
- pop %gs\r
- pop %fs\r
- pop %es\r
- pop %ds\r
- pop %edi\r
- pop %esi\r
- pop %ebx\r
- pop %ebp\r
- ret\r
-\r
- .const:\r
-\r
-ASM_PFX(m16Size): .word ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start)\r
-ASM_PFX(mThunk16Attr): .word ASM_PFX(ThunkAttr) - ASM_PFX(m16Start)\r
-ASM_PFX(m16Gdt): .word _NullSegDesc - ASM_PFX(m16Start)\r
-ASM_PFX(m16GdtrBase): .word _16GdtrBase - ASM_PFX(m16Start)\r
-ASM_PFX(mTransition): .word _EntryPoint - ASM_PFX(m16Start)\r