News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Uefi EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL

Started by HSE, May 23, 2022, 11:12:00 PM

Previous topic - Next topic

HSE

Hi all!

To test bitRAKE's WaitKey proc (2_event in https://github.com/bitRAKE/UEFI_playground) must be added this protocol.
 



EFI_KEY_STATE struct
KeyShiftState dd ?
KeyToggleState db ? ; EFI_KEY_TOGGLE_STATE
EFI_KEY_STATE ends
P_EFI_KEY_STATE TYPEDEF PTR EFI_KEY_STATE

EFI_KEY_DATA struct
Key   EFI_INPUT_KEY {?}
KeyState  EFI_KEY_STATE {?}
EFI_KEY_DATA ends
P_EFI_KEY_DATA TYPEDEF PTR EFI_KEY_DATA

EFI_KEY_TOGGLE_STATE TYPEDEF UINT8
P_EFI_KEY_TOGGLE_STATE TYPEDEF PTR EFI_KEY_TOGGLE_STATE

; dword KeyShiftState:
EFI_SHIFT_STATE_VALID equ 0x80000000
EFI_RIGHT_SHIFT_PRESSED equ 0x00000001
EFI_LEFT_SHIFT_PRESSED equ 0x00000002
EFI_RIGHT_CONTROL_PRESSED equ 0x00000004
EFI_LEFT_CONTROL_PRESSED equ 0x00000008
EFI_RIGHT_ALT_PRESSED equ 0x00000010
EFI_LEFT_ALT_PRESSED equ 0x00000020
EFI_RIGHT_LOGO_PRESSED equ 0x00000040
EFI_LEFT_LOGO_PRESSED equ 0x00000080
EFI_MENU_KEY_PRESSED equ 0x00000100
EFI_SYS_REQ_PRESSED    equ 0x00000200

; byte EFI_KEY_TOGGLE_STATE:
EFI_SCROLL_LOCK_ACTIVE     equ 0x01
EFI_NUM_LOCK_ACTIVE         equ 0x02
EFI_CAPS_LOCK_ACTIVE     equ 0x04
EFI_KEY_STATE_EXPOSED     equ 0x40
EFI_TOGGLE_STATE_VALID     equ 0x80


;-------------------------------------
;   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
;-------------------------------------

P_EFI_KEY_NOTIFY_FUNCTION TYPEDEF POINTER            ;PTR EFI_KEY_NOTIFY_FUNCTION

RAWINTERFACE ConInEx
STDFUNC Reset, <voidarg>, pThis:PTR ConInEx, ExtendedVerification:BOOLEAN
STDFUNC ReadKeyStrokeEx, <voidarg>, pThis:PTR ConInEx, KeyData: P_EFI_KEY_DATA
WaitForKeyEx EFI_EVENT ?
STDFUNC SetState, <voidarg>, pThis:PTR ConInEx, KeyToggleState: P_EFI_KEY_TOGGLE_STATE
STDFUNC RegisterKeyNotify, <voidarg>, pThis:PTR ConInEx, KeyData : P_EFI_KEY_DATA, KeyNotificationFunction: P_EFI_KEY_NOTIFY_FUNCTION
STDFUNC UnregisterKeyNotify , <voidarg>, pThis:PTR ConInEx, NotificationHandle: P_EFI_KEY_NOTIFY_FUNCTION
ENDRAWINTERFACE
PCONINEX TYPEDEF PTR ConInEx

.data
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID EFI_GUID <0xDD9E7534, 0x7762, 0x4698, {0x8C, 0x14, 0xF5, 0x85, 0x17, 0xA6, 0x25, 0xAA}>



include efiOA.inc
include efiGUID.inc
externdef pConsole:PCONOUT
externdef pBootServices:P_BOOT_SERVICES

.data
    ConInExProto qword 0   
    Handle           EFI_HANDLE 0
    SystemTablePtr   dq 0
    pConsole         PCONOUT 0
    pConsoleIn       PCONIN  0
    pBootServices    P_BOOT_SERVICES 0
    pRuntimeServices P_RUNTIME_SERVICES 0

.code

align ALIGN_CODE

WaitKey proc FRAME
   
local eindex : QWORD

       UseConsole "Waiting for a key....."

; rather than spin on key read, use event system to wait for key event:
        mov r11, pConsoleIn
mov r10, pBootServices
        invoke [r10].EFI_BOOT_SERVICES.WaitForEvent, 1, addr [r11].ConInEx.WaitForKeyEx, addr eindex
test rax,rax
jz @F ; EFI_SUCCESS, key event happened

ret

    @@:                       ; remove the key
mov rcx, pConsoleIn
invoke [rcx].ConInEx.Reset, rcx, FALSE
        ret
WaitKey endp


Main PROC FRAME imageHandle:EFI_HANDLE, SystemTable:PTR_EFI_SYSTEM_TABLE

                                                            ;Runtime model initialization
    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

    mov rcx,SystemTablePtr
    mov rax,[rcx].EFI_SYSTEM_TABLE.ConIn
    mov pConsoleIn,rax
    mov rax,[rcx].EFI_SYSTEM_TABLE.ConOut
    mov pConsole, rax
   
    mov rax, pBootServices
    invoke [rax].EFI_BOOT_SERVICES.LocateProtocol, ADDR EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, NULL, ADDR ConInExProto

    call WaitKey           

    CStr complete, "Complete",13,10
    mov rax, pBootServices
    invoke [rax].EFI_BOOT_SERVICES.Exit, Handle, EFI_SUCCESS, 10, addr complete

Main endp


Regards, HSE.
Equations in Assembly: SmplMath

johnsa

Would you like to modify the uefi inc file shipped with UASM and I'll update it for the next release?

HSE

#2
Quote from: johnsa on May 25, 2022, 06:22:50 PM
the uefi inc file shipped with UASM

:biggrin: I think it's not shipped with UASM.

Anyway, I'm using a different setup. I splitted in GUID and efi because I'm also making a library.

A new repository https://github.com/ASMHSE/ObjAsm-C.1uefi will show (I hope  :biggrin:) how I making things until Biterider have time to see a better way to integrate to ObjAsm (If he want). 
Equations in Assembly: SmplMath

Biterider


HSE

Equations in Assembly: SmplMath