[yellowstone] Add yellowstone server for endpoint registration.

This commit is contained in:
Drew Galbraith 2023-06-22 02:19:16 -07:00
parent 8dcb1ddabd
commit a46694d0f7
13 changed files with 248 additions and 31 deletions

View file

@ -2,6 +2,7 @@ add_executable(yellowstone
hw/gpt.cpp
hw/pcie.cpp
yellowstone.cpp
yellowstone_server.cpp
)
target_include_directories(yellowstone
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
@ -9,6 +10,7 @@ add_executable(yellowstone
target_link_libraries(yellowstone
cxx
mammoth_lib
glacier
libdenali
)
@ -16,3 +18,17 @@ set_target_properties(yellowstone PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)
add_library(yellowstonestub
stub/yellowstone_stub.cpp
)
target_include_directories(yellowstonestub
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
set_target_properties(yellowstonestub PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)

View file

@ -0,0 +1,12 @@
#pragma once
#include <stdint.h>
const uint64_t kYellowstoneGetAhci = 0x01;
const uint64_t kYellowstoneGetRegistration = 0x02;
struct YellowstoneGetReq {
uint64_t type;
};
struct YellowstoneGetRegistrationResp {};

View file

@ -0,0 +1,3 @@
// PLACEHOLDER
#include <stdint.h>
uint64_t a = 0;

View file

@ -1,4 +1,3 @@
#include <denali/denali.h>
#include <mammoth/debug.h>
#include <mammoth/endpoint_client.h>
#include <mammoth/init.h>
@ -7,32 +6,28 @@
#include "hw/gpt.h"
#include "hw/pcie.h"
#include "yellowstone_server.h"
uint64_t main(uint64_t port_cap) {
dbgln("Yellowstone Initializing.");
check(ParseInitPort(port_cap));
ASSIGN_OR_RETURN(YellowstoneServer server, YellowstoneServer::Create());
Thread server_thread = server.RunServer();
Thread registration_thread = server.RunRegistration();
DumpPciEDevices();
uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));
auto endpoint_or = SpawnProcessFromElfRegion(vaddr);
if (!endpoint_or) {
check(endpoint_or.error());
}
EndpointClient endpoint = endpoint_or.value();
DenaliClient client(endpoint);
GptReader reader(client);
check(reader.ParsePartitionTables());
ASSIGN_OR_RETURN(EndpointClient client, server.GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, client));
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
auto error_or = SpawnProcessFromElfRegion(vaddr);
if (!error_or) {
check(error_or.error());
}
ASSIGN_OR_RETURN(client, server.GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, client));
check(server_thread.Join());
check(registration_thread.Join());
dbgln("Yellowstone Finished Successfully.");
return 0;
}

View file

@ -0,0 +1,105 @@
#include "yellowstone_server.h"
#include <denali/denali.h>
#include <glacier/string/string.h>
#include <mammoth/debug.h>
#include <stdlib.h>
#include "hw/gpt.h"
#include "include/yellowstone.h"
// FIXME: This linkage was missing :(
void* operator new[](uint64_t size) { return malloc(size); }
namespace {
void ServerThreadBootstrap(void* yellowstone) {
dbgln("Yellowstone server starting");
static_cast<YellowstoneServer*>(yellowstone)->ServerThread();
}
void RegistrationThreadBootstrap(void* yellowstone) {
dbgln("Yellowstone registration starting");
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
}
glcr::ErrorCode HandleDenaliRegistration(z_cap_t endpoint_cap) {
EndpointClient endpoint = EndpointClient::AdoptEndpoint(endpoint_cap);
DenaliClient client(endpoint);
GptReader reader(client);
return reader.ParsePartitionTables();
}
} // namespace
glcr::ErrorOr<YellowstoneServer> YellowstoneServer::Create() {
ASSIGN_OR_RETURN(EndpointServer server, EndpointServer::Create());
ASSIGN_OR_RETURN(Port port, Port::Create());
return YellowstoneServer(server, port);
}
YellowstoneServer::YellowstoneServer(EndpointServer server, Port port)
: server_(server), register_port_(port) {}
Thread YellowstoneServer::RunServer() {
return Thread(ServerThreadBootstrap, this);
}
Thread YellowstoneServer::RunRegistration() {
return Thread(RegistrationThreadBootstrap, this);
}
void YellowstoneServer::ServerThread() {
while (true) {
uint64_t num_bytes = kBufferSize;
uint64_t reply_port_cap;
// FIXME: Error handling.
check(server_.Recieve(&num_bytes, server_buffer_, &reply_port_cap));
YellowstoneGetReq* req =
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
switch (req->type) {
case kYellowstoneGetAhci:
dbgln("Yellowstone::GetAHCI");
break;
case kYellowstoneGetRegistration: {
dbgln("Yellowstone::GetRegistration");
uint64_t reg_cap;
check(register_port_.Duplicate(&reg_cap));
YellowstoneGetRegistrationResp resp;
check(ZReplyPortSend(reply_port_cap, sizeof(resp), &resp, 1, &reg_cap));
break;
}
default:
dbgln("Unknown request type: %x", req->type);
break;
}
}
}
void YellowstoneServer::RegistrationThread() {
while (true) {
uint64_t num_bytes = kBufferSize;
z_cap_t endpoint_cap;
// FIXME: Better error handling here.
check(register_port_.RecvCap(&num_bytes, registration_buffer_,
&endpoint_cap));
glcr::String name(registration_buffer_);
if (name == "denali") {
denali_cap_ = endpoint_cap;
check(HandleDenaliRegistration(denali_cap_));
continue;
}
if (name == "victoriafalls") {
victoria_falls_cap_ = endpoint_cap;
continue;
}
dbgln("[WARN] Got endpoint cap type:");
dbgln(name.cstr());
}
}
glcr::ErrorOr<EndpointClient> YellowstoneServer::GetServerClient() {
return server_.CreateClient();
}

View file

@ -0,0 +1,33 @@
#pragma once
#include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h>
#include <mammoth/port.h>
#include <mammoth/thread.h>
class YellowstoneServer {
public:
static glcr::ErrorOr<YellowstoneServer> Create();
Thread RunServer();
Thread RunRegistration();
void ServerThread();
void RegistrationThread();
glcr::ErrorOr<EndpointClient> GetServerClient();
private:
EndpointServer server_;
Port register_port_;
static const uint64_t kBufferSize = 128;
uint8_t server_buffer_[kBufferSize];
char registration_buffer_[kBufferSize];
// TODO: Store these in a data structure.
z_cap_t denali_cap_ = 0;
z_cap_t victoria_falls_cap_ = 0;
YellowstoneServer(EndpointServer server, Port port);
};