Compare commits

...

10 Commits

66 changed files with 357 additions and 231 deletions

View File

@ -1,27 +1,33 @@
add_library(mammoth STATIC add_library(mammoth STATIC
src/channel.cpp file/file.cpp
src/debug.cpp ipc/channel.cpp
src/endpoint_client.cpp ipc/endpoint_client.cpp
src/endpoint_server.cpp ipc/endpoint_server.cpp
src/init.cpp ipc/port_client.cpp
src/memory_region.cpp ipc/port_server.cpp
src/mutex.cpp proc/process.cpp
src/new.cpp proc/thread.cpp
src/process.cpp sync/mutex.cpp
src/port_client.cpp sync/semaphore.cpp
src/port_server.cpp util/debug.cpp
src/semaphore.cpp util/init.cpp
src/thread.cpp util/memory_region.cpp
util/new.cpp
) )
target_include_directories(mammoth target_include_directories(mammoth
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
"${CMAKE_CURRENT_SOURCE_DIR}/.."
)
target_link_libraries(mammoth target_link_libraries(mammoth
glacier glacier
c c
zion_stub) victoriafalls_yunq
yellowstone_yunq
zion_stub
)
set_target_properties(mammoth PROPERTIES set_target_properties(mammoth PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"

47
lib/mammoth/file/file.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "file/file.h"
#include <victoriafalls/victoriafalls.yunq.client.h>
#include <yellowstone/yellowstone.yunq.client.h>
#include <zglobal.h>
#include "util/debug.h"
namespace mmth {
namespace {
VFSClient* gVfsClient = nullptr;
} // namespace
void SetVfsCap(z_cap_t vfs_cap) { gVfsClient = new VFSClient(vfs_cap); }
File File::Open(glcr::StringView path) {
if (gVfsClient == 0) {
YellowstoneClient client(gInitEndpointCap);
GetEndpointRequest yreq;
yreq.set_endpoint_name("victoriafalls");
Endpoint yresp;
check(client.GetEndpoint(yreq, yresp));
gVfsClient = new VFSClient(yresp.endpoint());
}
OpenFileRequest req;
req.set_path(path);
OpenFileResponse resp;
check(gVfsClient->OpenFile(req, resp));
return File(OwnedMemoryRegion::FromCapability(resp.memory()), resp.size());
}
glcr::StringView File::as_str() {
return glcr::StringView((char*)raw_ptr(), size_);
}
void* File::raw_ptr() { return reinterpret_cast<void*>(file_data_.vaddr()); }
uint8_t* File::byte_ptr() {
return reinterpret_cast<uint8_t*>(file_data_.vaddr());
}
} // namespace mmth

32
lib/mammoth/file/file.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include <glacier/memory/move.h>
#include <glacier/string/string_view.h>
#include "mammoth/util/memory_region.h"
namespace mmth {
// Intended for use in yellowstone since it already has the VFS cap.
void SetVfsCap(z_cap_t vfs_cap);
class File {
public:
static File Open(glcr::StringView path);
uint64_t size() { return size_; }
glcr::StringView as_str();
void* raw_ptr();
uint8_t* byte_ptr();
private:
OwnedMemoryRegion file_data_;
uint64_t size_;
File(OwnedMemoryRegion&& file, uint64_t size)
: file_data_(glcr::Move(file)), size_(size) {}
};
} // namespace mmth

View File

@ -1,9 +1,10 @@
#include "mammoth/channel.h" #include "ipc/channel.h"
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "util/debug.h"
namespace mmth {
namespace { namespace {
uint64_t strlen(const char* ptr) { uint64_t strlen(const char* ptr) {
@ -55,3 +56,5 @@ z_err_t CreateChannels(Channel& c1, Channel& c2) {
c2.adopt_cap(chan2); c2.adopt_cap(chan2);
return glcr::OK; return glcr::OK;
} }
} // namespace mmth

View File

@ -4,6 +4,8 @@
#include <stdint.h> #include <stdint.h>
#include <zcall.h> #include <zcall.h>
namespace mmth {
class Channel { class Channel {
public: public:
Channel() {} Channel() {}
@ -45,3 +47,5 @@ z_err_t Channel::ReadStructAndCap(T* obj, uint64_t* cap) {
} }
return glcr::OK; return glcr::OK;
} }
} // namespace mmth

View File

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

View File

@ -6,6 +6,8 @@
#include <zcall.h> #include <zcall.h>
#include <ztypes.h> #include <ztypes.h>
namespace mmth {
class EndpointClient { class EndpointClient {
public: public:
EndpointClient() = delete; EndpointClient() = delete;
@ -63,3 +65,5 @@ glcr::ErrorOr<Resp> EndpointClient::CallEndpoint(const Req& req) {
return resp; return resp;
} }
} // namespace mmth

View File

@ -1,7 +1,8 @@
#include "mammoth/endpoint_server.h" #include "ipc/endpoint_server.h"
#include "mammoth/debug.h" #include "util/debug.h"
namespace mmth {
// Declared as friend in EndpointServer. // Declared as friend in EndpointServer.
void EndpointServerThreadBootstrap(void* endpoint_server) { void EndpointServerThreadBootstrap(void* endpoint_server) {
reinterpret_cast<EndpointServer*>(endpoint_server)->ServerThread(); reinterpret_cast<EndpointServer*>(endpoint_server)->ServerThread();
@ -40,3 +41,5 @@ void EndpointServer::ServerThread() {
} }
} }
} }
} // namespace mmth

View File

@ -4,11 +4,12 @@
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <ztypes.h> #include <ztypes.h>
#include "mammoth/endpoint_client.h" #include "mammoth/ipc/endpoint_client.h"
#include "mammoth/request_context.h" #include "mammoth/ipc/request_context.h"
#include "mammoth/response_context.h" #include "mammoth/ipc/response_context.h"
#include "mammoth/thread.h" #include "mammoth/proc/thread.h"
namespace mmth {
class EndpointServer { class EndpointServer {
public: public:
EndpointServer() = delete; EndpointServer() = delete;
@ -34,3 +35,5 @@ class EndpointServer {
friend void EndpointServerThreadBootstrap(void* endpoint_server); friend void EndpointServerThreadBootstrap(void* endpoint_server);
void ServerThread(); void ServerThread();
}; };
} // namespace mmth

View File

@ -1,9 +1,11 @@
#include "mammoth/port_client.h" #include "ipc/port_client.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "util/debug.h"
namespace mmth {
PortClient PortClient::AdoptPort(z_cap_t cap) { return PortClient(cap); } PortClient PortClient::AdoptPort(z_cap_t cap) { return PortClient(cap); }
PortClient::PortClient(z_cap_t port_cap) : port_cap_(port_cap) {} PortClient::PortClient(z_cap_t port_cap) : port_cap_(port_cap) {}
@ -12,3 +14,5 @@ glcr::ErrorCode PortClient::WriteString(glcr::String str, z_cap_t cap) {
return static_cast<glcr::ErrorCode>( return static_cast<glcr::ErrorCode>(
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap)); ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
} }
} // namespace mmth

View File

@ -5,6 +5,8 @@
#include <stdint.h> #include <stdint.h>
#include <zcall.h> #include <zcall.h>
namespace mmth {
class PortClient { class PortClient {
public: public:
PortClient() {} PortClient() {}
@ -29,3 +31,5 @@ template <typename T>
z_err_t PortClient::WriteMessage(const T& obj, z_cap_t cap) { z_err_t PortClient::WriteMessage(const T& obj, z_cap_t cap) {
return ZPortSend(port_cap_, sizeof(obj), &obj, 1, &cap); return ZPortSend(port_cap_, sizeof(obj), &obj, 1, &cap);
} }
} // namespace mmth

View File

@ -1,7 +1,9 @@
#include "mammoth/port_server.h" #include "ipc/port_server.h"
#include <zcall.h> #include <zcall.h>
namespace mmth {
glcr::ErrorOr<PortServer> PortServer::Create() { glcr::ErrorOr<PortServer> PortServer::Create() {
z_cap_t port; z_cap_t port;
RET_ERR(ZPortCreate(&port)); RET_ERR(ZPortCreate(&port));
@ -44,3 +46,5 @@ glcr::ErrorCode PortServer::PollForIntCap(uint64_t *msg, uint64_t *cap) {
} }
return glcr::OK; return glcr::OK;
} }
} // namespace mmth

View File

@ -3,7 +3,9 @@
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <ztypes.h> #include <ztypes.h>
#include "mammoth/port_client.h" #include "mammoth/ipc/port_client.h"
namespace mmth {
class PortServer { class PortServer {
public: public:
@ -22,3 +24,5 @@ class PortServer {
PortServer(z_cap_t cap); PortServer(z_cap_t cap);
}; };
} // namespace mmth

View File

@ -1,16 +1,17 @@
#include "mammoth/process.h" #include "proc/process.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "ipc/endpoint_server.h"
#include "mammoth/endpoint_server.h" #include "ipc/port_client.h"
#include "mammoth/init.h" #include "ipc/port_server.h"
#include "mammoth/port_client.h" #include "util/debug.h"
#include "mammoth/port_server.h" #include "util/init.h"
#define MAM_PROC_DEBUG 0 #define MAM_PROC_DEBUG 0
namespace mmth {
namespace { namespace {
typedef struct { typedef struct {
@ -140,3 +141,5 @@ glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
return glcr::OK; return glcr::OK;
} }
} // namespace mmth

View File

@ -2,8 +2,11 @@
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <stdint.h> #include <stdint.h>
#include <ztypes.h>
#include "mammoth/endpoint_client.h" namespace mmth {
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program, glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
z_cap_t yellowstone_client); z_cap_t yellowstone_client);
} // namespace mmth

View File

@ -1,9 +1,9 @@
#include "mammoth/thread.h" #include "proc/thread.h"
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "util/debug.h"
#include "mammoth/init.h" #include "util/init.h"
namespace { namespace {

View File

@ -1,7 +1,9 @@
#include "mammoth/mutex.h" #include "sync/mutex.h"
#include <zcall.h> #include <zcall.h>
namespace mmth {
Mutex::Mutex(Mutex&& other) : mutex_cap_(other.mutex_cap_) { Mutex::Mutex(Mutex&& other) : mutex_cap_(other.mutex_cap_) {
other.mutex_cap_ = 0; other.mutex_cap_ = 0;
} }
@ -25,3 +27,5 @@ glcr::ErrorCode Mutex::Lock() {
glcr::ErrorCode Mutex::Release() { glcr::ErrorCode Mutex::Release() {
return static_cast<glcr::ErrorCode>(ZMutexRelease(mutex_cap_)); return static_cast<glcr::ErrorCode>(ZMutexRelease(mutex_cap_));
} }
} // namespace mmth

View File

@ -3,6 +3,8 @@
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <ztypes.h> #include <ztypes.h>
namespace mmth {
class Mutex { class Mutex {
public: public:
Mutex(const Mutex&) = delete; Mutex(const Mutex&) = delete;
@ -19,3 +21,5 @@ class Mutex {
Mutex(z_cap_t mutex_cap) : mutex_cap_(mutex_cap) {} Mutex(z_cap_t mutex_cap) : mutex_cap_(mutex_cap) {}
}; };
} // namespace mmth

View File

@ -1,11 +1,15 @@
#include "mammoth/semaphore.h" #include "sync/semaphore.h"
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "util/debug.h"
namespace mmth {
Semaphore::Semaphore() { check(ZSemaphoreCreate(&semaphore_cap_)); } Semaphore::Semaphore() { check(ZSemaphoreCreate(&semaphore_cap_)); }
Semaphore::~Semaphore() { check(ZCapRelease(semaphore_cap_)); } Semaphore::~Semaphore() { check(ZCapRelease(semaphore_cap_)); }
void Semaphore::Wait() { check(ZSemaphoreWait(semaphore_cap_)); } void Semaphore::Wait() { check(ZSemaphoreWait(semaphore_cap_)); }
void Semaphore::Signal() { check(ZSemaphoreSignal(semaphore_cap_)); } void Semaphore::Signal() { check(ZSemaphoreSignal(semaphore_cap_)); }
} // namespace mmth

View File

@ -2,6 +2,8 @@
#include <ztypes.h> #include <ztypes.h>
namespace mmth {
class Semaphore { class Semaphore {
public: public:
Semaphore(); Semaphore();
@ -13,3 +15,5 @@ class Semaphore {
private: private:
z_cap_t semaphore_cap_; z_cap_t semaphore_cap_;
}; };
} // namespace mmth

View File

@ -1,4 +1,4 @@
#include "include/mammoth/debug.h" #include "util/debug.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <zcall.h> #include <zcall.h>

View File

@ -1,10 +1,10 @@
#include "mammoth/init.h" #include "util/init.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <ztypes.h> #include <ztypes.h>
#include "mammoth/debug.h" #include "ipc/port_server.h"
#include "mammoth/port_server.h" #include "util/debug.h"
uint64_t gSelfProcCap = 0; uint64_t gSelfProcCap = 0;
uint64_t gSelfVmasCap = 0; uint64_t gSelfVmasCap = 0;
@ -17,7 +17,7 @@ uint64_t gBootPciVmmoCap = 0;
uint64_t gBootFramebufferVmmoCap = 0; uint64_t gBootFramebufferVmmoCap = 0;
z_err_t ParseInitPort(uint64_t init_port_cap) { z_err_t ParseInitPort(uint64_t init_port_cap) {
PortServer port = PortServer::AdoptCap(init_port_cap); mmth::PortServer port = mmth::PortServer::AdoptCap(init_port_cap);
z_err_t ret; z_err_t ret;
uint64_t init_sig, init_cap; uint64_t init_sig, init_cap;
while ((ret = port.PollForIntCap(&init_sig, &init_cap)) != glcr::EMPTY) { while ((ret = port.PollForIntCap(&init_sig, &init_cap)) != glcr::EMPTY) {

View File

@ -1,9 +1,11 @@
#include "mammoth/memory_region.h" #include "util/memory_region.h"
#include <zcall.h> #include <zcall.h>
#include "mammoth/debug.h" #include "util/debug.h"
#include "mammoth/init.h" #include "util/init.h"
namespace mmth {
OwnedMemoryRegion::OwnedMemoryRegion(OwnedMemoryRegion&& other) OwnedMemoryRegion::OwnedMemoryRegion(OwnedMemoryRegion&& other)
: OwnedMemoryRegion(other.vmmo_cap_, other.vaddr_, other.size_) { : OwnedMemoryRegion(other.vmmo_cap_, other.vaddr_, other.size_) {
@ -68,3 +70,5 @@ z_cap_t OwnedMemoryRegion::DuplicateCap() {
check(ZCapDuplicate(vmmo_cap_, kZionPerm_All, &cap)); check(ZCapDuplicate(vmmo_cap_, kZionPerm_All, &cap));
return cap; return cap;
} }
} // namespace mmth

View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <ztypes.h> #include <ztypes.h>
namespace mmth {
/* /*
* Memory Region class that unmaps its memory and releases its * Memory Region class that unmaps its memory and releases its
* capability when it goes out of scope. * capability when it goes out of scope.
@ -41,3 +42,5 @@ class OwnedMemoryRegion {
// TODO: We may want to differentiate between VMMO size and mapped size? // TODO: We may want to differentiate between VMMO size and mapped size?
uint64_t size_ = 0; uint64_t size_ = 0;
}; };
} // namespace mmth

View File

@ -1,7 +1,7 @@
#include "ahci/ahci_device.h" #include "ahci/ahci_device.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <string.h> #include <string.h>
#include <zcall.h> #include <zcall.h>
@ -14,7 +14,8 @@ AhciDevice::AhciDevice(AhciPort* port) : port_struct_(port) {
// 0x400-0x500 -> Received FIS // 0x400-0x500 -> Received FIS
// 0x500-0x2500 -> Command Tables (0x100 each) (Max PRDT Length is 8 for now) // 0x500-0x2500 -> Command Tables (0x100 each) (Max PRDT Length is 8 for now)
uint64_t paddr; uint64_t paddr;
command_structures_ = OwnedMemoryRegion::ContiguousPhysical(0x2500, &paddr); command_structures_ =
mmth::OwnedMemoryRegion::ContiguousPhysical(0x2500, &paddr);
command_list_ = reinterpret_cast<CommandList*>(command_structures_.vaddr()); command_list_ = reinterpret_cast<CommandList*>(command_structures_.vaddr());
port_struct_->command_list_base = paddr; port_struct_->command_list_base = paddr;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/memory_region.h> #include <mammoth/util/memory_region.h>
#include <ztypes.h> #include <ztypes.h>
#include "ahci/ahci.h" #include "ahci/ahci.h"
@ -26,7 +26,7 @@ class AhciDevice {
private: private:
AhciPort* port_struct_ = nullptr; AhciPort* port_struct_ = nullptr;
OwnedMemoryRegion command_structures_; mmth::OwnedMemoryRegion command_structures_;
CommandList* command_list_ = nullptr; CommandList* command_list_ = nullptr;
ReceivedFis* received_fis_ = nullptr; ReceivedFis* received_fis_ = nullptr;

View File

@ -2,7 +2,7 @@
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <stdint.h> #include <stdint.h>
#include <zcall.h> #include <zcall.h>
@ -21,7 +21,7 @@ void interrupt_thread(void* void_driver) {
} // namespace } // namespace
glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> AhciDriver::Init( glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> AhciDriver::Init(
OwnedMemoryRegion&& pci_region) { mmth::OwnedMemoryRegion&& pci_region) {
glcr::UniquePtr<AhciDriver> driver(new AhciDriver(glcr::Move(pci_region))); glcr::UniquePtr<AhciDriver> driver(new AhciDriver(glcr::Move(pci_region)));
// RET_ERR(driver->LoadCapabilities()); // RET_ERR(driver->LoadCapabilities());
RET_ERR(driver->LoadHbaRegisters()); RET_ERR(driver->LoadHbaRegisters());
@ -191,8 +191,8 @@ glcr::ErrorCode AhciDriver::RegisterIrq() {
} }
glcr::ErrorCode AhciDriver::LoadHbaRegisters() { glcr::ErrorCode AhciDriver::LoadHbaRegisters() {
ahci_region_ = ahci_region_ = mmth::OwnedMemoryRegion ::DirectPhysical(
OwnedMemoryRegion ::DirectPhysical(pci_device_header_->abar, 0x1100); pci_device_header_->abar, 0x1100);
ahci_hba_ = reinterpret_cast<AhciHba*>(ahci_region_.vaddr()); ahci_hba_ = reinterpret_cast<AhciHba*>(ahci_region_.vaddr());
num_ports_ = (ahci_hba_->capabilities & 0x1F) + 1; num_ports_ = (ahci_hba_->capabilities & 0x1F) + 1;
num_commands_ = ((ahci_hba_->capabilities & 0x1F00) >> 8) + 1; num_commands_ = ((ahci_hba_->capabilities & 0x1F00) >> 8) + 1;

View File

@ -2,7 +2,7 @@
#include <glacier/memory/unique_ptr.h> #include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
#include "ahci/ahci.h" #include "ahci/ahci.h"
@ -11,7 +11,7 @@
class AhciDriver { class AhciDriver {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> Init( static glcr::ErrorOr<glcr::UniquePtr<AhciDriver>> Init(
OwnedMemoryRegion&& ahci_phys); mmth::OwnedMemoryRegion&& ahci_phys);
glcr::ErrorCode RegisterIrq(); glcr::ErrorCode RegisterIrq();
void InterruptLoop(); void InterruptLoop();
@ -22,9 +22,9 @@ class AhciDriver {
void DumpPorts(); void DumpPorts();
private: private:
OwnedMemoryRegion pci_region_; mmth::OwnedMemoryRegion pci_region_;
PciDeviceHeader* pci_device_header_ = nullptr; PciDeviceHeader* pci_device_header_ = nullptr;
OwnedMemoryRegion ahci_region_; mmth::OwnedMemoryRegion ahci_region_;
AhciHba* ahci_hba_ = nullptr; AhciHba* ahci_hba_ = nullptr;
// TODO: Allocate these dynamically. // TODO: Allocate these dynamically.
@ -40,7 +40,7 @@ class AhciDriver {
glcr::ErrorCode LoadHbaRegisters(); glcr::ErrorCode LoadHbaRegisters();
glcr::ErrorCode LoadDevices(); glcr::ErrorCode LoadDevices();
AhciDriver(OwnedMemoryRegion&& pci_region) AhciDriver(mmth::OwnedMemoryRegion&& pci_region)
: pci_region_(glcr::Move(pci_region)), : pci_region_(glcr::Move(pci_region)),
pci_device_header_( pci_device_header_(
reinterpret_cast<PciDeviceHeader*>(pci_region_.vaddr())) {} reinterpret_cast<PciDeviceHeader*>(pci_region_.vaddr())) {}

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#include <mammoth/memory_region.h> #include <mammoth/sync/semaphore.h>
#include <mammoth/response_context.h>
#include <mammoth/semaphore.h>
#include <stdint.h> #include <stdint.h>
#include "ahci/ahci.h" #include "ahci/ahci.h"
@ -34,5 +32,5 @@ class DmaReadCommand : public Command {
uint64_t paddr_; uint64_t paddr_;
// TODO: Make this owned by the device so that we don't have to create a new // TODO: Make this owned by the device so that we don't have to create a new
// one with the kernel every time a command is issued. // one with the kernel every time a command is issued.
Semaphore callback_semaphore_; mmth::Semaphore callback_semaphore_;
}; };

View File

@ -1,8 +1,6 @@
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/endpoint_server.h> #include <mammoth/util/init.h>
#include <mammoth/init.h>
#include <mammoth/port_client.h>
#include <stdint.h> #include <stdint.h>
#include <yellowstone/yellowstone.yunq.client.h> #include <yellowstone/yellowstone.yunq.client.h>
@ -11,15 +9,13 @@
uint64_t main(uint64_t init_port_cap) { uint64_t main(uint64_t init_port_cap) {
check(ParseInitPort(init_port_cap)); check(ParseInitPort(init_port_cap));
glcr::UniquePtr<EndpointClient> yellowstone =
EndpointClient::AdoptEndpoint(gInitEndpointCap);
YellowstoneClient stub(gInitEndpointCap); YellowstoneClient stub(gInitEndpointCap);
Empty empty; Empty empty;
AhciInfo ahci; AhciInfo ahci;
RET_ERR(stub.GetAhciInfo(empty, ahci)); RET_ERR(stub.GetAhciInfo(empty, ahci));
OwnedMemoryRegion ahci_region = mmth::OwnedMemoryRegion ahci_region =
OwnedMemoryRegion::FromCapability(ahci.ahci_region()); mmth::OwnedMemoryRegion::FromCapability(ahci.ahci_region());
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(glcr::Move(ahci_region))); ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(glcr::Move(ahci_region)));
ASSIGN_OR_RETURN(glcr::UniquePtr<DenaliServer> server, ASSIGN_OR_RETURN(glcr::UniquePtr<DenaliServer> server,

View File

@ -2,7 +2,7 @@
#include <glacier/memory/move.h> #include <glacier/memory/move.h>
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create( glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
@ -17,8 +17,8 @@ glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id())); ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
uint64_t paddr; uint64_t paddr;
OwnedMemoryRegion region = mmth::OwnedMemoryRegion region =
OwnedMemoryRegion::ContiguousPhysical(req.size() * 512, &paddr); mmth::OwnedMemoryRegion::ContiguousPhysical(req.size() * 512, &paddr);
DmaReadCommand command(req.lba(), req.size(), paddr); DmaReadCommand command(req.lba(), req.size(), paddr);
device->IssueCommand(&command); device->IssueCommand(&command);
@ -44,8 +44,8 @@ glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
sector_cnt += req.sector_cnt().at(i); sector_cnt += req.sector_cnt().at(i);
} }
uint64_t region_paddr; uint64_t region_paddr;
OwnedMemoryRegion region = mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
OwnedMemoryRegion::ContiguousPhysical(sector_cnt * 512, &region_paddr); sector_cnt * 512, &region_paddr);
for (uint64_t i = 0; i < req.lba().size(); i++) { for (uint64_t i = 0; i < req.lba().size(); i++) {
uint64_t lba = req.lba().at(i); uint64_t lba = req.lba().at(i);

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/endpoint_server.h>
#include "ahci/ahci_driver.h" #include "ahci/ahci_driver.h"
#include "lib/denali/denali.yunq.server.h" #include "lib/denali/denali.yunq.server.h"

View File

@ -1,7 +1,7 @@
// Generated file -- DO NOT MODIFY. // Generated file -- DO NOT MODIFY.
#include "denali.yunq.server.h" #include "denali.yunq.server.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
namespace { namespace {

View File

@ -2,7 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
#include "denali.yunq.h" #include "denali.yunq.h"

View File

@ -1,6 +1,6 @@
#include "framebuffer/console.h" #include "framebuffer/console.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
void Console::WriteChar(char c) { void Console::WriteChar(char c) {
if (c == '\n') { if (c == '\n') {

View File

@ -3,8 +3,8 @@
Framebuffer::Framebuffer(const FramebufferInfo& info) Framebuffer::Framebuffer(const FramebufferInfo& info)
: fb_info_(info), cursor_pos_(0) { : fb_info_(info), cursor_pos_(0) {
uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch(); uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch();
fb_memory_ = OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(), fb_memory_ = mmth::OwnedMemoryRegion::DirectPhysical(fb_info_.address_phys(),
buff_size_bytes); buff_size_bytes);
fb_ = reinterpret_cast<uint32_t*>(fb_memory_.vaddr()); fb_ = reinterpret_cast<uint32_t*>(fb_memory_.vaddr());
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <mammoth/memory_region.h> #include <mammoth/util/memory_region.h>
#include <yellowstone/yellowstone.yunq.h> #include <yellowstone/yellowstone.yunq.h>
class Framebuffer { class Framebuffer {
@ -19,7 +19,7 @@ class Framebuffer {
// don't have to store a reference here. // don't have to store a reference here.
const FramebufferInfo& fb_info_; const FramebufferInfo& fb_info_;
OwnedMemoryRegion fb_memory_; mmth::OwnedMemoryRegion fb_memory_;
uint32_t* fb_; uint32_t* fb_;
uint32_t cursor_pos_; uint32_t cursor_pos_;
}; };

View File

@ -1,7 +1,7 @@
#include "framebuffer/psf.h" #include "framebuffer/psf.h"
#include <glacier/memory/move.h> #include <glacier/memory/move.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
namespace { namespace {
@ -9,9 +9,9 @@ const uint32_t kMagic = 0x864AB572;
} }
Psf::Psf(OwnedMemoryRegion&& psf_file) Psf::Psf(glcr::StringView path)
: psf_file_(glcr::Move(psf_file)), : psf_file_(mmth::File::Open(path)),
header_(reinterpret_cast<PsfHeader*>(psf_file_.vaddr())) { header_(reinterpret_cast<PsfHeader*>(psf_file_.raw_ptr())) {
EnsureValid(); EnsureValid();
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <mammoth/memory_region.h> #include <mammoth/file/file.h>
struct PsfHeader { struct PsfHeader {
uint32_t magic; /* magic bytes to identify PSF */ uint32_t magic; /* magic bytes to identify PSF */
@ -15,7 +15,7 @@ struct PsfHeader {
class Psf { class Psf {
public: public:
Psf(OwnedMemoryRegion&& psf_file); Psf(glcr::StringView path);
void DumpHeader(); void DumpHeader();
@ -24,12 +24,13 @@ class Psf {
uint32_t height() { return header_->height; } uint32_t height() { return header_->height; }
uint8_t* glyph(uint32_t index) { uint8_t* glyph(uint32_t index) {
return reinterpret_cast<uint8_t*>(psf_file_.vaddr() + header_->headersize + return reinterpret_cast<uint8_t*>(psf_file_.byte_ptr() +
header_->headersize +
(index * header_->bytesperglyph)); (index * header_->bytesperglyph));
} }
private: private:
OwnedMemoryRegion psf_file_; mmth::File psf_file_;
PsfHeader* header_; PsfHeader* header_;
void EnsureValid(); void EnsureValid();

View File

@ -1,5 +1,5 @@
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/init.h> #include <mammoth/util/init.h>
#include <victoriafalls/victoriafalls.yunq.client.h> #include <victoriafalls/victoriafalls.yunq.client.h>
#include <yellowstone/yellowstone.yunq.client.h> #include <yellowstone/yellowstone.yunq.client.h>
@ -25,19 +25,7 @@ uint64_t main(uint64_t init_port) {
// 2. Parse a font file. // 2. Parse a font file.
GetEndpointRequest req; Psf psf("/default8x16.psfu");
req.set_endpoint_name("victoriafalls");
Endpoint resp;
check(client.GetEndpoint(req, resp));
VFSClient vfs(resp.endpoint());
OpenFileRequest freq;
freq.set_path("/default8x16.psfu");
OpenFileResponse fresp;
check(vfs.OpenFile(freq, fresp));
Psf psf(OwnedMemoryRegion::FromCapability(fresp.memory()));
psf.DumpHeader(); psf.DumpHeader();
Console console(fbuf, psf); Console console(fbuf, psf);

View File

@ -1,6 +1,6 @@
#include "fs/ext2/ext2_block_reader.h" #include "fs/ext2/ext2_block_reader.h"
#include "mammoth/debug.h" #include <mammoth/util/debug.h>
glcr::ErrorOr<glcr::SharedPtr<Ext2BlockReader>> Ext2BlockReader::Init( glcr::ErrorOr<glcr::SharedPtr<Ext2BlockReader>> Ext2BlockReader::Init(
const DenaliInfo& denali_info) { const DenaliInfo& denali_info) {
@ -13,8 +13,8 @@ glcr::ErrorOr<glcr::SharedPtr<Ext2BlockReader>> Ext2BlockReader::Init(
req.set_size(2); req.set_size(2);
ReadResponse resp; ReadResponse resp;
RET_ERR(client.Read(req, resp)); RET_ERR(client.Read(req, resp));
OwnedMemoryRegion superblock = mmth::OwnedMemoryRegion superblock =
OwnedMemoryRegion::FromCapability(resp.memory()); mmth::OwnedMemoryRegion::FromCapability(resp.memory());
return glcr::SharedPtr<Ext2BlockReader>( return glcr::SharedPtr<Ext2BlockReader>(
new Ext2BlockReader(glcr::Move(client), denali_info.device_id(), new Ext2BlockReader(glcr::Move(client), denali_info.device_id(),
@ -59,11 +59,11 @@ uint64_t Ext2BlockReader::InodeTableBlockSize() {
return (InodeSize() * GetSuperblock()->inodes_per_group) / BlockSize(); return (InodeSize() * GetSuperblock()->inodes_per_group) / BlockSize();
} }
glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlock( glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2BlockReader::ReadBlock(
uint64_t block_number) { uint64_t block_number) {
return ReadBlocks(block_number, 1); return ReadBlocks(block_number, 1);
} }
glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlocks( glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
uint64_t block_number, uint64_t num_blocks) { uint64_t block_number, uint64_t num_blocks) {
ReadRequest req; ReadRequest req;
req.set_device_id(device_id_); req.set_device_id(device_id_);
@ -71,10 +71,10 @@ glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
req.set_size(num_blocks * SectorsPerBlock()); req.set_size(num_blocks * SectorsPerBlock());
ReadResponse resp; ReadResponse resp;
RET_ERR(denali_.Read(req, resp)); RET_ERR(denali_.Read(req, resp));
return OwnedMemoryRegion::FromCapability(resp.memory()); return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
} }
glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlocks( glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
const glcr::Vector<uint64_t>& block_list) { const glcr::Vector<uint64_t>& block_list) {
ReadManyRequest req; ReadManyRequest req;
req.set_device_id(device_id_); req.set_device_id(device_id_);
@ -93,12 +93,12 @@ glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
dbgln("Read many: {x}", req.lba().size()); dbgln("Read many: {x}", req.lba().size());
ReadResponse resp; ReadResponse resp;
RET_ERR(denali_.ReadMany(req, resp)); RET_ERR(denali_.ReadMany(req, resp));
return OwnedMemoryRegion::FromCapability(resp.memory()); return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
} }
Ext2BlockReader::Ext2BlockReader(DenaliClient&& denali, uint64_t device_id, Ext2BlockReader::Ext2BlockReader(DenaliClient&& denali, uint64_t device_id,
uint64_t lba_offset, uint64_t lba_offset,
OwnedMemoryRegion&& super_block) mmth::OwnedMemoryRegion&& super_block)
: denali_(glcr::Move(denali)), : denali_(glcr::Move(denali)),
device_id_(device_id), device_id_(device_id),
lba_offset_(lba_offset), lba_offset_(lba_offset),

View File

@ -3,7 +3,7 @@
#include <denali/denali.yunq.client.h> #include <denali/denali.yunq.client.h>
#include <glacier/memory/shared_ptr.h> #include <glacier/memory/shared_ptr.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/memory_region.h> #include <mammoth/util/memory_region.h>
#include <yellowstone/yellowstone.yunq.h> #include <yellowstone/yellowstone.yunq.h>
#include "fs/ext2/ext2.h" #include "fs/ext2/ext2.h"
@ -29,21 +29,21 @@ class Ext2BlockReader {
// because the last table will likely be smaller. // because the last table will likely be smaller.
uint64_t InodeTableBlockSize(); uint64_t InodeTableBlockSize();
glcr::ErrorOr<OwnedMemoryRegion> ReadBlock(uint64_t block_number); glcr::ErrorOr<mmth::OwnedMemoryRegion> ReadBlock(uint64_t block_number);
glcr::ErrorOr<OwnedMemoryRegion> ReadBlocks(uint64_t block_number, glcr::ErrorOr<mmth::OwnedMemoryRegion> ReadBlocks(uint64_t block_number,
uint64_t num_blocks); uint64_t num_blocks);
glcr::ErrorOr<OwnedMemoryRegion> ReadBlocks( glcr::ErrorOr<mmth::OwnedMemoryRegion> ReadBlocks(
const glcr::Vector<uint64_t>& block_list); const glcr::Vector<uint64_t>& block_list);
private: private:
DenaliClient denali_; DenaliClient denali_;
uint64_t device_id_; uint64_t device_id_;
uint64_t lba_offset_; uint64_t lba_offset_;
OwnedMemoryRegion super_block_region_; mmth::OwnedMemoryRegion super_block_region_;
Ext2BlockReader(DenaliClient&& denali, uint64_t device_id, Ext2BlockReader(DenaliClient&& denali, uint64_t device_id,
uint64_t lba_offset, OwnedMemoryRegion&& super_block); uint64_t lba_offset, mmth::OwnedMemoryRegion&& super_block);
uint64_t SectorsPerBlock(); uint64_t SectorsPerBlock();
}; };

View File

@ -1,14 +1,14 @@
#include "fs/ext2/ext2_driver.h" #include "fs/ext2/ext2_driver.h"
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
glcr::ErrorOr<Ext2Driver> Ext2Driver::Init(const DenaliInfo& denali_info) { glcr::ErrorOr<Ext2Driver> Ext2Driver::Init(const DenaliInfo& denali_info) {
ASSIGN_OR_RETURN(glcr::SharedPtr<Ext2BlockReader> reader, ASSIGN_OR_RETURN(glcr::SharedPtr<Ext2BlockReader> reader,
Ext2BlockReader::Init(glcr::Move(denali_info))); Ext2BlockReader::Init(glcr::Move(denali_info)));
ASSIGN_OR_RETURN( ASSIGN_OR_RETURN(
OwnedMemoryRegion bgdt, mmth::OwnedMemoryRegion bgdt,
reader->ReadBlocks(reader->BgdtBlockNum(), reader->BgdtBlockSize())); reader->ReadBlocks(reader->BgdtBlockNum(), reader->BgdtBlockSize()));
glcr::UniquePtr<InodeTable> inode_table( glcr::UniquePtr<InodeTable> inode_table(
new InodeTable(reader, glcr::Move(bgdt))); new InodeTable(reader, glcr::Move(bgdt)));
@ -63,7 +63,7 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
glcr::Vector<DirEntry> directory; glcr::Vector<DirEntry> directory;
for (uint64_t i = 0; i < real_block_cnt; i++) { for (uint64_t i = 0; i < real_block_cnt; i++) {
dbgln("Getting block {x}", inode->block[i]); dbgln("Getting block {x}", inode->block[i]);
ASSIGN_OR_RETURN(OwnedMemoryRegion block, ASSIGN_OR_RETURN(mmth::OwnedMemoryRegion block,
ext2_reader_->ReadBlock(inode->block[i])); ext2_reader_->ReadBlock(inode->block[i]));
uint64_t addr = block.vaddr(); uint64_t addr = block.vaddr();
while (addr < block.vaddr() + ext2_reader_->BlockSize()) { while (addr < block.vaddr() + ext2_reader_->BlockSize()) {
@ -86,7 +86,8 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
return directory; return directory;
} }
glcr::ErrorOr<OwnedMemoryRegion> Ext2Driver::ReadFile(uint64_t inode_number) { glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2Driver::ReadFile(
uint64_t inode_number) {
ASSIGN_OR_RETURN(Inode * inode, inode_table_->GetInode(inode_number)); ASSIGN_OR_RETURN(Inode * inode, inode_table_->GetInode(inode_number));
if (!(inode->mode & 0x8000)) { if (!(inode->mode & 0x8000)) {
@ -103,12 +104,13 @@ glcr::ErrorOr<OwnedMemoryRegion> Ext2Driver::ReadFile(uint64_t inode_number) {
return glcr::UNIMPLEMENTED; return glcr::UNIMPLEMENTED;
} }
mmth::OwnedMemoryRegion double_indirect_block;
if (inode->block[13]) { if (inode->block[13]) {
dbgln("Can't handle doubly-indirect blocks yet."); ASSIGN_OR_RETURN(double_indirect_block,
return glcr::UNIMPLEMENTED; ext2_reader_->ReadBlock(inode->block[13]));
} }
OwnedMemoryRegion indirect_block; mmth::OwnedMemoryRegion indirect_block;
if (inode->block[12]) { if (inode->block[12]) {
ASSIGN_OR_RETURN(indirect_block, ext2_reader_->ReadBlock(inode->block[12])); ASSIGN_OR_RETURN(indirect_block, ext2_reader_->ReadBlock(inode->block[12]));
} }
@ -118,10 +120,31 @@ glcr::ErrorOr<OwnedMemoryRegion> Ext2Driver::ReadFile(uint64_t inode_number) {
blocks_to_read.PushBack(inode->block[i]); blocks_to_read.PushBack(inode->block[i]);
} }
uint32_t* indr_block_array =
reinterpret_cast<uint32_t*>(indirect_block.vaddr());
for (uint64_t i = 12; i < 268 && i < real_block_cnt; i++) { for (uint64_t i = 12; i < 268 && i < real_block_cnt; i++) {
uint32_t* block_array = reinterpret_cast<uint32_t*>(indirect_block.vaddr());
uint64_t offset = i - 12; uint64_t offset = i - 12;
blocks_to_read.PushBack(block_array[offset]); blocks_to_read.PushBack(indr_block_array[offset]);
}
uint32_t* dbl_indr_block_array =
reinterpret_cast<uint32_t*>(double_indirect_block.vaddr());
for (uint64_t i = 0; i < 256; i++) {
uint64_t block = 268 + (256 * i);
if (block >= real_block_cnt) {
break;
}
ASSIGN_OR_RETURN(mmth::OwnedMemoryRegion single_indr_block,
ext2_reader_->ReadBlock(dbl_indr_block_array[i]));
uint32_t* single_indr_block_array =
reinterpret_cast<uint32_t*>(single_indr_block.vaddr());
for (uint64_t j = 0; j < 256; j++) {
uint64_t block_inner = block + j;
if (block_inner >= real_block_cnt) {
break;
}
blocks_to_read.PushBack(single_indr_block_array[j]);
}
} }
return ext2_reader_->ReadBlocks(blocks_to_read); return ext2_reader_->ReadBlocks(blocks_to_read);

View File

@ -18,7 +18,7 @@ class Ext2Driver {
glcr::ErrorOr<glcr::Vector<DirEntry>> ReadDirectory(uint32_t inode_number); glcr::ErrorOr<glcr::Vector<DirEntry>> ReadDirectory(uint32_t inode_number);
glcr::ErrorOr<OwnedMemoryRegion> ReadFile(uint64_t inode_number); glcr::ErrorOr<mmth::OwnedMemoryRegion> ReadFile(uint64_t inode_number);
private: private:
glcr::SharedPtr<Ext2BlockReader> ext2_reader_; glcr::SharedPtr<Ext2BlockReader> ext2_reader_;

View File

@ -1,9 +1,7 @@
#include "fs/ext2/inode_table.h" #include "fs/ext2/inode_table.h"
#include <mammoth/debug.h>
InodeTable::InodeTable(const glcr::SharedPtr<Ext2BlockReader>& reader, InodeTable::InodeTable(const glcr::SharedPtr<Ext2BlockReader>& reader,
OwnedMemoryRegion&& bgdt_region) mmth::OwnedMemoryRegion&& bgdt_region)
: ext2_reader_(reader), : ext2_reader_(reader),
bgdt_region_(glcr::Move(bgdt_region)), bgdt_region_(glcr::Move(bgdt_region)),
bgdt_(reinterpret_cast<BlockGroupDescriptor*>(bgdt_region_.vaddr())) { bgdt_(reinterpret_cast<BlockGroupDescriptor*>(bgdt_region_.vaddr())) {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <glacier/container/vector.h> #include <glacier/container/vector.h>
#include <mammoth/util/memory_region.h>
#include <stdint.h> #include <stdint.h>
#include "fs/ext2/ext2_block_reader.h" #include "fs/ext2/ext2_block_reader.h"
@ -8,16 +9,16 @@
class InodeTable { class InodeTable {
public: public:
InodeTable(const glcr::SharedPtr<Ext2BlockReader>& driver, InodeTable(const glcr::SharedPtr<Ext2BlockReader>& driver,
OwnedMemoryRegion&& bgdt_region); mmth::OwnedMemoryRegion&& bgdt_region);
glcr::ErrorOr<Inode*> GetInode(uint32_t inode_num); glcr::ErrorOr<Inode*> GetInode(uint32_t inode_num);
private: private:
glcr::SharedPtr<Ext2BlockReader> ext2_reader_; glcr::SharedPtr<Ext2BlockReader> ext2_reader_;
OwnedMemoryRegion bgdt_region_; mmth::OwnedMemoryRegion bgdt_region_;
BlockGroupDescriptor* bgdt_; BlockGroupDescriptor* bgdt_;
glcr::Vector<OwnedMemoryRegion> inode_tables_; glcr::Vector<mmth::OwnedMemoryRegion> inode_tables_;
glcr::ErrorOr<Inode*> GetRootOfInodeTable(uint64_t block_group_num); glcr::ErrorOr<Inode*> GetRootOfInodeTable(uint64_t block_group_num);
}; };

View File

@ -1,7 +1,7 @@
// Generated file -- DO NOT MODIFY. // Generated file -- DO NOT MODIFY.
#include "victoriafalls.yunq.server.h" #include "victoriafalls.yunq.server.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
namespace { namespace {

View File

@ -2,7 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
#include "victoriafalls.yunq.h" #include "victoriafalls.yunq.h"

View File

@ -1,5 +1,5 @@
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/init.h> #include <mammoth/util/init.h>
#include <yellowstone/yellowstone.yunq.client.h> #include <yellowstone/yellowstone.yunq.client.h>
#include "fs/ext2/ext2_driver.h" #include "fs/ext2/ext2_driver.h"

View File

@ -1,7 +1,7 @@
#include "victoriafalls_server.h" #include "victoriafalls_server.h"
#include <glacier/string/str_split.h> #include <glacier/string/str_split.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create( glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create(
@ -38,7 +38,7 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
} }
uint64_t inode_num; uint64_t inode_num;
OwnedMemoryRegion region; mmth::OwnedMemoryRegion region;
for (uint64_t j = 0; j < files.size(); j++) { for (uint64_t j = 0; j < files.size(); j++) {
if (path_tokens.at(path_tokens.size() - 1) == if (path_tokens.at(path_tokens.size() - 1) ==
glcr::StringView(files.at(j).name, files.at(j).name_len)) { glcr::StringView(files.at(j).name, files.at(j).name_len)) {

View File

@ -2,8 +2,8 @@
#include <glacier/memory/move.h> #include <glacier/memory/move.h>
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/memory_region.h> #include <mammoth/util/memory_region.h>
#include <zcall.h> #include <zcall.h>
#include <zglobal.h> #include <zglobal.h>
@ -64,8 +64,8 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
req.set_size(2); req.set_size(2);
ReadResponse resp; ReadResponse resp;
RET_ERR(denali_->Read(req, resp)); RET_ERR(denali_->Read(req, resp));
OwnedMemoryRegion lba_1_and_2 = mmth::OwnedMemoryRegion lba_1_and_2 =
OwnedMemoryRegion::FromCapability(resp.memory()); mmth::OwnedMemoryRegion::FromCapability(resp.memory());
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE); uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
if (*mbr_sig != 0xAA55) { if (*mbr_sig != 0xAA55) {
dbgln("Invalid MBR Sig: {x}", *mbr_sig); dbgln("Invalid MBR Sig: {x}", *mbr_sig);
@ -106,8 +106,8 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
req.set_lba(header->lba_partition_entries); req.set_lba(header->lba_partition_entries);
req.set_size(num_blocks); req.set_size(num_blocks);
RET_ERR(denali_->Read(req, resp)); RET_ERR(denali_->Read(req, resp));
OwnedMemoryRegion part_table = mmth::OwnedMemoryRegion part_table =
OwnedMemoryRegion::FromCapability(resp.memory()); mmth::OwnedMemoryRegion::FromCapability(resp.memory());
for (uint64_t i = 0; i < num_partitions; i++) { for (uint64_t i = 0; i < num_partitions; i++) {
PartitionEntry* entry = reinterpret_cast<PartitionEntry*>( PartitionEntry* entry = reinterpret_cast<PartitionEntry*>(
part_table.vaddr() + (i * entry_size)); part_table.vaddr() + (i * entry_size));

View File

@ -1,7 +1,7 @@
#include "hw/pcie.h" #include "hw/pcie.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/init.h> #include <mammoth/util/init.h>
#include <zcall.h> #include <zcall.h>
#define PCI_DEBUG 0 #define PCI_DEBUG 0

View File

@ -1,7 +1,7 @@
// Generated file -- DO NOT MODIFY. // Generated file -- DO NOT MODIFY.
#include "yellowstone.yunq.server.h" #include "yellowstone.yunq.server.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
namespace { namespace {

View File

@ -2,7 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
#include "yellowstone.yunq.h" #include "yellowstone.yunq.h"

View File

@ -1,10 +1,10 @@
#include <glacier/string/str_format.h> #include <glacier/string/str_format.h>
#include <glacier/string/str_split.h> #include <glacier/string/str_split.h>
#include <mammoth/debug.h> #include <mammoth/file/file.h>
#include <mammoth/endpoint_client.h> #include <mammoth/proc/process.h>
#include <mammoth/init.h> #include <mammoth/util/debug.h>
#include <mammoth/memory_region.h> #include <mammoth/util/init.h>
#include <mammoth/process.h> #include <mammoth/util/memory_region.h>
#include <zcall.h> #include <zcall.h>
#include <ztypes.h> #include <ztypes.h>
@ -13,8 +13,9 @@
#include "yellowstone_server.h" #include "yellowstone_server.h"
glcr::ErrorCode SpawnProcess(z_cap_t vmmo_cap, z_cap_t yellowstone_cap) { glcr::ErrorCode SpawnProcess(z_cap_t vmmo_cap, z_cap_t yellowstone_cap) {
OwnedMemoryRegion region = OwnedMemoryRegion::FromCapability(vmmo_cap); mmth::OwnedMemoryRegion region =
return SpawnProcessFromElfRegion(region.vaddr(), yellowstone_cap); mmth::OwnedMemoryRegion::FromCapability(vmmo_cap);
return mmth::SpawnProcessFromElfRegion(region.vaddr(), yellowstone_cap);
} }
uint64_t main(uint64_t port_cap) { uint64_t main(uint64_t port_cap) {
@ -27,38 +28,28 @@ uint64_t main(uint64_t port_cap) {
ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient()); ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient());
check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability())); check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability()));
check(server->WaitDenaliRegistered()); server->WaitDenaliRegistered();
ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient()); ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient());
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability())); check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability()));
check(server->WaitVictoriaFallsRegistered()); server->WaitVictoriaFallsRegistered();
dbgln("VFS Available."); dbgln("VFS Available.");
auto vfs_client = server->GetVFSClient(); mmth::File init_file = mmth::File::Open("/init.txt");
OpenFileRequest request;
request.set_path("/init.txt");
OpenFileResponse response;
check(vfs_client->OpenFile(request, response));
OwnedMemoryRegion filemem = glcr::Vector<glcr::StringView> files =
OwnedMemoryRegion::FromCapability(response.memory()); glcr::StrSplit(init_file.as_str(), '\n');
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size());
glcr::Vector<glcr::StringView> files = glcr::StrSplit(file, '\n');
for (uint64_t i = 0; i < files.size(); i++) { for (uint64_t i = 0; i < files.size(); i++) {
if (!files[i].empty()) { if (!files[i].empty()) {
dbgln("Starting {}", files[i]); mmth::File binary =
OpenFileRequest req; mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
req.set_path(glcr::StrFormat("/bin/{}", files[i]));
OpenFileResponse resp;
check(vfs_client->OpenFile(req, resp));
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient()); ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient());
check(SpawnProcess(resp.memory(), client3.Capability())); check(mmth::SpawnProcessFromElfRegion((uint64_t)binary.raw_ptr(),
client3.Capability()));
} }
} }

View File

@ -2,11 +2,12 @@
#include <denali/denali.yunq.client.h> #include <denali/denali.yunq.client.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <mammoth/debug.h> #include <mammoth/file/file.h>
#include <mammoth/init.h> #include <mammoth/util/debug.h>
#include <mammoth/memory_region.h> #include <mammoth/util/init.h>
#include <mammoth/process.h> #include <mammoth/util/memory_region.h>
#include <stdlib.h> #include <stdlib.h>
#include <zcall.h>
#include "hw/gpt.h" #include "hw/gpt.h"
#include "hw/pcie.h" #include "hw/pcie.h"
@ -34,21 +35,12 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
z_cap_t endpoint_cap; z_cap_t endpoint_cap;
RET_ERR(ZEndpointCreate(&endpoint_cap)); RET_ERR(ZEndpointCreate(&endpoint_cap));
ASSIGN_OR_RETURN(Mutex denali_mut, Mutex::Create()); return glcr::UniquePtr<YellowstoneServer>(
RET_ERR(denali_mut.Lock()); new YellowstoneServer(endpoint_cap));
ASSIGN_OR_RETURN(Mutex victoriafalls_mut, Mutex::Create());
RET_ERR(victoriafalls_mut.Lock());
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(
endpoint_cap, glcr::Move(denali_mut), glcr::Move(victoriafalls_mut)));
} }
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
Mutex&& victoriafalls_mutex) : YellowstoneServerBase(endpoint_cap) {}
: YellowstoneServerBase(endpoint_cap),
has_denali_mutex_(glcr::Move(denali_mutex)),
has_victoriafalls_mutex_(glcr::Move(victoriafalls_mutex)) {}
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&, glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
AhciInfo& info) { AhciInfo& info) {
@ -60,8 +52,8 @@ glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo( glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
const Empty&, FramebufferInfo& info) { const Empty&, FramebufferInfo& info) {
// FIXME: Don't do this for each request. // FIXME: Don't do this for each request.
OwnedMemoryRegion region = mmth::OwnedMemoryRegion region =
OwnedMemoryRegion::FromCapability(gBootFramebufferVmmoCap); mmth::OwnedMemoryRegion::FromCapability(gBootFramebufferVmmoCap);
ZFramebufferInfo* fb = reinterpret_cast<ZFramebufferInfo*>(region.vaddr()); ZFramebufferInfo* fb = reinterpret_cast<ZFramebufferInfo*>(region.vaddr());
info.set_address_phys(fb->address_phys); info.set_address_phys(fb->address_phys);
@ -105,12 +97,12 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
device_id_ = part_info_or.value().device_id; device_id_ = part_info_or.value().device_id;
lba_offset_ = part_info_or.value().partition_lba; lba_offset_ = part_info_or.value().partition_lba;
check(has_denali_mutex_.Release()); has_denali_semaphore_.Signal();
} else if (req.endpoint_name() == "victoriafalls") { } else if (req.endpoint_name() == "victoriafalls") {
// FIXME: Probably make a separate copy for use within yellowstone vs // FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes. // transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability()); mmth::SetVfsCap(req.endpoint_capability());
check(has_victoriafalls_mutex_.Release()); has_victoriafalls_semaphore_.Signal();
} else { } else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
} }
@ -129,16 +121,8 @@ glcr::ErrorCode YellowstoneServer::HandleGetEndpoint(
return glcr::OK; return glcr::OK;
} }
glcr::ErrorCode YellowstoneServer::WaitDenaliRegistered() { void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
RET_ERR(has_denali_mutex_.Lock());
return has_denali_mutex_.Release();
}
glcr::ErrorCode YellowstoneServer::WaitVictoriaFallsRegistered() { void YellowstoneServer::WaitVictoriaFallsRegistered() {
RET_ERR(has_victoriafalls_mutex_.Lock()); has_victoriafalls_semaphore_.Wait();
return has_victoriafalls_mutex_.Release();
}
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {
return vfs_client_;
} }

View File

@ -4,10 +4,7 @@
#include <glacier/memory/shared_ptr.h> #include <glacier/memory/shared_ptr.h>
#include <glacier/memory/unique_ptr.h> #include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h> #include <mammoth/sync/semaphore.h>
#include <mammoth/mutex.h>
#include <mammoth/port_server.h>
#include <mammoth/thread.h>
#include <victoriafalls/victoriafalls.yunq.client.h> #include <victoriafalls/victoriafalls.yunq.client.h>
#include "hw/pcie.h" #include "hw/pcie.h"
@ -26,10 +23,8 @@ class YellowstoneServer : public YellowstoneServerBase {
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
Endpoint&) override; Endpoint&) override;
glcr::ErrorCode WaitDenaliRegistered(); void WaitDenaliRegistered();
glcr::ErrorCode WaitVictoriaFallsRegistered(); void WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient();
private: private:
glcr::HashMap<glcr::String, z_cap_t> endpoint_map_; glcr::HashMap<glcr::String, z_cap_t> endpoint_map_;
@ -40,9 +35,8 @@ class YellowstoneServer : public YellowstoneServerBase {
PciReader pci_reader_; PciReader pci_reader_;
Mutex has_denali_mutex_; mmth::Semaphore has_denali_semaphore_;
Mutex has_victoriafalls_mutex_; mmth::Semaphore has_victoriafalls_semaphore_;
YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, YellowstoneServer(z_cap_t endpoint_cap);
Mutex&& victoriafalls_mutex);
}; };

View File

@ -1 +1,2 @@
teton teton

View File

@ -1,7 +1,7 @@
// Generated file -- DO NOT MODIFY. // Generated file -- DO NOT MODIFY.
#include "{{file}}.server.h" #include "{{file}}.server.h"
#include <mammoth/debug.h> #include <mammoth/util/debug.h>
#include <zcall.h> #include <zcall.h>
namespace { namespace {

View File

@ -2,7 +2,7 @@
#pragma once #pragma once
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/thread.h> #include <mammoth/proc/thread.h>
#include <ztypes.h> #include <ztypes.h>
#include "{{file}}.h" #include "{{file}}.h"