From 65b629e74ad57554e9195d3da5541e654e77e9e6 Mon Sep 17 00:00:00 2001
From: pjht <terppa05@gmail.com>
Date: Sat, 9 Feb 2019 14:33:29 -0600
Subject: [PATCH] Read framebuffer info from GRUB

---
 kernel/kernel.c          | 15 ++++++++++++++-
 libc/grub/text_fb_info.h | 12 ++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 libc/grub/text_fb_info.h

diff --git a/kernel/kernel.c b/kernel/kernel.c
index da92200..6c122e8 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,5 +1,18 @@
 #include "../cpu/cpu_init.h"
+#include <grub/text_fb_info.h>
+#include <stdlib.h>
+#include "multiboot.h"
 
-void kmain() {
+void kmain(multiboot_info_t* header) {
   cpu_init();
+  text_fb_info info;
+  if (header->flags&MULTIBOOT_INFO_FRAMEBUFFER_INFO&&header->framebuffer_type==2) {
+    info.address=(char*)((header->framebuffer_addr&0xFFFFFFFF)+0xC0000000);
+    info.width=header->framebuffer_width;
+    info.height=header->framebuffer_height;
+  } else {
+    info.address=(char*)0xC00B8000;
+    info.width=80;
+    info.height=25;
+  }
 }
diff --git a/libc/grub/text_fb_info.h b/libc/grub/text_fb_info.h
new file mode 100644
index 0000000..7ed0e84
--- /dev/null
+++ b/libc/grub/text_fb_info.h
@@ -0,0 +1,12 @@
+#ifndef GRUB_TEXT_FB_INFO_H
+#define GRUB_TEXT_FB_INFO_H
+
+#include <stdint.h>
+
+typedef struct {
+  char* address;
+  uint32_t width;
+  uint32_t height;
+} text_fb_info;
+
+#endif