VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSave.asm@ 60311

最後變更 在這個檔案從60311是 60218,由 vboxsync 提交於 9 年 前

bs3kit: Optimized BS3_MODE_CODE_V86 checks.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.7 KB
 
1; $Id: bs3-cmn-RegCtxSave.asm 60218 2016-03-28 00:26:40Z vboxsync $
2;; @file
3; BS3Kit - Bs3RegCtxSave.
4;
5
6;
7; Copyright (C) 2007-2016 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.alldomusa.eu.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27%include "bs3kit-template-header.mac"
28
29
30BS3_EXTERN_SYSTEM16 Bs3Gdt
31BS3_EXTERN_DATA16 g_bBs3CurrentMode
32%if TMPL_BITS == 16
33BS3_EXTERN_DATA16 g_uBs3CpuDetected
34%endif
35TMPL_BEGIN_TEXT
36
37
38
39;;
40; Restores the given register context.
41;
42; @param pRegCtx
43; @uses None.
44;
45BS3_PROC_BEGIN_CMN Bs3RegCtxSave
46 BS3_CALL_CONV_PROLOG 1
47 push xBP
48 mov xBP, xSP
49 xPUSHF ; xBP - xCB*1: save the incoming flags exactly.
50 push xAX ; xBP - xCB*2: save incoming xAX
51 push xCX ; xBP - xCB*3: save incoming xCX
52 push xDI ; xBP - xCB*4: save incoming xDI
53 BS3_ONLY_16BIT_STMT push es ; xBP - xCB*5
54 BS3_ONLY_16BIT_STMT push ds ; xBP - xCB*6
55
56 ;
57 ; Prologue. Load ES:xDI with pRegCtx.
58 ; (ASSUMES ds is BS3DATA16/FLAT of course.)
59 ;
60%if TMPL_BITS == 16
61 les di, [bp + 4]
62%else
63 mov xDI, [xBP + xCB*2]
64%endif
65
66 ;
67 ; Clear the whole structure first.
68 ;
69 xor xAX, xAX
70 cld
71 AssertCompileSizeAlignment(BS3REGCTX, 4)
72%if TMPL_BITS == 16
73 les xDI, [xBP + xCB*2]
74 mov xCX, BS3REGCTX_size / 2
75 rep stosw
76%else
77 mov xDI, [xBP + xCB*2]
78 mov xCX, BS3REGCTX_size / 4
79 rep stosd
80%endif
81 mov xDI, [xBP + xCB*2]
82
83 ;
84 ; Save the current mode.
85 ;
86 mov cl, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
87 mov [BS3_ONLY_16BIT(es:) xDI + BS3REGCTX.bMode], cl
88%if TMPL_BITS == 16
89
90 ;
91 ; In 16-bit mode we could be running on really ancient CPUs, so check
92 ; mode and detected CPU and proceed with care.
93 ;
94 cmp cl, BS3_MODE_PP16
95 jae .save_full
96
97 mov cl, [BS3_DATA16_WRT(g_uBs3CpuDetected)]
98 cmp cl, BS3CPU_80386
99 jae .save_full
100
101 ; load ES into DS so we can save some segment prefix bytes.
102 push es
103 pop ds
104
105 ; 16-bit GPRs not on the stack.
106 mov [xDI + BS3REGCTX.rdx], dx
107 mov [xDI + BS3REGCTX.rbx], bx
108 mov [xDI + BS3REGCTX.rsi], si
109
110 ; Join the common code.
111 cmp cl, BS3CPU_80286
112 jb .common_ancient
113
114 smsw [xDI + BS3REGCTX.cr0]
115 jmp .common_80286
116%endif
117
118
119.save_full:
120 ;
121 ; 80386 or later.
122 ;
123%if TMPL_BITS == 16
124 ; Load es into ds so we can save ourselves some segment prefix bytes.
125 push es
126 pop ds
127%endif
128
129 ; GPRs first.
130 mov [xDI + BS3REGCTX.rdx], sDX
131 mov [xDI + BS3REGCTX.rbx], sBX
132 mov [xDI + BS3REGCTX.rsi], sSI
133%if TMPL_BITS == 64
134 mov [xDI + BS3REGCTX.r8], r8
135 mov [xDI + BS3REGCTX.r9], r9
136 mov [xDI + BS3REGCTX.r10], r10
137 mov [xDI + BS3REGCTX.r11], r11
138 mov [xDI + BS3REGCTX.r12], r12
139 mov [xDI + BS3REGCTX.r13], r13
140 mov [xDI + BS3REGCTX.r14], r14
141 mov [xDI + BS3REGCTX.r15], r15
142%else
143 or byte [xDI + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_AMD64
144%endif
145%if TMPL_BITS == 16 ; Save high bits.
146 mov [xDI + BS3REGCTX.rax], eax
147 mov [xDI + BS3REGCTX.rcx], ecx
148 mov [xDI + BS3REGCTX.rdi], edi
149 mov [xDI + BS3REGCTX.rbp], ebp
150 mov [xDI + BS3REGCTX.rsp], esp
151 pushfd
152 pop dword [xDI + BS3REGCTX.rflags]
153%endif
154
155 ; 386 segment registers.
156 mov [xDI + BS3REGCTX.fs], fs
157 mov [xDI + BS3REGCTX.gs], gs
158
159%if TMPL_BITS == 16 ; v8086 and real mode woes.
160 mov cl, [xDI + BS3REGCTX.bMode]
161 cmp cl, BS3_MODE_RM
162 je .common_full_control_regs
163 test cl, BS3_MODE_CODE_V86
164 jnz .common_full_no_control_regs
165%endif
166 mov ax, ss
167 test al, 3
168 jnz .common_full_no_control_regs
169
170 ; Control registers (ring-0 and real-mode only).
171.common_full_control_regs:
172 mov sAX, cr0
173 mov [xDI + BS3REGCTX.cr0], sAX
174 mov sAX, cr2
175 mov [xDI + BS3REGCTX.cr2], sAX
176 mov sAX, cr3
177 mov [xDI + BS3REGCTX.cr3], sAX
178 mov sAX, cr4
179 mov [xDI + BS3REGCTX.cr4], sAX
180 jmp .common_80286
181
182.common_full_no_control_regs:
183 or byte [xDI + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
184
185 ; 80286 control registers.
186.common_80286:
187 str [xDI + BS3REGCTX.tr]
188 sldt [xDI + BS3REGCTX.ldtr]
189
190 ; Common stuff - stuff on the stack, 286 segment registers.
191.common_ancient:
192 mov xAX, [xBP - xCB*1]
193 mov [xDI + BS3REGCTX.rflags], xAX
194 mov xAX, [xBP - xCB*2]
195 mov [xDI + BS3REGCTX.rax], xAX
196 mov xAX, [xBP - xCB*3]
197 mov [xDI + BS3REGCTX.rcx], xAX
198 mov xAX, [xBP - xCB*4]
199 mov [xDI + BS3REGCTX.rdi], xAX
200 mov xAX, [xBP]
201 mov [xDI + BS3REGCTX.rbp], xAX
202 mov xAX, [xBP + xCB]
203 mov [xDI + BS3REGCTX.rip], xAX
204 lea xAX, [xBP + xCB*2]
205 mov [xDI + BS3REGCTX.rsp], xAX
206
207 mov [xDI + BS3REGCTX.cs], cs
208%if TMPL_BITS == 16
209 mov ax, [xBP - xCB*6]
210 mov [xDI + BS3REGCTX.ds], ax
211 mov ax, [xBP - xCB*5]
212 mov [xDI + BS3REGCTX.es], ax
213%else
214 mov [xDI + BS3REGCTX.ds], ds
215 mov [xDI + BS3REGCTX.es], es
216%endif
217 mov [xDI + BS3REGCTX.ss], ss
218
219 ;
220 ; Return.
221 ;
222.return:
223 BS3_ONLY_16BIT_STMT pop ds
224 BS3_ONLY_16BIT_STMT pop es
225 pop xDI
226 pop xCX
227 pop xAX
228 xPOPF
229 pop xBP
230 ret
231BS3_PROC_END_CMN Bs3RegCtxSave
232
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette