Untitled

 avatar
unknown
plain_text
3 years ago
1.2 kB
5
Indexable
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>

#define MESSAGE_BUFFER_SIZE  256

typedef struct {
  CHAR8 Message[MESSAGE_BUFFER_SIZE];
  UINTN MessageLength;
} MESSAGE_BUFFER;

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS Status;
  MESSAGE_BUFFER *MessageBuffer;
  UINTN MemorySize;
  CHAR8 MemoryAddressString[32];

  // Allocate memory for the message buffer
  MemorySize = sizeof(MESSAGE_BUFFER);
  MessageBuffer = NULL;
  Status = gBS->AllocatePool (EfiRuntimeServicesData, MemorySize, (VOID**)&MessageBuffer);
  if (EFI_ERROR (Status)) {
    return Status;
  }

  // Write a message to the buffer
  AsciiStrCpy (MessageBuffer->Message, "Hello, Operating System!");
  MessageBuffer->MessageLength = AsciiStrLen (MessageBuffer->Message);

  // Print the address of the message buffer to the screen
  AsciiSPrint (MemoryAddressString, sizeof(MemoryAddressString), "%llu", (UINT64)(UINTN)MessageBuffer);
  Print (L"Address of the message buffer: %a\n", MemoryAddressString);

  return EFI_SUCCESS;
}
Editor is loading...