From fe44804dd9b2e73feddccd74e6859107c7e808a0 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Tue, 21 Nov 2023 19:14:02 -0800 Subject: [PATCH] [Teton] Load a font file and write a character to the screen. --- lib/glacier/container/hash_map.h | 13 +++ lib/glacier/string/string.cpp | 40 +++++++ lib/glacier/string/string.h | 7 +- sys/teton/CMakeLists.txt | 2 + sys/teton/framebuffer/framebuffer.cpp | 18 ++- sys/teton/framebuffer/framebuffer.h | 3 + sys/teton/framebuffer/psf.cpp | 46 ++++++++ sys/teton/framebuffer/psf.h | 34 ++++++ sys/teton/teton.cpp | 19 ++++ .../lib/yellowstone/yellowstone.yunq | 9 ++ .../yellowstone/yellowstone.yunq.client.cpp | 38 ++++++- .../lib/yellowstone/yellowstone.yunq.client.h | 2 + .../lib/yellowstone/yellowstone.yunq.cpp | 107 ++++++++++++++++++ .../lib/yellowstone/yellowstone.yunq.h | 40 +++++++ .../yellowstone/yellowstone.yunq.server.cpp | 15 ++- .../lib/yellowstone/yellowstone.yunq.server.h | 2 + sys/yellowstone/yellowstone_server.cpp | 26 +++-- sys/yellowstone/yellowstone_server.h | 8 +- sysroot/default8x16.psfu | Bin 0 -> 4969 bytes 19 files changed, 412 insertions(+), 17 deletions(-) create mode 100644 sys/teton/framebuffer/psf.cpp create mode 100644 sys/teton/framebuffer/psf.h create mode 100644 sysroot/default8x16.psfu diff --git a/lib/glacier/container/hash_map.h b/lib/glacier/container/hash_map.h index 1c066b4..81c5c31 100644 --- a/lib/glacier/container/hash_map.h +++ b/lib/glacier/container/hash_map.h @@ -6,6 +6,7 @@ #include "glacier/container/linked_list.h" #include "glacier/container/pair.h" #include "glacier/status/error.h" +#include "glacier/string/string.h" namespace glcr { @@ -22,6 +23,18 @@ struct HashFunc { } }; +template <> +struct HashFunc { + uint64_t operator()(const String& value) { + // FIXME: Write a real hash function. + uint64_t acc = 0; + for (uint64_t i = 0; i < value.length(); i++) { + acc += value[i]; + } + return 0xABBAABBAABBAABBA ^ acc; + } +}; + template > class HashMap { public: diff --git a/lib/glacier/string/string.cpp b/lib/glacier/string/string.cpp index 3e7cc16..e0a5b67 100644 --- a/lib/glacier/string/string.cpp +++ b/lib/glacier/string/string.cpp @@ -28,6 +28,46 @@ String::String(const char* cstr, uint64_t str_len) : length_(str_len) { String::String(StringView str) : String(str.data(), str.size()) {} +String::String(const String& other) : String(other.cstr_, other.length_) {} + +String& String::operator=(const String& other) { + if (cstr_) { + delete cstr_; + } + length_ = other.length_; + cstr_ = new char[length_ + 1]; + for (uint64_t i = 0; i < length_; i++) { + cstr_[i] = other.cstr_[i]; + } + cstr_[length_] = '\0'; + + return *this; +} + +String::String(String&& other) : cstr_(other.cstr_), length_(other.length_) { + other.cstr_ = nullptr; + other.length_ = 0; +} + +String& String::operator=(String&& other) { + if (cstr_) { + delete cstr_; + } + cstr_ = other.cstr_; + length_ = other.length_; + + other.cstr_ = nullptr; + other.length_ = 0; + + return *this; +} + +String::~String() { + if (cstr_) { + delete cstr_; + } +} + bool String::operator==(const String& other) { if (other.length_ != length_) { return false; diff --git a/lib/glacier/string/string.h b/lib/glacier/string/string.h index a1c3d8f..4093a41 100644 --- a/lib/glacier/string/string.h +++ b/lib/glacier/string/string.h @@ -13,7 +13,12 @@ class String { String(const char* cstr, uint64_t str_len); String(StringView str); - String(const String&) = delete; + String(const String&); + String& operator=(const String&); + String(String&&); + String& operator=(String&&); + + ~String(); const char* cstr() const { return cstr_; } uint64_t length() const { return length_; } diff --git a/sys/teton/CMakeLists.txt b/sys/teton/CMakeLists.txt index 4758b4a..aebb887 100644 --- a/sys/teton/CMakeLists.txt +++ b/sys/teton/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(teton framebuffer/framebuffer.cpp + framebuffer/psf.cpp teton.cpp ) @@ -10,6 +11,7 @@ target_include_directories(teton target_link_libraries(teton glacier mammoth + victoriafalls_yunq yellowstone_yunq ) diff --git a/sys/teton/framebuffer/framebuffer.cpp b/sys/teton/framebuffer/framebuffer.cpp index 3a507f0..817f1e0 100644 --- a/sys/teton/framebuffer/framebuffer.cpp +++ b/sys/teton/framebuffer/framebuffer.cpp @@ -1,6 +1,7 @@ #include "framebuffer/framebuffer.h" -Framebuffer::Framebuffer(const FramebufferInfo& info) : fb_info_(info) { +Framebuffer::Framebuffer(const FramebufferInfo& info) + : fb_info_(info), cursor_pos_(0) { uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch(); fb_memory_ = OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(), buff_size_bytes); @@ -11,3 +12,18 @@ 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 index 7e82a10..78f859b 100644 --- a/sys/teton/framebuffer/framebuffer.h +++ b/sys/teton/framebuffer/framebuffer.h @@ -9,6 +9,8 @@ class Framebuffer { void DrawPixel(uint32_t row, uint32_t col, uint32_t pixel); + void DrawGlyph(uint8_t* glyph); + private: // FIXME: Implement Yunq copy or move so we // don't have to store a reference here. @@ -16,4 +18,5 @@ class Framebuffer { OwnedMemoryRegion fb_memory_; uint32_t* fb_; + uint32_t cursor_pos_; }; diff --git a/sys/teton/framebuffer/psf.cpp b/sys/teton/framebuffer/psf.cpp new file mode 100644 index 0000000..0c78ac1 --- /dev/null +++ b/sys/teton/framebuffer/psf.cpp @@ -0,0 +1,46 @@ +#include "framebuffer/psf.h" + +#include +#include + +namespace { + +const uint32_t kMagic = 0x864AB572; + +} + +Psf::Psf(OwnedMemoryRegion&& psf_file) + : psf_file_(glcr::Move(psf_file)), + header_(reinterpret_cast(psf_file_.vaddr())) { + EnsureValid(); +} + +void Psf::DumpHeader() { + 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); +} + +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 new file mode 100644 index 0000000..038cee4 --- /dev/null +++ b/sys/teton/framebuffer/psf.h @@ -0,0 +1,34 @@ +#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(OwnedMemoryRegion&& psf_file); + + void DumpHeader(); + + uint32_t size() { return header_->numglyph; } + + uint8_t* glyph(uint32_t index) { + return reinterpret_cast(psf_file_.vaddr() + header_->headersize + + (index * header_->bytesperglyph)); + } + + private: + OwnedMemoryRegion psf_file_; + PsfHeader* header_; + + void EnsureValid(); +}; diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp index 3a9cae2..cbd8f72 100644 --- a/sys/teton/teton.cpp +++ b/sys/teton/teton.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include "framebuffer/framebuffer.h" +#include "framebuffer/psf.h" uint64_t main(uint64_t init_port) { ParseInitPort(init_port); @@ -28,6 +30,23 @@ uint64_t main(uint64_t init_port) { // 2. Parse a font file. + GetEndpointRequest req; + req.set_endpoint_name("victoriafalls"); + Endpoint resp; + check(client.GetEndpoint(req, resp)); + + VFSClient vfs(resp.endpoint()); + + OpenFileRequest freq; + freq.set_path("/default8x16.psfu"); + OpenFileResponse fresp; + check(vfs.OpenFile(freq, fresp)); + + Psf psf(OwnedMemoryRegion::FromCapability(fresp.memory())); + psf.DumpHeader(); + + fbuf.DrawGlyph(psf.glyph('C')); + // 3. Write a line to the screen. return 0; diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq b/sys/yellowstone/lib/yellowstone/yellowstone.yunq index 0022629..e6c1680 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq @@ -1,5 +1,6 @@ interface Yellowstone { method RegisterEndpoint(RegisterEndpointRequest) -> (Empty); + method GetEndpoint(GetEndpointRequest) -> (Endpoint); method GetAhciInfo(Empty) -> (AhciInfo); method GetFramebufferInfo(Empty) -> (FramebufferInfo); method GetDenali(Empty) -> (DenaliInfo); @@ -14,6 +15,14 @@ message Empty { } +message GetEndpointRequest { + string endpoint_name; +} + +message Endpoint { + capability endpoint; +} + message AhciInfo { capability ahci_region; u64 region_length; diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp index d1d2f69..1c2f74f 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.cpp @@ -40,7 +40,7 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques -glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& response) { +glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) { uint64_t buffer_size = kBufferSize; uint64_t cap_size = kCapBufferSize; @@ -72,7 +72,7 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& r -glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, FramebufferInfo& response) { +glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& response) { uint64_t buffer_size = kBufferSize; uint64_t cap_size = kCapBufferSize; @@ -104,7 +104,7 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, Fram -glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& response) { +glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(const Empty& request, FramebufferInfo& response) { uint64_t buffer_size = kBufferSize; uint64_t cap_size = kCapBufferSize; @@ -135,3 +135,35 @@ glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& r } + +glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& response) { + uint64_t buffer_size = kBufferSize; + uint64_t cap_size = kCapBufferSize; + + const uint32_t kSentinel = 0xBEEFDEAD; + buffer_.WriteAt(0, kSentinel); + buffer_.WriteAt(8, 4); + + cap_buffer_.Reset(); + uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); + buffer_.WriteAt(4, 16 + length); + + z_cap_t reply_port_cap; + RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); + + // FIXME: Add a way to zero out the first buffer. + RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); + + if (buffer_.At(0) != kSentinel) { + return glcr::INVALID_RESPONSE; + } + + // Check Response Code. + RET_ERR(buffer_.At(8)); + + response.ParseFromBytes(buffer_, 16, cap_buffer_); + + return glcr::OK; +} + + diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h index 9b3c035..a03f375 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.client.h @@ -19,6 +19,8 @@ class YellowstoneClient { [[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response); + [[nodiscard]] glcr::ErrorCode GetEndpoint(const GetEndpointRequest& request, Endpoint& response); + [[nodiscard]] glcr::ErrorCode GetAhciInfo(const Empty& request, AhciInfo& response); [[nodiscard]] glcr::ErrorCode GetFramebufferInfo(const Empty& request, FramebufferInfo& response); diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp index f2c56f0..c3394cb 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.cpp @@ -134,6 +134,113 @@ uint64_t Empty::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr: return next_extension; } +void GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { + ParseFromBytesInternal(bytes, offset); +} + +void GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { + ParseFromBytesInternal(bytes, offset); +} + +void GetEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { + CheckHeader(bytes); + // Parse endpoint_name. + auto endpoint_name_pointer = bytes.At(offset + header_size + (8 * 0)); + + set_endpoint_name(bytes.StringAt(offset + endpoint_name_pointer.offset, endpoint_name_pointer.length)); + +} + +uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { + uint32_t next_extension = header_size + 8 * 1; + const uint32_t core_size = next_extension; + // Write endpoint_name. + ExtPointer endpoint_name_ptr{ + .offset = next_extension, + // FIXME: Check downcast of str length. + .length = (uint32_t)endpoint_name().length(), + }; + + bytes.WriteStringAt(offset + next_extension, endpoint_name()); + next_extension += endpoint_name_ptr.length; + + bytes.WriteAt(offset + header_size + (8 * 0), endpoint_name_ptr); + + // The next extension pointer is the length of the message. + WriteHeader(bytes, offset, core_size, next_extension); + + return next_extension; +} + +uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { + uint32_t next_extension = header_size + 8 * 1; + const uint32_t core_size = next_extension; + uint64_t next_cap = 0; + // Write endpoint_name. + ExtPointer endpoint_name_ptr{ + .offset = next_extension, + // FIXME: Check downcast of str length. + .length = (uint32_t)endpoint_name().length(), + }; + + bytes.WriteStringAt(offset + next_extension, endpoint_name()); + next_extension += endpoint_name_ptr.length; + + bytes.WriteAt(offset + header_size + (8 * 0), endpoint_name_ptr); + + // The next extension pointer is the length of the message. + WriteHeader(bytes, offset, core_size, next_extension); + + return next_extension; +} +void Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { + ParseFromBytesInternal(bytes, offset); + // Parse endpoint. + // FIXME: Implement in-buffer capabilities for inprocess serialization. + set_endpoint(0); +} + +void Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) { + ParseFromBytesInternal(bytes, offset); + // Parse endpoint. + uint64_t endpoint_ptr = bytes.At(offset + header_size + (8 * 0)); + + set_endpoint(caps.At(endpoint_ptr)); +} + +void Endpoint::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) { + CheckHeader(bytes); + // Parse endpoint. + // Skip Cap. + +} + +uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { + uint32_t next_extension = header_size + 8 * 1; + const uint32_t core_size = next_extension; + // Write endpoint. + // FIXME: Implement inbuffer capabilities. + bytes.WriteAt(offset + header_size + (8 * 0), 0); + + // The next extension pointer is the length of the message. + WriteHeader(bytes, offset, core_size, next_extension); + + return next_extension; +} + +uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { + uint32_t next_extension = header_size + 8 * 1; + const uint32_t core_size = next_extension; + uint64_t next_cap = 0; + // Write endpoint. + caps.WriteAt(next_cap, endpoint()); + bytes.WriteAt(offset + header_size + (8 * 0), next_cap++); + + // The next extension pointer is the length of the message. + WriteHeader(bytes, offset, core_size, next_extension); + + return next_extension; +} void AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { ParseFromBytesInternal(bytes, offset); // Parse ahci_region. diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h index 797240f..d9ebc14 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.h @@ -46,6 +46,46 @@ class Empty { // Parses everything except for caps. void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); }; +class GetEndpointRequest { + public: + GetEndpointRequest() {} + // Delete copy and move until implemented. + GetEndpointRequest(const GetEndpointRequest&) = delete; + GetEndpointRequest(GetEndpointRequest&&) = delete; + + void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset); + void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; + const glcr::String& endpoint_name() const { return endpoint_name_; } + void set_endpoint_name(const glcr::String& value) { endpoint_name_ = value; } + + private: + glcr::String endpoint_name_; + + // Parses everything except for caps. + void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); +}; +class Endpoint { + public: + Endpoint() {} + // Delete copy and move until implemented. + Endpoint(const Endpoint&) = delete; + Endpoint(Endpoint&&) = delete; + + void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset); + void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&); + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; + const z_cap_t& endpoint() const { return endpoint_; } + void set_endpoint(const z_cap_t& value) { endpoint_ = value; } + + private: + z_cap_t endpoint_; + + // Parses everything except for caps. + void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset); +}; class AhciInfo { public: AhciInfo() {} diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp index 199eaf1..d57144f 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp @@ -98,6 +98,17 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req break; } case 1: { + GetEndpointRequest yunq_request; + Endpoint yunq_response; + + yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); + + RET_ERR(HandleGetEndpoint(yunq_request, yunq_response)); + + resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); + break; + } + case 2: { Empty yunq_request; AhciInfo yunq_response; @@ -108,7 +119,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); break; } - case 2: { + case 3: { Empty yunq_request; FramebufferInfo yunq_response; @@ -119,7 +130,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); break; } - case 3: { + case 4: { Empty yunq_request; DenaliInfo yunq_response; diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h index 41e7901..92b4ae3 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.h @@ -23,6 +23,8 @@ class YellowstoneServerBase { [[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, Empty&) = 0; + [[nodiscard]] virtual glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0; + [[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) = 0; [[nodiscard]] virtual glcr::ErrorCode HandleGetFramebufferInfo(const Empty&, FramebufferInfo&) = 0; diff --git a/sys/yellowstone/yellowstone_server.cpp b/sys/yellowstone/yellowstone_server.cpp index 509f45f..d6a26c7 100644 --- a/sys/yellowstone/yellowstone_server.cpp +++ b/sys/yellowstone/yellowstone_server.cpp @@ -82,8 +82,11 @@ glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo( glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&, DenaliInfo& info) { + if (!endpoint_map_.Contains("denali")) { + return glcr::NOT_FOUND; + } z_cap_t new_denali; - check(ZCapDuplicate(denali_cap_, kZionPerm_All, &new_denali)); + check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali)); info.set_denali_endpoint(new_denali); info.set_device_id(device_id_); info.set_lba_offset(lba_offset_); @@ -93,11 +96,9 @@ glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&, glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( const RegisterEndpointRequest& req, Empty&) { dbgln("Registering {}.", req.endpoint_name().view()); + check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability())); if (req.endpoint_name() == "denali") { - // FIXME: Rather than blocking and calling the denali service - // immediately we should signal the main thread that it can continue init. - denali_cap_ = req.endpoint_capability(); - auto part_info_or = HandleDenaliRegistration(denali_cap_); + auto part_info_or = HandleDenaliRegistration(req.endpoint_capability()); if (!part_info_or.ok()) { check(part_info_or.error()); } @@ -106,10 +107,9 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( check(has_denali_mutex_.Release()); } else if (req.endpoint_name() == "victoriafalls") { - victoria_falls_cap_ = req.endpoint_capability(); // FIXME: Probably make a separate copy for use within yellowstone vs // transmit to other processes. - vfs_client_ = glcr::MakeShared(victoria_falls_cap_); + vfs_client_ = glcr::MakeShared(req.endpoint_capability()); check(has_victoriafalls_mutex_.Release()); } else { dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); @@ -117,6 +117,18 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( return glcr::OK; } +glcr::ErrorCode YellowstoneServer::HandleGetEndpoint( + const GetEndpointRequest& req, Endpoint& resp) { + if (!endpoint_map_.Contains(req.endpoint_name())) { + return glcr::NOT_FOUND; + } + z_cap_t cap = endpoint_map_.at(req.endpoint_name()); + z_cap_t new_cap; + check(ZCapDuplicate(cap, kZionPerm_All, &new_cap)); + resp.set_endpoint(new_cap); + return glcr::OK; +} + glcr::ErrorCode YellowstoneServer::WaitDenaliRegistered() { RET_ERR(has_denali_mutex_.Lock()); return has_denali_mutex_.Release(); diff --git a/sys/yellowstone/yellowstone_server.h b/sys/yellowstone/yellowstone_server.h index 3606441..c7c279b 100644 --- a/sys/yellowstone/yellowstone_server.h +++ b/sys/yellowstone/yellowstone_server.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -22,6 +23,8 @@ class YellowstoneServer : public YellowstoneServerBase { glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) override; glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, Empty&) override; + glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, + Endpoint&) override; glcr::ErrorCode WaitDenaliRegistered(); glcr::ErrorCode WaitVictoriaFallsRegistered(); @@ -29,11 +32,10 @@ class YellowstoneServer : public YellowstoneServerBase { glcr::SharedPtr GetVFSClient(); private: - // TODO: Store these in a data structure. - z_cap_t denali_cap_ = 0; + glcr::HashMap endpoint_map_; + uint64_t device_id_ = 0; uint64_t lba_offset_ = 0; - z_cap_t victoria_falls_cap_ = 0; glcr::SharedPtr vfs_client_; PciReader pci_reader_; diff --git a/sysroot/default8x16.psfu b/sysroot/default8x16.psfu new file mode 100644 index 0000000000000000000000000000000000000000..e789b77189b9c3e585075eeed5a5eba693f3c435 GIT binary patch literal 4969 zcmZu!TWlO>6&`}L;$h{6w-K?N0^xq?(t@+JgAJkF3KS@m`(;VWHo(xD0*;}>W}P~& zLoL*ccN5dnI7yQ<7bp!)5NV<;Gt!6$Yx9OyT4P1?V80+_sZ!#HXg|L5UuI`qj{VQf z`Oo*C|J?pFvyYs=XWAj%%JBwy;AJy!GTtQo>!>z)d~)*g{N!X!i)!cs(JEkg$MJil zpe!mBZ7v5{*7dyA)m7K^jM(*RT-@h5O^Bd}QQ9 z18=!~Vv#hVHF#B$=W+whkKQp_B8{zG)BN6Ddv}o@TwQ7D3D@m#b{R>%H~0 zYpuExZz>E7jr2x_1`3-D+@or@W({^^I}-0&zPH=$KDtFn@j+ZE`*G}-i*cX<>M9}A zEW@GonRsfRQ^tOIBK0?9xQe}^kt!XfO0QDND0f<|meHa`7h)B;MLkn;i;CR7hgA=riMGNpI(9Fsg@$AnIBBh>a_bK#HWkD^lW!-8 z<1T4UbKP$rrprp*JM{8{=iFA~Nw<7)Sgq(z{fl?6MhxS@%U)t@`U)-mC81J+Zs8vufgH_)29h zvwk^_t9NQ%c2e7!{iOI5d0IZCs-b`0SGd*01UFsL^0kVhbU*1N-AKsjU%B2}Zuk9B zu@=_&tNarc#y%te*K$xC5DiK$KAQa~uat|0bUnKBIeSI5BBNiK5=CrL+8)JsyRiL3 ziCnL0?WLSplJOtWv?T8zk?xI-r;kgiWaJJz*jRZm?N^>YKE3MaoRVor~7C{OLVitgn-ynDL2{-3kKtaqyVC7~1fr`qJi7(~j0$&V@s)bX( zKQ8)Bd|8@h6;R_}q2LVgIFQ)pxtMre00ytY{df_w0`}x?mrt6OM7@nSr*w+@{%CoS zmVmX-9_gj=YQH|zdRBn-Z*!@1Q&KWKXm)cPVx(*}>xlDJe{lPx{i6d$yDkEwmeZi%EK!<%=Fopq#~vb5DQ29e^;d>+5mP4ULQ?baW4 z-(DI`can$EQeJ+;N%bonoEsa~r+6bz@d|gNk5~4gug~a7@pk=2|8n~c52yAj9Q{-4 z>?Px`nHt@&9+ubksN-t4l>5efrSVfgf-)DQKb=|IK(}ll1GJXv`}k6)(^=Br=Z^fg z>MXJav9SyB+l+@%NH`(+{1?(30qkl0_Y-GpRM%16MM2cdmmRic7K|@xR}EWZ3s=A3 z3~$;q+k_%vW7+P%njhll?1-q;{YfTkeA(Bul-D;F$iG&z+YOc~(%vhjL4&aUHMT2w zSoFV{Fh4JBO_ziR^`9N7mVR!_9&D2Q*QENPdG6or%RHTN z?b9vl^X@;s?`eNJ5*nKdg2pPX;Q<%dU9|I$#jDYFCn~u@FZo#OuxwS6vs0h zPjftpWae-(OO4ZWgq-8Jgj>Ufq+U9|WFt($NkK#_;1rHy?2uAU7 zd;&Z0N!*Q3;nVmGK8w%c9(*2Oz!z~ZzJxF1E4U9|#n*5@zK(C;oA?&Kjql*Q_#VEG zAE1ICVkdUt0sIJ6Jc!-+F@A!d!pG0>5FW-DevU`*3;Ytl!Z`L|0>8#@@F)WO7BwWZ z`w%^j=n|q+h>jw90nq}Y(2!XgILk2pjqD7{%D_#bt?PtX7W literal 0 HcmV?d00001