Changeset 36862 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Apr 27, 2011 6:32:31 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 71439
- Location:
- trunk/src/VBox/VMM/testcase
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/testcase/Makefile.kmk
r36858 r36862 44 44 tstVMMR0CallHost-1 \ 45 45 tstVMMR0CallHost-2 46 ifn1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.amd64 linux.amd64solaris.x86 solaris.amd64 win.amd64 ) ## TODO: Fix the code.46 ifn1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.amd64 solaris.x86 solaris.amd64 win.amd64 ) ## TODO: Fix the code. 47 47 PROGRAMS += tstX86-1 48 48 endif -
trunk/src/VBox/VMM/testcase/tstX86-1.cpp
r36791 r36862 22 22 #include <iprt/test.h> 23 23 #include <iprt/param.h> 24 #include <iprt/mem.h> 25 #include <iprt/err.h> 26 #include <iprt/assert.h> 24 27 25 28 #ifdef RT_OS_WINDOWS … … 53 56 RT_C_DECLS_BEGIN 54 57 uint8_t *g_pbEfPage = NULL; 58 uint8_t *g_pbEfExecPage = NULL; 55 59 extern TRAPINFO g_aTrapInfo[]; 56 60 RT_C_DECLS_END … … 64 68 65 69 66 static PCTRAPINFO findTrapInfo(uintptr_t uTrapPC )70 static PCTRAPINFO findTrapInfo(uintptr_t uTrapPC, uintptr_t uTrapSP) 67 71 { 72 /* Search by trap program counter. */ 68 73 for (unsigned i = 0; g_aTrapInfo[i].uTrapPC; i++) 69 74 if (g_aTrapInfo[i].uTrapPC == uTrapPC) 75 return &g_aTrapInfo[i]; 76 77 /* Search by return address. */ 78 uintptr_t uReturn = *(uintptr_t *)uTrapSP; 79 for (unsigned i = 0; g_aTrapInfo[i].uTrapPC; i++) 80 if (g_aTrapInfo[i].uTrapPC + g_aTrapInfo[i].cbInstr == uReturn) 70 81 return &g_aTrapInfo[i]; 71 82 … … 77 88 { 78 89 ucontext_t *pCtx = (ucontext_t *)pvSigCtx; 90 79 91 # if defined(RT_ARCH_AMD64) && defined(RT_OS_DARWIN) 80 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__rip; 92 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__rip; 93 uintptr_t uSP = pCtx->uc_mcontext->__ss.__rsp; 94 uintptr_t uTrapNo = ~(uintptr_t)0; 95 uintptr_t uErr = ~(uintptr_t)0; 96 81 97 # elif defined(RT_ARCH_AMD64) && defined(RT_OS_FREEBSD) 82 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_rip; 98 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_rip; 99 uintptr_t uSP = pCtx->uc_mcontext.mc_rsp; 100 uintptr_t uTrapNo = ~(uintptr_t)0; 101 uintptr_t uErr = ~(uintptr_t)0; 102 83 103 # elif defined(RT_ARCH_AMD64) 84 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RIP]; 104 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RIP]; 105 uintptr_t uSP = pCtx->uc_mcontext.gregs[REG_RSP]; 106 uintptr_t uTrapNo = pCtx->uc_mcontext.gregs[REG_TRAPNO]; 107 uintptr_t uErr = pCtx->uc_mcontext.gregs[REG_ERR]; 108 85 109 # elif defined(RT_ARCH_X86) && defined(RT_OS_DARWIN) 86 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__eip; 110 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__eip; 111 uintptr_t uSP = pCtx->uc_mcontext->__ss.__esp; 112 uintptr_t uTrapNo = ~(uintptr_t)0; 113 uintptr_t uErr = ~(uintptr_t)0; 114 87 115 # elif defined(RT_ARCH_X86) && defined(RT_OS_FREEBSD) 88 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_eip; 116 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_eip; 117 uintptr_t uSP = pCtx->uc_mcontext.mc_esp; 118 uintptr_t uTrapNo = ~(uintptr_t)0; 119 uintptr_t uErr = ~(uintptr_t)0; 120 89 121 # elif defined(RT_ARCH_X86) 90 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_EIP]; 122 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_EIP]; 123 uintptr_t uSP = pCtx->uc_mcontext.gregs[REG_ESP]; 124 uintptr_t uTrapNo = pCtx->uc_mcontext.gregs[REG_TRAPNO]; 125 uintptr_t uErr = pCtx->uc_mcontext.gregs[REG_ERR]; 126 91 127 # else 92 uintptr_t *puPC = NULL; 128 uintptr_t *puPC = NULL; 129 uintptr_t uTrapNo = ~(uintptr_t)0; 130 uintptr_t uErr = ~(uintptr_t)0; 93 131 # endif 132 RTAssertMsg2("tstX86-1: Trap #%#04x err=%#06x at %p\n", uTrapNo, uErr, *puPC); 94 133 95 PCTRAPINFO pTrapInfo = findTrapInfo(*puPC );134 PCTRAPINFO pTrapInfo = findTrapInfo(*puPC, uSP); 96 135 if (pTrapInfo) 97 136 { … … 117 156 if (rcExit != RTEXITCODE_SUCCESS) 118 157 return rcExit; 158 RTTestBanner(hTest); 159 119 160 g_pbEfPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE); 120 161 RTTESTI_CHECK(g_pbEfPage != NULL); 121 162 163 g_pbEfExecPage = (uint8_t *)RTMemExecAlloc(PAGE_SIZE*2); 164 RTTESTI_CHECK(g_pbEfExecPage != NULL); 165 RTTESTI_CHECK(!((uintptr_t)g_pbEfExecPage & PAGE_OFFSET_MASK)); 166 RTTESTI_CHECK_RC(RTMemProtect(g_pbEfExecPage + PAGE_SIZE, PAGE_SIZE, RTMEM_PROT_NONE), VINF_SUCCESS); 167 122 168 #ifdef USE_SIGNAL 123 static int const s_aiSigs[] = { SIGBUS, SIGSEGV, SIGFPE };169 static int const s_aiSigs[] = { SIGBUS, SIGSEGV, SIGFPE, SIGILL }; 124 170 for (unsigned i = 0; i < RT_ELEMENTS(s_aiSigs); i++) 125 171 { -
trunk/src/VBox/VMM/testcase/tstX86-1A.asm
r36838 r36862 38 38 BEGINDATA 39 39 extern NAME(g_pbEfPage) 40 extern NAME(g_pbEfExecPage) 40 41 41 42 g_szAlpha: … … 53 54 ; Defined Constants And Macros ; 54 55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 56 %define X86_XCPT_UD 6 55 57 %define X86_XCPT_GP 13 56 58 %define X86_XCPT_PF 14 59 60 ;; Reference a global variable 61 %ifdef RT_ARCH_AMD64 62 %define REF_GLOBAL(a_Name) [NAME(a_Name) wrt rip] 63 %else 64 %define REF_GLOBAL(a_Name) [NAME(a_Name)] 65 %endif 57 66 58 67 ;; … … 62 71 ; @param 2+ The instruction which should trap. 63 72 %macro ShouldTrap 2+ 64 ..trap:73 %%trap: 65 74 %2 66 ..trap_end:75 %%trap_end: 67 76 mov eax, __LINE__ 68 77 jmp .failed 69 78 BEGINDATA 70 ..trapinfo: istruc TRAPINFO71 at TRAPINFO.uTrapPC, RTCCPTR_DEF ..trap72 at TRAPINFO.uResumePC, RTCCPTR_DEF ..resume79 %%trapinfo: istruc TRAPINFO 80 at TRAPINFO.uTrapPC, RTCCPTR_DEF %%trap 81 at TRAPINFO.uResumePC, RTCCPTR_DEF %%resume 73 82 at TRAPINFO.u8TrapNo, db %1 74 at TRAPINFO.cbInstr, db ( ..trap_end - ..trap)83 at TRAPINFO.cbInstr, db (%%trap_end - %%trap) 75 84 iend 76 85 BEGINCODE 77 ..resume:86 %%resume: 78 87 %endmacro 79 88 … … 300 309 ; Loading is always a word access. 301 310 mov eax, __LINE__ 302 mov xDI, [NAME(g_pbEfPage)]311 mov xDI, REF_GLOBAL(g_pbEfPage) 303 312 lea xDI, [xDI + 0x1000 - 2] 304 313 mov xDX, es … … 308 317 ; Saving is always a word access. 309 318 mov eax, __LINE__ 310 mov xDI, [NAME(g_pbEfPage)]319 mov xDI, REF_GLOBAL(g_pbEfPage) 311 320 mov dword [xDI + 0x1000 - 4], -1 312 321 mov [xDI + 0x1000 - 2], ss ; Should not crash. … … 320 329 call x861_ClearRegisters 321 330 mov eax, __LINE__ 322 mov xDI, [NAME(g_pbEfPage)]331 mov xDI, REF_GLOBAL(g_pbEfPage) 323 332 mov dword [xDI + 0x1000 - 4], -1 324 333 db 04ah … … 384 393 mov dx, ds 385 394 mov es, dx 386 mov xDI, [NAME(g_pbEfPage)]395 mov xDI, REF_GLOBAL(g_pbEfPage) 387 396 xor eax, eax 388 397 mov ecx, 01000h 389 398 rep stosb 390 399 391 mov xDI, [NAME(g_pbEfPage)]400 mov xDI, REF_GLOBAL(g_pbEfPage) 392 401 mov ecx, 4 393 402 mov eax, 0ffh … … 398 407 jne .failed 399 408 mov eax, __LINE__ 400 mov xDI, [NAME(g_pbEfPage)]409 mov xDI, REF_GLOBAL(g_pbEfPage) 401 410 cmp dword [xDI], 0ffffffffh 402 411 jne .failed … … 404 413 jne .failed 405 414 406 mov xDI, [NAME(g_pbEfPage)]415 mov xDI, REF_GLOBAL(g_pbEfPage) 407 416 mov ecx, 4 408 417 mov eax, 0feh … … 413 422 jne .failed 414 423 mov eax, __LINE__ 415 mov xDI, [NAME(g_pbEfPage)]424 mov xDI, REF_GLOBAL(g_pbEfPage) 416 425 cmp dword [xDI], 0fefefefeh 417 426 jne .failed … … 426 435 mov dx, ds 427 436 mov es, dx 428 mov xDI, [NAME(g_pbEfPage)]437 mov xDI, REF_GLOBAL(g_pbEfPage) 429 438 xor xCX, xCX 430 439 rep stosb ; no trap … … 452 461 jz .failed 453 462 463 ; 464 ; Will the CPU decode the whole r/m+sib stuff before signalling a lock 465 ; prefix error? Use the EF exec page and a LOCK ADD CL,[rDI + disp32] 466 ; instruction at the very end of it. 467 ; 468 mov eax, __LINE__ 469 mov xDI, REF_GLOBAL(g_pbEfExecPage) 470 add xDI, 1000h - 4h 471 mov byte [xDI+0], 0f0h 472 mov byte [xDI+1], 002h 473 mov byte [xDI+2], 08Fh 474 mov byte [xDI+3], 000h 475 ShouldTrap X86_XCPT_PF, call xDI 476 477 mov eax, __LINE__ 478 mov xDI, REF_GLOBAL(g_pbEfExecPage) 479 add xDI, 1000h - 7h 480 mov byte [xDI+0], 0f0h 481 mov byte [xDI+1], 002h 482 mov byte [xDI+2], 08Fh 483 mov dword [xDI+3], 000000000h 484 ShouldTrap X86_XCPT_UD, call xDI 454 485 455 486
Note:
See TracChangeset
for help on using the changeset viewer.