News:

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

Main Menu

UEFI Graphic Console

Started by HSE, September 11, 2022, 02:15:59 AM

Previous topic - Next topic

HSE

Hi all!

A UEFI application can use a Text Mode Console to show messages, but that is a Boot Service.

Boot Services are a system of programs that are using the processor. To take control you have to stop Boot Services, but then you can't see nothing because text console has gone  :biggrin:

You need others mean to see messages, and could be interesting to have a console, I thinked a graphical one.

That can be maked easily but...

So far we used EfiBootServicesData memory type, but apparently this kind of memory is marked free when exit Boot Services, and can be overwrited after that.

Then MemAlloc requiere memory type:
Code (MemAlloc_X_UEFI.inc) Select

; Procedure:  MemAlloc_UEFI
; Purpose:    Allocate a memory block.
; Arguments:  Arg1: Memory block attributes [0, MEM_INIT_ZERO].
;             Arg2: Memory block size in BYTEs.
;             Arg3: Memory type   
; Return:     xax -> Memory block or NULL if failed.

align ALIGN_CODE
MemAlloc_UEFI proc uses xbx dAttr:DWORD, dMemSize:DWORD, dType:DWORD
  local pMemBlock:POINTER
 
  mov xbx, pBootServices
  invoke [xbx].EFI_BOOT_SERVICES.AllocatePool, dType, dMemSize, addr pMemBlock
  .ifBitSet xax, EFI_ERROR
    xor eax, eax
  .else
    .ifBitSet dAttr, MEM_INIT_ZERO
      invoke MemZero, pMemBlock, dMemSize
    .endif
    mov xax, pMemBlock
  .endif
  ret
MemAlloc_UEFI endp

and
Code (Memory.inc) Select
MemAlloc macro MemSize:req, Flags:=<MEM_DEFAULT>
  if TARGET_PLATFORM eq PLATFORM_WINDOWS
    $$MemAttr = MEM_DEFAULT
    if (Flags and MEM_INIT_ZERO)
      $$MemAttr = $$MemAttr or HEAP_ZERO_MEMORY
    endif
    if (Flags and MEM_GENERATE_EXEPTION)
      $$MemAttr = $$MemAttr or HEAP_GENERATE_EXCEPTIONS
    endif
    if (Flags and MEM_NO_SERIALIZE)
      $$MemAttr = $$MemAttr or HEAP_NO_SERIALIZE
    endif
    invoke HeapAlloc, hProcessHeap, $$MemAttr, MemSize
  elseif TARGET_PLATFORM eq PLATFORM_UEFI
    ifndef PLATFORM_UEFI_MEMORY 
        PLATFORM_UEFI_MEMORY = EFI_MEMORY_TYPE_EfiBootServicesData
    endif
    invoke MemAlloc_UEFI, Flags, MemSize, PLATFORM_UEFI_MEMORY
  endif
  if DEBUGGING
    .if xax == NULL
      DbgWarning "MemAlloc failed"
    .endif
  endif
endm


then in the example:    PLATFORM_UEFI_MEMORY = EFI_MEMORY_TYPE_EfiLoaderData
    New ConsoleUEFI
    mov pGraphicConsole, xax
    PLATFORM_UEFI_MEMORY = EFI_MEMORY_TYPE_EfiBootServicesData       



This Graphic Console can be used in a dedicated system using all machine resources, or a UEFI loader can send it to an OS kernel.

In the example, after you press a key, application stop Boot Services, but Graphic Console continue showing messages.

Regards, HSE.

 
Equations in Assembly: SmplMath

Biterider

Hi HSE
Very good stuff!  :biggrin:
I added the new code and also updated the ObjMem.inc and ObjMem.api files.
A question about the following lines in the MemAlloc macro (Memory.inc)

      ifndef PLATFORM_UEFI_MEMORY
        PLATFORM_UEFI_MEMORY = EFI_MEMORY_TYPE_EfiBootServicesData
      endif

How can PLATFORM_UEFI_MEMORY be undefined?

Biterider

HSE

Hi Biterider!

Quote from: Biterider on September 11, 2022, 03:34:47 PM
How can PLATFORM_UEFI_MEMORY be undefined?

PLATFORM_UEFI_MEMORY always must be defined.

The idea is redefine like default after allocate a persistent object.

I'm not sure how these different types of memories work. Perhaps there is no problem using always in a loader or dedicated system EFI_MEMORY_TYPE_EfiLoaderData if you free pieces of memory that don't have to persist. Perhaps memory could be next toy  :biggrin:

HSE
Equations in Assembly: SmplMath

Biterider

Hi HSE
Today I finished something I've been working on intensely and totally absorbed me.
I have now tried your "UEFI graphics console" project.
I had to update and configure the required additional software, which by the way was an old pending, and everything worked right out of the box.  :thumbsup:
It was really impressive what was going on under the hood, especially the psf font rendering at this basic interface level. I've also seen a lot of graphics routines, which tells me you prepare more stuff like this.  :thup:

Keep it up, it's a really good work.  :biggrin:

Biterider

HSE

Hi Biterider!

This console is just a descendent of same UEFI Pixel and UEFI Chars used in the UEFI Plot.   :biggrin:

HSE
Equations in Assembly: SmplMath