Compare commits

..

No commits in common. "08abe776a4cf16c9ab30724abd715cefa735edb6" and "b7a962cc2691510cfc6c59b2c69ec9dba2f083db" have entirely different histories.

25 changed files with 80 additions and 182 deletions

View File

@ -1,25 +0,0 @@
#pragma once
namespace glcr {
template <typename T>
struct RemoveReference {
typedef T type;
};
template <typename T>
struct RemoveReference<T&> {
typedef T type;
};
template <typename T>
struct RemoveReference<T&&> {
typedef T type;
};
template <typename T>
typename RemoveReference<T>::type&& Move(T&& arg) {
return static_cast<typename RemoveReference<T>::type&&>(arg);
}
} // namespace glcr

View File

@ -1,52 +0,0 @@
#pragma once
namespace glcr {
template <typename T>
class UniquePtr {
public:
UniquePtr() : ptr_(nullptr) {}
UniquePtr(decltype(nullptr)) : ptr_(nullptr) {}
UniquePtr(T* ptr) : ptr_(ptr) {}
UniquePtr(const UniquePtr<T>&) = delete;
UniquePtr& operator=(const UniquePtr<T>&) = delete;
UniquePtr(UniquePtr<T>&& other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }
UniquePtr& operator=(UniquePtr<T>&& other) {
T* temp = ptr_;
ptr_ = other.ptr_;
other.ptr_ = temp;
return *this;
}
~UniquePtr() {
if (ptr_ != nullptr) {
delete ptr_;
}
}
explicit operator bool() const { return ptr_ != nullptr; }
bool empty() const { return ptr_ == nullptr; }
T* get() const { return ptr_; }
T* operator->() const { return ptr_; }
T& operator*() const { return *ptr_; }
T* release() {
T* tmp = ptr_;
ptr_ = nullptr;
return tmp;
}
private:
T* ptr_;
};
template <typename T, typename... Args>
UniquePtr<T> MakeUnique(Args... args) {
return UniquePtr<T>(new T(args...));
}
} // namespace glcr

View File

@ -1,6 +1,5 @@
#pragma once
#include <glacier/memory/move.h>
#include <glacier/status/error.h>
namespace glcr {
@ -16,7 +15,7 @@ class ErrorOr {
ErrorOr(ErrorCode code) : error_(code), ok_(false) {}
ErrorOr(const T& obj) : obj_(obj), ok_(true) {}
ErrorOr(T&& obj) : obj_(glcr::Move(obj)), ok_(true) {}
ErrorOr(T&& obj) : obj_(obj), ok_(true) {}
bool ok() { return ok_; }
operator bool() { return ok_; }
@ -42,6 +41,6 @@ class ErrorOr {
if (!AOR_VAR(__LINE__).ok()) { \
return AOR_VAR(__LINE__).error(); \
} \
lhs = glcr::Move(AOR_VAR(__LINE__).value());
lhs = AOR_VAR(__LINE__).value();
} // namespace glcr

View File

@ -10,7 +10,7 @@ target_include_directories(c
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(c
zion_stub
zion_lib
)
set_target_properties(c PROPERTIES

View File

@ -1,4 +1,4 @@
add_library(mammoth STATIC
add_library(mammoth_lib STATIC
src/channel.cpp
src/debug.cpp
src/endpoint_client.cpp
@ -12,16 +12,16 @@ add_library(mammoth STATIC
src/thread.cpp
)
target_include_directories(mammoth
target_include_directories(mammoth_lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(mammoth
target_link_libraries(mammoth_lib
glacier
c
zion_stub)
zion_lib)
set_target_properties(mammoth PROPERTIES
set_target_properties(mammoth_lib PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)

View File

@ -1,18 +1,13 @@
#pragma once
#include <glacier/container/pair.h>
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
#include <zcall.h>
#include <ztypes.h>
class EndpointClient {
public:
EndpointClient() = delete;
EndpointClient(const EndpointClient&) = delete;
EndpointClient& operator=(const EndpointClient&) = delete;
static glcr::UniquePtr<EndpointClient> AdoptEndpoint(z_cap_t cap);
static EndpointClient AdoptEndpoint(z_cap_t cap);
template <typename Req, typename Resp>
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> CallEndpoint(const Req& req);

View File

@ -1,6 +1,5 @@
#pragma once
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
#include <ztypes.h>
@ -8,14 +7,10 @@
class EndpointServer {
public:
EndpointServer() = delete;
EndpointServer(const EndpointServer&) = delete;
EndpointServer& operator=(const EndpointServer&) = delete;
static glcr::ErrorOr<EndpointServer> Create();
static EndpointServer Adopt(z_cap_t endpoint_cap);
static glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> Create();
static glcr::UniquePtr<EndpointServer> Adopt(z_cap_t endpoint_cap);
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient();
glcr::ErrorOr<EndpointClient> CreateClient();
// FIXME: Release Cap here.
z_cap_t GetCap() { return endpoint_cap_; }

View File

@ -5,5 +5,5 @@
#include "mammoth/endpoint_client.h"
glcr::ErrorCode SpawnProcessFromElfRegion(
uint64_t program, glcr::UniquePtr<EndpointClient> client);
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client);

View File

@ -1,5 +1,3 @@
#include "mammoth/endpoint_server.h"
glcr::UniquePtr<EndpointClient> EndpointClient::AdoptEndpoint(z_cap_t cap) {
return glcr::UniquePtr<EndpointClient>(new EndpointClient(cap));
}
EndpointClient EndpointClient::AdoptEndpoint(z_cap_t cap) { return {cap}; }

View File

@ -1,16 +1,16 @@
#include "mammoth/endpoint_server.h"
glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> EndpointServer::Create() {
glcr::ErrorOr<EndpointServer> EndpointServer::Create() {
uint64_t cap;
RET_ERR(ZEndpointCreate(&cap));
return glcr::UniquePtr<EndpointServer>(new EndpointServer(cap));
return EndpointServer(cap);
}
glcr::UniquePtr<EndpointServer> EndpointServer::Adopt(z_cap_t endpoint_cap) {
return glcr::UniquePtr<EndpointServer>(new EndpointServer(endpoint_cap));
EndpointServer EndpointServer::Adopt(z_cap_t endpoint_cap) {
return EndpointServer(endpoint_cap);
}
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
glcr::ErrorOr<EndpointClient> EndpointServer::CreateClient() {
uint64_t client_cap;
// FIXME: Restrict permissions to send-only here.
RET_ERR(ZCapDuplicate(endpoint_cap_, &client_cap));

View File

@ -96,8 +96,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
} // namespace
glcr::ErrorCode SpawnProcessFromElfRegion(
uint64_t program, glcr::UniquePtr<EndpointClient> client) {
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client) {
uint64_t proc_cap;
uint64_t as_cap;
uint64_t foreign_port_id;
@ -125,7 +125,7 @@ glcr::ErrorCode SpawnProcessFromElfRegion(
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_SELF_PROC, proc_cap));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_SELF_VMAS, as_cap));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, client->GetCap()));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, client.GetCap()));
#if MAM_PROC_DEBUG
dbgln("Thread start");

View File

@ -13,8 +13,8 @@ target_include_directories(denali
target_link_libraries(denali
glacier
mammoth
yellowstone_stub
mammoth_lib
yellowstonestub
)
set_target_properties(denali PROPERTIES
@ -22,18 +22,18 @@ set_target_properties(denali PROPERTIES
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)
add_library(denali_stub
add_library(libdenali
client/denali_client.cpp
)
target_include_directories(denali_stub
target_include_directories(libdenali
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(denali_stub
mammoth)
target_link_libraries(libdenali
mammoth_lib)
set_target_properties(denali_stub PROPERTIES
set_target_properties(libdenali PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)

View File

@ -11,7 +11,7 @@ glcr::ErrorOr<MappedMemoryRegion> DenaliClient::ReadSectors(
.lba = lba,
.size = num_sectors,
};
auto pair_or = endpoint_->CallEndpoint<DenaliRead, DenaliReadResponse>(read);
auto pair_or = endpoint_.CallEndpoint<DenaliRead, DenaliReadResponse>(read);
if (!pair_or) {
return pair_or.error();
}

View File

@ -14,15 +14,13 @@ uint64_t main(uint64_t init_port_cap) {
AhciDriver driver;
RET_ERR(driver.Init());
glcr::UniquePtr<EndpointClient> yellowstone =
EndpointClient::AdoptEndpoint(gInitEndpointCap);
EndpointClient yellowstone = EndpointClient::AdoptEndpoint(gInitEndpointCap);
YellowstoneGetReq req{
.type = kYellowstoneGetRegistration,
};
auto resp_cap_or =
yellowstone
->CallEndpoint<YellowstoneGetReq, YellowstoneGetRegistrationResp>(
req);
.CallEndpoint<YellowstoneGetReq, YellowstoneGetRegistrationResp>(req);
if (!resp_cap_or.ok()) {
dbgln("Bad call");
check(resp_cap_or.error());
@ -30,13 +28,11 @@ uint64_t main(uint64_t init_port_cap) {
auto resp_cap = resp_cap_or.value();
PortClient notify = PortClient::AdoptPort(resp_cap.second());
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointServer> endpoint,
EndpointServer::Create());
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
endpoint->CreateClient());
notify.WriteMessage("denali", client->GetCap());
ASSIGN_OR_RETURN(EndpointServer endpoint, EndpointServer::Create());
ASSIGN_OR_RETURN(EndpointClient client, endpoint.CreateClient());
notify.WriteMessage("denali", client.GetCap());
DenaliServer server(glcr::Move(endpoint), driver);
DenaliServer server(endpoint, driver);
RET_ERR(server.RunServer());
// FIXME: Add thread join.
return 0;

View File

@ -1,6 +1,5 @@
#include "denali_server.h"
#include <glacier/memory/move.h>
#include <glacier/status/error.h>
#include <mammoth/debug.h>
#include <zcall.h>
@ -13,9 +12,8 @@ void HandleResponse(z_cap_t reply_port, uint64_t lba, uint64_t size,
}
} // namespace
DenaliServer::DenaliServer(glcr::UniquePtr<EndpointServer> server,
AhciDriver& driver)
: server_(glcr::Move(server)), driver_(driver) {
DenaliServer::DenaliServer(EndpointServer server, AhciDriver& driver)
: server_(server), driver_(driver) {
gServer = this;
}
@ -23,7 +21,7 @@ glcr::ErrorCode DenaliServer::RunServer() {
while (true) {
uint64_t buff_size = kBuffSize;
z_cap_t reply_port;
RET_ERR(server_->Recieve(&buff_size, read_buffer_, &reply_port));
RET_ERR(server_.Recieve(&buff_size, read_buffer_, &reply_port));
if (buff_size < sizeof(uint64_t)) {
dbgln("Skipping invalid message");
continue;

View File

@ -8,7 +8,7 @@
class DenaliServer {
public:
DenaliServer(glcr::UniquePtr<EndpointServer> server, AhciDriver& driver);
DenaliServer(EndpointServer server, AhciDriver& driver);
glcr::ErrorCode RunServer();
@ -17,7 +17,7 @@ class DenaliServer {
private:
static const uint64_t kBuffSize = 1024;
glcr::UniquePtr<EndpointServer> server_;
EndpointServer server_;
uint8_t read_buffer_[kBuffSize];
AhciDriver& driver_;

View File

@ -6,13 +6,12 @@
class DenaliClient {
public:
DenaliClient(glcr::UniquePtr<EndpointClient> endpoint)
: endpoint_(glcr::Move(endpoint)) {}
DenaliClient(const EndpointClient& endpoint) : endpoint_(endpoint) {}
glcr::ErrorOr<MappedMemoryRegion> ReadSectors(uint64_t device_id,
uint64_t lba,
uint64_t num_sectors);
private:
glcr::UniquePtr<EndpointClient> endpoint_;
EndpointClient endpoint_;
};

View File

@ -7,7 +7,7 @@ target_include_directories(victoriafalls
target_link_libraries(victoriafalls
glacier
mammoth
mammoth_lib
)
set_target_properties(victoriafalls PROPERTIES

View File

@ -8,9 +8,9 @@ add_executable(yellowstone
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(yellowstone
mammoth
mammoth_lib
glacier
denali_stub
libdenali
)
set_target_properties(yellowstone PROPERTIES
@ -19,15 +19,15 @@ set_target_properties(yellowstone PROPERTIES
)
add_library(yellowstone_stub
add_library(yellowstonestub
stub/yellowstone_stub.cpp
)
target_include_directories(yellowstone_stub
target_include_directories(yellowstonestub
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
set_target_properties(yellowstone_stub PROPERTIES
set_target_properties(yellowstonestub PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
)

View File

@ -47,12 +47,11 @@ struct PartitionEntry {
char partition_name[72];
} __attribute__((packed));
GptReader::GptReader(glcr::UniquePtr<DenaliClient> denali)
: denali_(glcr::Move(denali)) {}
GptReader::GptReader(const DenaliClient& client) : denali_(client) {}
glcr::ErrorCode GptReader::ParsePartitionTables() {
ASSIGN_OR_RETURN(MappedMemoryRegion lba_1_and_2,
denali_->ReadSectors(0, 0, 2));
denali_.ReadSectors(0, 0, 2));
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
if (*mbr_sig != 0xAA55) {
return glcr::FAILED_PRECONDITION;
@ -87,7 +86,7 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
ASSIGN_OR_RETURN(
MappedMemoryRegion part_table,
denali_->ReadSectors(0, header->lba_partition_entries, num_blocks));
denali_.ReadSectors(0, header->lba_partition_entries, num_blocks));
dbgln("Entries");
for (uint64_t i = 0; i < num_partitions; i++) {
PartitionEntry* entry = reinterpret_cast<PartitionEntry*>(

View File

@ -6,10 +6,10 @@
class GptReader {
public:
GptReader(glcr::UniquePtr<DenaliClient> denali);
GptReader(const DenaliClient&);
glcr::ErrorCode ParsePartitionTables();
private:
glcr::UniquePtr<DenaliClient> denali_;
DenaliClient denali_;
};

View File

@ -12,20 +12,19 @@ uint64_t main(uint64_t port_cap) {
dbgln("Yellowstone Initializing.");
check(ParseInitPort(port_cap));
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread server_thread = server->RunServer();
Thread registration_thread = server->RunRegistration();
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));
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
server->GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, glcr::Move(client)));
ASSIGN_OR_RETURN(EndpointClient client, server.GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, client));
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
ASSIGN_OR_RETURN(client, server->GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, glcr::Move(client)));
ASSIGN_OR_RETURN(client, server.GetServerClient());
check(SpawnProcessFromElfRegion(vaddr, client));
check(server_thread.Join());
check(registration_thread.Join());

View File

@ -21,24 +21,23 @@ void RegistrationThreadBootstrap(void* yellowstone) {
}
glcr::ErrorCode HandleDenaliRegistration(z_cap_t endpoint_cap) {
GptReader reader(glcr::UniquePtr<DenaliClient>(
new DenaliClient(EndpointClient::AdoptEndpoint(endpoint_cap))));
EndpointClient endpoint = EndpointClient::AdoptEndpoint(endpoint_cap);
DenaliClient client(endpoint);
GptReader reader(client);
return reader.ParsePartitionTables();
}
} // namespace
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
ASSIGN_OR_RETURN(auto server, EndpointServer::Create());
glcr::ErrorOr<YellowstoneServer> YellowstoneServer::Create() {
ASSIGN_OR_RETURN(EndpointServer server, EndpointServer::Create());
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
return glcr::UniquePtr<YellowstoneServer>(
new YellowstoneServer(glcr::Move(server), port));
return YellowstoneServer(server, port);
}
YellowstoneServer::YellowstoneServer(glcr::UniquePtr<EndpointServer> server,
PortServer port)
: server_(glcr::Move(server)), register_port_(port) {}
YellowstoneServer::YellowstoneServer(EndpointServer server, PortServer port)
: server_(server), register_port_(port) {}
Thread YellowstoneServer::RunServer() {
return Thread(ServerThreadBootstrap, this);
@ -53,7 +52,7 @@ void YellowstoneServer::ServerThread() {
uint64_t num_bytes = kBufferSize;
uint64_t reply_port_cap;
// FIXME: Error handling.
check(server_->Recieve(&num_bytes, server_buffer_, &reply_port_cap));
check(server_.Recieve(&num_bytes, server_buffer_, &reply_port_cap));
YellowstoneGetReq* req =
reinterpret_cast<YellowstoneGetReq*>(server_buffer_);
switch (req->type) {
@ -102,7 +101,6 @@ void YellowstoneServer::RegistrationThread() {
}
}
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>>
YellowstoneServer::GetServerClient() {
return server_->CreateClient();
glcr::ErrorOr<EndpointClient> YellowstoneServer::GetServerClient() {
return server_.CreateClient();
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h>
#include <mammoth/port_server.h>
@ -8,7 +7,7 @@
class YellowstoneServer {
public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
static glcr::ErrorOr<YellowstoneServer> Create();
Thread RunServer();
Thread RunRegistration();
@ -16,10 +15,10 @@ class YellowstoneServer {
void ServerThread();
void RegistrationThread();
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> GetServerClient();
glcr::ErrorOr<EndpointClient> GetServerClient();
private:
glcr::UniquePtr<EndpointServer> server_;
EndpointServer server_;
PortServer register_port_;
static const uint64_t kBufferSize = 128;
@ -30,5 +29,5 @@ class YellowstoneServer {
z_cap_t denali_cap_ = 0;
z_cap_t victoria_falls_cap_ = 0;
YellowstoneServer(glcr::UniquePtr<EndpointServer> server, PortServer port);
YellowstoneServer(EndpointServer server, PortServer port);
};

View File

@ -82,14 +82,14 @@ set_target_properties(zion
add_library(zion_stub STATIC
add_library(zion_lib STATIC
usr/crt0.s
usr/zcall.cpp)
target_include_directories(zion_stub
target_include_directories(zion_lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(zion_stub
set_target_properties(zion_lib
PROPERTIES
COMPILE_FLAGS "${_Z_COMPILE_FLAGS}")