mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
Stratosphere: Add debugging to loader, it can now be talked to on console successfully.
This commit is contained in:
parent
8ba3894c3a
commit
7fed8a4428
7 changed files with 46 additions and 16 deletions
|
@ -18,6 +18,13 @@ class IWaitable {
|
||||||
return this->parent_waitable != NULL;
|
return this->parent_waitable != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_parent(IWaitable *p) {
|
||||||
|
if (has_parent()) {
|
||||||
|
/* TODO: Panic? */
|
||||||
|
}
|
||||||
|
this->parent_waitable = p;
|
||||||
|
}
|
||||||
|
|
||||||
IWaitable *get_parent() {
|
IWaitable *get_parent() {
|
||||||
return this->parent_waitable;
|
return this->parent_waitable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#include <cstdio>
|
||||||
#include "ldr_debug_monitor.hpp"
|
#include "ldr_debug_monitor.hpp"
|
||||||
#include "ldr_launch_queue.hpp"
|
#include "ldr_launch_queue.hpp"
|
||||||
|
|
||||||
|
@ -6,6 +7,8 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||||
|
|
||||||
Result rc = 0xF601;
|
Result rc = 0xF601;
|
||||||
|
|
||||||
|
fprintf(stderr, "TLS: %p\n", armGetTls());
|
||||||
|
|
||||||
/* TODO: Prepare SFCO. */
|
/* TODO: Prepare SFCO. */
|
||||||
|
|
||||||
switch ((DebugMonitorServiceCmd)cmd_id) {
|
switch ((DebugMonitorServiceCmd)cmd_id) {
|
||||||
|
@ -17,7 +20,7 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||||
|
|
||||||
rc = add_title_to_launch_queue(((u64 *)in_rawdata)[0], (const char *)r->Statics[0], r->StaticSizes[0]);
|
rc = add_title_to_launch_queue(((u64 *)in_rawdata)[0], (const char *)r->Statics[0], r->StaticSizes[0]);
|
||||||
|
|
||||||
*out_raw_data_count = 0;
|
*out_raw_data_count = 4;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Dmnt_Cmd_ClearLaunchQueue:
|
case Dmnt_Cmd_ClearLaunchQueue:
|
||||||
|
@ -26,7 +29,7 @@ Result DebugMonitorService::dispatch(IpcParsedCommand *r, IpcCommand *out_c, u32
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = clear_launch_queue();
|
rc = clear_launch_queue();
|
||||||
*out_raw_data_count = 0;
|
*out_raw_data_count = 4;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Dmnt_Cmd_GetNsoInfo:
|
case Dmnt_Cmd_GetNsoInfo:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
#include "ldr_launch_queue.hpp"
|
#include "ldr_launch_queue.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +18,10 @@ namespace LaunchQueue {
|
||||||
|
|
||||||
g_launch_queue[idx].tid = tid;
|
g_launch_queue[idx].tid = tid;
|
||||||
g_launch_queue[idx].arg_size = arg_size;
|
g_launch_queue[idx].arg_size = arg_size;
|
||||||
|
|
||||||
|
fprintf(stderr, "TID: %016llx, args: %p, size: %016llx\n", tid, args, arg_size);
|
||||||
|
fprintf(stderr, "Args: %s\n", args);
|
||||||
|
|
||||||
std::copy(args, args + arg_size, g_launch_queue[idx].args);
|
std::copy(args, args + arg_size, g_launch_queue[idx].args);
|
||||||
return 0x0;
|
return 0x0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,14 @@ void __libnx_initheap(void)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
consoleDebugInit(debugDevice_SVC);
|
||||||
|
|
||||||
/* TODO: What's a good timeout value to use here? */
|
/* TODO: What's a good timeout value to use here? */
|
||||||
WaitableManager *server_manager = new WaitableManager(U64_MAX);
|
WaitableManager *server_manager = new WaitableManager(U64_MAX);
|
||||||
|
|
||||||
/* Add services to manager. */
|
/* Add services to manager. */
|
||||||
server_manager->add_waitable(new ServiceServer<ShellService>("ldr:shel", 3));
|
server_manager->add_waitable(new ServiceServer<ShellService>("dbg:shel", 3));
|
||||||
server_manager->add_waitable(new ServiceServer<DebugMonitorService>("ldr:dmnt", 2));
|
server_manager->add_waitable(new ServiceServer<DebugMonitorService>("dbg:dmnt", 2));
|
||||||
|
|
||||||
/* Loop forever, servicing our services. */
|
/* Loop forever, servicing our services. */
|
||||||
server_manager->process();
|
server_manager->process();
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ServiceServer : public IWaitable {
|
||||||
ServiceSession<T> **sessions;
|
ServiceSession<T> **sessions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServiceServer(const char *service_name, unsigned int max_s) {
|
ServiceServer(const char *service_name, unsigned int max_s) : max_sessions(max_s) {
|
||||||
if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) {
|
if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) {
|
||||||
/* TODO: Panic. */
|
/* TODO: Panic. */
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,11 @@ class ServiceServer : public IWaitable {
|
||||||
Handle session_h;
|
Handle session_h;
|
||||||
svcAcceptSession(&session_h, this->port_handle);
|
svcAcceptSession(&session_h, this->port_handle);
|
||||||
|
|
||||||
|
fprintf(stderr, "Accept %08X -> %08X\n", this->port_handle, session_h);
|
||||||
|
fprintf(stderr, "Sessions: %08X/%08X\n", this->num_sessions, this->max_sessions);
|
||||||
|
|
||||||
if (this->num_sessions >= this->max_sessions) {
|
if (this->num_sessions >= this->max_sessions) {
|
||||||
|
fprintf(stderr, "Closing because of max sessions...\n");
|
||||||
svcCloseHandle(session_h);
|
svcCloseHandle(session_h);
|
||||||
return 0x10601;
|
return 0x10601;
|
||||||
}
|
}
|
||||||
|
@ -105,6 +109,7 @@ class ServiceServer : public IWaitable {
|
||||||
}
|
}
|
||||||
|
|
||||||
this->sessions[i] = new ServiceSession<T>(this, session_h, 0);
|
this->sessions[i] = new ServiceSession<T>(this, session_h, 0);
|
||||||
|
this->sessions[i]->set_parent(this);
|
||||||
this->num_sessions++;
|
this->num_sessions++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "iserviceobject.hpp"
|
#include "iserviceobject.hpp"
|
||||||
#include "iwaitable.hpp"
|
#include "iwaitable.hpp"
|
||||||
|
@ -70,6 +71,8 @@ class ServiceSession : public IWaitable {
|
||||||
IpcParsedCommand r;
|
IpcParsedCommand r;
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
|
|
||||||
|
fprintf(stderr, "Doing ServiceSession parse...\n");
|
||||||
|
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
|
|
||||||
retval = ipcParse(&r);
|
retval = ipcParse(&r);
|
||||||
|
@ -81,17 +84,21 @@ class ServiceSession : public IWaitable {
|
||||||
out_words += extra_rawdata_count;
|
out_words += extra_rawdata_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
if (retval != 0xF601) {
|
||||||
u64 magic;
|
struct {
|
||||||
u64 retval;
|
u64 magic;
|
||||||
} *raw;
|
u64 retval;
|
||||||
|
} *raw;
|
||||||
|
|
||||||
raw = (decltype(raw))ipcPrepareHeader(&c, out_words);
|
raw = (decltype(raw))ipcPrepareHeader(&c, out_words);
|
||||||
|
|
||||||
raw->magic = SFCO_MAGIC;
|
raw->magic = SFCO_MAGIC;
|
||||||
raw->retval = retval;
|
raw->retval = retval;
|
||||||
|
|
||||||
rc = svcReplyAndReceive(&handle_index, &this->server_handle, 1, this->server_handle, 0);
|
rc = svcReplyAndReceive(&handle_index, &this->server_handle, 1, this->server_handle, 0);
|
||||||
|
} else {
|
||||||
|
rc = retval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "waitablemanager.hpp"
|
#include "waitablemanager.hpp"
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ void WaitableManager::process() {
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
/* Handle a signaled waitable. */
|
/* Handle a signaled waitable. */
|
||||||
/* TODO: What timeout should be passed here? */
|
/* TODO: What timeout should be passed here? */
|
||||||
|
|
||||||
rc = signalables[handle_index]->handle_signaled(0);
|
rc = signalables[handle_index]->handle_signaled(0);
|
||||||
|
|
||||||
for (int i = 0; i < handle_index; i++) {
|
for (int i = 0; i < handle_index; i++) {
|
||||||
|
|
Loading…
Reference in a new issue