pretty colors

This commit is contained in:
Freya Murphy 2024-02-02 16:41:19 -05:00
parent 019de3cb22
commit 72df91d99b
Signed by: freya
GPG key ID: 744AB800E383AE52
7 changed files with 51 additions and 4 deletions

View file

@ -55,7 +55,7 @@ run: all
@qemu-system-x86_64 \ @qemu-system-x86_64 \
-cdrom build/$(ISO) \ -cdrom build/$(ISO) \
-serial stdio \ -serial stdio \
-display gtk,show-menubar=off,zoom-to-fit=on \ -display sdl \
-m 1G \ -m 1G \
-enable-kvm \ -enable-kvm \
-name corn -name corn

View file

@ -1,5 +1,7 @@
set timeout=1 set timeout=1
set default=0 set default=0
terminal_input at_keyboard
termianl_output console
menuentry "corn" { menuentry "corn" {
multiboot2 /boot/kernel.bin multiboot2 /boot/kernel.bin

3
include/fpu.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
void enable_fpu();

View file

@ -3,6 +3,7 @@
#include <serial.h> #include <serial.h>
#include <stdint.h> #include <stdint.h>
#include <panic.h> #include <panic.h>
#include <pci.h>
#include "bindings.h" #include "bindings.h"
@ -25,6 +26,9 @@
#define DATA_LFB_ENABLE 0x40 #define DATA_LFB_ENABLE 0x40
#define DATA_NO_CLEAR_MEM 0x80 #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) { static void write(uint16_t index, uint16_t data) {
outw(INDEX, index); outw(INDEX, index);
outw(DATA, data); outw(DATA, data);
@ -60,5 +64,27 @@ int fb_init(uint16_t width, uint16_t height) {
if (!is_available()) if (!is_available())
panic("bochs framebuffer not avaliable"); 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;
} }

12
src/arch/amd64/fpu.c Normal file
View file

@ -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));
}

View file

@ -102,12 +102,10 @@ static struct pci_table_entry *load_device(struct pci_device dev) {
entry->prog_if = (dword2 >> 8) & 0xFF; entry->prog_if = (dword2 >> 8) & 0xFF;
entry->revision = dword2 & 0xFF; entry->revision = dword2 & 0xFF;
print_device(entry);
return entry; return entry;
} }
void pci_init(void) { void pci_init(void) {
kprintf("PCI DEVICES\n");
pci_table_next = 0; pci_table_next = 0;
struct pci_device pcidev; struct pci_device pcidev;
for(int bus = 0; bus < 256; bus++) { 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"); kprintf("\n");
} }

View file

@ -1,3 +1,4 @@
#include "fpu.h"
#include <acpi.h> #include <acpi.h>
#include <memory.h> #include <memory.h>
#include <lib.h> #include <lib.h>
@ -8,6 +9,7 @@
#include <pci.h> #include <pci.h>
void kmain(struct boot_info *info) { void kmain(struct boot_info *info) {
enable_fpu();
memory_init(&info->map); memory_init(&info->map);
pci_init(); pci_init();
fb_init(1024, 768); fb_init(1024, 768);