MdePkg BaseLib NASM Thunk16: Use NASM local labels

http://www.nasm.us/doc/nasmdoc3.html#section-3.9

A local label is a label beginning with the period, and it's actual
name is prefixed by the previous non-local label.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16022 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jordan Justen 2014-09-01 17:23:39 +00:00 committed by jljusten
parent fbb5393cb7
commit a8458d6cb3
2 changed files with 65 additions and 65 deletions

View File

@ -59,7 +59,7 @@ SECTION .data
; These are global constant to convey information to C code. ; These are global constant to convey information to C code.
; ;
ASM_PFX(m16Size) DW InternalAsmThunk16 - ASM_PFX(m16Start) ASM_PFX(m16Size) DW InternalAsmThunk16 - ASM_PFX(m16Start)
ASM_PFX(mThunk16Attr) DW _ThunkAttr - ASM_PFX(m16Start) ASM_PFX(mThunk16Attr) DW _BackFromUserCode.ThunkAttr - ASM_PFX(m16Start)
ASM_PFX(m16Gdt) DW _NullSegDesc - ASM_PFX(m16Start) ASM_PFX(m16Gdt) DW _NullSegDesc - ASM_PFX(m16Start)
ASM_PFX(m16GdtrBase) DW _16GdtrBase - ASM_PFX(m16Start) ASM_PFX(m16GdtrBase) DW _16GdtrBase - ASM_PFX(m16Start)
ASM_PFX(mTransition) DW _EntryPoint - ASM_PFX(m16Start) ASM_PFX(mTransition) DW _EntryPoint - ASM_PFX(m16Start)
@ -85,8 +85,8 @@ _BackFromUserCode:
push ss push ss
push cs push cs
DB 66h DB 66h
call @Base ; push eip call .Base ; push eip
@Base: .Base:
pushfw ; pushfd actually pushfw ; pushfd actually
cli ; disable interrupts cli ; disable interrupts
push gs push gs
@ -95,19 +95,19 @@ _BackFromUserCode:
push ds push ds
pushaw ; pushad actually pushaw ; pushad actually
DB 66h, 0bah ; mov edx, imm32 DB 66h, 0bah ; mov edx, imm32
_ThunkAttr: dd 0 .ThunkAttr: dd 0
test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15
jz @1 jz .1
mov eax, 15cd2401h ; mov ax, 2401h & int 15h mov eax, 15cd2401h ; mov ax, 2401h & int 15h
cli ; disable interrupts cli ; disable interrupts
jnc @2 jnc .2
@1: .1:
test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL
jz @2 jz .2
in al, 92h in al, 92h
or al, 2 or al, 2
out 92h, al ; deactivate A20M# out 92h, al ; deactivate A20M#
@2: .2:
xor ax, ax ; xor eax, eax xor ax, ax ; xor eax, eax
mov eax, ss ; mov ax, ss mov eax, ss ; mov ax, ss
DB 67h DB 67h
@ -122,18 +122,18 @@ _ThunkAttr: dd 0
shl ax, 4 ; shl eax, 4 shl ax, 4 ; shl eax, 4
add bp, ax ; add ebp, eax add bp, ax ; add ebp, eax
DB 66h, 0b8h ; mov eax, imm32 DB 66h, 0b8h ; mov eax, imm32
SavedCr4: DD 0 .SavedCr4: DD 0
mov cr4, eax mov cr4, eax
DB 66h DB 66h
lgdt [cs:edi + (SavedGdt - @Base)] lgdt [cs:edi + (SavedGdt - .Base)]
DB 66h, 0b8h ; mov eax, imm32 DB 66h, 0b8h ; mov eax, imm32
SavedCr0: DD 0 .SavedCr0: DD 0
mov cr0, eax mov cr0, eax
DB 0b8h ; mov ax, imm16 DB 0b8h ; mov ax, imm16
SavedSs DW 0 .SavedSs DW 0
mov ss, eax mov ss, eax
DB 66h, 0bch ; mov esp, imm32 DB 66h, 0bch ; mov esp, imm32
SavedEsp DD 0 .SavedEsp DD 0
DB 66h DB 66h
retf ; return to protected mode retf ; return to protected mode
@ -162,7 +162,7 @@ _ToUserCode:
mov cr0, eax ; real mode starts at next instruction mov cr0, eax ; real mode starts at next instruction
; which (per SDM) *must* be a far JMP. ; which (per SDM) *must* be a far JMP.
DB 0eah DB 0eah
_RealAddr: DW 0, 0 .RealAddr: DW 0, 0
mov cr4, ebp mov cr4, ebp
mov ss, esi ; set up 16-bit stack segment mov ss, esi ; set up 16-bit stack segment
@ -172,12 +172,12 @@ _RealAddr: DW 0, 0
DB 67h DB 67h
mov ebp, [esp + IA32_REGS.size] ; BackFromUserCode address from stack mov ebp, [esp + IA32_REGS.size] ; BackFromUserCode address from stack
; mov cs:[bp + (SavedSs - _BackFromUserCode)], dx ; mov cs:[bp + (_BackFromUserCode.SavedSs - _BackFromUserCode)], dx
mov [cs:esi + (SavedSs - _BackFromUserCode)], edx mov [cs:esi + (_BackFromUserCode.SavedSs - _BackFromUserCode)], edx
; mov cs:[bp + (SavedEsp - _BackFromUserCode)], ebx ; mov cs:[bp + (_BackFromUserCode.SavedEsp - _BackFromUserCode)], ebx
DB 2eh, 66h, 89h, 9eh DB 2eh, 66h, 89h, 9eh
DW SavedEsp - _BackFromUserCode DW _BackFromUserCode.SavedEsp - _BackFromUserCode
; lidt cs:[bp + (_16Idtr - _BackFromUserCode)] ; lidt cs:[bp + (_16Idtr - _BackFromUserCode)]
DB 2eh, 66h, 0fh, 01h, 9eh DB 2eh, 66h, 0fh, 01h, 9eh
@ -241,28 +241,28 @@ ASM_PFX(InternalAsmThunk16):
rep movsd ; copy RegSet rep movsd ; copy RegSet
mov eax, [esp + 40] ; eax <- address of transition code mov eax, [esp + 40] ; eax <- address of transition code
mov esi, edx ; esi <- 16-bit stack segment mov esi, edx ; esi <- 16-bit stack segment
lea edx, [eax + (SavedCr0 - ASM_PFX(m16Start))] lea edx, [eax + (_BackFromUserCode.SavedCr0 - ASM_PFX(m16Start))]
mov ecx, eax mov ecx, eax
and ecx, 0fh and ecx, 0fh
shl eax, 12 shl eax, 12
lea ecx, [ecx + (_BackFromUserCode - ASM_PFX(m16Start))] lea ecx, [ecx + (_BackFromUserCode - ASM_PFX(m16Start))]
mov ax, cx mov ax, cx
stosd ; [edi] <- return address of user code stosd ; [edi] <- return address of user code
add eax, _RealAddr + 4 - _BackFromUserCode add eax, _ToUserCode.RealAddr + 4 - _BackFromUserCode
mov [edx + (_RealAddr - SavedCr0)], eax mov [edx + (_ToUserCode.RealAddr - _BackFromUserCode.SavedCr0)], eax
sgdt [edx + (SavedGdt - SavedCr0)] sgdt [edx + (SavedGdt - _BackFromUserCode.SavedCr0)]
sidt [esp + 36] ; save IDT stack in argument space sidt [esp + 36] ; save IDT stack in argument space
mov eax, cr0 mov eax, cr0
mov [edx], eax ; save CR0 in SavedCr0 mov [edx], eax ; save CR0 in _BackFromUserCode.SavedCr0
and eax, 7ffffffeh ; clear PE, PG bits and eax, 7ffffffeh ; clear PE, PG bits
mov ebp, cr4 mov ebp, cr4
mov [edx + (SavedCr4 - SavedCr0)], ebp mov [edx + (_BackFromUserCode.SavedCr4 - _BackFromUserCode.SavedCr0)], ebp
and ebp, ~30h ; clear PAE, PSE bits and ebp, ~30h ; clear PAE, PSE bits
push 10h push 10h
pop ecx ; ecx <- selector for data segments pop ecx ; ecx <- selector for data segments
lgdt [edx + (_16Gdtr - SavedCr0)] lgdt [edx + (_16Gdtr - _BackFromUserCode.SavedCr0)]
pushfd ; Save df/if indeed pushfd ; Save df/if indeed
call dword far [edx + (_EntryPoint - SavedCr0)] call dword far [edx + (_EntryPoint - _BackFromUserCode.SavedCr0)]
popfd popfd
lidt [esp + 36] ; restore protected mode IDTR lidt [esp + 36] ; restore protected mode IDTR
lea eax, [ebp - IA32_REGS.size] ; eax <- the address of IA32_REGS lea eax, [ebp - IA32_REGS.size] ; eax <- the address of IA32_REGS

View File

@ -57,7 +57,7 @@ SECTION .data
; These are global constant to convey information to C code. ; These are global constant to convey information to C code.
; ;
ASM_PFX(m16Size) DW InternalAsmThunk16 - ASM_PFX(m16Start) ASM_PFX(m16Size) DW InternalAsmThunk16 - ASM_PFX(m16Start)
ASM_PFX(mThunk16Attr) DW _ThunkAttr - ASM_PFX(m16Start) ASM_PFX(mThunk16Attr) DW _BackFromUserCode.ThunkAttr - ASM_PFX(m16Start)
ASM_PFX(m16Gdt) DW _NullSeg - ASM_PFX(m16Start) ASM_PFX(m16Gdt) DW _NullSeg - ASM_PFX(m16Start)
ASM_PFX(m16GdtrBase) DW _16GdtrBase - ASM_PFX(m16Start) ASM_PFX(m16GdtrBase) DW _16GdtrBase - ASM_PFX(m16Start)
ASM_PFX(mTransition) DW _EntryPoint - ASM_PFX(m16Start) ASM_PFX(mTransition) DW _EntryPoint - ASM_PFX(m16Start)
@ -86,8 +86,8 @@ _BackFromUserCode:
DB 16h ; push ss DB 16h ; push ss
DB 0eh ; push cs DB 0eh ; push cs
DB 66h DB 66h
call @Base ; push eip call .Base ; push eip
@Base: .Base:
DB 66h DB 66h
push 0 ; reserved high order 32 bits of EFlags push 0 ; reserved high order 32 bits of EFlags
pushfw ; pushfd actually pushfw ; pushfd actually
@ -98,19 +98,19 @@ _BackFromUserCode:
DB 1eh ; push ds DB 1eh ; push ds
DB 66h, 60h ; pushad DB 66h, 60h ; pushad
DB 66h, 0bah ; mov edx, imm32 DB 66h, 0bah ; mov edx, imm32
_ThunkAttr: dd 0 .ThunkAttr: dd 0
test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15
jz @1 jz .1
mov eax, 15cd2401h ; mov ax, 2401h & int 15h mov eax, 15cd2401h ; mov ax, 2401h & int 15h
cli ; disable interrupts cli ; disable interrupts
jnc @2 jnc .2
@1: .1:
test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL test dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL
jz @2 jz .2
in al, 92h in al, 92h
or al, 2 or al, 2
out 92h, al ; deactivate A20M# out 92h, al ; deactivate A20M#
@2: .2:
xor ax, ax ; xor eax, eax xor ax, ax ; xor eax, eax
mov eax, ss ; mov ax, ss mov eax, ss ; mov ax, ss
lea bp, [esp + IA32_REGS.size] lea bp, [esp + IA32_REGS.size]
@ -124,32 +124,32 @@ _ThunkAttr: dd 0
add bp, ax ; add ebp, eax add bp, ax ; add ebp, eax
mov ax, cs mov ax, cs
shl ax, 4 shl ax, 4
lea ax, [eax + ebx + (@64BitCode - @Base)] lea ax, [eax + ebx + (.64BitCode - .Base)]
DB 66h, 2eh, 89h, 87h ; mov cs:[bx + (@64Eip - @Base)], eax DB 66h, 2eh, 89h, 87h ; mov cs:[bx + (.64Eip - .Base)], eax
DW @64Eip - @Base DW .64Eip - .Base
DB 66h, 0b8h ; mov eax, imm32 DB 66h, 0b8h ; mov eax, imm32
SavedCr4: DD 0 .SavedCr4: DD 0
mov cr4, rax mov cr4, rax
; ;
; rdi in the instruction below is indeed bx in 16-bit code ; rdi in the instruction below is indeed bx in 16-bit code
; ;
DB 66h, 2eh ; 2eh is "cs:" segment override DB 66h, 2eh ; 2eh is "cs:" segment override
lgdt [rdi + (SavedGdt - @Base)] lgdt [rdi + (SavedGdt - .Base)]
DB 66h DB 66h
mov ecx, 0c0000080h mov ecx, 0c0000080h
rdmsr rdmsr
or ah, 1 or ah, 1
wrmsr wrmsr
DB 66h, 0b8h ; mov eax, imm32 DB 66h, 0b8h ; mov eax, imm32
SavedCr0: DD 0 .SavedCr0: DD 0
mov cr0, rax mov cr0, rax
DB 66h, 0eah ; jmp far cs:@64Bit DB 66h, 0eah ; jmp far cs:.64Bit
@64Eip: DD 0 .64Eip: DD 0
SavedCs: DW 0 .SavedCs: DW 0
@64BitCode: .64BitCode:
db 090h db 090h
db 048h, 0bch ; mov rsp, imm64 db 048h, 0bch ; mov rsp, imm64
SavedSp: DQ 0 ; restore stack .SavedSp: DQ 0 ; restore stack
nop nop
ret ret
@ -184,16 +184,16 @@ _ToUserCode:
mov ss, esi ; set up 16-bit stack segment mov ss, esi ; set up 16-bit stack segment
mov sp, bx ; set up 16-bit stack pointer mov sp, bx ; set up 16-bit stack pointer
DB 66h ; make the following call 32-bit DB 66h ; make the following call 32-bit
call @ToUserCodeBase ; push eip call .Base ; push eip
@ToUserCodeBase: .Base:
pop bp ; ebp <- address of @ToUserCodeBase pop bp ; ebp <- address of .Base
push qword [esp + IA32_REGS.size + 2] push qword [esp + IA32_REGS.size + 2]
lea eax, [rsi + (@RealMode - @ToUserCodeBase)] ; rsi is "bp" in 16-bit code lea eax, [rsi + (.RealMode - .Base)] ; rsi is "bp" in 16-bit code
push rax push rax
retf ; execution begins at next instruction retf ; execution begins at next instruction
@RealMode: .RealMode:
DB 66h, 2eh ; CS and operand size override DB 66h, 2eh ; CS and operand size override
lidt [rsi + (_16Idtr - @ToUserCodeBase)] lidt [rsi + (_16Idtr - .Base)]
DB 66h, 61h ; popad DB 66h, 61h ; popad
DB 1fh ; pop ds DB 1fh ; pop ds
DB 07h ; pop es DB 07h ; pop es
@ -269,7 +269,7 @@ ASM_PFX(InternalAsmThunk16):
add edi, eax ; edi <- linear address of 16-bit stack add edi, eax ; edi <- linear address of 16-bit stack
pop rcx pop rcx
rep movsd ; copy RegSet rep movsd ; copy RegSet
lea ecx, [rdx + (SavedCr4 - ASM_PFX(m16Start))] lea ecx, [rdx + (_BackFromUserCode.SavedCr4 - ASM_PFX(m16Start))]
mov eax, edx ; eax <- transition code address mov eax, edx ; eax <- transition code address
and edx, 0fh and edx, 0fh
shl eax, 12 ; segment address in high order 16 bits shl eax, 12 ; segment address in high order 16 bits
@ -278,11 +278,11 @@ ASM_PFX(InternalAsmThunk16):
sgdt [rsp + 60h] ; save GDT stack in argument space sgdt [rsp + 60h] ; save GDT stack in argument space
movzx r10, word [rsp + 60h] ; r10 <- GDT limit movzx r10, word [rsp + 60h] ; r10 <- GDT limit
lea r11, [rcx + (InternalAsmThunk16 - SavedCr4) + 0xf] lea r11, [rcx + (InternalAsmThunk16 - _BackFromUserCode.SavedCr4) + 0xf]
and r11, ~0xf ; r11 <- 16-byte aligned shadowed GDT table in real mode buffer and r11, ~0xf ; r11 <- 16-byte aligned shadowed GDT table in real mode buffer
mov [rcx + (SavedGdt - SavedCr4)], r10w ; save the limit of shadowed GDT table mov [rcx + (SavedGdt - _BackFromUserCode.SavedCr4)], r10w ; save the limit of shadowed GDT table
mov [rcx + (SavedGdt - SavedCr4) + 2], r11 ; save the base address of shadowed GDT table mov [rcx + (SavedGdt - _BackFromUserCode.SavedCr4) + 2], r11 ; save the base address of shadowed GDT table
mov rsi, [rsp + 62h] ; rsi <- the original GDT base address mov rsi, [rsp + 62h] ; rsi <- the original GDT base address
xchg rcx, r10 ; save rcx to r10 and initialize rcx to be the limit of GDT table xchg rcx, r10 ; save rcx to r10 and initialize rcx to be the limit of GDT table
@ -294,25 +294,25 @@ ASM_PFX(InternalAsmThunk16):
sidt [rsp + 50h] ; save IDT stack in argument space sidt [rsp + 50h] ; save IDT stack in argument space
mov rax, cr0 mov rax, cr0
mov [rcx + (SavedCr0 - SavedCr4)], eax mov [rcx + (_BackFromUserCode.SavedCr0 - _BackFromUserCode.SavedCr4)], eax
and eax, 7ffffffeh ; clear PE, PG bits and eax, 7ffffffeh ; clear PE, PG bits
mov rbp, cr4 mov rbp, cr4
mov [rcx], ebp ; save CR4 in SavedCr4 mov [rcx], ebp ; save CR4 in _BackFromUserCode.SavedCr4
and ebp, ~30h ; clear PAE, PSE bits and ebp, ~30h ; clear PAE, PSE bits
mov esi, r8d ; esi <- 16-bit stack segment mov esi, r8d ; esi <- 16-bit stack segment
DB 6ah, DATA32 ; push DATA32 DB 6ah, DATA32 ; push DATA32
pop rdx ; rdx <- 32-bit data segment selector pop rdx ; rdx <- 32-bit data segment selector
lgdt [rcx + (_16Gdtr - SavedCr4)] lgdt [rcx + (_16Gdtr - _BackFromUserCode.SavedCr4)]
mov ss, edx mov ss, edx
pushfq pushfq
lea edx, [rdx + DATA16 - DATA32] lea edx, [rdx + DATA16 - DATA32]
lea r8, [REL @RetFromRealMode] lea r8, [REL .RetFromRealMode]
push r8 push r8
mov r8d, cs mov r8d, cs
mov [rcx + (SavedCs - SavedCr4)], r8w mov [rcx + (_BackFromUserCode.SavedCs - _BackFromUserCode.SavedCr4)], r8w
mov [rcx + (SavedSp - SavedCr4)], rsp mov [rcx + (_BackFromUserCode.SavedSp - _BackFromUserCode.SavedCr4)], rsp
jmp dword far [rcx + (_EntryPoint - SavedCr4)] jmp dword far [rcx + (_EntryPoint - _BackFromUserCode.SavedCr4)]
@RetFromRealMode: .RetFromRealMode:
popfq popfq
lgdt [rsp + 60h] ; restore protected mode GDTR lgdt [rsp + 60h] ; restore protected mode GDTR
lidt [rsp + 50h] ; restore protected mode IDTR lidt [rsp + 50h] ; restore protected mode IDTR