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

BIN
kernel/font/prefs.psf Normal file

Binary file not shown.

View File

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

View File

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

View File

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

View File

@ -8,9 +8,21 @@
#define PSF2_HAS_UNICODE_TABLE 0x00000001 #define PSF2_HAS_UNICODE_TABLE 0x00000001
extern char _binary_font_prefs_psf_start;
extern char _binary_font_prefs_psf_end;
namespace Kernel 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) BAN::ErrorOr<Font> Font::load(BAN::StringView path)
{ {
if (!VirtualFileSystem::is_initialized()) if (!VirtualFileSystem::is_initialized())

View File

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

View File

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