[Teton] Remove old C++ implementation.

This commit is contained in:
Drew Galbraith 2024-08-17 12:56:30 -07:00
parent 006f9f8ac5
commit c6dbc395aa
11 changed files with 0 additions and 411 deletions

View File

@ -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)

View File

@ -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)

View File

@ -1,54 +0,0 @@
#include "framebuffer/console.h"
#include <mammoth/util/debug.h>
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();
}

View File

@ -1,26 +0,0 @@
#pragma once
#include <glacier/string/string_view.h>
#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();
};

View File

@ -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<uint32_t*>(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);
}
}
}
};

View File

@ -1,25 +0,0 @@
#pragma once
#include <mammoth/util/memory_region.h>
#include <yellowstone/yellowstone.yunq.h>
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_;
};

View File

@ -1,50 +0,0 @@
#include "framebuffer/psf.h"
#include <glacier/memory/move.h>
#include <mammoth/util/debug.h>
#define PSF_DEBUG 0
namespace {
const uint32_t kMagic = 0x864AB572;
}
Psf::Psf(glcr::StringView path)
: psf_file_(mmth::File::Open(path)),
header_(reinterpret_cast<PsfHeader*>(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);
}
}

View File

@ -1,37 +0,0 @@
#pragma once
#include <mammoth/file/file.h>
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<uint8_t*>(psf_file_.byte_ptr() +
header_->headersize +
(index * header_->bytesperglyph));
}
private:
mmth::File psf_file_;
PsfHeader* header_;
void EnsureValid();
};

View File

@ -1,96 +0,0 @@
#include "terminal.h"
#include <glacier/string/str_format.h>
#include <glacier/string/str_split.h>
#include <mammoth/file/file.h>
#include <mammoth/proc/process.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
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<glcr::ErrorCode>(err_code)));
}
} else {
console_.WriteString("Unknown command: ");
console_.WriteString(command);
console_.WriteChar('\n');
}
console_.WriteChar('>');
}

View File

@ -1,19 +0,0 @@
#include <glacier/string/string_builder.h>
#include <mammoth/input/keyboard.h>
#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_ = "/";
};

View File

@ -1,48 +0,0 @@
#include <mammoth/ipc/port_server.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
#include <victoriafalls/victoriafalls.yunq.client.h>
#include <yellowstone/yellowstone.yunq.client.h>
#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;
}