Skip to content

Commit dbb9d5e

Browse files
committed
[GEN][ZH] Replacements for rest of asm code
1 parent 8e5bb95 commit dbb9d5e

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

Generals/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void StackDump(void (*callback)(const char*))
7676

7777
DWORD myeip,myesp,myebp;
7878

79+
#ifdef _MSC_VER
7980
_asm
8081
{
8182
MYEIP1:
@@ -86,6 +87,12 @@ _asm
8687
mov eax, ebp
8788
mov dword ptr [myebp] , eax
8889
}
90+
#else
91+
RtlCaptureContext(&gsContext);
92+
myeip = gsContext.Eip;
93+
myesp = gsContext.Esp;
94+
myebp = gsContext.Ebp;
95+
#endif
8996

9097

9198
MakeStackTrace(myeip,myesp,myebp, 2, callback);
@@ -340,6 +347,7 @@ void FillStackAddresses(void**addresses, unsigned int count, unsigned int skip)
340347
gsContext.ContextFlags = CONTEXT_FULL;
341348

342349
DWORD myeip,myesp,myebp;
350+
#ifdef _MSC_VER
343351
_asm
344352
{
345353
MYEIP2:
@@ -351,6 +359,12 @@ _asm
351359
mov dword ptr [myebp] , eax
352360
xor eax,eax
353361
}
362+
#else
363+
RtlCaptureContext(&gsContext);
364+
myeip = gsContext.Eip;
365+
myesp = gsContext.Esp;
366+
myebp = gsContext.Ebp;
367+
#endif
354368
memset(&stack_frame, 0, sizeof(STACKFRAME));
355369
stack_frame.AddrPC.Mode = AddrModeFlat;
356370
stack_frame.AddrPC.Offset = myeip;
@@ -360,17 +374,6 @@ stack_frame.AddrFrame.Mode = AddrModeFlat;
360374
stack_frame.AddrFrame.Offset = myebp;
361375

362376
{
363-
/*
364-
if(GetThreadContext(thread, &gsContext))
365-
{
366-
memset(&stack_frame, 0, sizeof(STACKFRAME));
367-
stack_frame.AddrPC.Mode = AddrModeFlat;
368-
stack_frame.AddrPC.Offset = gsContext.Eip;
369-
stack_frame.AddrStack.Mode = AddrModeFlat;
370-
stack_frame.AddrStack.Offset = gsContext.Esp;
371-
stack_frame.AddrFrame.Mode = AddrModeFlat;
372-
stack_frame.AddrFrame.Offset = gsContext.Ebp;
373-
*/
374377

375378
Bool stillgoing = TRUE;
376379
// unsigned int cd = count;

GeneralsMD/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void StackDump(void (*callback)(const char*))
7676

7777
DWORD myeip,myesp,myebp;
7878

79+
#ifdef _MSC_VER
7980
_asm
8081
{
8182
MYEIP1:
@@ -86,6 +87,12 @@ _asm
8687
mov eax, ebp
8788
mov dword ptr [myebp] , eax
8889
}
90+
#else
91+
RtlCaptureContext(&gsContext);
92+
myeip = gsContext.Eip;
93+
myesp = gsContext.Esp;
94+
myebp = gsContext.Ebp;
95+
#endif
8996

9097

9198
MakeStackTrace(myeip,myesp,myebp, 2, callback);
@@ -340,6 +347,7 @@ void FillStackAddresses(void**addresses, unsigned int count, unsigned int skip)
340347
gsContext.ContextFlags = CONTEXT_FULL;
341348

342349
DWORD myeip,myesp,myebp;
350+
#ifdef _MSC_VER
343351
_asm
344352
{
345353
MYEIP2:
@@ -351,6 +359,12 @@ _asm
351359
mov dword ptr [myebp] , eax
352360
xor eax,eax
353361
}
362+
#else
363+
RtlCaptureContext(&gsContext);
364+
myeip = gsContext.Eip;
365+
myesp = gsContext.Esp;
366+
myebp = gsContext.Ebp;
367+
#endif
354368
memset(&stack_frame, 0, sizeof(STACKFRAME));
355369
stack_frame.AddrPC.Mode = AddrModeFlat;
356370
stack_frame.AddrPC.Offset = myeip;
@@ -360,17 +374,6 @@ stack_frame.AddrFrame.Mode = AddrModeFlat;
360374
stack_frame.AddrFrame.Offset = myebp;
361375

362376
{
363-
/*
364-
if(GetThreadContext(thread, &gsContext))
365-
{
366-
memset(&stack_frame, 0, sizeof(STACKFRAME));
367-
stack_frame.AddrPC.Mode = AddrModeFlat;
368-
stack_frame.AddrPC.Offset = gsContext.Eip;
369-
stack_frame.AddrStack.Mode = AddrModeFlat;
370-
stack_frame.AddrStack.Offset = gsContext.Esp;
371-
stack_frame.AddrFrame.Mode = AddrModeFlat;
372-
stack_frame.AddrFrame.Offset = gsContext.Ebp;
373-
*/
374377

375378
Bool stillgoing = TRUE;
376379
// unsigned int cd = count;

GeneralsMD/Code/Libraries/Source/debug/debug_debug.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdio.h>
3232
#include <string.h>
3333
#include <new> // needed for placement new prototype
34+
#include <Utility/intrin_compat.h>
3435

3536
// a little dummy variable that makes the linker actually include
3637
// us...
@@ -270,11 +271,15 @@ bool Debug::SkipNext(void)
270271
// do not implement this function inline, we do need
271272
// a valid frame pointer here!
272273
unsigned help;
274+
#ifdef _MSC_VER
273275
_asm
274276
{
275277
mov eax,[ebp+4] // return address
276278
mov help,eax
277279
};
280+
#else
281+
help = (unsigned)_ReturnAddress();
282+
#endif
278283
curStackFrame=help;
279284

280285
// do we know if to skip the following code?
@@ -386,7 +391,7 @@ bool Debug::AssertDone(void)
386391
}
387392
break;
388393
case IDRETRY:
389-
_asm int 0x03
394+
__debugbreak();
390395
break;
391396
default:
392397
((void)0);
@@ -654,7 +659,7 @@ bool Debug::CrashDone(bool die)
654659
}
655660
break;
656661
case IDRETRY:
657-
_asm int 0x03
662+
__debugbreak();
658663
break;
659664
default:
660665
((void)0);

GeneralsMD/Code/Libraries/Source/debug/debug_except.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,18 @@ void DebugExceptionhandler::LogFPURegisters(Debug &dbg, struct _EXCEPTION_POINTE
173173
double fpVal;
174174

175175
// convert from temporary real (10 byte) to double
176+
#ifdef _MSC_VER
176177
_asm
177178
{
178179
mov eax,value
179180
fld tbyte ptr [eax]
180181
fstp qword ptr [fpVal]
181182
}
183+
#else
184+
__float80 fp80val;
185+
memcpy(&fp80val, value, 10);
186+
fpVal = (double) fp80val;
187+
#endif
182188

183189
dbg << " " << fpVal << "\n";
184190
}

GeneralsMD/Code/Libraries/Source/debug/debug_stack.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ int DebugStackwalk::StackWalk(Signature &sig, struct _CONTEXT *ctx)
363363
{
364364
// walk stack back using current call chain
365365
unsigned long reg_eip, reg_ebp, reg_esp;
366+
#ifdef _MSC_VER
366367
__asm
367368
{
368369
here:
@@ -371,6 +372,13 @@ int DebugStackwalk::StackWalk(Signature &sig, struct _CONTEXT *ctx)
371372
mov reg_ebp,ebp
372373
mov reg_esp,esp
373374
};
375+
#else
376+
CONTEXT ctx2;
377+
RtlCaptureContext(&ctx2);
378+
reg_eip = ctx2.Eip;
379+
reg_ebp = ctx2.Ebp;
380+
reg_esp = ctx2.Esp;
381+
#endif
374382
stackFrame.AddrPC.Offset = reg_eip;
375383
stackFrame.AddrStack.Offset = reg_esp;
376384
stackFrame.AddrFrame.Offset = reg_ebp;

0 commit comments

Comments
 (0)