summaryrefslogtreecommitdiff
path: root/src/arch/amd64/fb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/amd64/fb.c')
-rw-r--r--src/arch/amd64/fb.c28
1 files changed, 27 insertions, 1 deletions
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;
}