Kernel: Add prefs font for terminal output before file system

This commit is contained in:
Bananymous 2023-02-23 01:22:50 +02:00
parent a4980acc88
commit 390a747768
8 changed files with 43 additions and 18 deletions

View File

@ -31,6 +31,7 @@ BUILDDIR=$(abspath build)
KERNEL_OBJS= \
$(KERNEL_ARCH_OBJS) \
font/prefs.o \
kernel/APIC.o \
kernel/ATA.o \
kernel/build_libc.o \
@ -74,7 +75,7 @@ $(ARCHDIR)/crtend.o \
$(ARCHDIR)/crtn.o \
.PHONY: all always clean install install-headers install-kernel
.SUFFIXES: .o .c .cpp .S
.SUFFIXES: .o .c .cpp .S .psf
all: banan-os.kernel
@ -94,10 +95,14 @@ $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
.S.o:
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
.psf.o:
objcopy -O elf64-x86-64 -B i386 -I binary $< $(BUILDDIR)/$@
always:
mkdir -p $(BUILDDIR)/$(ARCHDIR)
mkdir -p $(BUILDDIR)/kernel
mkdir -p $(BUILDDIR)/kernel/FS
mkdir -p $(BUILDDIR)/font
clean:
rm -rf $(BUILDDIR)

BIN
kernel/font/prefs.psf Normal file

Binary file not shown.

View File

@ -10,6 +10,7 @@ namespace Kernel
{
public:
static BAN::ErrorOr<Font> load(BAN::StringView);
static BAN::ErrorOr<Font> prefs();
uint32_t width() const { return m_width; }
uint32_t height() const { return m_height; }

View File

@ -22,7 +22,7 @@ public:
};
public:
TerminalDriver(const Kernel::Font& font) : m_font(font) {}
TerminalDriver() : m_font(MUST(Kernel::Font::prefs())) {}
virtual ~TerminalDriver() {}
virtual uint32_t width() const = 0;
virtual uint32_t height() const = 0;

View File

@ -5,7 +5,7 @@
class VesaTerminalDriver final : public TerminalDriver
{
public:
static VesaTerminalDriver* create(const Kernel::Font&);
static VesaTerminalDriver* create();
~VesaTerminalDriver();
virtual uint32_t width() const override { return m_width / font().width(); }
@ -17,9 +17,8 @@ public:
virtual void set_cursor_position(uint32_t, uint32_t) override;
private:
VesaTerminalDriver(uint32_t width, uint32_t height, uint32_t pitch, uint8_t bpp, uintptr_t address, const Kernel::Font& font)
: TerminalDriver(font)
, m_width(width)
VesaTerminalDriver(uint32_t width, uint32_t height, uint32_t pitch, uint8_t bpp, uintptr_t address)
: m_width(width)
, m_height(height)
, m_pitch(pitch)
, m_bpp(bpp)

View File

@ -8,9 +8,21 @@
#define PSF2_HAS_UNICODE_TABLE 0x00000001
extern char _binary_font_prefs_psf_start;
extern char _binary_font_prefs_psf_end;
namespace Kernel
{
BAN::ErrorOr<Font> Font::prefs()
{
size_t font_data_size = &_binary_font_prefs_psf_end - &_binary_font_prefs_psf_start;
BAN::Vector<uint8_t> font_data;
TRY(font_data.resize(font_data_size));
memcpy(font_data.data(), &_binary_font_prefs_psf_start, font_data_size);
return parse_psf1(font_data);
}
BAN::ErrorOr<Font> Font::load(BAN::StringView path)
{
if (!VirtualFileSystem::is_initialized())

View File

@ -4,7 +4,7 @@
#include <kernel/multiboot.h>
#include <kernel/VesaTerminalDriver.h>
VesaTerminalDriver* VesaTerminalDriver::create(const Kernel::Font& font)
VesaTerminalDriver* VesaTerminalDriver::create()
{
if (!(g_multiboot_info->flags & MULTIBOOT_FLAGS_FRAMEBUFFER))
{
@ -41,8 +41,7 @@ VesaTerminalDriver* VesaTerminalDriver::create(const Kernel::Font& font)
framebuffer.height,
framebuffer.pitch,
framebuffer.bpp,
framebuffer.addr,
font
framebuffer.addr
);
driver->set_cursor_position(0, 0);
driver->clear(TerminalColor::BLACK);

View File

@ -81,10 +81,10 @@ extern "C" void kernel_main()
MMU::intialize();
dprintln("MMU initialized");
//TerminalDriver* terminal_driver = VesaTerminalDriver::create();
//ASSERT(terminal_driver);
//dprintln("VESA initialized");
//TTY* tty1 = new TTY(terminal_driver);
TerminalDriver* terminal_driver = VesaTerminalDriver::create();
ASSERT(terminal_driver);
dprintln("VESA initialized");
TTY* tty1 = new TTY(terminal_driver);
InterruptController::initialize(cmdline.force_pic);
dprintln("Interrupt controller initialized");
@ -99,15 +99,24 @@ extern "C" void kernel_main()
Scheduler::initialize();
Scheduler& scheduler = Scheduler::get();
MUST(scheduler.add_thread(BAN::Function<void()>(
[]
[terminal_driver]
{
DiskIO::initialize();
dprintln("Disk IO initialized");
auto font = MUST(Font::load("/usr/share/fonts/zap-ext-vga16.psf"));
dprintln("Font loaded");
Shell(new TTY(VesaTerminalDriver::create(font))).run();
auto font_or_error = Font::load("/usr/share/fonts/zap-ext-vga16.psf");
if (font_or_error.is_error())
dprintln("{}", font_or_error.error());
else
terminal_driver->set_font(font_or_error.release_value());
}
)));
MUST(scheduler.add_thread(BAN::Function<void()>(
[tty1]
{
Shell* shell = new Shell(tty1);
ASSERT(shell);
shell->run();
}
)));
scheduler.start();