More examples
parent
430c3baf70
commit
45d41bc1ca
@ -0,0 +1,4 @@
|
||||
TARGET = png.efi
|
||||
|
||||
#USE_GCC=1
|
||||
include uefi/Makefile
|
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,80 @@
|
||||
#include <uefi.h>
|
||||
|
||||
/* public domain image loader - http://nothings.org/stb_image.h */
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
/**
|
||||
* Display PNG image
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
efi_status_t status;
|
||||
efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||
efi_gop_t *gop = NULL;
|
||||
efi_gop_mode_info_t *info = NULL;
|
||||
uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
|
||||
FILE *f;
|
||||
unsigned char *buff;
|
||||
uint32_t *data;
|
||||
int w, h, l;
|
||||
long int size;
|
||||
stbi__context s;
|
||||
stbi__result_info ri;
|
||||
|
||||
/* load image */
|
||||
if((f = fopen("\\0C_png\\image.png", "r"))) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buff = (unsigned char*)malloc(size);
|
||||
if(!buff) {
|
||||
fprintf(stderr, "unable to allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
fread(buff, size, 1, f);
|
||||
fclose(f);
|
||||
ri.bits_per_channel = 8;
|
||||
s.read_from_callbacks = 0;
|
||||
s.img_buffer = s.img_buffer_original = buff;
|
||||
s.img_buffer_end = s.img_buffer_original_end = buff + size;
|
||||
data = (uint32_t*)stbi__png_load(&s, &w, &h, &l, 0, &ri);
|
||||
if(!data) {
|
||||
fprintf(stderr, "Unable to decode png: %s\n", stbi__g_failure_reason);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Unable to load image\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set video mode */
|
||||
status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
|
||||
if(!EFI_ERROR(status) && gop) {
|
||||
status = gop->SetMode(gop, 0);
|
||||
ST->ConOut->Reset(ST->ConOut, 0);
|
||||
ST->StdErr->Reset(ST->StdErr, 0);
|
||||
if(EFI_ERROR(status)) {
|
||||
fprintf(stderr, "unable to set video mode\n");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "unable to get graphics output protocol\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* display image */
|
||||
if(gop->Mode->Information->PixelFormat == PixelBlueGreenRedReserved8BitPerColor ||
|
||||
(gop->Mode->Information->PixelFormat == PixelBitMask && gop->Mode->Information->PixelInformation.BlueMask != 0xff0000)) {
|
||||
/* png is RGBA, but UEFI needs BGRA */
|
||||
for(l = 0; l < w * h; l++)
|
||||
data[l] = ((data[l] & 0xff) << 16) | (data[l] & 0xff00) | ((data[l] >> 16) & 0xff);
|
||||
}
|
||||
gop->Blt(gop, data, EfiBltBufferToVideo, 0, 0, (gop->Mode->Information->HorizontalResolution - w) / 2,
|
||||
(gop->Mode->Information->VerticalResolution - h) / 2, w, h, 0);
|
||||
|
||||
/* free resources exit */
|
||||
free(data);
|
||||
free(buff);
|
||||
return 0;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
../../uefi
|
@ -0,0 +1,4 @@
|
||||
TARGET = memmap.efi
|
||||
|
||||
#USE_GCC=1
|
||||
include uefi/Makefile
|
@ -0,0 +1,53 @@
|
||||
#include <uefi.h>
|
||||
|
||||
/**
|
||||
* List memory map
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
efi_status_t status;
|
||||
efi_memory_descriptor_t *memory_map = NULL, *mement;
|
||||
uintn_t memory_map_size=0, map_key=0, desc_size=0, i;
|
||||
const char *types[] = {
|
||||
"EfiReservedMemoryType",
|
||||
"EfiLoaderCode",
|
||||
"EfiLoaderData",
|
||||
"EfiBootServicesCode",
|
||||
"EfiBootServicesData",
|
||||
"EfiRuntimeServicesCode",
|
||||
"EfiRuntimeServicesData",
|
||||
"EfiConventionalMemory",
|
||||
"EfiUnusableMemory",
|
||||
"EfiACPIReclaimMemory",
|
||||
"EfiACPIMemoryNVS",
|
||||
"EfiMemoryMappedIO",
|
||||
"EfiMemoryMappedIOPortSpace",
|
||||
"EfiPalCode"
|
||||
};
|
||||
|
||||
/* get the memory map */
|
||||
status = BS->GetMemoryMap(&memory_map_size, NULL, &map_key, &desc_size, NULL);
|
||||
if(status != EFI_BUFFER_TOO_SMALL || !memory_map_size) goto err;
|
||||
memory_map_size += 2 * desc_size;
|
||||
memory_map = (efi_memory_descriptor_t*)malloc(memory_map_size);
|
||||
if(!memory_map) {
|
||||
fprintf(stderr, "unable to allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
status = BS->GetMemoryMap(&memory_map_size, memory_map, &map_key, &desc_size, NULL);
|
||||
if(EFI_ERROR(status)) {
|
||||
err: fprintf(stderr, "Unable to get memory map\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Address Size Type\n");
|
||||
for(mement = memory_map; (uint8_t*)mement < (uint8_t*)memory_map + memory_map_size;
|
||||
mement = NextMemoryDescriptor(mement, desc_size)) {
|
||||
printf("%016x %8d %02x %s\n", mement->PhysicalStart, mement->NumberOfPages, mement->Type, types[mement->Type]);
|
||||
}
|
||||
|
||||
free(memory_map);
|
||||
return 0;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
@ -0,0 +1 @@
|
||||
../../uefi
|
Loading…
Reference in New Issue