- 時間撮記:
- 2016-3-9 下午11:00:02 (9 年 以前)
- 位置:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- 檔案:
-
- 新增 2 筆資料
- 刪除 1 筆資料
- 修改 12 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
r59934 r59975 82 82 bs3-cmn-PagingInitRootForPAE.c \ 83 83 bs3-cmn-PagingInitRootForLM.c \ 84 bs3-cmn-RegCtxRestore.asm \ 85 bs3-cmn-RegCtxConvertToRingX.c \ 84 86 bs3-cmn-SelProtFar32ToFlat32.c \ 85 87 bs3-cmn-SlabInit.c \ … … 169 171 bs3-wc32-U8RS.asm \ 170 172 bs3-wc32-U8LS.asm \ 171 bs3-c32-Trap32Generic.asm \ 172 bs3-c32-Trap32ResumeFrame.asm 173 bs3-c32-Trap32Generic.asm 173 174 174 175 # The 64-bit BS3Kit library. -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm
r59952 r59975 104 104 105 105 ; save the registers. 106 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.rax], eax107 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.rsp], esp108 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.rbp], ebp106 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rax], eax 107 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rsp], esp 108 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rbp], ebp 109 109 mov ax, ss 110 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.ss], ax110 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.ss], ax 111 111 mov ax, ds 112 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.ds], ax112 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.ds], ax 113 113 mov ax, es 114 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.es], ax114 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.es], ax 115 115 mov ax, fs 116 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.fs], ax116 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.fs], ax 117 117 mov ax, gs 118 118 … … 134 134 pushfd 135 135 pop eax 136 mov [BS3_ADDR_REG_SAVE + BS3REG S.rflags], eax137 mov [BS3_ADDR_REG_SAVE + BS3REG S.rbx], ebx138 mov [BS3_ADDR_REG_SAVE + BS3REG S.rcx], ecx139 mov [BS3_ADDR_REG_SAVE + BS3REG S.rdx], edx140 mov [BS3_ADDR_REG_SAVE + BS3REG S.rsi], esi141 mov [BS3_ADDR_REG_SAVE + BS3REG S.rdi], edi136 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rflags], eax 137 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rbx], ebx 138 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rcx], ecx 139 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdx], edx 140 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rsi], esi 141 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.rdi], edi 142 142 mov eax, cr2 143 mov [BS3_ADDR_REG_SAVE + BS3REG S.cr2], eax143 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.cr2], eax 144 144 mov eax, cr3 145 mov [BS3_ADDR_REG_SAVE + BS3REG S.cr3], eax145 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.cr3], eax 146 146 mov eax, cr4 147 mov [BS3_ADDR_REG_SAVE + BS3REG S.cr4], eax148 mov byte [BS3_ADDR_REG_SAVE + BS3REG S.bMode], BS3_MODE_RM147 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.cr4], eax 148 mov byte [BS3_ADDR_REG_SAVE + BS3REGCTX.bMode], BS3_MODE_RM 149 149 xor eax, eax 150 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.cs], ax150 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.cs], ax 151 151 mov ax, start 152 mov [cs:BS3_ADDR_REG_SAVE + BS3REG S.rip], eax152 mov [cs:BS3_ADDR_REG_SAVE + BS3REGCTX.rip], eax 153 153 154 154 ; Make sure caching is enabled and alignment is off. 155 155 mov eax, cr0 156 mov [BS3_ADDR_REG_SAVE + BS3REG S.cr0], eax156 mov [BS3_ADDR_REG_SAVE + BS3REGCTX.cr0], eax 157 157 and eax, ~(X86_CR0_NW | X86_CR0_CD | X86_CR0_AM) 158 158 mov cr0, eax -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm
r59287 r59975 25 25 ; 26 26 27 ;********************************************************************************************************************************* 28 ;* Header Files * 29 ;********************************************************************************************************************************* 27 30 %include "bs3kit-template-header.mac" 28 31 … … 31 34 %endif 32 35 36 37 ;********************************************************************************************************************************* 38 ;* External Symbols * 39 ;********************************************************************************************************************************* 40 BS3_EXTERN_DATA16 g_bBs3CurrentMode 41 TMPL_BEGIN_TEXT 42 BS3_EXTERN_CMN Bs3TrapDefaultHandler 43 BS3_EXTERN_CMN Bs3RegCtxRestore 44 TMPL_BEGIN_TEXT 45 46 47 ;********************************************************************************************************************************* 48 ;* Global Variables * 49 ;********************************************************************************************************************************* 33 50 BS3_BEGIN_DATA16 34 51 ;; Easy to access flat address of Bs3Trap32GenericEntries. … … 44 61 resd 256 45 62 46 47 TMPL_BEGIN_TEXT48 BS3_EXTERN_CMN Bs3TrapDefaultHandler49 BS3_EXTERN_CMN Bs3Trap32ResumeFrame50 63 51 64 … … 210 223 211 224 ; 225 ; Copy and update the mode now that we've got a flat DS. 226 ; 227 mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)] 228 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], al 229 and al, ~BS3_MODE_CODE_MASK 230 or al, BS3_MODE_CODE_32 231 mov [BS3_DATA16_WRT(g_bBs3CurrentMode)], al 232 233 ; 212 234 ; Copy iret info. 213 235 ; … … 216 238 mov ecx, [ebp + 12] 217 239 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], ecx 218 mov c x, [ebp + 8]240 mov cl, [ebp + 8] 219 241 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx 220 242 test dword [ebp + 12], X86_EFL_VM 221 243 jnz .iret_frame_v8086 222 244 mov ax, ss 223 and ax, 3 224 and cx, 3 225 cmp ax, ax 245 and al, 3 246 and cl, 3 247 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl 248 cmp cl, al 226 249 je .iret_frame_same_cpl 227 250 … … 244 267 245 268 .iret_frame_v8086: 269 mov byte [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], 3 270 or byte [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], BS3_MODE_CODE_V86 ; paranoia ^ 2 246 271 lea ecx, [ebp + 12] 247 272 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx … … 282 307 .clear_and_dispatch_to_handler: ; The double fault code joins us here. 283 308 xor edx, edx 284 mov dword [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.cBits], 32285 mov dword [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.abPadding + 3], edx309 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.abPadding], dx 310 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.abPadding + 2], edx 286 311 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.rax + 4], edx 287 312 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx + 4], edx … … 311 336 ; 312 337 movzx ebx, byte [esp + BS3TRAPFRAME.bXcpt] 313 mov eax, [ BS3_DATA_NM(g_apfnBs3TrapHandlers_c32) + ebx * 4]338 mov eax, [ebx * 4 + BS3_DATA16_WRT(_g_apfnBs3TrapHandlers_c32)] 314 339 or eax, eax 315 340 jnz .call_handler … … 324 349 ; 325 350 push 0 351 add edi, BS3TRAPFRAME.Ctx 326 352 push edi 327 call Bs3 Trap32ResumeFrame353 call Bs3RegCtxRestore 328 354 .panic: 329 int3330 355 hlt 331 356 jmp .panic … … 443 468 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], ecx 444 469 445 mov dword [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.cBits], 32 470 ; 471 ; Set CPL; copy and update mode. 472 ; 473 mov cl, [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.ss] 474 and cl, 3 475 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl 476 477 mov cl, [BS3_DATA16_WRT(g_bBs3CurrentMode)] 478 mov [esp + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], cl 479 and cl, ~BS3_MODE_CODE_MASK 480 or cl, BS3_MODE_CODE_32 481 mov [BS3_DATA16_WRT(g_bBs3CurrentMode)], cl 446 482 447 483 ; -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapDefaultHandler.c
r59286 r59975 33 33 BS3_DECL(void) Bs3TrapDefaultHandler(PBS3TRAPFRAME pTrapFrame) 34 34 { 35 #if TMPL_BITS != 64 36 /* 37 * Deal with GPs in V8086 mode. 38 */ 39 Bs3Printf("bXcpt=%#x\n", pTrapFrame->bXcpt); 40 Bs3Printf("bXcpt=%#x\n", pTrapFrame->bXcpt); 41 Bs3Printf("eflags=%#RX32 (%d)\n", pTrapFrame->Ctx.rflags.u32, RT_BOOL(pTrapFrame->Ctx.rflags.u32 & X86_EFL_VM)); 42 Bs3Printf("cs=%#x\n", pTrapFrame->Ctx.cs); 43 for (;;) { } 44 if ( pTrapFrame->bXcpt == X86_XCPT_GP 45 && (pTrapFrame->Ctx.rflags.u32 & X86_EFL_VM) 46 && pTrapFrame->Ctx.cs == BS3_SEL_TEXT16) 47 { 48 bool fHandled = true; 49 uint8_t cBitsOpcode = 16; 50 uint8_t bOpCode; 51 uint8_t const BS3_FAR *pbCodeStart; 52 uint8_t const BS3_FAR *pbCode; 53 uint16_t BS3_FAR *pusStack; 54 for (;;) { } 55 56 pusStack = (uint16_t BS3_FAR *)BS3_MAKE_PROT_R0PTR_FROM_REAL(pTrapFrame->Ctx.ss, pTrapFrame->Ctx.rsp.u16); 57 pbCode = (uint8_t const BS3_FAR *)BS3_MAKE_PROT_R0PTR_FROM_REAL(pTrapFrame->Ctx.cs, pTrapFrame->Ctx.rip.u16); 58 pbCodeStart = pbCode; 59 60 bOpCode = *++pbCode; 61 if (bOpCode == 0x66) 62 { 63 cBitsOpcode = 32; 64 bOpCode = *++pbCode; 65 } 66 67 /* INT xx: Real mode behaviour, but intercepting and implementing most of our syscall interface. */ 68 if (bOpCode == 0xcd) 69 { 70 uint8_t bVector = *++pbCode; 71 if (bVector == BS3_TRAP_SYSCALL) 72 { 73 /* Minimal syscall. */ 74 if (pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_PRINT_CHR) 75 Bs3PrintChr(pTrapFrame->Ctx.rax.u8); 76 else if ( pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING0 77 || pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING1 78 || pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING2 79 || pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING3) 80 { 81 Bs3RegCtxConvertToRingX(&pTrapFrame->Ctx, pTrapFrame->Ctx.rax.u16 - BS3_SYSCALL_TO_RING0); 82 for (;;) { } 83 } 84 else 85 Bs3Panic(); 86 } 87 else 88 { 89 /* Real mode behaviour. */ 90 uint16_t BS3_FAR *pusIvte = (uint16_t BS3_FAR *)BS3_MAKE_PROT_R0PTR_FROM_REAL(0, 0); 91 pusIvte += (uint16_t)bVector *2; 92 93 pusStack[0] = pTrapFrame->Ctx.rflags.u16; 94 pusStack[1] = pTrapFrame->Ctx.cs; 95 pusStack[2] = pTrapFrame->Ctx.rip.u16 + (uint16_t)(pbCode - pbCodeStart); 96 97 pTrapFrame->Ctx.rip.u16 = pusIvte[0]; 98 pTrapFrame->Ctx.cs = pusIvte[1]; 99 pTrapFrame->Ctx.rflags.u16 &= ~X86_EFL_IF; /** @todo this isn't all, but it'll do for now, I hope. */ 100 Bs3RegCtxRestore(&pTrapFrame->Ctx, 0/*fFlags*/); /* does not return. */ 101 } 102 } 103 /* PUSHF: Real mode behaviour. */ 104 else if (bOpCode == 0x9c) 105 { 106 if (cBitsOpcode == 32) 107 *pusStack++ = pTrapFrame->Ctx.rflags.au16[1] & ~(X86_EFL_VM | X86_EFL_RF); 108 *pusStack++ = pTrapFrame->Ctx.rflags.u16; 109 pTrapFrame->Ctx.rsp.u16 += cBitsOpcode / 8; 110 } 111 /* POPF: Real mode behaviour. */ 112 else if (bOpCode == 0x9d) 113 { 114 if (cBitsOpcode == 32) 115 { 116 pTrapFrame->Ctx.rflags.u32 &= ~X86_EFL_POPF_BITS; 117 pTrapFrame->Ctx.rflags.u32 |= X86_EFL_POPF_BITS & *(uint32_t const *)pusStack; 118 } 119 else 120 { 121 pTrapFrame->Ctx.rflags.u32 &= ~(X86_EFL_POPF_BITS | UINT32_C(0xffff0000)) & ~X86_EFL_RF; 122 pTrapFrame->Ctx.rflags.u16 |= (uint16_t)X86_EFL_POPF_BITS & *pusStack; 123 } 124 pTrapFrame->Ctx.rsp.u16 -= cBitsOpcode / 8; 125 } 126 /* CLI: Real mode behaviour. */ 127 else if (bOpCode == 0xfa) 128 pTrapFrame->Ctx.rflags.u16 &= ~X86_EFL_IF; 129 /* STI: Real mode behaviour. */ 130 else if (bOpCode == 0xfb) 131 pTrapFrame->Ctx.rflags.u16 |= X86_EFL_IF; 132 /* Unexpected. */ 133 else 134 fHandled = false; 135 for (;;) { } 136 if (fHandled) 137 { 138 pTrapFrame->Ctx.rip.u16 += (uint16_t)(pbCode - pbCodeStart); 139 Bs3RegCtxRestore(&pTrapFrame->Ctx, 0 /*fFlags*/); /* does not return. */ 140 return; 141 } 142 } 143 144 #endif 145 35 146 Bs3TrapPrintFrame(pTrapFrame); 36 147 Bs3Panic(); 37 148 } 38 149 39 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapPrintFrame.c
r59286 r59975 38 38 pTrapFrame->uErrCd, 39 39 pTrapFrame->Ctx.cs, 40 pTrapFrame->Ctx.rip );40 pTrapFrame->Ctx.rip.u64); 41 41 } 42 42 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm
r59949 r59975 111 111 ; Always 64-bit in long mode, otherwise according to TMPL_BITS. 112 112 ; 113 mov ax, X86DESCGENERIC_BIT_OFF_TYPE + 1 ; For clearing the busy bit in the TSS descriptor type.114 113 %if BS3_MODE_IS_64BIT_SYS(TMPL_MODE) 115 114 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss64 116 115 TMPL_BEGIN_TEXT 117 btr [Bs3Gdte_Tss64 TMPL_WRT_SYSTEM16_OR_FLAT], ax116 and byte [5 + Bs3Gdte_Tss64 TMPL_WRT_SYSTEM16_OR_FLAT], ~X86_SEL_TYPE_SYS_TSS_BUSY_MASK 118 117 mov ax, BS3_SEL_TSS64 119 118 … … 122 121 BS3_EXTERN_SYSTEM16 Bs3Gdte_Tss16DoubleFault 123 122 TMPL_BEGIN_TEXT 124 btr [Bs3Gdte_Tss16 TMPL_WRT_SYSTEM16_OR_FLAT], ax125 btr [Bs3Gdte_Tss16DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax123 and byte [5 + Bs3Gdte_Tss16 TMPL_WRT_SYSTEM16_OR_FLAT], ~X86_SEL_TYPE_SYS_TSS_BUSY_MASK 124 and byte [5 + Bs3Gdte_Tss16DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ~X86_SEL_TYPE_SYS_TSS_BUSY_MASK 126 125 mov ax, BS3_SEL_TSS16 127 126 … … 132 131 BS3_EXTERN_SYSTEM16 Bs3Tss32DoubleFault 133 132 TMPL_BEGIN_TEXT 134 btr [Bs3Gdte_Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], ax135 btr [Bs3Gdte_Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ax133 and byte [5 + Bs3Gdte_Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], ~X86_SEL_TYPE_SYS_TSS_BUSY_MASK 134 and byte [5 + Bs3Gdte_Tss32DoubleFault TMPL_WRT_SYSTEM16_OR_FLAT], ~X86_SEL_TYPE_SYS_TSS_BUSY_MASK 136 135 mov eax, cr3 137 136 mov [X86TSS32.cr3 + Bs3Tss32 TMPL_WRT_SYSTEM16_OR_FLAT], eax -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm
r59950 r59975 63 63 ; 64 64 ; Protected mode. 65 ; 65 ; 80286 requirements for PE16 clutters the code a little. 66 ; 67 %if TMPL_MODE == BS3_MODE_PE16 68 mov ax, BS3_SEL_DATA16 69 mov ds, ax ; Bs3EnterMode_rm will set ds, so no need to preserve it 70 cmp byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80286 71 ja .do_386_prologue 72 push bp 73 push ax 74 push bx 75 pushf 76 push word 1 77 jmp .done_prologue 78 %endif 79 .do_386_prologue: 80 push sBP 66 81 push sAX 67 82 push sBX 68 83 sPUSHF 84 %if TMPL_MODE == BS3_MODE_PE16 85 push word 0 86 %endif 87 .done_prologue: 69 88 70 89 ; … … 80 99 ; On 80286 we must reset the CPU to get back to real mode. 81 100 ; 82 mov ax, BS3_SEL_DATA1683 mov ds,ax84 cmp byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_8028685 j ne.is_386_or_better101 pop ax 102 push ax 103 test ax, ax 104 jz .is_386_or_better 86 105 .implement_this_later: 87 106 int3 … … 143 162 call NAME(Bs3EnteredMode_rm) 144 163 145 %if TMPL_BITS == 64 164 %if TMPL_MODE == BS3_MODE_PE16 165 pop ax 166 test ax, ax 167 jz .do_386_epilogue 168 popf 169 pop bx 170 pop ax 171 pop bp 172 %endif 173 %if TMPL_BITS != 64 174 .do_386_epilogue: 175 popfd 176 pop ebx 177 pop eax 178 %if 0 179 pop ebp 180 %else 181 add esp, 4 182 %endif 183 %else 146 184 pop eax 147 185 popfd … … 150 188 pop eax 151 189 pop eax 152 %else 153 popfd 154 pop ebx 155 pop eax 156 %endif 157 retn BS3_IF_16_32_64BIT(0, 2, 6) 190 pop ebp 191 pop ebp 192 %endif 193 retn (TMPL_BITS - 16) / 8 158 194 159 195 %if TMPL_BITS != 16 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c
r59946 r59975 335 335 } 336 336 337 if (paEntries[i].pfnDoPAEV86 && fDoV86Mode)337 if (paEntries[i].pfnDoPAEV86 /*&& fDoV86Mode*/) 338 338 { 339 339 bErrNo = TMPL_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_BS3TEXT16(paEntries[i].pfnDoPAEV86)); -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm
r59952 r59975 32 32 TMPL_BEGIN_TEXT 33 33 34 %if TMPL_BITS == 32 35 BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32 36 %endif 37 BS3_EXTERN_CMN Bs3RegCtxConvertToRingX 38 BS3_EXTERN_CMN Bs3RegCtxRestore 39 BS3_EXTERN_CMN Bs3Panic 40 TMPL_BEGIN_TEXT 41 34 42 35 43 ;; … … 42 50 ; stuff. Generally, though, we preserve all registers not used as return 43 51 ; values or otherwise implicitly transformed by the call. 52 ; 53 ; Note! The 16-bit versions of this code must be careful with using extended 54 ; registers as we wish this code to work on real 8086 CPUs too! 44 55 ; 45 56 BS3_PROC_BEGIN_MODE Bs3TrapSystemCallHandler … … 99 110 dw .print_chr wrt BS3TEXT16 100 111 dw .print_str wrt BS3TEXT16 101 dw .to_ring 0wrt BS3TEXT16102 dw .to_ring 1wrt BS3TEXT16103 dw .to_ring 2wrt BS3TEXT16104 dw .to_ring 3wrt BS3TEXT16112 dw .to_ringX wrt BS3TEXT16 113 dw .to_ringX wrt BS3TEXT16 114 dw .to_ringX wrt BS3TEXT16 115 dw .to_ringX wrt BS3TEXT16 105 116 %else 106 117 dd .invalid_syscall wrt FLAT 107 118 dd .print_chr wrt FLAT 108 119 dd .print_str wrt FLAT 109 dd .to_ring 0wrt FLAT110 dd .to_ring 1wrt FLAT111 dd .to_ring 2wrt FLAT112 dd .to_ring 3wrt FLAT120 dd .to_ringX wrt FLAT 121 dd .to_ringX wrt FLAT 122 dd .to_ringX wrt FLAT 123 dd .to_ringX wrt FLAT 113 124 %endif 114 125 … … 120 131 jmp .return 121 132 133 122 134 ; 123 135 ; Print char in the CL register. … … 132 144 %endif 133 145 .print_chr: 146 push xDI 147 push xSI 134 148 %ifndef TMPL_CMN_R86 135 149 ; Switch to real mode (20h param scratch area not required). … … 151 165 BS3_SET_BITS TMPL_BITS 152 166 %endif 167 pop xSI 168 pop xDI 153 169 jmp .return 154 170 %ifndef TMPL_16BIT 155 171 TMPL_BEGIN_TEXT 156 172 %endif 173 157 174 158 175 ; … … 179 196 180 197 ; 181 ; Switch the caller to ring-0. 182 ; 183 .to_ring0: 184 sub xSP, BS3REGS_size 185 mov xBX, xSP ; xBP = BS3REGS pointer. 198 ; Switch the caller to ring-0, ring-1, ring-2 or ring-3. 199 ; 200 ; This implement this by saving the entire register context, calling 201 ; a transformation function (C) and restoring the modified register 202 ; context using a generic worker. 203 ; 204 .to_ringX: 205 sub xSP, BS3REGCTX_size 206 mov xBX, xSP ; xBP = BS3REGCTX pointer. 186 207 call .save_context 187 208 188 189 jmp .return 190 191 ;; @todo the remainder could be implemented in client code using SwitchToRing0 192 .to_ring1: 193 int3 194 jmp .return 195 196 .to_ring2: 197 int3 198 jmp .return 199 200 .to_ring3: 201 int3 202 jmp .return 209 %if TMPL_BITS == 32 210 ; Convert xBP to flat pointer in 32-bit 211 push ss 212 push xBX 213 call Bs3SelProtFar32ToFlat32 214 add sSP, 8 215 mov xBX, xAX 216 %endif 217 ; Prepare the last call frame. 218 BS3_ONLY_16BIT_STMT push ss 219 push xBX 220 221 ; Convert the register context from whatever it is to ring-0. 222 BS3_ONLY_16BIT_STMT push ss 223 push xBX 224 mov ax, VAR_CALLER_AX 225 sub ax, BS3_SYSCALL_TO_RING0 226 push xAX 227 BS3_CALL Bs3RegCtxConvertToRingX, 2 228 add xSP, sCB 229 230 ; Restore the register context (does not return). 231 pop xBX ; restore saved pointer. 232 BS3_ONLY_16BIT_STMT push ss 233 push xBX 234 BS3_CALL Bs3RegCtxRestore, 1 235 jmp Bs3Panic 203 236 204 237 … … 236 269 237 270 ; 238 ; Internal function. ss:xBX = Pointer to register frame (BS3REG S).271 ; Internal function. ss:xBX = Pointer to register frame (BS3REGCTX). 239 272 ; @uses xAX 240 273 ; … … 257 290 mov word [ss:bx + di + 6], 0 258 291 add di, 8 259 cmp di, BS3REG S_size292 cmp di, BS3REGCTX_size 260 293 jb .save_context_16_clear_loop 261 294 pop di … … 263 296 ; Do the 8086/80186/80286 state saving. 264 297 mov ax, VAR_CALLER_AX 265 mov [ss:bx + BS3REG S.rax], ax298 mov [ss:bx + BS3REGCTX.rax], ax 266 299 mov cx, VAR_CALLER_CX 267 mov [ss:bx + BS3REG S.rcx], ax300 mov [ss:bx + BS3REGCTX.rcx], ax 268 301 mov ax, VAR_CALLER_DX 269 mov [ss:bx + BS3REG S.rdx], ax302 mov [ss:bx + BS3REGCTX.rdx], ax 270 303 mov ax, VAR_CALLER_BX 271 mov [ss:bx + BS3REG S.rbx], ax272 mov [ss:bx + BS3REG S.rsi], si273 mov [ss:bx + BS3REG S.rdi], di304 mov [ss:bx + BS3REGCTX.rbx], ax 305 mov [ss:bx + BS3REGCTX.rsi], si 306 mov [ss:bx + BS3REGCTX.rdi], di 274 307 mov ax, VAR_CALLER_BP 275 mov [ss:bx + BS3REG S.rbp], ax276 mov [ss:bx + BS3REG S.es], es308 mov [ss:bx + BS3REGCTX.rbp], ax 309 mov [ss:bx + BS3REGCTX.es], es 277 310 mov ax, [xBP + xCB] 278 mov [ss:bx + BS3REG S.rip], ax311 mov [ss:bx + BS3REGCTX.rip], ax 279 312 mov ax, [xBP + xCB*2] 280 mov [ss:bx + BS3REG S.cs], ax313 mov [ss:bx + BS3REGCTX.cs], ax 281 314 and al, X86_SEL_RPL 282 mov [ss:bx + BS3REG S.bCpl], al315 mov [ss:bx + BS3REGCTX.bCpl], al 283 316 cmp al, 0 284 317 je .save_context_16_same 285 318 mov ax, [xBP + xCB*4] 286 mov [ss:bx + BS3REG S.rsp], ax319 mov [ss:bx + BS3REGCTX.rsp], ax 287 320 mov ax, [xBP + xCB*5] 288 mov [ss:bx + BS3REG S.ss], ax321 mov [ss:bx + BS3REGCTX.ss], ax 289 322 jmp .save_context_16_done_stack 290 323 .save_context_16_same: 291 324 mov ax, bp 292 325 add ax, xCB * (1 + 3) 293 mov [ss:bx + BS3REG S.rsp], ax326 mov [ss:bx + BS3REGCTX.rsp], ax 294 327 mov ax, ss 295 mov [ss:bx + BS3REG S.ss], ax328 mov [ss:bx + BS3REGCTX.ss], ax 296 329 .save_context_16_done_stack: 297 330 mov ax, [xBP + xCB*3] 298 mov [ss:bx + BS3REG S.rflags], ax331 mov [ss:bx + BS3REGCTX.rflags], ax 299 332 mov al, VAR_CALLER_MODE 300 mov [ss:bx + BS3REG S.bMode], al333 mov [ss:bx + BS3REGCTX.bMode], al 301 334 cmp byte [g_uBs3CpuDetected], BS3CPU_80286 302 335 jne .save_context_16_return 303 smsw [ss:bx + BS3REG S.cr0]304 str [ss:bx + BS3REG S.tr]305 sldt [ss:bx + BS3REG S.ldtr]336 smsw [ss:bx + BS3REGCTX.cr0] 337 str [ss:bx + BS3REGCTX.tr] 338 sldt [ss:bx + BS3REGCTX.ldtr] 306 339 .save_context_16_return: 307 340 ret … … 321 354 mov dword [ss:xBX + xDI + 4], 0 322 355 add xDI, 8 323 cmp xDI, BS3REG S_size356 cmp xDI, BS3REGCTX_size 324 357 jb .save_context_32_clear_loop 325 358 pop xDI … … 328 361 ; Do the 386+ state saving. 329 362 %if TMPL_BITS == 16 ; save the high word of registered pushed on the stack. 330 mov [ss:bx + BS3REGS.rax], eax 331 mov [ss:bx + BS3REGS.rcx], ecx 332 mov [ss:bx + BS3REGS.rdx], edx 333 mov [ss:bx + BS3REGS.rbx], ebx 334 mov [ss:bx + BS3REGS.rbp], ebp 335 mov [ss:bx + BS3REGS.rsp], esp 363 mov [ss:bx + BS3REGCTX.rax], eax 364 mov [ss:bx + BS3REGCTX.rcx], ecx 365 mov [ss:bx + BS3REGCTX.rdx], edx 366 mov [ss:bx + BS3REGCTX.rbx], ebx 367 mov [ss:bx + BS3REGCTX.rbp], ebp 368 mov [ss:bx + BS3REGCTX.rsp], esp 369 pushfd 370 pop dword [ss:bx + BS3REGCTX.rflags] 336 371 %endif 337 372 mov xAX, VAR_CALLER_AX 338 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rax], xAX373 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rax], xAX 339 374 mov xCX, VAR_CALLER_CX 340 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rcx], xCX375 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rcx], xCX 341 376 mov xAX, VAR_CALLER_DX 342 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rdx], xAX377 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rdx], xAX 343 378 mov xAX, VAR_CALLER_BX 344 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rbx], xAX345 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rsi], sSI346 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rdi], sDI379 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rbx], xAX 380 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rsi], sSI 381 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rdi], sDI 347 382 mov xAX, VAR_CALLER_BP 348 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rbp], xAX 349 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.es], es 383 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rbp], xAX 384 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.es], es 385 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.fs], fs 386 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.gs], gs 350 387 mov xAX, [xBP + xCB] 351 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rip], xAX388 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rip], xAX 352 389 mov ax, [xBP + xCB*2] 353 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.cs], ax390 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.cs], ax 354 391 %if TMPL_MODE != BS3_MODE_RM 355 392 and al, X86_SEL_RPL 356 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.bCpl], al393 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.bCpl], al 357 394 cmp al, 0 358 395 je .save_context_full_same 359 396 mov xAX, [xBP + xCB*4] 360 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rsp], xAX397 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rsp], xAX 361 398 mov ax, [xBP + xCB*5] 362 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.ss], ax399 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.ss], ax 363 400 jmp .save_context_full_done_stack 364 401 %else 365 mov byte [BS3_NOT_64BIT(ss:) xBX + BS3REG S.bCpl], 0402 mov byte [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.bCpl], 0 366 403 %endif 367 404 .save_context_full_same: 368 405 mov xAX, xBP 369 406 add xAX, xCB * (1 + 3) 370 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.rsp], xAX407 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rsp], xAX 371 408 mov ax, ss 372 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.ss], ax409 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.ss], ax 373 410 .save_context_full_done_stack: 374 411 mov xAX, [xBP + xCB*3] 375 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rflags], xAX 412 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rflags], sAX 413 376 414 mov al, VAR_CALLER_MODE 377 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.bMode], al415 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.bMode], al 378 416 %if TMPL_BITS == 64 379 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r8], r8 380 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r9], r9 381 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r10], r10 382 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r11], r11 383 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r12], r12 384 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r13], r13 385 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r14], r14 386 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r15], r15 387 %endif 388 ; Save state according to detected CPU. 389 str [BS3_NOT_64BIT(ss:) xBX + BS3REGS.tr] 390 sldt [BS3_NOT_64BIT(ss:) xBX + BS3REGS.ldtr] 391 cmp byte [g_uBs3CpuDetected], BS3CPU_80286 392 ja .save_context_full_return 393 smsw [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr0] 394 jmp .save_context_full_return 395 396 .save_context_full_386_plus: 417 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r8], r8 418 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r9], r9 419 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r10], r10 420 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r11], r11 421 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r12], r12 422 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r13], r13 423 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r14], r14 424 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.r15], r15 425 %endif 426 str [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.tr] 427 sldt [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.ldtr] 397 428 mov sAX, cr0 398 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.cr0], sAX429 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.cr0], sAX 399 430 mov sAX, cr2 400 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.cr2], sAX431 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.cr2], sAX 401 432 mov sAX, cr3 402 mov [BS3_NOT_64BIT(ss:) xBX + BS3REG S.cr3], sAX433 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.cr3], sAX 403 434 mov sAX, cr4 404 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr4], sAX 405 435 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.cr4], sAX 436 437 %if TMPL_BITS != 64 438 ; Deal with extended v8086 frame. 439 %if TMPL_BITS == 32 440 test dword [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rflags], X86_EFL_VM 441 jz .save_context_full_return 442 %else 443 mov al, VAR_CALLER_MODE 444 and al, BS3_MODE_CODE_MASK 445 cmp al, BS3_MODE_CODE_V86 446 jne .save_context_full_return 447 mov dword [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rflags], X86_EFL_VM 448 %endif 449 mov xAX, [xBP + xCB*4] 450 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.rsp], xAX 451 mov ax, [xBP + xCB*5] 452 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.ss], ax 453 mov ax, [xBP + xCB*6] 454 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.es], ax 455 mov ax, [xBP + xCB*7] 456 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.ds], ax 457 mov ax, [xBP + xCB*8] 458 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.fs], ax 459 mov ax, [xBP + xCB*9] 460 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.gs], ax 461 mov byte [BS3_NOT_64BIT(ss:) xBX + BS3REGCTX.bCpl], 3 462 %endif 406 463 .save_context_full_return: 407 464 ret -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc32-U8RS.asm
r58809 r59975 59 59 jmp .return 60 60 61 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
r59952 r59975 138 138 /** Where we save the boot registers during init. 139 139 * Located right before the code. */ 140 #define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REG S) - 8)140 #define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REGCTX) - 8) 141 141 /** Where the stack starts (initial RSP value). 142 142 * Located 16 bytes (assumed by boot sector) before the saved registers. … … 210 210 211 211 #define BS3_SEL_RING_SHIFT 8 /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */ 212 #define BS3_SEL_RING_SUB_MASK 0x00f8 /**< Mask for getting the sub-selector. For use with BS3_SEL_R*_FIRST. */ 212 213 213 214 #define BS3_SEL_R0_FIRST 0x0100 /**< The first selector in the ring-0 block. */ … … 376 377 /** @def BS3_FP_SEG 377 378 * Get the selector (segment) part of a far pointer. 379 * 378 380 * @returns selector. 379 381 * @param a_pv Far pointer. … … 382 384 /** @def BS3_FP_OFF 383 385 * Get the segment offset part of a far pointer. 386 * 384 387 * @returns offset. 385 388 * @param a_pv Far pointer. … … 388 391 /** @def BS3_FP_MAKE 389 392 * Create a far pointer. 390 * @returns selector. 391 * @param a_pv Far pointer. 393 * 394 * @returns Far pointer. 395 * @param a_uSeg The selector/segment. 396 * @param a_off The offset into the segment. 392 397 */ 393 398 # define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off))) 399 394 400 #endif 401 402 /** @def BS3_MAKE_PROT_PTR_FROM_FLAT 403 * Creates a protected mode pointer from a flat address. 404 * 405 * For sake of convenience, this macro also works in 32-bit and 64-bit mode, 406 * only there it doesn't return a far pointer but a flat point. 407 * 408 * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit 409 * and 64-bit. 410 * @param a_uFlat Flat address in the first 16MB. */ 411 #if ARCH_BITS == 16 412 # define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) \ 413 BS3_FP_MAKE(((uint16_t)(a_uFlat >> 16) << 3) + BS3_SEL_TILED, (uint16_t)(a_uFlat)) 414 #else 415 # define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) ((void *)(uintptr_t)(a_uFlat)) 416 #endif 417 418 /** @def BS3_MAKE_PROT_R0PTR_FROM_REAL 419 * Creates a protected mode pointer from a far real mode address. 420 * 421 * For sake of convenience, this macro also works in 32-bit and 64-bit mode, 422 * only there it doesn't return a far pointer but a flat point. 423 * 424 * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit 425 * and 64-bit. 426 * @param a_uSeg The selector/segment. 427 * @param a_off The offset into the segment. 428 */ 429 #if ARCH_BITS == 16 430 # define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) BS3_FP_MAKE(((a_uSeg) << 3) + BS3_SEL_TILED, a_off) 431 #else 432 # define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) ( (void *)(uintptr_t)(((uint32_t)(a_uSeg) << 16) | (uint16_t)(a_off)) ) 433 #endif 434 395 435 396 436 /** @def BS3_CALL … … 1922 1962 typedef struct BS3REGCTX 1923 1963 { 1924 BS3REG rax; 1925 BS3REG rcx; 1926 BS3REG rdx; 1927 BS3REG rbx; 1928 BS3REG rsp; 1929 BS3REG rbp; 1930 BS3REG rsi; 1931 BS3REG rdi; 1932 BS3REG r8; 1933 BS3REG r9; 1934 BS3REG r10; 1935 BS3REG r11; 1936 BS3REG r12; 1937 BS3REG r13; 1938 BS3REG r14; 1939 BS3REG r15; 1940 BS3REG rflags; 1941 BS3REG rip; 1942 uint16_t cs; 1943 uint16_t ds; 1944 uint16_t es; 1945 uint16_t fs; 1946 uint16_t gs; 1947 uint16_t ss; 1948 uint16_t tr; 1949 uint16_t ldtr; 1950 uint8_t bMode; /**< BS3_MODE_XXX. */1951 uint8_t bCpl; /**< 0 -3, 0 is used for real mode. */1952 uint8_t abPadding[6]; 1953 BS3REG cr0; 1954 BS3REG cr2; 1955 BS3REG cr3; 1956 BS3REG cr4; 1964 BS3REG rax; /**< 0x00 */ 1965 BS3REG rcx; /**< 0x08 */ 1966 BS3REG rdx; /**< 0x10 */ 1967 BS3REG rbx; /**< 0x18 */ 1968 BS3REG rsp; /**< 0x20 */ 1969 BS3REG rbp; /**< 0x28 */ 1970 BS3REG rsi; /**< 0x30 */ 1971 BS3REG rdi; /**< 0x38 */ 1972 BS3REG r8; /**< 0x40 */ 1973 BS3REG r9; /**< 0x48 */ 1974 BS3REG r10; /**< 0x50 */ 1975 BS3REG r11; /**< 0x58 */ 1976 BS3REG r12; /**< 0x60 */ 1977 BS3REG r13; /**< 0x68 */ 1978 BS3REG r14; /**< 0x70 */ 1979 BS3REG r15; /**< 0x78 */ 1980 BS3REG rflags; /**< 0x80 */ 1981 BS3REG rip; /**< 0x88 */ 1982 uint16_t cs; /**< 0x90 */ 1983 uint16_t ds; /**< 0x92 */ 1984 uint16_t es; /**< 0x94 */ 1985 uint16_t fs; /**< 0x96 */ 1986 uint16_t gs; /**< 0x98 */ 1987 uint16_t ss; /**< 0x9a */ 1988 uint16_t tr; /**< 0x9c */ 1989 uint16_t ldtr; /**< 0x9e */ 1990 uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */ 1991 uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */ 1992 uint8_t abPadding[6]; /**< 0xa2 */ 1993 BS3REG cr0; /**< 0xa8 */ 1994 BS3REG cr2; /**< 0xb0 */ 1995 BS3REG cr3; /**< 0xb8 */ 1996 BS3REG cr4; /**< 0xc0 */ 1957 1997 } BS3REGCTX; 1958 1998 /** Pointer to a register context. */ … … 1960 2000 /** Pointer to a const register context. */ 1961 2001 typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX; 2002 2003 2004 /** 2005 * Transforms a register context to a different ring. 2006 * 2007 * @param pRegCtx The register context. 2008 * @param bRing The target ring (0..3). 2009 */ 2010 BS3_DECL(void) Bs3RegCtxConvertToRingX_c16(PBS3REGCTX pRegCtx, uint8_t bRing); 2011 BS3_DECL(void) Bs3RegCtxConvertToRingX_c32(PBS3REGCTX pRegCtx, uint8_t bRing); /**< @copydoc Bs3RegCtxConvertToRingX_c16 */ 2012 BS3_DECL(void) Bs3RegCtxConvertToRingX_c64(PBS3REGCTX pRegCtx, uint8_t bRing); /**< @copydoc Bs3RegCtxConvertToRingX_c16 */ 2013 #define Bs3RegCtxConvertToRingX BS3_CMN_NM(Bs3RegCtxConvertToRingX) /**< Selects #Bs3RegCtxConvertToRingX_c16, #Bs3RegCtxConvertToRingX_c32 or #Bs3RegCtxConvertToRingX_c64. */ 2014 2015 /** 2016 * Restores a register context. 2017 * 2018 * @param pRegCtx The register context to be restored and resumed. 2019 * @param fFlags BS3REGCTXRESTORE_F_XXX. 2020 * 2021 * @remarks Caller must be in ring-0! 2022 * @remarks Does not return. 2023 */ 2024 BS3_DECL(void) Bs3RegCtxRestore_c16(PCBS3REGCTX pRegCtx, uint16_t fFlags); 2025 BS3_DECL(void) Bs3RegCtxRestore_c32(PCBS3REGCTX pRegCtx, uint16_t fFlags); /**< @copydoc Bs3RegCtxRestore_c16 */ 2026 BS3_DECL(void) Bs3RegCtxRestore_c64(PCBS3REGCTX pRegCtx, uint16_t fFlags); /**< @copydoc Bs3RegCtxRestore_c16 */ 2027 #define Bs3RegCtxRestore BS3_CMN_NM(Bs3RegCtxRestore) /**< Selects #Bs3RegCtxRestore_c16, #Bs3RegCtxRestore_c32 or #Bs3RegCtxRestore_c64. */ 2028 2029 /** Skip restoring the CRx registers. */ 2030 #define BS3REGCTXRESTORE_F_SKIP_CRX UINT16_C(0x0001) 1962 2031 1963 2032 … … 1975 2044 /** The handler SS. */ 1976 2045 uint16_t uHandlerSs; 2046 /** Explicit alignment. */ 2047 uint16_t usAlignment; 1977 2048 /** The handler RSP (top of iret frame). */ 1978 2049 uint64_t uHandlerRsp; … … 1989 2060 typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME; 1990 2061 1991 /** 1992 * Resumes execution of a 32-bit trap frame. 1993 * 1994 * @param pTrapFrame Trap frame to resume. 1995 * @param fFlags Flags, BS3TRAPRESUME_F_XXX. 1996 */ 1997 BS3_DECL(void) Bs3Trap32ResumeFrame_c32(BS3TRAPFRAME BS3_FAR *pTrapFrame, uint16_t fFlags); 1998 #define Bs3Trap32ResumeFrame BS3_CMN_NM(Bs3Trap32ResumeFrame) /**< Selects Bs3Trap32ResumeFrame_c16 (not implemented), #Bs3Trap32ResumeFrame_c32 or Bs3Trap32ResumeFrame_c64 (not implemented). */ 1999 2000 /** Skip restoring the CRx registers. */ 2001 #define BS3TRAPRESUME_F_SKIP_CRX UINT16_C(0x0001) 2062 2002 2063 2003 2064 /** -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
r59952 r59975 1085 1085 ;; Where we save the boot registers during init. 1086 1086 ; Located right before the code. 1087 %define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - BS3REG S_size - 8)1087 %define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - BS3REGCTX_size - 8) 1088 1088 ;; Where the stack starts (initial RSP value). 1089 1089 ; Located 16 bytes (assumed by boot sector) before the saved registers. SS.BASE=0. … … 1123 1123 1124 1124 ;; 1125 ; Registers. Used by traps and such. 1126 ; 1127 struc BS3REGS 1128 .rax resq 1 1129 .rcx resq 1 1130 .rdx resq 1 1131 .rbx resq 1 1132 .rsp resq 1 1133 .rbp resq 1 1134 .rsi resq 1 1135 .rdi resq 1 1136 .r8 resq 1 1137 .r9 resq 1 1138 .r10 resq 1 1139 .r11 resq 1 1140 .r12 resq 1 1141 .r13 resq 1 1142 .r14 resq 1 1143 .r15 resq 1 1144 .rflags resq 1 1145 .rip resq 1 1146 .cs resw 1 1147 .ds resw 1 1148 .es resw 1 1149 .fs resw 1 1150 .gs resw 1 1151 .ss resw 1 1152 .tr resw 1 1153 .ldtr resw 1 1154 .bMode resb 1 1155 .bCpl resb 1 1156 .abPadding resb 6 1157 .cr0 resq 1 1158 .cr2 resq 1 1159 .cr3 resq 1 1160 .cr4 resq 1 1161 1162 ;; @todo Add floating point registers when they are active. 1125 ; BS3 register context. Used by traps and such. 1126 ; 1127 struc BS3REGCTX 1128 .rax resq 1 ; BS3REG rax; /**< 0x00 */ 1129 .rcx resq 1 ; BS3REG rcx; /**< 0x08 */ 1130 .rdx resq 1 ; BS3REG rdx; /**< 0x10 */ 1131 .rbx resq 1 ; BS3REG rbx; /**< 0x18 */ 1132 .rsp resq 1 ; BS3REG rsp; /**< 0x20 */ 1133 .rbp resq 1 ; BS3REG rbp; /**< 0x28 */ 1134 .rsi resq 1 ; BS3REG rsi; /**< 0x30 */ 1135 .rdi resq 1 ; BS3REG rdi; /**< 0x38 */ 1136 .r8 resq 1 ; BS3REG r8; /**< 0x40 */ 1137 .r9 resq 1 ; BS3REG r9; /**< 0x48 */ 1138 .r10 resq 1 ; BS3REG r10; /**< 0x50 */ 1139 .r11 resq 1 ; BS3REG r11; /**< 0x58 */ 1140 .r12 resq 1 ; BS3REG r12; /**< 0x60 */ 1141 .r13 resq 1 ; BS3REG r13; /**< 0x68 */ 1142 .r14 resq 1 ; BS3REG r14; /**< 0x70 */ 1143 .r15 resq 1 ; BS3REG r15; /**< 0x78 */ 1144 .rflags resq 1 ; BS3REG rflags; /**< 0x80 */ 1145 .rip resq 1 ; BS3REG rip; /**< 0x88 */ 1146 .cs resw 1 ; uint16_t cs; /**< 0x90 */ 1147 .ds resw 1 ; uint16_t ds; /**< 0x92 */ 1148 .es resw 1 ; uint16_t es; /**< 0x94 */ 1149 .fs resw 1 ; uint16_t fs; /**< 0x96 */ 1150 .gs resw 1 ; uint16_t gs; /**< 0x98 */ 1151 .ss resw 1 ; uint16_t ss; /**< 0x9a */ 1152 .tr resw 1 ; uint16_t tr; /**< 0x9c */ 1153 .ldtr resw 1 ; uint16_t ldtr; /**< 0x9e */ 1154 .bMode resb 1 ; uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */ 1155 .bCpl resb 1 ; uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */ 1156 .abPadding resb 6 ; uint8_t abPadding[6]; /**< 0xa2 */ 1157 .cr0 resq 1 ; BS3REG cr0; /**< 0xa8 */ 1158 .cr2 resq 1 ; BS3REG cr2; /**< 0xb0 */ 1159 .cr3 resq 1 ; BS3REG cr3; /**< 0xb8 */ 1160 .cr4 resq 1 ; BS3REG cr4; /**< 0xc0 */ 1163 1161 endstruc 1164 1162 1163 ;; 1164 ; BS3 Trap Frame. 1165 ; 1166 struc BS3TRAPFRAME 1167 .bXcpt resb 1 1168 .bAlignment resb 1 1169 .uHandlerCs resw 1 1170 .uHandlerSs resw 1 1171 .usAlignment resw 1 1172 .uHandlerRsp resq 1 1173 .fHandlerRfl resq 1 1174 .uErrCd resq 1 1175 .Ctx resb BS3REGCTX_size 1176 endstruc 1177 1178 ;; Flag for Bs3TrapXxResumeFrame methods. 1179 %define BS3TRAPRESUME_F_SKIP_CRX 1 1165 1180 1166 1181 … … 1380 1395 %endif 1381 1396 1382 ;1383 ; BS3 register context (without FPU).1384 ;1385 struc BS3REGCTX1386 .rax resq 11387 .rcx resq 11388 .rdx resq 11389 .rbx resq 11390 .rsp resq 11391 .rbp resq 11392 .rsi resq 11393 .rdi resq 11394 .r8 resq 11395 .r9 resq 11396 .r10 resq 11397 .r11 resq 11398 .r12 resq 11399 .r13 resq 11400 .r14 resq 11401 .r15 resq 11402 .rflags resq 11403 .rip resq 11404 .cs resw 11405 .ds resw 11406 .es resw 11407 .fs resw 11408 .gs resw 11409 .ss resw 11410 .tr resw 11411 .ldtr resw 11412 .cBits resb 11413 .abPadding resb 71414 .cr0 resq 11415 .cr2 resq 11416 .cr3 resq 11417 .cr4 resq 11418 endstruc1419 1420 ;;1421 ; BS3 Trap Frame.1422 ;1423 struc BS3TRAPFRAME1424 .bXcpt resb 11425 .bAlignment resb 11426 .uHandlerCs resw 11427 .uHandlerSs resw 11428 .uHandlerRsp resq 11429 .fHandlerRfl resq 11430 .uErrCd resq 11431 .Ctx resb BS3REGCTX_size1432 endstruc1433 1434 ;; Flag for Bs3TrapXxResumeFrame methods.1435 %define BS3TRAPRESUME_F_SKIP_CRX 11436 1437 1397 1438 1398 ;; @name BS3CPU_XXX - Bs3CpuDetect_mmm return value and g_bBs3CpuDetected.
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器