Compare commits
No commits in common. "8365d47cbedfe54274d2deac9ff7f8e323905ea2" and "838ef01a2a767c6fcf033d30b48b26a805c02d51" have entirely different histories.
8365d47cbe
...
838ef01a2a
|
@ -15,8 +15,4 @@ glcr::ErrorCode PortClient::WriteString(glcr::String str, z_cap_t cap) {
|
||||||
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
|
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode PortClient::WriteByte(uint8_t byte) {
|
|
||||||
return static_cast<glcr::ErrorCode>(
|
|
||||||
ZPortSend(port_cap_, 1, &byte, 0, nullptr));
|
|
||||||
}
|
|
||||||
} // namespace mmth
|
} // namespace mmth
|
||||||
|
|
|
@ -17,8 +17,6 @@ class PortClient {
|
||||||
|
|
||||||
glcr::ErrorCode WriteString(glcr::String str, z_cap_t cap);
|
glcr::ErrorCode WriteString(glcr::String str, z_cap_t cap);
|
||||||
|
|
||||||
glcr::ErrorCode WriteByte(uint8_t byte);
|
|
||||||
|
|
||||||
z_cap_t cap() { return port_cap_; }
|
z_cap_t cap() { return port_cap_; }
|
||||||
|
|
||||||
bool empty() { return port_cap_ == 0; }
|
bool empty() { return port_cap_ == 0; }
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace mmth {
|
||||||
|
|
||||||
class PortServer {
|
class PortServer {
|
||||||
public:
|
public:
|
||||||
PortServer() {}
|
|
||||||
static glcr::ErrorOr<PortServer> Create();
|
static glcr::ErrorOr<PortServer> Create();
|
||||||
static PortServer AdoptCap(z_cap_t cap);
|
static PortServer AdoptCap(z_cap_t cap);
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,25 @@ void dbgln(glcr::StringView string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(uint64_t code) {
|
void check(uint64_t code) {
|
||||||
if (code == glcr::OK) {
|
switch (code) {
|
||||||
|
case glcr::OK:
|
||||||
return;
|
return;
|
||||||
|
case glcr::UNIMPLEMENTED:
|
||||||
|
dbgln("crash: UNIMPLEMENTED");
|
||||||
|
break;
|
||||||
|
case glcr::CAP_NOT_FOUND:
|
||||||
|
dbgln("crash: missing capability");
|
||||||
|
break;
|
||||||
|
case glcr::CAP_WRONG_TYPE:
|
||||||
|
dbgln("crash: capability of the wrong type");
|
||||||
|
break;
|
||||||
|
case glcr::CAP_PERMISSION_DENIED:
|
||||||
|
dbgln("crash: capability permissions error");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dbgln("Unhandled code");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
dbgln("crash!");
|
|
||||||
(void)ZProcessExit(code);
|
(void)ZProcessExit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||||
add_subdirectory(denali)
|
add_subdirectory(denali)
|
||||||
add_subdirectory(teton)
|
add_subdirectory(teton)
|
||||||
add_subdirectory(victoriafalls)
|
add_subdirectory(victoriafalls)
|
||||||
add_subdirectory(voyageurs)
|
|
||||||
add_subdirectory(yellowstone)
|
add_subdirectory(yellowstone)
|
||||||
|
|
||||||
set(SYS_BUNDLE
|
set(SYS_BUNDLE
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
add_executable(voyageurs
|
|
||||||
keyboard/keyboard_driver.cpp
|
|
||||||
voyageurs_server.cpp
|
|
||||||
voyageurs.cpp)
|
|
||||||
|
|
||||||
target_include_directories(voyageurs
|
|
||||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
|
|
||||||
target_link_libraries(voyageurs
|
|
||||||
glacier
|
|
||||||
mammoth
|
|
||||||
voyageurs_yunq
|
|
||||||
yellowstone_yunq
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(voyageurs PROPERTIES
|
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
|
||||||
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS voyageurs)
|
|
||||||
|
|
||||||
yunq_gen(lib/voyageurs lib voyageurs)
|
|
|
@ -1,34 +0,0 @@
|
||||||
#include "keyboard/keyboard_driver.h"
|
|
||||||
|
|
||||||
#include <mammoth/util/debug.h>
|
|
||||||
|
|
||||||
void InterruptEnter(void* void_keyboard) {
|
|
||||||
KeyboardDriver* keyboard = static_cast<KeyboardDriver*>(void_keyboard);
|
|
||||||
|
|
||||||
keyboard->InterruptLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyboardDriver::KeyboardDriver() { check(ZIrqRegister(kZIrqKbd, &irq_cap_)); }
|
|
||||||
|
|
||||||
void KeyboardDriver::RegisterListener(uint64_t port_cap) {
|
|
||||||
listeners_.PushFront(mmth::PortClient::AdoptPort(port_cap));
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread KeyboardDriver::StartInterruptLoop() {
|
|
||||||
return Thread(InterruptEnter, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyboardDriver::InterruptLoop() {
|
|
||||||
dbgln("Interrupt");
|
|
||||||
while (true) {
|
|
||||||
uint8_t scancode;
|
|
||||||
uint64_t num_bytes = 1;
|
|
||||||
uint64_t num_caps = 0;
|
|
||||||
check(ZPortRecv(irq_cap_, &num_bytes, &scancode, &num_caps, nullptr));
|
|
||||||
dbgln("Scan {x}", scancode);
|
|
||||||
|
|
||||||
for (mmth::PortClient& client : listeners_) {
|
|
||||||
client.WriteByte(scancode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glacier/container/linked_list.h>
|
|
||||||
#include <mammoth/ipc/port_client.h>
|
|
||||||
#include <mammoth/ipc/port_server.h>
|
|
||||||
#include <mammoth/proc/thread.h>
|
|
||||||
|
|
||||||
class KeyboardDriver {
|
|
||||||
public:
|
|
||||||
KeyboardDriver();
|
|
||||||
KeyboardDriver(const KeyboardDriver&) = delete;
|
|
||||||
KeyboardDriver(KeyboardDriver&&) = delete;
|
|
||||||
|
|
||||||
void RegisterListener(uint64_t port_cap);
|
|
||||||
|
|
||||||
Thread StartInterruptLoop();
|
|
||||||
void InterruptLoop();
|
|
||||||
|
|
||||||
private:
|
|
||||||
z_cap_t irq_cap_;
|
|
||||||
glcr::LinkedList<mmth::PortClient> listeners_;
|
|
||||||
};
|
|
|
@ -1,12 +0,0 @@
|
||||||
interface Voyageurs {
|
|
||||||
method RegisterKeyboardListener(KeyboardListener) -> (None);
|
|
||||||
}
|
|
||||||
|
|
||||||
message KeyboardListener {
|
|
||||||
capability port_capability;
|
|
||||||
}
|
|
||||||
|
|
||||||
message None {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
// Generated file - DO NOT MODIFY
|
|
||||||
#include "voyageurs.yunq.client.h"
|
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
|
||||||
#include <zcall.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request, None& 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, 0);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Generated file - DO NOT MODIFY
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
|
||||||
#include <glacier/status/error.h>
|
|
||||||
#include <ztypes.h>
|
|
||||||
|
|
||||||
#include "voyageurs.yunq.h"
|
|
||||||
|
|
||||||
class VoyageursClient {
|
|
||||||
public:
|
|
||||||
VoyageursClient(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
|
|
||||||
VoyageursClient(const VoyageursClient&) = delete;
|
|
||||||
VoyageursClient(VoyageursClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
|
|
||||||
|
|
||||||
z_cap_t Capability() { return endpoint_; }
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode RegisterKeyboardListener(const KeyboardListener& request, None& response);
|
|
||||||
|
|
||||||
private:
|
|
||||||
z_cap_t endpoint_;
|
|
||||||
uint64_t kBufferSize = 0x1000;
|
|
||||||
glcr::ByteBuffer buffer_{kBufferSize};
|
|
||||||
uint64_t kCapBufferSize = 0x10;
|
|
||||||
glcr::CapBuffer cap_buffer_{kCapBufferSize};
|
|
||||||
};
|
|
|
@ -1,110 +0,0 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
|
||||||
#include "voyageurs.yunq.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
|
||||||
|
|
||||||
struct ExtPointer {
|
|
||||||
uint32_t offset;
|
|
||||||
uint32_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
// Parse port_capability.
|
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
|
||||||
set_port_capability(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
// Parse port_capability.
|
|
||||||
uint64_t port_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
|
||||||
|
|
||||||
set_port_capability(caps.At(port_capability_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeyboardListener::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
CheckHeader(bytes);
|
|
||||||
// Parse port_capability.
|
|
||||||
// Skip Cap.
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
|
||||||
uint32_t next_extension = header_size + 8 * 1;
|
|
||||||
const uint32_t core_size = next_extension;
|
|
||||||
// Write port_capability.
|
|
||||||
// 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 KeyboardListener::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 port_capability.
|
|
||||||
caps.WriteAt(next_cap, port_capability());
|
|
||||||
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 None::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void None::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
|
||||||
ParseFromBytesInternal(bytes, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void None::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
|
||||||
CheckHeader(bytes);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t None::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
|
||||||
uint32_t next_extension = header_size + 8 * 0;
|
|
||||||
const uint32_t core_size = next_extension;
|
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
|
||||||
|
|
||||||
return next_extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t None::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
|
||||||
uint32_t next_extension = header_size + 8 * 0;
|
|
||||||
const uint32_t core_size = next_extension;
|
|
||||||
uint64_t next_cap = 0;
|
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
|
||||||
|
|
||||||
return next_extension;
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
// Generated file - DO NOT MODIFY
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
|
||||||
#include <glacier/container/vector.h>
|
|
||||||
#include <glacier/string/string.h>
|
|
||||||
#include <ztypes.h>
|
|
||||||
class KeyboardListener {
|
|
||||||
public:
|
|
||||||
KeyboardListener() {}
|
|
||||||
// Delete copy and move until implemented.
|
|
||||||
KeyboardListener(const KeyboardListener&) = delete;
|
|
||||||
KeyboardListener(KeyboardListener&&) = 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& port_capability() const { return port_capability_; }
|
|
||||||
void set_port_capability(const z_cap_t& value) { port_capability_ = value; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
z_cap_t port_capability_;
|
|
||||||
|
|
||||||
// Parses everything except for caps.
|
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
|
||||||
};
|
|
||||||
class None {
|
|
||||||
public:
|
|
||||||
None() {}
|
|
||||||
// Delete copy and move until implemented.
|
|
||||||
None(const None&) = delete;
|
|
||||||
None(None&&) = 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;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Parses everything except for caps.
|
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
|
||||||
};
|
|
|
@ -1,105 +0,0 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
|
||||||
#include "voyageurs.yunq.server.h"
|
|
||||||
|
|
||||||
#include <mammoth/util/debug.h>
|
|
||||||
#include <zcall.h>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const uint32_t kSentinel = 0xBEEFDEAD;
|
|
||||||
const uint32_t kHeaderSize = 0x10;
|
|
||||||
|
|
||||||
void WriteError(glcr::ByteBuffer& buffer, glcr::ErrorCode err) {
|
|
||||||
buffer.WriteAt<uint32_t>(0, kSentinel);
|
|
||||||
buffer.WriteAt<uint32_t>(4, kHeaderSize);
|
|
||||||
buffer.WriteAt<uint64_t>(8, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& buffer, uint64_t message_length) {
|
|
||||||
buffer.WriteAt<uint32_t>(0, kSentinel);
|
|
||||||
buffer.WriteAt<uint32_t>(4, kHeaderSize + message_length);
|
|
||||||
buffer.WriteAt<uint64_t>(8, glcr::OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void VoyageursServerBaseThreadBootstrap(void* server_base) {
|
|
||||||
((VoyageursServerBase*)server_base)->ServerThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
glcr::ErrorOr<VoyageursClient> VoyageursServerBase::CreateClient() {
|
|
||||||
uint64_t client_cap;
|
|
||||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
|
||||||
return VoyageursClient(client_cap);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread VoyageursServerBase::RunServer() {
|
|
||||||
return Thread(VoyageursServerBaseThreadBootstrap, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoyageursServerBase::ServerThread() {
|
|
||||||
glcr::ByteBuffer recv_buffer(0x1000);
|
|
||||||
glcr::CapBuffer recv_cap(0x10);
|
|
||||||
glcr::ByteBuffer resp_buffer(0x1000);
|
|
||||||
glcr::CapBuffer resp_cap(0x10);
|
|
||||||
z_cap_t reply_port_cap;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
uint64_t recv_cap_size = 0x10;
|
|
||||||
uint64_t recv_buf_size = 0x1000;
|
|
||||||
recv_cap.Reset();
|
|
||||||
glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap));
|
|
||||||
if (recv_err != glcr::OK) {
|
|
||||||
dbgln("Error in receive: {x}", recv_err);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t resp_length = 0;
|
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
|
||||||
resp_cap.Reset();
|
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
|
||||||
if (err != glcr::OK) {
|
|
||||||
WriteError(resp_buffer, err);
|
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
|
||||||
} else {
|
|
||||||
WriteHeader(resp_buffer, resp_length);
|
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()));
|
|
||||||
}
|
|
||||||
if (reply_err != glcr::OK) {
|
|
||||||
dbgln("Error in reply: {x}", reply_err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
|
||||||
const glcr::CapBuffer& req_caps,
|
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
|
||||||
glcr::CapBuffer& resp_caps) {
|
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
|
||||||
return glcr::INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
|
||||||
|
|
||||||
switch(method_select) {
|
|
||||||
case 0: {
|
|
||||||
KeyboardListener yunq_request;
|
|
||||||
None yunq_response;
|
|
||||||
|
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
|
||||||
|
|
||||||
RET_ERR(HandleRegisterKeyboardListener(yunq_request, yunq_response));
|
|
||||||
|
|
||||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return glcr::UNIMPLEMENTED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return glcr::OK;
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
// Generated File -- DO NOT MODIFY.
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
|
||||||
#include <mammoth/proc/thread.h>
|
|
||||||
#include <ztypes.h>
|
|
||||||
|
|
||||||
#include "voyageurs.yunq.h"
|
|
||||||
#include "voyageurs.yunq.client.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VoyageursServerBase {
|
|
||||||
public:
|
|
||||||
VoyageursServerBase(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
|
|
||||||
VoyageursServerBase(const VoyageursServerBase&) = delete;
|
|
||||||
VoyageursServerBase(VoyageursServerBase&&) = delete;
|
|
||||||
|
|
||||||
glcr::ErrorOr<VoyageursClient> CreateClient();
|
|
||||||
|
|
||||||
[[nodiscard]] Thread RunServer();
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&, None&) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
z_cap_t endpoint_;
|
|
||||||
|
|
||||||
friend void VoyageursServerBaseThreadBootstrap(void*);
|
|
||||||
void ServerThread();
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
|
||||||
glcr::CapBuffer& resp_caps);
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
#include <mammoth/util/debug.h>
|
|
||||||
#include <mammoth/util/init.h>
|
|
||||||
|
|
||||||
#include "keyboard/keyboard_driver.h"
|
|
||||||
#include "voyageurs_server.h"
|
|
||||||
|
|
||||||
uint64_t main(uint64_t init_port) {
|
|
||||||
ParseInitPort(init_port);
|
|
||||||
|
|
||||||
dbgln("Initializing PS/2 Driver.");
|
|
||||||
KeyboardDriver driver;
|
|
||||||
|
|
||||||
dbgln("Starting PS/2 Thread.");
|
|
||||||
Thread keyboard_thread = driver.StartInterruptLoop();
|
|
||||||
|
|
||||||
dbgln("Starting voyaguers server.");
|
|
||||||
ASSIGN_OR_RETURN(glcr::UniquePtr<VoyageursServer> server,
|
|
||||||
VoyageursServer::Create(driver));
|
|
||||||
|
|
||||||
Thread server_thread = server->RunServer();
|
|
||||||
|
|
||||||
check(server_thread.Join());
|
|
||||||
check(keyboard_thread.Join());
|
|
||||||
|
|
||||||
return glcr::OK;
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
#include "voyageurs_server.h"
|
|
||||||
|
|
||||||
glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> VoyageursServer::Create(
|
|
||||||
KeyboardDriver& keyboard_driver) {
|
|
||||||
z_cap_t cap;
|
|
||||||
RET_ERR(ZEndpointCreate(&cap));
|
|
||||||
return glcr::UniquePtr<VoyageursServer>(
|
|
||||||
new VoyageursServer(cap, keyboard_driver));
|
|
||||||
}
|
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener(
|
|
||||||
const KeyboardListener& listener, None&) {
|
|
||||||
keyboard_driver_.RegisterListener(listener.port_capability());
|
|
||||||
return glcr::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap,
|
|
||||||
KeyboardDriver& keyboard_driver)
|
|
||||||
: VoyageursServerBase(voyageurs_cap), keyboard_driver_(keyboard_driver) {}
|
|
|
@ -1,20 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glacier/memory/unique_ptr.h>
|
|
||||||
#include <glacier/status/error_or.h>
|
|
||||||
|
|
||||||
#include "keyboard/keyboard_driver.h"
|
|
||||||
#include "voyageurs/voyageurs.yunq.server.h"
|
|
||||||
|
|
||||||
class VoyageursServer : public VoyageursServerBase {
|
|
||||||
public:
|
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create(
|
|
||||||
KeyboardDriver& keyboard_driver);
|
|
||||||
|
|
||||||
virtual glcr::ErrorCode HandleRegisterKeyboardListener(
|
|
||||||
const KeyboardListener& listener, None&) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
KeyboardDriver& keyboard_driver_;
|
|
||||||
VoyageursServer(z_cap_t voyageurs_cap, KeyboardDriver& keyboard_driver);
|
|
||||||
};
|
|
|
@ -1,3 +1,2 @@
|
||||||
voyageurs
|
|
||||||
teton
|
teton
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ class Parser():
|
||||||
def consume_check(self, lex_type: LexemeType):
|
def consume_check(self, lex_type: LexemeType):
|
||||||
tok = self.consume()
|
tok = self.consume()
|
||||||
if tok.type != lex_type:
|
if tok.type != lex_type:
|
||||||
sys.exit("Expected %s got %s" % (lex_type, tok.type))
|
sys.exit("Expected %s got %s" % (lex_type, tok_type))
|
||||||
|
|
||||||
def consume_check_identifier(self, name: str):
|
def consume_check_identifier(self, name: str):
|
||||||
tok = self.consume()
|
tok = self.consume()
|
||||||
|
|
|
@ -15,8 +15,7 @@ class DriverManager {
|
||||||
|
|
||||||
void WriteMessage(uint64_t irq_num, IpcMessage&& message);
|
void WriteMessage(uint64_t irq_num, IpcMessage&& message);
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode RegisterListener(uint64_t irq_num,
|
glcr::ErrorCode RegisterListener(uint64_t irq_num, glcr::RefPtr<Port> port);
|
||||||
glcr::RefPtr<Port> port);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glcr::HashMap<uint64_t, glcr::RefPtr<Port>> driver_map_;
|
glcr::HashMap<uint64_t, glcr::RefPtr<Port>> driver_map_;
|
||||||
|
|
|
@ -160,9 +160,9 @@ glcr::ErrorCode IrqRegister(ZIrqRegisterReq* req) {
|
||||||
auto& proc = gScheduler->CurrentProcess();
|
auto& proc = gScheduler->CurrentProcess();
|
||||||
|
|
||||||
glcr::RefPtr<Port> port = glcr::MakeRefCounted<Port>();
|
glcr::RefPtr<Port> port = glcr::MakeRefCounted<Port>();
|
||||||
|
|
||||||
*req->port_cap = proc.AddNewCapability(port);
|
*req->port_cap = proc.AddNewCapability(port);
|
||||||
return DriverManager::Get().RegisterListener(req->irq_num, port);
|
DriverManager::Get().RegisterListener(req->irq_num, port);
|
||||||
|
return glcr::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode EndpointCreate(ZEndpointCreateReq* req) {
|
glcr::ErrorCode EndpointCreate(ZEndpointCreateReq* req) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool IsKernel(uint64_t addr) { return (addr & 0xFFFF'8000'0000'0000); }
|
bool IsKernel(uint64_t addr) { return (addr & 0xFFFF'FF80'0000'0000); }
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ glcr::ErrorCode ThreadStart(ZThreadStartReq* req) {
|
||||||
auto thread = cap->obj<Thread>();
|
auto thread = cap->obj<Thread>();
|
||||||
|
|
||||||
if (IsKernel(req->entry) || IsKernel(req->arg1) || IsKernel(req->arg2)) {
|
if (IsKernel(req->entry) || IsKernel(req->arg1) || IsKernel(req->arg2)) {
|
||||||
dbgln("Thread start invalid arg: rip {x}, rdi {x}, rsi {x}", req->entry,
|
|
||||||
req->arg1, req->arg2);
|
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue