:: commit b8fff872defdf16127ecac9aaa536231540f2986

mintsuki <mintsuki@protonmail.com> — 2023-08-04 12:56

parents: 820d4751d3

test: Use Flanterm

diff --git a/test/.gitignore b/test/.gitignore
index 4ce83ce5..7db6f164 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,2 +1,3 @@
 test.o
 test.elf
+flanterm
diff --git a/test/GNUmakefile b/test/GNUmakefile
index 53c9b448..3fd3b44a 100644
--- a/test/GNUmakefile
+++ b/test/GNUmakefile
@@ -45,7 +45,8 @@ override INTERNALCFLAGS  :=       \
 	-mgeneral-regs-only  \
 	-mno-red-zone        \
 	-I.                  \
-	-I..
+	-I..                 \
+    -D_LIMINE_PROTO
 
 ifneq ($(findstring riscv,$(CC_FOR_TARGET)),)
 override INTERNALCFLAGS += -march=rv64imac -mabi=lp64 -mno-relax
@@ -74,7 +75,11 @@ else
 all: test.elf
 endif
 
-test.elf: limine.o e9print.o memory.o
+flanterm:
+	mkdir -p flanterm
+	cp -rv ../common/flanterm/* ./flanterm/
+
+test.elf: limine.o e9print.o memory.o flanterm/flanterm.o flanterm/backends/fb.o
 	$(LD) $^ $(LDFLAGS) $(INTERNALLDFLAGS) -o $@
 
 multiboot2.elf: multiboot2_trampoline.o
@@ -87,7 +92,7 @@ multiboot.elf: multiboot_trampoline.o
 	$(CC) $(CFLAGS) $(INTERNALCFLAGS_MB) -c e9print.c -o e9print.o
 	$(LD) $^ multiboot.o e9print.o $(LDFLAGS) $(INTERNAL_LD_FLAGS_MULTIBOOT1) -m elf_i386 -o $@
 
-%.o: %.c
+%.o: %.c flanterm
 	$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
 
 %.o: %.asm
@@ -97,3 +102,4 @@ clean:
 	rm -rf test.elf limine.o e9print.o memory.o
 	rm -rf multiboot2.o multiboot2.elf multiboot2_trampoline.o
 	rm -rf multiboot.o multiboot_trampoline.o multiboot.elf
+	rm -rf flanterm
diff --git a/test/e9print.c b/test/e9print.c
index f26a991e..a969d4e0 100644
--- a/test/e9print.c
+++ b/test/e9print.c
@@ -2,12 +2,22 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#if defined (_LIMINE_PROTO)
+#include <flanterm/flanterm.h>
+extern struct flanterm_context *ft_ctx;
+#endif
+
 static const char CONVERSION_TABLE[] = "0123456789abcdef";
 
 void e9_putc(char c) {
 #if defined (__x86_64__) || defined (__i386__)
     __asm__ __volatile__ ("outb %0, %1" :: "a" (c), "Nd" (0xe9) : "memory");
 #endif
+#if defined (_LIMINE_PROTO)
+    if (ft_ctx != NULL) {
+        flanterm_write(ft_ctx, &c, 1);
+    }
+#endif
 }
 
 void e9_print(const char *msg) {
diff --git a/test/limine.c b/test/limine.c
index cc98aa96..3a74fbcf 100644
--- a/test/limine.c
+++ b/test/limine.c
@@ -2,6 +2,8 @@
 #include <stddef.h>
 #include <limine.h>
 #include <e9print.h>
+#include <flanterm/flanterm.h>
+#include <flanterm/backends/fb.h>
 
 static void limine_main(void);
 
@@ -232,9 +234,20 @@ void ap_entry(struct limine_smp_info *info) {
 
 extern char kernel_start[];
 
+struct flanterm_context *ft_ctx = NULL;
+
 void limine_main(void) {
     e9_printf("\nWe're alive");
 
+    struct limine_framebuffer *fb = framebuffer_request.response->framebuffers[0];
+
+    ft_ctx = flanterm_fb_simple_init(
+        fb->address,
+        fb->width,
+        fb->height,
+        fb->pitch
+    );
+
     uint64_t kernel_slide = (uint64_t)kernel_start - 0xffffffff80000000;
 
     e9_printf("Kernel slide: %x", kernel_slide);
tab: 248 wrap: offon