mirror of
https://git.stationery.faith/corn/corn.git
synced 2024-11-23 11:52:18 +00:00
pretty colors
This commit is contained in:
parent
019de3cb22
commit
72df91d99b
7 changed files with 51 additions and 4 deletions
2
Makefile
2
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
|
||||
|
|
2
grub.cfg
2
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
|
||||
|
|
3
include/fpu.h
Normal file
3
include/fpu.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void enable_fpu();
|
|
@ -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;
|
||||
}
|
||||
|
|
12
src/arch/amd64/fpu.c
Normal file
12
src/arch/amd64/fpu.c
Normal 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));
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue