⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdsh3.c

📁 WinCE5.0部分核心源码
💻 C
📖 第 1 页 / 共 4 页
字号:
        TargetPc = ContextRecord->Fir;
        for (Index = 0; Index < ScopeTable->Count; Index += 1) {
            if ((ControlPc >= ScopeTable->ScopeRecord[Index].BeginAddress) &&
                (ControlPc < ScopeTable->ScopeRecord[Index].EndAddress)) {
                // If the target PC is within the same scope the control PC
                // is within, then this is an uplevel goto out of an inner try
                // scope or a long jump back into a try scope. Terminate the
                // scan termination handlers.
                //
                // N.B. The target PC can be just beyond the end of the scope,
                //      in which case it is a leave from the scope.
                if ((TargetPc >= ScopeTable->ScopeRecord[Index].BeginAddress) &&
                    (TargetPc < ScopeTable->ScopeRecord[Index].EndAddress))
                    break;
                // If the scope table entry describes an exception filter
                // and the associated exception handler is the target of
                // the unwind, then terminate the scan for termination
                // handlers. Otherwise, if the scope table entry describes
                // a termination handler, then record the address of the
                // end of the scope as the new control PC address and call
                // the termination handler.
                if (ScopeTable->ScopeRecord[Index].JumpTarget) {
                    if (TargetPc == ScopeTable->ScopeRecord[Index].JumpTarget)
                        break;
                } else {
                    DispatcherContext->ControlPc = ScopeTable->ScopeRecord[Index].EndAddress + 4;
                    TerminationHandler = (TERMINATION_HANDLER)ScopeTable->ScopeRecord[Index].HandlerAddress;
                    __C_ExecuteTerminationHandler(TRUE,TerminationHandler,(ULONG)EstablisherFrame);
                }
            }
        }
    }
    // Continue search for exception or termination handlers.
    return ExceptionContinueSearch;
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL 
DoThreadGetContext(
    HANDLE hTh, 
    LPCONTEXT lpContext
    ) 
{
    PTHREAD pth;
    ULONG   ulContextFlags = lpContext->ContextFlags; // Keep a local copy of the context flag
    if (!(pth = HandleToThread(hTh))) {
        SetLastError(ERROR_INVALID_HANDLE);
        return FALSE;
    }
    if (ulContextFlags & ~CONTEXT_FULL) {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    // Clear the SH3 and SH4 bits in the context flags.  These are use to differentiate
    // SH3 and SH4.  Without doing so, the masking will always be true because of these 
    // bits.  For example, (CONTEXT_CONTROL & CONTEXT_INTEGER) will be either 0x40 or 0xc0 
    // depending on the processor, but it will never be zero.  So the consequence is that
    // we always return the full context no mater what flags users specify.
    // (Please see \public\common\sdk\inc\winnt.h for details.)
    ulContextFlags &= ~CONTEXT_SH4; 

    if (pth->pThrdDbg && pth->pThrdDbg->psavedctx) {
        ACCESSKEY ulOldKey;
        SWITCHKEY(ulOldKey,0xffffffff);
        if (ulContextFlags & CONTEXT_CONTROL) {
            lpContext->PR = pth->pThrdDbg->psavedctx->PR;
            lpContext->R15 = pth->pThrdDbg->psavedctx->R15;
            lpContext->Fir = pth->pThrdDbg->psavedctx->Fir;
            lpContext->Psr = pth->pThrdDbg->psavedctx->Psr;
        }
        if (ulContextFlags & CONTEXT_INTEGER) {
            lpContext->MACH = pth->pThrdDbg->psavedctx->MACH;
            lpContext->MACL = pth->pThrdDbg->psavedctx->MACL;
            lpContext->GBR = pth->pThrdDbg->psavedctx->GBR;
            lpContext->R0 = pth->pThrdDbg->psavedctx->R0;
            lpContext->R1 = pth->pThrdDbg->psavedctx->R1;
            lpContext->R2 = pth->pThrdDbg->psavedctx->R2;
            lpContext->R3 = pth->pThrdDbg->psavedctx->R3;
            lpContext->R4 = pth->pThrdDbg->psavedctx->R4;
            lpContext->R5 = pth->pThrdDbg->psavedctx->R5;
            lpContext->R6 = pth->pThrdDbg->psavedctx->R6;
            lpContext->R7 = pth->pThrdDbg->psavedctx->R7;
            lpContext->R8 = pth->pThrdDbg->psavedctx->R8;
            lpContext->R9 = pth->pThrdDbg->psavedctx->R9;
            lpContext->R10 = pth->pThrdDbg->psavedctx->R10;
            lpContext->R11 = pth->pThrdDbg->psavedctx->R11;
            lpContext->R12 = pth->pThrdDbg->psavedctx->R12;
            lpContext->R13 = pth->pThrdDbg->psavedctx->R13;
            lpContext->R14 = pth->pThrdDbg->psavedctx->R14;
        }
#ifdef SH3
        if ( SH3DSP && (ulContextFlags & CONTEXT_DSP_REGISTERS)) {
            DSPFlushContext();
            lpContext->DSR = pth->pThrdDbg->psavedctx->DSR;
            lpContext->MOD = pth->pThrdDbg->psavedctx->MOD;
            lpContext->RS = pth->pThrdDbg->psavedctx->RS;
            lpContext->RE = pth->pThrdDbg->psavedctx->RE;
            lpContext->A0 = pth->pThrdDbg->psavedctx->A0;
            lpContext->A1 = pth->pThrdDbg->psavedctx->A1;
            lpContext->M0 = pth->pThrdDbg->psavedctx->M0;
            lpContext->M1 = pth->pThrdDbg->psavedctx->M1;
            lpContext->X0 = pth->pThrdDbg->psavedctx->X0;
            lpContext->X1 = pth->pThrdDbg->psavedctx->X1;
            lpContext->Y0 = pth->pThrdDbg->psavedctx->Y0;
            lpContext->Y1 = pth->pThrdDbg->psavedctx->Y1;
            lpContext->A0G = pth->pThrdDbg->psavedctx->A0G;
            lpContext->A1G = pth->pThrdDbg->psavedctx->A1G;
        }
#endif

#ifdef SH4
        if (ulContextFlags & CONTEXT_FLOATING_POINT) {
            FPUFlushContext();
            lpContext->Fpscr = pth->pThrdDbg->psavedctx->Fpscr;
            lpContext->Fpul = pth->pThrdDbg->psavedctx->Fpul;
            memcpy(lpContext->FRegs,pth->pThrdDbg->psavedctx->FRegs,sizeof(lpContext->FRegs));
            memcpy(lpContext->xFRegs,pth->pThrdDbg->psavedctx->xFRegs,sizeof(lpContext->xFRegs));
        }
#endif
        if (ulContextFlags & CONTEXT_DEBUG_REGISTERS) {

        }
        SETCURKEY(ulOldKey);
    } else {
        if (ulContextFlags & CONTEXT_CONTROL) {
            lpContext->PR = pth->ctx.PR;
            lpContext->R15 = pth->ctx.R15;
            lpContext->Fir = pth->ctx.Fir;
            lpContext->Psr = pth->ctx.Psr;
        }
        if (ulContextFlags & CONTEXT_INTEGER) {
            lpContext->MACH = pth->ctx.MACH;
            lpContext->MACL = pth->ctx.MACL;
            lpContext->GBR = pth->ctx.GBR;
            lpContext->R0 = pth->ctx.R0;
            lpContext->R1 = pth->ctx.R1;
            lpContext->R2 = pth->ctx.R2;
            lpContext->R3 = pth->ctx.R3;
            lpContext->R4 = pth->ctx.R4;
            lpContext->R5 = pth->ctx.R5;
            lpContext->R6 = pth->ctx.R6;
            lpContext->R7 = pth->ctx.R7;
            lpContext->R8 = pth->ctx.R8;
            lpContext->R9 = pth->ctx.R9;
            lpContext->R10 = pth->ctx.R10;
            lpContext->R11 = pth->ctx.R11;
            lpContext->R12 = pth->ctx.R12;
            lpContext->R13 = pth->ctx.R13;
            lpContext->R14 = pth->ctx.R14;
        }
#ifdef SH3
        if ( SH3DSP && (ulContextFlags & CONTEXT_DSP_REGISTERS)) {
            DSPFlushContext();
            lpContext->DSR = pth->ctx.DSR;
            lpContext->MOD = pth->ctx.MOD;
            lpContext->RS = pth->ctx.RS;
            lpContext->RE = pth->ctx.RE;
            lpContext->A0 = pth->ctx.A0;
            lpContext->A1 = pth->ctx.A1;
            lpContext->M0 = pth->ctx.M0;
            lpContext->M1 = pth->ctx.M1;
            lpContext->X0 = pth->ctx.X0;
            lpContext->X1 = pth->ctx.X1;
            lpContext->Y0 = pth->ctx.Y0;
            lpContext->Y1 = pth->ctx.Y1;
            lpContext->A0G = pth->ctx.A0G;
            lpContext->A1G = pth->ctx.A1G;
        }
#endif
#ifdef SH4
        if (ulContextFlags & CONTEXT_FLOATING_POINT) {
            FPUFlushContext();
            lpContext->Fpscr = pth->ctx.Fpscr;
            lpContext->Fpul = pth->ctx.Fpul;
            memcpy(lpContext->FRegs,pth->ctx.FRegs,sizeof(lpContext->FRegs));
            memcpy(lpContext->xFRegs,pth->ctx.xFRegs,sizeof(lpContext->xFRegs));
        }
#endif
        if (ulContextFlags & CONTEXT_DEBUG_REGISTERS) {

        }
    }
    return TRUE;
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL 
DoThreadSetContext(
    HANDLE hTh, 
    const CONTEXT *lpContext
    ) 
{
    PTHREAD pth;
    ULONG   ulContextFlags = lpContext->ContextFlags; // Keep a local copy of the context flag
    if (!(pth = HandleToThread(hTh))) {
        SetLastError(ERROR_INVALID_HANDLE);
        return FALSE;
    }
    if (ulContextFlags & ~CONTEXT_FULL) {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    // Clear the SH3 and SH4 bits in the context flags.  These are use to differentiate
    // SH3 and SH4.  Without doing so, the masking will always be true because of these 
    // bits.  For example, (CONTEXT_CONTROL & CONTEXT_INTEGER) will be either 0x40 or 0xc0 
    // depending on the processor, but it will never be zero.  So the consequence is that
    // we always return the full context no mater what flags users specify.
    // (Please see \public\common\sdk\inc\winnt.h for details.)
    ulContextFlags &= ~CONTEXT_SH4; 

    if (pth->pThrdDbg && pth->pThrdDbg->psavedctx) {
        ACCESSKEY ulOldKey;
        SWITCHKEY(ulOldKey,0xffffffff);
        if (ulContextFlags & CONTEXT_CONTROL) {
            pth->pThrdDbg->psavedctx->PR = lpContext->PR;
            pth->pThrdDbg->psavedctx->R15 = lpContext->R15;
            pth->pThrdDbg->psavedctx->Fir = lpContext->Fir;
            pth->pThrdDbg->psavedctx->Psr = (pth->ctx.Psr & 0xfffffcfc) | (lpContext->Psr & 0x00000303);
        }
        if (ulContextFlags & CONTEXT_INTEGER) {
            pth->pThrdDbg->psavedctx->MACH = lpContext->MACH;
            pth->pThrdDbg->psavedctx->MACL = lpContext->MACL;
            pth->pThrdDbg->psavedctx->GBR = lpContext->GBR;
            pth->pThrdDbg->psavedctx->R0 = lpContext->R0;
            pth->pThrdDbg->psavedctx->R1 = lpContext->R1;
            pth->pThrdDbg->psavedctx->R2 = lpContext->R2;
            pth->pThrdDbg->psavedctx->R3 = lpContext->R3;
            pth->pThrdDbg->psavedctx->R4 = lpContext->R4;
            pth->pThrdDbg->psavedctx->R5 = lpContext->R5;
            pth->pThrdDbg->psavedctx->R6 = lpContext->R6;
            pth->pThrdDbg->psavedctx->R7 = lpContext->R7;
            pth->pThrdDbg->psavedctx->R8 = lpContext->R8;
            pth->pThrdDbg->psavedctx->R9 = lpContext->R9;
            pth->pThrdDbg->psavedctx->R10 = lpContext->R10;
            pth->pThrdDbg->psavedctx->R11 = lpContext->R11;
            pth->pThrdDbg->psavedctx->R12 = lpContext->R12;
            pth->pThrdDbg->psavedctx->R13 = lpContext->R13;
            pth->pThrdDbg->psavedctx->R14 = lpContext->R14;
        }
#ifdef SH3
        if ( SH3DSP && (ulContextFlags & CONTEXT_DSP_REGISTERS)) {
            DSPFlushContext();
            pth->pThrdDbg->psavedctx->DSR = lpContext->DSR;
            pth->pThrdDbg->psavedctx->MOD = lpContext->MOD;
            pth->pThrdDbg->psavedctx->RS = lpContext->RS;
            pth->pThrdDbg->psavedctx->RE = lpContext->RE;
            pth->pThrdDbg->psavedctx->A0 = lpContext->A0;
            pth->pThrdDbg->psavedctx->A1 = lpContext->A1;
            pth->pThrdDbg->psavedctx->M0 = lpContext->M0;
            pth->pThrdDbg->psavedctx->M1 = lpContext->M1;
            pth->pThrdDbg->psavedctx->X0 = lpContext->X0;
            pth->pThrdDbg->psavedctx->X1 = lpContext->X1;
            pth->pThrdDbg->psavedctx->Y0 = lpContext->Y0;
            pth->pThrdDbg->psavedctx->Y1 = lpContext->Y1;
            pth->pThrdDbg->psavedctx->A0G = lpContext->A0G;
            pth->pThrdDbg->psavedctx->A1G = lpContext->A1G;
        }
#endif
#ifdef SH4
        if (ulContextFlags & CONTEXT_FLOATING_POINT) {
            FPUFlushContext();
            pth->pThrdDbg->psavedctx->Fpscr = lpContext->Fpscr;
            pth->pThrdDbg->psavedctx->Fpul = lpContext->Fpul;
            memcpy(pth->pThrdDbg->psavedctx->FRegs,lpContext->FRegs,sizeof(lpContext->FRegs));
            memcpy(pth->pThrdDbg->psavedctx->xFRegs,lpContext->xFRegs,sizeof(lpContext->xFRegs));
        }
#endif
        if (ulContextFlags & CONTEXT_DEBUG_REGISTERS) {

        }
        SETCURKEY(ulOldKey);
    } else {
        if (ulContextFlags & CONTEXT_CONTROL) {
            pth->ctx.PR = lpContext->PR;
            pth->ctx.R15 = lpContext->R15;
            pth->ctx.Fir = lpContext->Fir;
            pth->ctx.Psr = (pth->ctx.Psr & 0xfffffcfc) | (lpContext->Psr & 0x00000303);
        }
        if (ulContextFlags & CONTEXT_INTEGER) {
            pth->ctx.MACH = lpContext->MACH;
            pth->ctx.MACL = lpContext->MACL;
            pth->ctx.GBR = lpContext->GBR;
            pth->ctx.R0 = lpContext->R0;
            pth->ctx.R1 = lpContext->R1;
            pth->ctx.R2 = lpContext->R2;
            pth->ctx.R3 = lpContext->R3;
            pth->ctx.R4 = lpContext->R4;
            pth->ctx.R5 = lpContext->R5;
            pth->ctx.R6 = lpContext->R6;
            pth->ctx.R7 = lpContext->R7;
            pth->ctx.R8 = lpContext->R8;
            pth->ctx.R9 = lpContext->R9;
            pth->ctx.R10 = lpContext->R10;
            pth->ctx.R11 = lpContext->R11;
            pth->ctx.R12 = lpContext->R12;
            pth->ctx.R13 = lpContext->R13;
            pth->ctx.R14 = lpContext->R14;
        }
#ifdef SH3
        if ( SH3DSP && (ulContextFlags & CONTEXT_DSP_REGISTERS)) {
            DSPFlushContext();
            pth->ctx.DSR = lpContext->DSR;
            pth->ctx.MOD = lpContext->MOD;
            pth->ctx.RS = lpContext->RS;
            pth->ctx.RE = lpContext->RE;
            pth->ctx.A0 = lpContext->A0;
            pth->ctx.A1 = lpContext->A1;
            pth->ctx.M0 = lpContext->M0;
            pth->ctx.M1 = lpContext->M1;
            pth->ctx.X0 = lpContext->X0;
            pth->ctx.X1 = lpContext->X1;
            pth->ctx.Y0 = lpContext->Y0;
            pth->ctx.Y1 = lpContext->Y1;
            pth->ctx.A0G = lpContext->A0G;
            pth->ctx.A1G = lpContext->A1G;
        }
#endif
#ifdef SH4
        if (ulContextFlags & CONTEXT_FLOATING_POINT) {
            FPUFlushContext();
            pth->ctx.Fpscr = lpContext->Fpscr;
            pth->ctx.Fpul = lpContext->Fpul;
            memcpy(pth->ctx.FRegs,lpContext->FRegs,sizeof(lpContext->FRegs));
            memcpy(pth->ctx.xFRegs,lpContext->xFRegs,sizeof(lpContext->xFRegs));
        }
#endif
        if (ulContextFlags & CONTEXT_DEBUG_REGISTERS) {

        }
    }
    return TRUE;
}

void MDRestoreCalleeSavedRegisters (PCALLSTACK pcstk, PCONTEXT pCtx)
{
    ULONG *pRegs = (ULONG *) pcstk->dwPrevSP;

    pCtx->R8  = pRegs[0];
    pCtx->R9  = pRegs[1];
    pCtx->R10 = pRegs[2];
    pCtx->R11 = pRegs[3];
    pCtx->R12 = pRegs[4];
    pCtx->R13 = pRegs[5];
    pCtx->R14 = pRegs[6];
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -