From 31f06ea7c899c7b016fb1d20d9fcede9def7b63f Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Wed, 13 Apr 2022 14:30:52 +0100 Subject: [PATCH] Add a framebuffer test when EFI debug is enabled. --- boot/efisetup.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/boot/efisetup.c b/boot/efisetup.c index 3e52eef..6effe8a 100644 --- a/boot/efisetup.c +++ b/boot/efisetup.c @@ -124,6 +124,48 @@ static void wait_for_key(void) while (efi_call_proto(efi_table_attr(sys_table, con_in), read_key_stroke, &input_key) == EFI_NOT_READY) {} } + +static void test_frame_buffer(screen_info_t *si) +{ + uint32_t r_value = 0xffffffff >> (32 - si->red_size); + uint32_t g_value = 0; + uint32_t b_value = 0; + + int pixel_size = (si->lfb_depth / 8); + + union { + uint8_t byte[4]; + uint32_t word; + } pixel_value; + + pixel_value.word = (r_value << si->red_pos) | (g_value << si->green_pos) | (b_value << si->blue_pos); + + uintptr_t lfb_base = si->lfb_base; +#ifdef __x86_64__ + if (LFB_CAPABILITY_64BIT_BASE & si->capabilities) { + lfb_base |= (uintptr_t)si->ext_lfb_base << 32; + } +#endif + + uint8_t *lfb_row = (uint8_t *)lfb_base; + for (int y = 0; y < 8; y++) { + for (int x = 0; x < si->lfb_width; x++) { + for (int b = 0; b < pixel_size; b++) { + lfb_row[x * pixel_size + b] = pixel_value.byte[b]; + } + } + lfb_row += si->lfb_linelength; + } + lfb_row += (si->lfb_height - 16) * si->lfb_linelength; + for (int y = 0; y < 8; y++) { + for (int x = 0; x < si->lfb_width; x++) { + for (int b = 0; b < pixel_size; b++) { + lfb_row[x * pixel_size + b] = pixel_value.byte[b]; + } + } + lfb_row += si->lfb_linelength; + } +} #endif static efi_memory_desc_t *get_memory_desc(uintptr_t map_addr, size_t desc_size, size_t n) @@ -449,6 +491,12 @@ static efi_status_t set_screen_info_from_gop(screen_info_t *si, efi_handle_t *ha return status; } +#if DEBUG + test_frame_buffer(si); + print_string("Press any key to continue...\n"); + wait_for_key(); +#endif + return EFI_SUCCESS; }