fb: Change reactions of protocols to high fb sizes
diff --git a/common/drivers/gop.c b/common/drivers/gop.c
index c4f36cf5..0fbd0984 100644
--- a/common/drivers/gop.c
+++ b/common/drivers/gop.c
@@ -34,6 +34,8 @@ static void linear_mask_to_mask_shift(
// Most of this code taken from https://wiki.osdev.org/GOP
+bool gop_force_16 = false;
+
static bool try_mode(struct fb_info *ret, size_t mode, uint64_t width, uint64_t height, int bpp) {
EFI_STATUS status;
@@ -96,6 +98,14 @@ static bool try_mode(struct fb_info *ret, size_t mode, uint64_t width, uint64_t
return false;
}
+ if (gop_force_16) {
+ if (mode_info->HorizontalResolution >= 65536
+ || mode_info->VerticalResolution >= 65536
+ || mode_info->PixelsPerScanLine * (ret->framebuffer_bpp / 8) >= 65536) {
+ return false;
+ }
+ }
+
printv("gop: Found matching mode %x, attempting to set...\n", mode);
if ((int)mode == current_video_mode) {
@@ -191,8 +201,10 @@ bool init_gop(struct fb_info *ret,
retry:
for (size_t i = 0; i < modes_count; i++) {
- if (try_mode(ret, i, target_width, target_height, target_bpp))
+ if (try_mode(ret, i, target_width, target_height, target_bpp)) {
+ gop_force_16 = false;
return true;
+ }
}
fallback:
@@ -220,8 +232,10 @@ fallback:
if (current_fallback == 1) {
current_fallback++;
- if (try_mode(ret, preset_mode, 0, 0, 0))
+ if (try_mode(ret, preset_mode, 0, 0, 0)) {
+ gop_force_16 = false;
return true;
+ }
}
if (current_fallback < SIZEOF_ARRAY(fallback_resolutions)) {
@@ -233,6 +247,7 @@ fallback:
goto retry;
}
+ gop_force_16 = false;
return false;
}
diff --git a/common/drivers/gop.h b/common/drivers/gop.h
index 4d31917e..147b5dfa 100644
--- a/common/drivers/gop.h
+++ b/common/drivers/gop.h
@@ -11,6 +11,8 @@
bool init_gop(struct fb_info *ret,
uint64_t target_width, uint64_t target_height, uint16_t target_bpp);
+extern bool gop_force_16;
+
#endif
#endif
diff --git a/common/protos/limine.c b/common/protos/limine.c
index 160f481c..b66d614c 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -123,6 +123,11 @@ static void term_write_shim(uint64_t context, uint64_t buf, uint64_t count) {
term_write(buf, count);
}
+static noreturn void fb_too_big(void) {
+ panic(true, "limine: Framebuffer is too large for the legacy terminal/framebuffer requests to handle.\n"
+ " Please update kernel to the new requests, or file a bug report to the upstream kernel if necessary.");
+}
+
bool limine_load(char *config, char *cmdline) {
uint32_t eax, ebx, ecx, edx;
@@ -559,6 +564,11 @@ FEAT_START
fb = fbinfo;
+ if (fb.framebuffer_width >= 65536 || fb.framebuffer_height >= 65536
+ || fb.framebuffer_pitch >= 65536) {
+ fb_too_big();
+ }
+
if (terminal_request->callback != 0) {
#if defined (__i386__)
term_callback = stivale2_term_callback;
@@ -651,6 +661,8 @@ FEAT_START
framebuffer_response->framebuffers = reported_addr(fb_list);
framebuffer_request->response = reported_addr(framebuffer_response);
+
+ goto no_legacy_fb;
FEAT_END
// Framebuffer feature (legacy)
@@ -667,6 +679,11 @@ FEAT_START
break; // next feature
}
+ if (fb.framebuffer_width >= 65536 || fb.framebuffer_height >= 65536
+ || fb.framebuffer_pitch >= 65536) {
+ fb_too_big();
+ }
+
struct limine_framebuffer_legacy_response *framebuffer_response =
ext_mem_alloc(sizeof(struct limine_framebuffer_legacy_response));
@@ -698,6 +715,7 @@ FEAT_START
framebuffer_request->response = reported_addr(framebuffer_response);
FEAT_END
+no_legacy_fb:;
// Boot time feature
FEAT_START
struct limine_boot_time_request *boot_time_request = get_request(LIMINE_BOOT_TIME_REQUEST);
diff --git a/common/protos/linux.c b/common/protos/linux.c
index 9c962f8d..195a7640 100644
--- a/common/protos/linux.c
+++ b/common/protos/linux.c
@@ -16,6 +16,7 @@
#include <lib/acpi.h>
#include <drivers/edid.h>
#include <drivers/vga_textmode.h>
+#include <drivers/gop.h>
noreturn void linux_spinup(void *entry, void *boot_params);
@@ -513,6 +514,9 @@ bool linux_load(char *config, char *cmdline) {
parse_resolution(&req_width, &req_height, &req_bpp, resolution);
struct fb_info fbinfo;
+#if uefi == 1
+ gop_force_16 = true;
+#endif
if (!fb_init(&fbinfo, req_width, req_height, req_bpp)) {
#if uefi == 1
panic(true, "linux: Unable to set video mode");
diff --git a/common/protos/stivale.c b/common/protos/stivale.c
index 5ffdfa52..8ac7bf05 100644
--- a/common/protos/stivale.c
+++ b/common/protos/stivale.c
@@ -24,6 +24,7 @@
#include <mm/pmm.h>
#include <stivale.h>
#include <drivers/vga_textmode.h>
+#include <drivers/gop.h>
#define REPORTED_ADDR(PTR) \
((PTR) + ((stivale_hdr.flags & (1 << 3)) ? \
@@ -309,6 +310,9 @@ bool stivale_load(char *config, char *cmdline) {
parse_resolution(&req_width, &req_height, &req_bpp, resolution);
struct fb_info fbinfo;
+#if uefi == 1
+ gop_force_16 = true;
+#endif
if (!fb_init(&fbinfo, req_width, req_height, req_bpp))
panic(true, "stivale: Unable to set video mode");
diff --git a/common/protos/stivale2.c b/common/protos/stivale2.c
index 8080ebf3..0024ff97 100644
--- a/common/protos/stivale2.c
+++ b/common/protos/stivale2.c
@@ -27,6 +27,7 @@
#include <pxe/tftp.h>
#include <drivers/edid.h>
#include <drivers/vga_textmode.h>
+#include <drivers/gop.h>
#include <lib/rand.h>
#define REPORTED_ADDR(PTR) \
@@ -538,6 +539,9 @@ failed_to_load_header_section:
term_textmode();
textmode = true;
} else {
+#if uefi == 1
+ gop_force_16 = true;
+#endif
term_vbe(req_width, req_height);
if (current_video_mode < 0) {
@@ -606,6 +610,9 @@ failed_to_load_header_section:
if (hdrtag != NULL || (avtag != NULL && uefi) || (avtag != NULL && preference == 0)) {
term_deinit();
+#if uefi == 1
+ gop_force_16 = true;
+#endif
if (fb_init(fb, req_width, req_height, req_bpp)) {
have_fb_tag:;
struct stivale2_struct_tag_framebuffer *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_framebuffer));
