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