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-11-22 16:58:13 -08:00
|
|
|
#include <mammoth/file/file.h>
|
2023-11-22 14:10:10 -08:00
|
|
|
#include <mammoth/proc/process.h>
|
2023-11-22 14:39:27 -08:00
|
|
|
#include <mammoth/util/debug.h>
|
|
|
|
#include <mammoth/util/init.h>
|
|
|
|
#include <mammoth/util/memory_region.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) {
|
2023-11-22 14:59:41 -08:00
|
|
|
mmth::OwnedMemoryRegion region =
|
|
|
|
mmth::OwnedMemoryRegion::FromCapability(vmmo_cap);
|
2023-12-02 13:26:42 -08:00
|
|
|
auto error_or =
|
|
|
|
mmth::SpawnProcessFromElfRegion(region.vaddr(), yellowstone_cap);
|
|
|
|
if (error_or.ok()) {
|
|
|
|
return glcr::OK;
|
|
|
|
}
|
|
|
|
return error_or.error();
|
2023-11-19 21:38:04 -08:00
|
|
|
}
|
|
|
|
|
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-11-30 08:50:43 -08:00
|
|
|
ASSIGN_OR_RETURN(auto server, yellowstone::YellowstoneServer::Create());
|
2023-08-01 16:08:34 -07:00
|
|
|
Thread server_thread = server->RunServer();
|
2023-06-19 21:54:40 -07:00
|
|
|
|
2023-11-27 08:28:58 -08:00
|
|
|
ASSIGN_OR_RETURN(uint64_t client_cap, server->CreateClientCap());
|
|
|
|
check(SpawnProcess(gBootDenaliVmmoCap, client_cap));
|
2023-10-25 19:08:00 -07:00
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
server->WaitDenaliRegistered();
|
2023-10-25 19:08:00 -07:00
|
|
|
|
2023-11-27 08:28:58 -08:00
|
|
|
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
|
|
|
|
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client_cap));
|
2023-06-07 22:45:42 -07:00
|
|
|
|
2023-11-22 13:30:59 -08:00
|
|
|
server->WaitVictoriaFallsRegistered();
|
2023-11-02 18:55:05 -07:00
|
|
|
|
|
|
|
dbgln("VFS Available.");
|
|
|
|
|
2023-11-22 16:58:13 -08:00
|
|
|
mmth::File init_file = mmth::File::Open("/init.txt");
|
2023-11-02 19:28:27 -07:00
|
|
|
|
2023-11-22 16:58:13 -08:00
|
|
|
glcr::Vector<glcr::StringView> files =
|
|
|
|
glcr::StrSplit(init_file.as_str(), '\n');
|
2023-11-09 12:55:44 -08:00
|
|
|
|
2024-01-11 17:13:35 -08:00
|
|
|
for (glcr::StringView& file : files) {
|
|
|
|
if (!file.empty()) {
|
2024-02-24 15:12:21 -08:00
|
|
|
// TODO: Implement startup dependencies.
|
|
|
|
if (file == "teton") {
|
|
|
|
server->WaitVoyageursRegistered();
|
|
|
|
}
|
2024-01-11 17:13:35 -08:00
|
|
|
mmth::File binary = mmth::File::Open(glcr::StrFormat("/bin/{}", file));
|
2023-11-09 12:55:44 -08:00
|
|
|
|
2023-11-27 08:28:58 -08:00
|
|
|
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
|
2023-12-02 13:26:42 -08:00
|
|
|
auto error_or = mmth::SpawnProcessFromElfRegion(
|
|
|
|
(uint64_t)binary.raw_ptr(), client_cap);
|
|
|
|
if (!error_or.ok()) {
|
|
|
|
check(error_or.error());
|
|
|
|
}
|
2023-11-09 12:55:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|