dmnt: pull in from ams.tma branch

This commit is contained in:
Michael Scire 2019-02-27 01:44:47 -08:00
commit 89503049b3
9 changed files with 957 additions and 10 deletions

View file

@ -41,6 +41,8 @@ static bool HasLaunchedTitle(Boot2KnownTitleId title_id) {
return std::find(g_boot2_titles.begin(), g_boot2_titles.end(), title_id) != g_boot2_titles.end();
}
static std::vector<Boot2KnownTitleId> g_launched_titles;
static bool IsHexadecimal(const char *str) {
while (*str) {
if (isxdigit(*str)) {
@ -52,8 +54,20 @@ static bool IsHexadecimal(const char *str) {
return true;
}
static bool HasLaunchedTitle(Boot2KnownTitleId title_id) {
return std::find(g_launched_titles.begin(), g_launched_titles.end(), title_id) != g_launched_titles.end();
}
static void SetLaunchedTitle(Boot2KnownTitleId title_id) {
g_launched_titles.push_back(title_id);
}
static void ClearLaunchedTitles() {
g_launched_titles.clear();
}
static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
u64 local_pid;
u64 local_pid = 0;
/* Don't launch a title twice during boot2. */
if (HasLaunchedTitle(title_id)) {
@ -64,15 +78,15 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
switch (rc) {
case 0xCE01:
/* Out of resource! */
/* TODO: Panic(). */
std::abort();
break;
case 0xDE01:
/* Out of memory! */
/* TODO: Panic(). */
std::abort();
break;
case 0xD001:
/* Limit Reached! */
/* TODO: Panic(). */
std::abort();
break;
default:
/* We don't care about other issues. */
@ -235,8 +249,9 @@ void EmbeddedBoot2::Main() {
/* Launch usb. */
LaunchTitle(Boot2KnownTitleId::usb, FsStorageId_NandSystem, 0, NULL);
/* Launch tma. */
LaunchTitle(Boot2KnownTitleId::tma, FsStorageId_NandSystem, 0, NULL);
/* Launch Atmosphere dmnt, using FsStorageId_None to force SD card boot. */
LaunchTitle(Boot2KnownTitleId::dmnt, FsStorageId_None, 0, NULL);
/* Launch default programs. */
for (auto &launch_program : g_additional_launch_programs) {
@ -251,7 +266,10 @@ void EmbeddedBoot2::Main() {
if (titles_dir != NULL) {
while ((ent = readdir(titles_dir)) != NULL) {
if (strlen(ent->d_name) == 0x10 && IsHexadecimal(ent->d_name)) {
u64 title_id = strtoul(ent->d_name, NULL, 16);
Boot2KnownTitleId title_id = (Boot2KnownTitleId)strtoul(ent->d_name, NULL, 16);
if (HasLaunchedTitle(title_id)) {
continue;
}
char title_path[FS_MAX_PATH] = {0};
strcpy(title_path, "sdmc:/atmosphere/titles/");
strcat(title_path, ent->d_name);
@ -259,7 +277,7 @@ void EmbeddedBoot2::Main() {
FILE *f_flag = fopen(title_path, "rb");
if (f_flag != NULL) {
fclose(f_flag);
LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL);
LaunchTitle(title_id, FsStorageId_None, 0, NULL);
} else {
/* TODO: Deprecate this in the future. */
memset(title_path, 0, FS_MAX_PATH);
@ -269,13 +287,16 @@ void EmbeddedBoot2::Main() {
f_flag = fopen(title_path, "rb");
if (f_flag != NULL) {
fclose(f_flag);
LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL);
LaunchTitle(title_id, FsStorageId_None, 0, NULL);
}
}
}
}
closedir(titles_dir);
}
/* Free the memory used to track what boot2 launches. */
ClearLaunchedTitles();
/* We no longer need the SD card. */
fsdevUnmountAll();