2023-11-03 02:48:21 -07:00
|
|
|
#include <glacier/string/str_format.h>
|
2023-11-09 12:55:44 -08:00
|
|
|
#include <glacier/string/str_split.h>
|
2023-06-07 00:04:53 -07:00
|
|
|
#include <mammoth/debug.h>
|
2023-06-21 21:26:24 -07:00
|
|
|
#include <mammoth/endpoint_client.h>
|
2023-06-16 23:51:49 -07:00
|
|
|
#include <mammoth/init.h>
|
2023-11-02 19:28:27 -07:00
|
|
|
#include <mammoth/memory_region.h>
|
2023-06-07 00:04:53 -07:00
|
|
|
#include <mammoth/process.h>
|
2023-06-07 00:19:15 -07:00
|
|
|
#include <zcall.h>
|
2023-11-09 11:20:41 -08:00
|
|
|
#include <ztypes.h>
|
2023-05-30 20:55:03 -07:00
|
|
|
|
2023-06-19 21:54:40 -07:00
|
|
|
#include "hw/gpt.h"
|
2023-06-07 22:45:42 -07:00
|
|
|
#include "hw/pcie.h"
|
2023-06-22 02:19:16 -07:00
|
|
|
#include "yellowstone_server.h"
|
2023-06-07 22:45:42 -07:00
|
|
|
|
2023-10-25 19:08:00 -07:00
|
|
|
glcr::ErrorCode SpawnProcess(z_cap_t vmmo_cap, z_cap_t yellowstone_cap) {
|
|
|
|
uint64_t vaddr;
|
|
|
|
RET_ERR(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
|
|
|
return SpawnProcessFromElfRegion(vaddr, yellowstone_cap);
|
|
|
|
}
|
|
|
|
|
2023-06-16 23:15:41 -07:00
|
|
|
uint64_t main(uint64_t port_cap) {
|
2023-06-16 23:51:49 -07:00
|
|
|
check(ParseInitPort(port_cap));
|
2023-11-03 02:48:21 -07:00
|
|
|
dbgln("Yellowstone Initializing.");
|
2023-06-16 23:51:49 -07:00
|
|
|
|
2023-06-26 11:38:17 -07:00
|
|
|
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
|
2023-08-01 16:08:34 -07:00
|
|
|
Thread server_thread = server->RunServer();
|
2023-06-19 21:54:40 -07:00
|
|
|
|
2023-10-25 19:08:00 -07:00
|
|
|
ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient());
|
|
|
|
check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability()));
|
|
|
|
|
|
|
|
check(server->WaitDenaliRegistered());
|
|
|
|
|
|
|
|
ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient());
|
|
|
|
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability()));
|
2023-06-07 22:45:42 -07:00
|
|
|
|
2023-11-02 18:55:05 -07:00
|
|
|
check(server->WaitVictoriaFallsRegistered());
|
|
|
|
|
|
|
|
dbgln("VFS Available.");
|
|
|
|
|
2023-11-02 19:28:27 -07:00
|
|
|
auto vfs_client = server->GetVFSClient();
|
|
|
|
OpenFileRequest request;
|
|
|
|
request.set_path("/init.txt");
|
|
|
|
OpenFileResponse response;
|
|
|
|
check(vfs_client->OpenFile(request, response));
|
|
|
|
|
2023-11-19 20:33:15 -08:00
|
|
|
OwnedMemoryRegion filemem =
|
|
|
|
OwnedMemoryRegion::FromCapability(response.memory());
|
2023-11-02 21:02:56 -07:00
|
|
|
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
|
|
|
|
response.size());
|
2023-11-02 19:28:27 -07:00
|
|
|
|
2023-11-09 12:55:44 -08:00
|
|
|
glcr::Vector<glcr::StringView> files = glcr::StrSplit(file, '\n');
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < files.size(); i++) {
|
|
|
|
if (!files[i].empty()) {
|
|
|
|
dbgln("Starting {}", files[i]);
|
|
|
|
OpenFileRequest req;
|
|
|
|
req.set_path(glcr::StrFormat("/bin/{}", files[i]));
|
|
|
|
OpenFileResponse resp;
|
|
|
|
check(vfs_client->OpenFile(req, resp));
|
|
|
|
|
|
|
|
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient());
|
|
|
|
check(SpawnProcess(resp.memory(), client3.Capability()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 16:08:34 -07:00
|
|
|
check(server_thread.Join());
|
2023-06-07 11:18:35 -07:00
|
|
|
dbgln("Yellowstone Finished Successfully.");
|
2023-05-29 00:32:54 -07:00
|
|
|
return 0;
|
|
|
|
}
|