[Teton] Load a font file and write a character to the screen.

This commit is contained in:
Drew Galbraith 2023-11-21 19:14:02 -08:00
parent 96063126cb
commit fe44804dd9
19 changed files with 412 additions and 17 deletions

View file

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

View file

@ -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<uint32_t>(0, kSentinel);
buffer_.WriteAt<uint64_t>(8, 4);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(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<uint32_t>(0) != kSentinel) {
return glcr::INVALID_RESPONSE;
}
// Check Response Code.
RET_ERR(buffer_.At<uint64_t>(8));
response.ParseFromBytes(buffer_, 16, cap_buffer_);
return glcr::OK;
}

View file

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

View file

@ -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<ExtPointer>(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<ExtPointer>(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<ExtPointer>(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<uint64_t>(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<uint64_t>(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<uint64_t>(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.

View file

@ -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() {}

View file

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

View file

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

View file

@ -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<VFSClient>(victoria_falls_cap_);
vfs_client_ = glcr::MakeShared<VFSClient>(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();

View file

@ -1,5 +1,6 @@
#pragma once
#include <glacier/container/hash_map.h>
#include <glacier/memory/shared_ptr.h>
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
@ -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<VFSClient> GetVFSClient();
private:
// TODO: Store these in a data structure.
z_cap_t denali_cap_ = 0;
glcr::HashMap<glcr::String, z_cap_t> endpoint_map_;
uint64_t device_id_ = 0;
uint64_t lba_offset_ = 0;
z_cap_t victoria_falls_cap_ = 0;
glcr::SharedPtr<VFSClient> vfs_client_;
PciReader pci_reader_;