From 3382121c3a745575fe7ec755d341ed28d617926d Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 29 Apr 2017 11:06:31 +0000 Subject: [PATCH] added working LFB driver and some helper scripts --- .gitignore | 1 + buildtools/grub-iso.sh | 2 + buildtools/mkfirm.py | 65 +++++++++++++++++++++++++++ buildtools/sighax-firm.sh | 3 ++ iso/{grub2 => boot/grub}/grub.cfg | 0 kernel/hw/framebuffer/framebuffer.cpp | 18 ++++++-- kernel/hw/pc/vesafb/vesafb.cpp | 9 +++- kernel/src/main.cpp | 3 +- 8 files changed, 95 insertions(+), 6 deletions(-) create mode 100755 buildtools/grub-iso.sh create mode 100755 buildtools/mkfirm.py create mode 100755 buildtools/sighax-firm.sh rename iso/{grub2 => boot/grub}/grub.cfg (100%) diff --git a/.gitignore b/.gitignore index e2eab30..7c56a09 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ build/ __pycache__/ *.iso iso/kernel +*.firm diff --git a/buildtools/grub-iso.sh b/buildtools/grub-iso.sh new file mode 100755 index 0000000..135acd1 --- /dev/null +++ b/buildtools/grub-iso.sh @@ -0,0 +1,2 @@ +cp build/kernel/kernel iso +grub-mkrescue -o bootable.iso iso diff --git a/buildtools/mkfirm.py b/buildtools/mkfirm.py new file mode 100755 index 0000000..8fe1011 --- /dev/null +++ b/buildtools/mkfirm.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +import sys +if len(sys.argv) < 4: + print("USAGE: mkfirm.py ") +print("WARNING: Currently you cannot install this FIRM, because YOU'LL BRICK YOUR 3DS!") +sighax_sig = b'\x00'*256 #TODO insert sighax signature here. +import struct +import hashlib +def get_elf_seg(f): #Return entry,section_beg,section_size,section + f.seek(0) + if f.read(4) != b"\x7FELF": + raise Exception("Not an ELF file!") + if f.read(1) != b"\x01": + raise Exception("ELF64s are not supported!") + if f.read(1) != b"\x01": + raise Exception("Little Endian ELF required!") + if f.read(1) != b"\x01": + raise Exception("Unknown ELF version!") + if struct.unpack(" void { if (width == 16) this->x++; if (!width) return; int color; - for (int px = x * 8; px < (x * 8) + width; x++) - for (int py = y * 16; py < (y * 16) + 16; y++) { + for (int px = x * 8; px < (x * 8) + width; px++) + for (int py = y * 16; py < (y * 16) + 16; py++) { color = rgbColor; if (!useRGB) { switch (curColor) { @@ -32,7 +32,19 @@ auto Framebuffer::plotChar(int x, int y, int c) -> void { rgbColor = color; useRGB = true; } - plotPixel(px, py, color); + unsigned char *chara = (unsigned char *)font_ptr[c]; + int bx = px - (x * 8); + int by = py - (y * 16); + if (width == 16) { + by *= 2; + if (bx > 7) { + by++; + bx -= 8; + } + plotPixel(px, py, (chara[by] & (1 << (7 - bx))) ? color : 0); + } else { + plotPixel(px, py, (chara[by] & (1 << (7 - bx))) ? color : 0); + } } } Framebuffer::Framebuffer(int height, int width) : TTY(height, width) {} diff --git a/kernel/hw/pc/vesafb/vesafb.cpp b/kernel/hw/pc/vesafb/vesafb.cpp index 15ee25e..1f4d9d5 100644 --- a/kernel/hw/pc/vesafb/vesafb.cpp +++ b/kernel/hw/pc/vesafb/vesafb.cpp @@ -1,8 +1,13 @@ #include "vesafb.hpp" #include auto VESAfb::plotPixel(int x, int y, int col) -> void { - int *lfb = (int *)((uintptr_t)(mb_info->framebuffer_addr)); - lfb[y * mb_info->framebuffer_pitch + x] = col; + unsigned char *lfb = (unsigned char *)((uintptr_t)(mb_info->framebuffer_addr)); + int off = y * mb_info->framebuffer_pitch / (mb_info->framebuffer_bpp / 8) + x; + off *= mb_info->framebuffer_bpp / 8; + for (int i = 0; i < mb_info->framebuffer_bpp / 8; i++) { + lfb[off++] = col; + col >>= 8; + } } VESAfb::VESAfb(multiboot_info_t *mb_info) : mb_info(mb_info), Framebuffer(mb_info->framebuffer_width / 8, mb_info->framebuffer_height / 16) {} diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index ba6b59b..753eb97 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -7,6 +7,7 @@ extern "C" void (*end_dtors)(); void main() { for (auto ctor = &start_ctors; ctor < &end_ctors; ctor++) (**ctor)(); drivers_init(); - *out << "Hallo!\n"; + *out << "Hello!\n"; + *out << "ใƒ†ใ‚นใƒˆ\n"; for (auto dtor = &start_dtors; dtor != &end_dtors; dtor++) (**dtor)(); }