summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-02 16:41:19 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-02 16:41:19 -0500
commit72df91d99ba7e9a032d6cb171571e075d0f6ce53 (patch)
tree5ccba5a02821a54f953d85a092429939e6c577f0
parentcheck for bochs (diff)
downloadcorn-72df91d99ba7e9a032d6cb171571e075d0f6ce53.tar.gz
corn-72df91d99ba7e9a032d6cb171571e075d0f6ce53.tar.bz2
corn-72df91d99ba7e9a032d6cb171571e075d0f6ce53.zip
pretty colors
-rw-r--r--Makefile2
-rw-r--r--grub.cfg2
-rw-r--r--include/fpu.h3
-rw-r--r--src/arch/amd64/fb.c28
-rw-r--r--src/arch/amd64/fpu.c12
-rw-r--r--src/arch/amd64/pci.c6
-rw-r--r--src/kmain.c2
7 files changed, 51 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 19b2342..d8ab7a8 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ run: all
@qemu-system-x86_64 \
-cdrom build/$(ISO) \
-serial stdio \
- -display gtk,show-menubar=off,zoom-to-fit=on \
+ -display sdl \
-m 1G \
-enable-kvm \
-name corn
diff --git a/grub.cfg b/grub.cfg
index 3aa3a12..d34c818 100644
--- a/grub.cfg
+++ b/grub.cfg
@@ -1,5 +1,7 @@
set timeout=1
set default=0
+terminal_input at_keyboard
+termianl_output console
menuentry "corn" {
multiboot2 /boot/kernel.bin
diff --git a/include/fpu.h b/include/fpu.h
new file mode 100644
index 0000000..88dfe47
--- /dev/null
+++ b/include/fpu.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void enable_fpu();
diff --git a/src/arch/amd64/fb.c b/src/arch/amd64/fb.c
index ab15dd6..8484f29 100644
--- a/src/arch/amd64/fb.c
+++ b/src/arch/amd64/fb.c
@@ -3,6 +3,7 @@
#include <serial.h>
#include <stdint.h>
#include <panic.h>
+#include <pci.h>
#include "bindings.h"
@@ -25,6 +26,9 @@
#define DATA_LFB_ENABLE 0x40
#define DATA_NO_CLEAR_MEM 0x80
+#define BOCHS_PCI_VENDOR 0x1234
+#define BOCHS_PCI_DEVICE 0x1111
+
static void write(uint16_t index, uint16_t data) {
outw(INDEX, index);
outw(DATA, data);
@@ -60,5 +64,27 @@ int fb_init(uint16_t width, uint16_t height) {
if (!is_available())
panic("bochs framebuffer not avaliable");
- return 0;
+ struct pci_device bochs = {0};
+ bool found = pci_findby_id(&bochs, BOCHS_PCI_DEVICE, BOCHS_PCI_VENDOR, NULL);
+ if (!found)
+ panic("bochs pci device not avaliable");
+
+ uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D);
+ uint32_t *fb = (uint32_t*) (uintptr_t) bar0;
+ fb = mmap(fb, width * height * 4);
+
+ for (uint16_t y = 0; y < height; y++) {
+ for (uint16_t x = 0; x < width; x++) {
+ double dx = x / (double) width,
+ dy = y / (double) height,
+ dz = (2 - dx - dy) / 2;
+ uint32_t r = (uint32_t)(dx * 255),
+ g = (uint32_t)(dy * 255),
+ b = (uint32_t)(dz * 255);
+ fb[x + y * width] = (b << 0) | (g << 8) | (r << 16);
+ }
+ }
+
+
+ return 0;
}
diff --git a/src/arch/amd64/fpu.c b/src/arch/amd64/fpu.c
new file mode 100644
index 0000000..551485e
--- /dev/null
+++ b/src/arch/amd64/fpu.c
@@ -0,0 +1,12 @@
+#include <fpu.h>
+#include <stddef.h>
+#include <stdint.h>
+
+void enable_fpu() {
+ size_t cr4;
+ uint16_t cw = 0x37F;
+ __asm__ volatile ("mov %%cr4, %0" : "=r"(cr4));
+ cr4 |= 0x200;
+ __asm__ volatile ("mov %0, %%cr4" :: "r"(cr4));
+ __asm__ volatile("fldcw %0" :: "m"(cw));
+}
diff --git a/src/arch/amd64/pci.c b/src/arch/amd64/pci.c
index 0deac03..7b30f0e 100644
--- a/src/arch/amd64/pci.c
+++ b/src/arch/amd64/pci.c
@@ -102,12 +102,10 @@ static struct pci_table_entry *load_device(struct pci_device dev) {
entry->prog_if = (dword2 >> 8) & 0xFF;
entry->revision = dword2 & 0xFF;
- print_device(entry);
return entry;
}
void pci_init(void) {
- kprintf("PCI DEVICES\n");
pci_table_next = 0;
struct pci_device pcidev;
for(int bus = 0; bus < 256; bus++) {
@@ -134,6 +132,10 @@ void pci_init(void) {
}
}
}
+ kprintf("PCI DEVICES\n");
+ for (size_t i = 0; i < pci_table_next; i++) {
+ print_device(&pci_table[i]);
+ }
kprintf("\n");
}
diff --git a/src/kmain.c b/src/kmain.c
index 476bcdc..bc1d225 100644
--- a/src/kmain.c
+++ b/src/kmain.c
@@ -1,3 +1,4 @@
+#include "fpu.h"
#include <acpi.h>
#include <memory.h>
#include <lib.h>
@@ -8,6 +9,7 @@
#include <pci.h>
void kmain(struct boot_info *info) {
+ enable_fpu();
memory_init(&info->map);
pci_init();
fb_init(1024, 768);