aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorEmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com>2024-05-07 11:07:03 -0400
committerEmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com>2024-05-07 11:07:03 -0400
commitabaab98bd757cd0818cfcddc983eee25ab7672ed (patch)
tree4e5d407cf55877b38699ac12b904be2dc3d99864 /kernel
parent47d94ed4fd724d0e8b7819e7e3d0783c798ea190 (diff)
Made framebuffer class, serial write functions, and finally got makefile to build without having to make clean
Diffstat (limited to 'kernel')
-rw-r--r--kernel/arch/x86_64/limine.cpp8
-rw-r--r--kernel/arch/x86_64/serial.cpp23
-rw-r--r--kernel/framebuffer.cpp22
-rw-r--r--kernel/include/arch/x86_64/serial.h19
-rw-r--r--kernel/include/framebuffer.h18
-rw-r--r--kernel/makefile19
6 files changed, 101 insertions, 8 deletions
diff --git a/kernel/arch/x86_64/limine.cpp b/kernel/arch/x86_64/limine.cpp
index 8c67c52..9ea2bbc 100644
--- a/kernel/arch/x86_64/limine.cpp
+++ b/kernel/arch/x86_64/limine.cpp
@@ -1,6 +1,9 @@
#include <stdint.h>
#include <stddef.h>
+#include <stdio.h>
+#include <arch/x86_64/serial.h>
#include "limine.h"
+#include <framebuffer.h>
namespace {
__attribute__((used, section(".requests")))
@@ -63,7 +66,12 @@ extern "C" void _start() {
fb_ptr[i * (framebuffer->pitch / 4) + i] = 0xffffff;
}
+ Framebuffer fb((uint32_t*)framebuffer->address, framebuffer->width, framebuffer->height);
+ fb.drawpixel(727, 727, 0x9528fd);
+ printf("video modes: %lx", framebuffer->mode_count);
+
+ kernel_main();
// We're done, just hang...
hcf();
diff --git a/kernel/arch/x86_64/serial.cpp b/kernel/arch/x86_64/serial.cpp
new file mode 100644
index 0000000..e90bcde
--- /dev/null
+++ b/kernel/arch/x86_64/serial.cpp
@@ -0,0 +1,23 @@
+#include <io.h>
+#include <string.h>
+
+#define PORT 0x3f8
+
+int is_transmit_empty() {
+ return inb(PORT + 5) & 0x20;
+}
+
+extern "C" void serial_putchar(char c) {
+ while (is_transmit_empty() == 0);
+ outb(PORT, c);
+}
+
+void serial_write(const char* data, size_t size) {
+ for (size_t i = 0; i < size; i++) {
+ serial_putchar(data[i]);
+ }
+}
+
+void serial_writestring(const char* data) {
+ serial_write(data, strlen(data));
+} \ No newline at end of file
diff --git a/kernel/framebuffer.cpp b/kernel/framebuffer.cpp
new file mode 100644
index 0000000..a07d61a
--- /dev/null
+++ b/kernel/framebuffer.cpp
@@ -0,0 +1,22 @@
+#include <framebuffer.h>
+#include <stdint.h>
+#include <stddef.h>
+
+Framebuffer::Framebuffer(uint32_t* addr, const uint64_t width, const uint64_t height)
+ : addr {addr}, width {width}, height {height} {
+ clear();
+}
+
+void Framebuffer::clear() {
+ for (size_t y = 0; y < height; y++) {
+ for (size_t x = 0; x < width; x++) {
+ const size_t i = y * width + x;
+ addr[i] = 0x000000;
+ }
+ }
+}
+
+void Framebuffer::drawpixel(const uint64_t x, const uint64_t y, const uint32_t color) {
+ const size_t pos = y * width + x;
+ addr[pos] = color;
+} \ No newline at end of file
diff --git a/kernel/include/arch/x86_64/serial.h b/kernel/include/arch/x86_64/serial.h
new file mode 100644
index 0000000..2ee63c5
--- /dev/null
+++ b/kernel/include/arch/x86_64/serial.h
@@ -0,0 +1,19 @@
+#ifndef SERIAL_H
+#define SERIAL_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+void serial_putchar(char c);
+void serial_write(const char* data, size_t size);
+void serial_writestring(const char* data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/kernel/include/framebuffer.h b/kernel/include/framebuffer.h
new file mode 100644
index 0000000..6080810
--- /dev/null
+++ b/kernel/include/framebuffer.h
@@ -0,0 +1,18 @@
+#ifndef FRAMEBUFFER_H
+#define FRAMEBUFFER_H
+
+#include <stdint.h>
+
+class Framebuffer {
+ private:
+ uint32_t* addr;
+ const uint64_t width;
+ const uint64_t height;
+
+ public:
+ Framebuffer(uint32_t* addr, const uint64_t width, const uint64_t height);
+ void clear();
+ void drawpixel(const uint64_t x, const uint64_t y, const uint32_t color);
+};
+
+#endif \ No newline at end of file
diff --git a/kernel/makefile b/kernel/makefile
index 8c2832d..33ab941 100644
--- a/kernel/makefile
+++ b/kernel/makefile
@@ -1,8 +1,11 @@
# Kernel makefile
-CFLAGS := -ffreestanding -Wall -Wextra -g -std=gnu99 -O2 -Iinclude --sysroot=$(SYSROOT)
-CXXFLAGS := -ffreestanding -Wall -Wextra -fno-exceptions -fno-rtti -g -O2 -Iinclude --sysroot=$(SYSROOT)
-LDFLAGS := -T arch/$(ARCH)/linker.ld -ffreestanding -g -O2 -Iinclude --sysroot=$(SYSROOT)
+CFLAGS := -ffreestanding -Wall -Wextra -g -std=gnu99 -O2 -Iinclude --sysroot=$(SYSROOT) \
+ -isystem="/usr/include"
+CXXFLAGS := -ffreestanding -Wall -Wextra -fno-exceptions -fno-rtti -g -O2 -Iinclude --sysroot=$(SYSROOT) \
+ -isystem="/usr/include"
+LDFLAGS := -T arch/$(ARCH)/linker.ld -ffreestanding -g -O2 -Iinclude --sysroot=$(SYSROOT) \
+ -isystem="/usr/include"
ASMFLAGS :=
ifeq ($(ARCH),x86_64)
@@ -21,7 +24,7 @@ LIBS = -nostdlib -lc -lgcc
#Find all the source files
CPP_SRCS := $(shell find . -type f -name '*.cpp' -not -path './arch/*') \
$(shell find $(PWD)/kernel/arch/$(ARCH) -type f -name '*.cpp')
-#HEADERS := $(shell find $(PWD) -type f -name '*.h')
+HEADERS := $(shell find ./include -type f -name '*.h')
#ASMFILES := $(shell find $(PWD) -type f -name '*.asm' -prune $(PWD)/arch) \
$(shell find $(PWD)/kernel/arch/$(ARCH) -type f -name '*.asm')
@@ -50,11 +53,11 @@ kernel.bin: ${OBJS}
$(CXX) ${LDFLAGS} -o $@ $(LINKLST)
%.o: %.cpp
- $(info [INFO] Compiling $<)
+# $(info [INFO] Compiling $<)
$(CXX) ${CXXFLAGS} -MMD -MP -c $< -o $@
%.o: %.c
- $(info [INFO] Compiling $<)
+# $(info [INFO] Compiling $<)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
%.o: %.asm
@@ -67,9 +70,9 @@ kernel.bin: ${OBJS}
# crtn.o:
# $(NASM) arch/$(ARCH)/crtn.asm $(ASMFLAGS) -o $@
-install-headers:
+install-headers: $(HEADERS)
cp -r --preserve=timestamps include/. $(SYSROOT)/usr/include
clean:
$(info [INFO] Cleaning)
- $(RM) ${OBJS} $(DEPFILES) \ No newline at end of file
+ $(RM) ${OBJS} $(DEPFILES) kernel.bin \ No newline at end of file