Thanks a lot Andrew and I shall first understand this and then make it work for
me. Thanks for taking the time to put in all this ReadyToGo fashion for me.
When I works I will post back.
Regards
Ananda
From: Andrew Fish [mailto:[email protected]]
Sent: Wednesday, July 17, 2013 2:50 PM
To: Vardhana, Ananda
Cc: Chip Ueltschey; [email protected]
Subject: Re: [edk2] How to run assembly code in EFI
On Jul 17, 2013, at 2:06 PM, "Vardhana, Ananda"
<[email protected]<mailto:[email protected]>> wrote:
Thanks Chip I shall do so. Here is what I would do please tell me if this will
work. Andrew really speaking I don't care what the assembly program does all I
need is that I transition from executing from a regular C code to pure assembly
and back. Please don't ask me why I want to do that ... :)
Well I spend time in my day job yelling at vendors that show up with edk2 code
that does not compile for me due to a compiler specific usage of inline
assemble, or only writing .asm files, when I need .S files. It is even worse
when they are doing this for things that already exist in libraries in the
MdePkg libraries.
Thanks
Ananda
File 1:
Junk.c:
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
RunAsmCode();
}
File 2:
Bunk.asm
Your syntax looks a little different than the rest of the edk2 .asm files:
https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/MdePkg/Library/BaseLib/X64/LongJump.asm
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; InternalLongJump (
; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
; IN UINTN Value
; );
;------------------------------------------------------------------------------
InternalLongJump PROC
mov rbx, [rcx]
mov rsp, [rcx + 8]
mov rbp, [rcx + 10h]
mov rdi, [rcx + 18h]
mov rsi, [rcx + 20h]
mov r12, [rcx + 28h]
mov r13, [rcx + 30h]
mov r14, [rcx + 38h]
mov r15, [rcx + 40h]
; load non-volatile fp registers
ldmxcsr [rcx + 50h]
movdqu xmm6, [rcx + 58h]
movdqu xmm7, [rcx + 68h]
movdqu xmm8, [rcx + 78h]
movdqu xmm9, [rcx + 88h]
movdqu xmm10, [rcx + 98h]
movdqu xmm11, [rcx + 0A8h]
movdqu xmm12, [rcx + 0B8h]
movdqu xmm13, [rcx + 0C8h]
movdqu xmm14, [rcx + 0D8h]
movdqu xmm15, [rcx + 0E8h]
mov rax, rdx ; set return value
jmp qword ptr [rcx + 48h]
InternalLongJump ENDP
END
LEAF_ENTRY RunAsmCode, _TEXT$00
push rbx
push rax
push rcx
push rdx
Looks like you don't understand the calling conventions. You should study up on
them.
RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile and must be considered
destroyed on function calls, so there is no reason to save them.
First 4 parameters - RCX, RDX, R8, R9. Others passed on stack.
The registers RBX, RBP, RDI, RSI, R12, R13, R14, and R15 are considered
nonvolatile and must be saved and restored by a function that uses them.
mov ebx, ecx
mov ecx, 0ffffffffh
/* More code will come here */
pop rdx
pop rcx
pop rax
pop rbx
ret
LEAF_END RunAsmCode, _TEXT$00
end
You also need a .S file:
https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/MdePkg/Library/BaseLib/X64/LongJump.S
to support all the compilers (Xcode/clang and gcc) that the edk2 supports.
#------------------------------------------------------------------------------
# VOID
# EFIAPI
# InternalLongJump (
# IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
# IN UINTN Value
# );
#------------------------------------------------------------------------------
ASM_GLOBAL ASM_PFX(InternalLongJump)
ASM_PFX(InternalLongJump):
mov (%rcx), %rbx
mov 0x8(%rcx), %rsp
mov 0x10(%rcx), %rbp
mov 0x18(%rcx), %rdi
mov 0x20(%rcx), %rsi
mov 0x28(%rcx), %r12
mov 0x30(%rcx), %r13
mov 0x38(%rcx), %r14
mov 0x40(%rcx), %r15
# load non-volatile fp registers
ldmxcsr 0x50(%rcx)
movdqu 0x58(%rcx), %xmm6
movdqu 0x68(%rcx), %xmm7
movdqu 0x78(%rcx), %xmm8
movdqu 0x88(%rcx), %xmm9
movdqu 0x98(%rcx), %xmm10
movdqu 0xA8(%rcx), %xmm11
movdqu 0xB8(%rcx), %xmm12
movdqu 0xC8(%rcx), %xmm13
movdqu 0xD8(%rcx), %xmm14
movdqu 0xE8(%rcx), %xmm15
mov %rdx, %rax # set return value
jmp *0x48(%rcx)
You then list the .asm/.S files in the INF file. The style of edk2 is to place
processor specific code in a processor specific directory.
So you can add an X64 directory to your driver and update the INF file to point
at the the code.
[Sources.X64]
X64/Bunk.asm
X64/Bunk.S
Since VC++ only has a rule for .asm and not .S it compiles the .asm. Since
GCC/Xcode have rules for .S and not .asm they only compile the .S file.
Example:
https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/MdePkg/Library/BaseLib/BaseLib.inf
Thanks,
Andrew Fish
From: Chip Ueltschey [mailto:[email protected]<http://gmail.com>]
Sent: Wednesday, July 17, 2013 1:54 PM
To: Vardhana, Ananda
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [edk2] How to run assembly code in EFI
Inline assembly is not supported for 64-bit code.
You would need to put your assembly code in a separate file.
-chip
On Wed, Jul 17, 2013 at 1:29 PM, Vardhana, Ananda
<[email protected]<mailto:[email protected]>> wrote:
I am new to EFI and have a very simple question. I want to compile this
following short program. I am running on a 64 bit machine and the EDKII is also
64 bit. I have tried with _asm and __asm both failed. Might be I have to use ()
instead of {}? I don't know. Help pelase
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
_asm {
push ebx
push eax
push ecx
push edx
/* Other code follows*/
}
}
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel