Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wutcrt: Fix the trap instruction and move it directly into __rpx_start #302

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

Maschell
Copy link
Contributor

Apparently the trap instruction (tw 0x1f, 30, 0 / 0x7ffe0008) is a "DBGCTL_INSTRUCTION" which excepts specific values in r3,r4 and r5. The gdb stub of the coreinit.rpl uses it to set an "initial breakpoint" which gets removed immediatly after it's hit once. Retail software loads "main" into r4 and "ctors" into r5. For now I decided to set r4 and r5 both to "main"

The code that is handling the exception does somelthing like this

[...]
auto trap_symbol = (DBGCTL_FLAGS) MasterAgent_GetRegister32(coreInfo, coreInfo->stoppedContext, 3);
auto r4          = MasterAgent_GetRegister32(coreInfo, coreInfo->stoppedContext, 4);
if(trap_symbol == DBGCTL_INIT_BREAKPOINT /* 2 */) {
    auto r5 = MasterAgent_GetRegister32(coreInfo, coreInfo->stoppedContext, 5);
    auto r5 = MasterAgent_GetRegister32(coreInfo, coreInfo->stoppedContext, 5);
    if (gInitialBreakpointSet == 0) {
        auto appFlags = __OSGetAppFlags();
        if (((appFlags & 0x40) != 0) || ((appFlags & 0x10) != 0)) {
            MasterAgent_SetInitialBreakpoint(r5);
        } else if ((appFlags & 0x20) == 0) {
            MasterAgent_SetInitialBreakpoint(r4);
        }
    }
    [...]
    return;
}

So depending on the "AppFlags" the breakpoint is set to either r4 or r5 (or not at all?).

I also moved it to the crt0_rpx.s instead of __init_wutto not have it in rpl (and anything else that uses __init_wut)

@Maschell
Copy link
Contributor Author

Maybe instead setting the initial breakpoint tomain, we should set it to __init_wut? Otherwise we are not able to debug __init_wut at all

@Maschell Maschell marked this pull request as ready for review February 17, 2023 10:48
@fincs fincs merged commit 7f6e450 into devkitPro:master Feb 17, 2023
@Maschell Maschell deleted the dbg_ctl branch March 26, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants