include efiOA.inc
% include @Environ(OBJASM_PATH)\Code\Macros\Model.inc ;Include & initialize standard modules
SysSetup OOP, WIDE_STRING, EFI64;, DEBUG(CON) ;Load OOP files and basic OS support
.data
Handle EFI_HANDLE 0
SystemTablePtr dq 0
HelloMsg dw 'H','e','l','l','o',' ','U','E','F','I',' ','W','o','r','l','d','!',13,10,0
;HelloMsg dw 'Hello UEFI World!',13,10,0
pConsole PCONOUT 0
pConsoleIn PCONIN 0
pBootServices P_BOOT_SERVICES 0
pRuntimeServices P_RUNTIME_SERVICES 0
mapSize UINTN 512*SIZEOF(EFI_MEMORY_DESCRIPTOR)
descriptors EFI_MEMORY_DESCRIPTOR 512 DUP (<?>)
mapKey UINTN 0
descSize UINTN 0
descVer UINT32 0
include efiUtil.inc
MakeObjects Primer, Demo01
pShape_1 $ObjPtr(Triangle) NULL
pShape_2 $ObjPtr(Rectangle) NULL
.code
Main PROC FRAME imageHandle:EFI_HANDLE, SystemTable:PTR_EFI_SYSTEM_TABLE
mov Handle,rcx
mov SystemTablePtr,rdx
mov rax,SystemTablePtr
mov rsi,[rax].EFI_SYSTEM_TABLE.RuntimeServices
mov pRuntimeServices,rsi
mov rsi,[rax].EFI_SYSTEM_TABLE.BootServices
mov pBootServices,rsi
;=====================================================================================
; The normal ASM way to make a 64bit FASTCALL.
;=====================================================================================
sub rsp,20h
lea rdx,HelloMsg
mov rcx,SystemTablePtr
mov rcx,[rcx + EFI_SYSTEM_TABLE_CONOUT]
call qword ptr [rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_OUTPUTSTRING]
add rsp,20h
;=====================================================================================
; The smarter UASM way...
;=====================================================================================
mov rcx,SystemTablePtr
mov rax,[rcx].EFI_SYSTEM_TABLE.ConIn
mov pConsoleIn,rax
mov rax,[rcx].EFI_SYSTEM_TABLE.ConOut
mov pConsole,rax
invoke [rax].ConOut.OutputString, pConsole, L"Hello Smarter UEFI World!\r\n"
mov rax, pConsole
invoke [rax].ConOut.SetAttribute, pConsole, 017h
; Or if you have a list of calls to make against the same protocol/interface
ASSUME rcx:PTR ConOut
mov rcx,pConsole
invoke [rcx].OutputString, pConsole, ADDR HelloMsg
ASSUME rcx:NOTHING
;-----------------------------------
; Here !!!!!!!
;-----------------------------------
mov rax, pConsole ;Colors change
invoke [rax].ConOut.SetAttribute, pConsole, 05Fh
New Triangle ;Create an new instance of Triangle
mov pShape_1, xax ;Store instance pointer
OCall pShape_1::Triangle.Init, 10, 15 ;Initialize Triangle
OCall pShape_1::Shape.GetArea ;Invoke GetArea method of Triangle
invoke PrintHexDWORD, eax ;Result = 75
mov rcx,pConsole
invoke [rcx].ConOut.OutputString, pConsole, L"\r\n"
New Rectangle ;Create an new instance of Rectangle
mov pShape_2, xax ;Store instance pointer
OCall pShape_2::Rectangle.Init, 10, 15 ;Initialize Rectangle
OCall pShape_2::Shape.GetArea ;Invoke GetArea method of Rectangle
invoke PrintHexDWORD, eax ;Result = 150
mov rcx,pConsole
invoke [rcx].ConOut.OutputString, pConsole, L"\r\n"
OCall pShape_2::Rectangle.GetPerimeter ;Invoke GetPerimeter method
invoke PrintHexDWORD, eax ;Result = 50
mov rcx,pConsole
invoke [rcx].ConOut.OutputString, pConsole, L"\r\n"
Destroy pShape_2 ;Invoke Rectangle's Done and disposes it
Destroy pShape_1 ;Invoke Triangle's Done and disposes it
mov rax, pConsole ;Colors change
invoke [rax].ConOut.SetAttribute, pConsole, 07h
loop1:
jmp loop1
mov rax, pBootServices
invoke [rax].EFI_BOOT_SERVICES.Exit, Handle, EFI_SUCCESS, 10, L"Complete\r\n"
ret
Main ENDP
END Main Now I fully understand what you meant here http://masm32.com/board/index.php?topic=7942.msg109335#msg109335 (http://masm32.com/board/index.php?topic=7942.msg109335#msg109335)That is the idea. With UEFI you can boot from an almost regular X64 file of any size. UEFI is more like a micro OS than Bios, but perhaps will requiere to build some functions, I don't know yet.
I now need to install and run whatever is needed until I can build the binary.There is an additional UASM package in UASM EFI/UEFI Library v1.1 (http://www.terraspace.co.uk/uasm.html#p15) with explanations.
Maybe I need help from you...I will try :biggrin:
| include macrolib.inc include efiOA.inc include efiGUID.inc externdef pConsole:PCONOUT externdef pBootServices:P_BOOT_SERVICES % include @Environ(OBJASM_PATH)\Code\Macros\Model.inc ;Include & initialize standard modules SysSetup OOP, WIDE_STRING, EFI64;, DEBUG(CON) ;Load OOP files and basic OS support .data Handle EFI_HANDLE 0 SystemTablePtr dq 0 HelloMsg dw 'H','e','l','l','o',' ','U','E','F','I',' ','W','o','r','l','d','!',13,10,0 ;HelloMsg dw 'Hello UEFI World!',13,10,0 pConsole PCONOUT 0 pConsoleIn PCONIN 0 pBootServices P_BOOT_SERVICES 0 pRuntimeServices P_RUNTIME_SERVICES 0 mapSize UINTN 512*SIZEOF(EFI_MEMORY_DESCRIPTOR) descriptors EFI_MEMORY_DESCRIPTOR 512 DUP (<?>) mapKey UINTN 0 descSize UINTN 0 descVer UINT32 0 include efiUtil.inc |
\masm32\bin64\uasm64\uasm64 -c -win64 -nomlib -Zp8 DarylUEFI.asm
link /dll /IGNORE:4086 DarylUEFI.obj %OBJASM_PATH%\Code\Lib\64\ObjAsm\ObjMemEFI.lib
\UEFI\EFI_Toolkit_2.0\build\tools\bin\fwimage app DarylUEFI.dll DarylUEFI.EFI
copy DarylUEFI.EFI e:\EFI\BOOT\BOOTX64.EFI
copy DarylUEFI.EFI e:\App1.EFI
This means that the USB stick is not recognized as a boot device. Did you do anything special about this?
The trick for me was to use the Virtual Machine USB Boot program
mov tcb.ProcNum, 2
Virtual Machine USB Boot V1.72 is from April 2018 and works perfectly with the latest VirtualBox version 6.1.
The reason I chose it is that creating the USB.vmdk didn't work for me. The VM didn't recognize a file system and what's worse, you have to detach and recreate the USB.vmdk file every time you boot your computer. The reason is that internally some UUIDs change during boot process and the previous file becomes unusable.
Maybe QEMU works differently, but I didn't have time to check it.