diff --git a/sys/CMakeLists.txt b/sys/CMakeLists.txt index e2eb139..3f4f9ca 100644 --- a/sys/CMakeLists.txt +++ b/sys/CMakeLists.txt @@ -1,7 +1,6 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") add_subdirectory(denali) -add_subdirectory(teton) add_subdirectory(victoriafalls) add_subdirectory(voyageurs) add_subdirectory(yellowstone) diff --git a/sys/teton/CMakeLists.txt b/sys/teton/CMakeLists.txt deleted file mode 100644 index 19a6706..0000000 --- a/sys/teton/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -add_executable(teton - framebuffer/console.cpp - framebuffer/framebuffer.cpp - framebuffer/psf.cpp - terminal.cpp - teton.cpp - ) - -target_include_directories(teton - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - "${CMAKE_CURRENT_SOURCE_DIR}/include") - -target_link_libraries(teton - glacier - mammoth - victoriafalls_yunq - voyageurs_yunq - yellowstone_yunq - ) - -set_target_properties(teton PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" - LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" - ) - -install(TARGETS teton) diff --git a/sys/teton/framebuffer/console.cpp b/sys/teton/framebuffer/console.cpp deleted file mode 100644 index 7e0a02e..0000000 --- a/sys/teton/framebuffer/console.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "framebuffer/console.h" - -#include - -void Console::WriteChar(char c) { - if (c == '\n') { - CursorReturn(); - return; - } - if (c == '\t') { - WriteString(" "); - return; - } - if (c == '\b') { - cursor_pos_--; - WriteChar(' '); - cursor_pos_--; - return; - } - - uint64_t row = cursor_pos_ / cols(); - if (row >= rows()) { - crash("Unimplemented console scroll.", glcr::UNIMPLEMENTED); - } - uint64_t fb_row = row * (psf_.height() + 1); - uint64_t col = cursor_pos_ % cols(); - uint64_t fb_col = col * (psf_.width() + 1); - - uint8_t* glyph = psf_.glyph(c); - - for (uint32_t r = fb_row; r < fb_row + psf_.height(); r++) { - for (uint32_t j = fb_col; j < fb_col + psf_.width(); j++) { - uint8_t glyph_offset = psf_.width() - (j - fb_col) - 1; - if ((glyph[r - fb_row] & (1 << glyph_offset))) { - framebuf_.DrawPixel(r, j, 0xFFFFFFF); - } else { - framebuf_.DrawPixel(r, j, 0); - } - } - } - - cursor_pos_++; -} - -void Console::WriteString(glcr::StringView str) { - for (uint64_t i = 0; i < str.size(); i++) { - WriteChar(str[i]); - } -} - -void Console::CursorReturn() { - cursor_pos_ -= cursor_pos_ % cols(); - cursor_pos_ += cols(); -} diff --git a/sys/teton/framebuffer/console.h b/sys/teton/framebuffer/console.h deleted file mode 100644 index 9afd2f4..0000000 --- a/sys/teton/framebuffer/console.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -#include "framebuffer/framebuffer.h" -#include "framebuffer/psf.h" - -class Console { - public: - explicit Console(Framebuffer& fb, Psf& psf) : framebuf_(fb), psf_(psf) {} - - void WriteChar(char c); - void WriteString(glcr::StringView str); - - uint32_t rows() { return framebuf_.height() / (psf_.height() + 1); } - uint32_t cols() { return framebuf_.width() / (psf_.width() + 1); } - - private: - // TODO: Don't store a reference here. - Framebuffer& framebuf_; - Psf& psf_; - uint64_t cursor_pos_ = 0; - - void CursorIncr(); - void CursorReturn(); -}; diff --git a/sys/teton/framebuffer/framebuffer.cpp b/sys/teton/framebuffer/framebuffer.cpp deleted file mode 100644 index 5960c84..0000000 --- a/sys/teton/framebuffer/framebuffer.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "framebuffer/framebuffer.h" - -Framebuffer::Framebuffer(const yellowstone::FramebufferInfo& info) - : fb_info_(info), cursor_pos_(0) { - uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch(); - fb_memory_ = mmth::OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(), - buff_size_bytes); - fb_ = reinterpret_cast(fb_memory_.vaddr()); -} - -void Framebuffer::DrawPixel(uint32_t row, uint32_t col, uint32_t pixel) { - // Div by 4 because pitch is in bytes and fb_ is a 32bit array. - fb_[(row * fb_info_.pitch() / 4) + col] = pixel; -} - -void Framebuffer::DrawGlyph(uint8_t* glyph) { - uint32_t gl_width = 8; - uint32_t gl_height = 16; - - for (uint8_t r = 0; r < gl_height; r++) { - for (uint8_t c = 0; c < gl_width; c++) { - if (((glyph[r] >> c) % 2) == 1) { - DrawPixel(r, gl_width - c - 1, 0xFFFF'FFFF); - } else { - DrawPixel(r, gl_width - c - 1, 0); - } - } - } -}; diff --git a/sys/teton/framebuffer/framebuffer.h b/sys/teton/framebuffer/framebuffer.h deleted file mode 100644 index d6db590..0000000 --- a/sys/teton/framebuffer/framebuffer.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -class Framebuffer { - public: - Framebuffer(const yellowstone::FramebufferInfo& info); - - void DrawPixel(uint32_t row, uint32_t col, uint32_t pixel); - - void DrawGlyph(uint8_t* glyph); - - uint64_t width() { return fb_info_.width(); } - uint64_t height() { return fb_info_.height(); } - - private: - // FIXME: Implement Yunq copy or move so we - // don't have to store a reference here. - const yellowstone::FramebufferInfo& fb_info_; - - mmth::OwnedMemoryRegion fb_memory_; - uint32_t* fb_; - uint32_t cursor_pos_; -}; diff --git a/sys/teton/framebuffer/psf.cpp b/sys/teton/framebuffer/psf.cpp deleted file mode 100644 index 1e8aaf2..0000000 --- a/sys/teton/framebuffer/psf.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "framebuffer/psf.h" - -#include -#include - -#define PSF_DEBUG 0 - -namespace { - -const uint32_t kMagic = 0x864AB572; - -} - -Psf::Psf(glcr::StringView path) - : psf_file_(mmth::File::Open(path)), - header_(reinterpret_cast(psf_file_.raw_ptr())) { - EnsureValid(); -} - -void Psf::DumpHeader() { -#if PSF_DEBUG - dbgln("Magic: {x}", header_->magic); - dbgln("Version: {x}", header_->version); - dbgln("Header Sz: {x}", header_->headersize); - dbgln("Flags: {x}", header_->flags); - dbgln("Length: {x}", header_->numglyph); - dbgln("Glyph Size: {x}", header_->bytesperglyph); - dbgln("Height: {x}", header_->height); - dbgln("Width: {x}", header_->width); -#endif -} - -void Psf::EnsureValid() { - if (header_->magic != kMagic) { - dbgln("PSF: Magic value: {x}", header_->magic); - crash("PSF: Invalid magic value", glcr::INVALID_ARGUMENT); - } - - if (header_->version != 0) { - crash("PSF non-zero version", glcr::INVALID_ARGUMENT); - } - - if (header_->height != 0x10) { - crash("PSF height other than 16 not handled", glcr::UNIMPLEMENTED); - } - - if (header_->width != 0x8) { - crash("PSF width other than 8 not handled", glcr::UNIMPLEMENTED); - } -} diff --git a/sys/teton/framebuffer/psf.h b/sys/teton/framebuffer/psf.h deleted file mode 100644 index bfa890d..0000000 --- a/sys/teton/framebuffer/psf.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include - -struct PsfHeader { - uint32_t magic; /* magic bytes to identify PSF */ - uint32_t version; /* zero */ - uint32_t headersize; /* offset of bitmaps in file, 32 */ - uint32_t flags; /* 0 if there's no unicode table */ - uint32_t numglyph; /* number of glyphs */ - uint32_t bytesperglyph; /* size of each glyph */ - uint32_t height; /* height in pixels */ - uint32_t width; /* width in pixels */ -}; - -class Psf { - public: - Psf(glcr::StringView path); - - void DumpHeader(); - - uint32_t size() { return header_->numglyph; } - uint32_t width() { return header_->width; } - uint32_t height() { return header_->height; } - - uint8_t* glyph(uint32_t index) { - return reinterpret_cast(psf_file_.byte_ptr() + - header_->headersize + - (index * header_->bytesperglyph)); - } - - private: - mmth::File psf_file_; - PsfHeader* header_; - - void EnsureValid(); -}; diff --git a/sys/teton/terminal.cpp b/sys/teton/terminal.cpp deleted file mode 100644 index 9adb28d..0000000 --- a/sys/teton/terminal.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "terminal.h" - -#include -#include -#include -#include -#include -#include - -void Terminal::HandleCharacter(char c) { - console_.WriteChar(c); - if (c == '\n') { - glcr::String str = current_command_.ToString(); - ExecuteCommand(str); - current_command_.Reset(); - } else if (c == '\b') { - current_command_.DeleteLast(); - } else { - current_command_.PushBack(c); - } -} - -void Terminal::ExecuteCommand(const glcr::String& command) { - auto tokens = glcr::StrSplit(command, ' '); - if (tokens.size() == 0) { - console_.WriteChar('>'); - return; - } - glcr::StringView cmd = tokens[0]; - if (cmd == "help") { - console_.WriteString("Available Commands: pwd cd ls\n"); - } else if (cmd == "pwd") { - console_.WriteString(cwd_); - console_.WriteChar('\n'); - } else if (cmd == "cd") { - if (tokens.size() != 2) { - console_.WriteString("Provide an absolute path.\n>"); - return; - } - auto files_or = mmth::ListDirectory(tokens[1]); - if (files_or.ok()) { - cwd_ = tokens[1]; - } else { - console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error())); - } - - } else if (cmd == "ls") { - glcr::StringView directory; - if (tokens.size() > 1) { - directory = tokens[1]; - } else { - directory = cwd_; - } - auto files_or = mmth::ListDirectory(directory); - if (!files_or.ok()) { - console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error())); - } else { - for (const auto& file : files_or.value()) { - console_.WriteString(file); - console_.WriteChar('\n'); - } - } - } else if (cmd == "exec") { - if (tokens.size() != 2) { - console_.WriteString("Provide the name of an executable.\n>"); - return; - } - auto file = mmth::File::Open(tokens[1]); - - z_cap_t endpoint; - if (ZCapDuplicate(gInitEndpointCap, kZionPerm_All, &endpoint) != glcr::OK) { - console_.WriteString("Couldn't duplicate yellowstone cap for spawn"); - return; - } - - auto error_or_cap = - mmth::SpawnProcessFromElfRegion((uint64_t)file.raw_ptr(), endpoint); - if (!error_or_cap.ok()) { - console_.WriteString( - glcr::StrFormat("Error: {}\n", error_or_cap.error())); - return; - } - uint64_t err_code; - check(ZProcessWait(error_or_cap.value(), &err_code)); - if (err_code != 0) { - console_.WriteString(glcr::StrFormat( - "Process Error: {}\n", static_cast(err_code))); - } - - } else { - console_.WriteString("Unknown command: "); - console_.WriteString(command); - console_.WriteChar('\n'); - } - console_.WriteChar('>'); -} diff --git a/sys/teton/terminal.h b/sys/teton/terminal.h deleted file mode 100644 index 71408a2..0000000 --- a/sys/teton/terminal.h +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -#include "framebuffer/console.h" - -class Terminal : public mmth::KeyboardListenerBase { - public: - Terminal(Console& c) : mmth::KeyboardListenerBase(), console_(c) {} - - virtual void HandleCharacter(char c) override; - - void ExecuteCommand(const glcr::String& command); - - private: - Console& console_; - glcr::VariableStringBuilder current_command_; - - glcr::String cwd_ = "/"; -}; diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp deleted file mode 100644 index f89c689..0000000 --- a/sys/teton/teton.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include - -#include "framebuffer/console.h" -#include "framebuffer/framebuffer.h" -#include "framebuffer/psf.h" -#include "terminal.h" - -using yellowstone::FramebufferInfo; -using yellowstone::YellowstoneClient; - -uint64_t main(uint64_t init_port) { - ParseInitPort(init_port); - - dbgln("Teton Starting"); - - // 1. Set up framebuffer. - YellowstoneClient client(gInitEndpointCap); - - FramebufferInfo framebuffer; - check(client.GetFramebufferInfo(framebuffer)); - dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}", - framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(), - framebuffer.height(), framebuffer.pitch()); - - Framebuffer fbuf(framebuffer); - - // 2. Parse a font file. - - Psf psf("/default8x16.psfu"); - psf.DumpHeader(); - - // 3. Write a line to the screen. - Console console(fbuf, psf); - console.WriteChar('>'); - - Terminal terminal(console); - terminal.Register(); - - Thread lthread = terminal.Listen(); - - check(lthread.Join()); - - return glcr::OK; -}