VirtualBox

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

Last change on this file since 60044 was 60024, checked in by vboxsync, 9 years ago

bs3kit: updates (-> office).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1; $Id: bs3-cmn-RegCtxSave.asm 60024 2016-03-15 08:59:49Z 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.virtualbox.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%if BS3REGCTX_size %
39
40
41;;
42; Restores the given register context.
43;
44; @param pRegCtx
45; @uses None.
46;
47BS3_PROC_BEGIN_CMN Bs3RegCtxSave
48 BS3_CALL_CONV_PROLOG 1
49 push xBP
50 mov xBP, xSP
51 xPUSHF ; save the incoming flags exactly.
52 push xAX ; save incoming xAX
53 push xCX ; save incoming xCX
54 push xDI
55 BS3_ONLY_16BIT_STMT push es
56 BS3_ONLY_16BIT_STMT push ds
57
58 ;
59 ; Prologue. Load ES:xDI with pRegCtx.
60 ; (ASSUMES ds is BS3DATA16/FLAT of course.)
61 ;
62%if TMPL_BITS == 16
63 les di, [bp + 4]
64%else
65 mov xDI, [xBP + xCB*2]
66%endif
67
68%if TMPL_BITS != 64
69 ;
70 ; Clear the whole structure first, unless 64-bit
71 ;
72 push es
73 les
74 push ds
75 pop ds
76 xor xAX, xAX
77 cld
78 %if TMPL_BITS == 16
79 mov xCX, BS3REGCTX_size / 2
80 rep stosw
81 mov di, [bp + 4]
82 %else
83 mov xCX, BS3REGCTX_size / 4
84 rep stosd
85 mov xDI, [xBP + xCB*2]
86 %endif
87%endif
88
89 ;
90 ; Save the current mode.
91 ;
92 mov cl, BS3_DATA16_WRT(g_bBs3CurrentMode)
93 mov [BS3_ONLY_16BIT(es:) xDI + BS3REGCTX.bMode], cl
94
95%if TMPL_BITS == 16
96 ;
97 ; Check what the CPU can do.
98 ;
99 cmp byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80386
100 jae .save_full
101
102 ; Do the 80286 specifics first and load ES into DS so we can save some segment prefix bytes.
103 cmp byte [es:BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80286
104 push es
105 pop ds
106 jb .save_16_bit_ancient
107
108 smsw [xDI + BS3REGCTX.cr0]
109 sldt [xDI + BS3REGCTX.ldtr]
110 str [xDI + BS3REGCTX.tr]
111
112.save_16_bit_ancient:
113 ; 16-bit GPRs not on the stack.
114 mov [xDI + BS3REGCTX.rdx], dx
115 mov [xDI + BS3REGCTX.rbx], bx
116 mov [xDI + BS3REGCTX.rsi], si
117
118 ; flags
119 mov xAX, [xBP + xCB - xCB]
120 mov [xDI + BS3REGCTX.rflags], xAX
121
122 jmp .common
123%endif
124
125
126.save_full:
127 ;
128 ; 80386 or later.
129 ;
130%if TMPL_BITS == 16
131 ; Load es into ds so we can save ourselves some segment prefix bytes.
132 push es
133 pop ds
134%endif
135
136 ; GPRs first.
137 mov [xDI + BS3REGCTX.rdx], sDX
138 mov [xDI + BS3REGCTX.rbx], sBX
139 mov [xDI + BS3REGCTX.rsi], sSI
140%if TMPL_BITS == 64
141 mov [xDI + BS3REGCTX.r8], r8
142 mov [xDI + BS3REGCTX.r9], r9
143 mov [xDI + BS3REGCTX.r10], r10
144 mov [xDI + BS3REGCTX.r11], r11
145 mov [xDI + BS3REGCTX.r12], r12
146 mov [xDI + BS3REGCTX.r13], r13
147 mov [xDI + BS3REGCTX.r14], r14
148 mov [xDI + BS3REGCTX.r15], r15
149%endif
150%if TMPL_BITS == 16 ; Save high bits.
151 mov [xDI + BS3REGCTX.eax], eax
152 mov [xDI + BS3REGCTX.ecx], ecx
153 mov [xDI + BS3REGCTX.edi], edi
154 mov [xDI + BS3REGCTX.ebp], ebp
155 mov [xDI + BS3REGCTX.esp], esp
156 pushfd
157 pop [xDI + BS3REGCTX.rflags]
158%endif
159
160 ; Control registers.
161 mov sAX, cr0
162 mov [xDI + BS3REGCTX.cr0], sAX
163 mov sAX, cr2
164 mov [xDI + BS3REGCTX.cr2], sAX
165 mov sAX, cr3
166 mov [xDI + BS3REGCTX.cr3], sAX
167 mov sAX, cr4
168 mov [xDI + BS3REGCTX.cr4], sAX
169 str [xDI + BS3REGCTX.tr]
170 sldt [xDI + BS3REGCTX.ldtr]
171
172 ; Segment registers.
173 mov [xDI + BS3REGCTX.fs], fs
174 mov [xDI + BS3REGCTX.gs], gs
175
176 ; Common stuff - stuff on the stack, 286 segment registers.
177.common:
178 mov xAX, [xBP - xCB]
179 mov [xDI + BS3REGCTX.rflags], xAX
180 mov xAX, [xBP - xCB*2]
181 mov [xDI + BS3REGCTX.eax], xAX
182 mov xAX, [xBP - xCB*3]
183 mov [xDI + BS3REGCTX.ecx], xAX
184 mov xAX, [xBP - xCB*4]
185 mov [xDI + BS3REGCTX.edi], xAX
186 mov xAX, [xBP]
187 mov [xDI + BS3REGCTX.ebp], xAX
188 mov xAX, [xBP + xCB]
189 mov [xDI + BS3REGCTX.rip], xAX
190 lea xAX, [xBP + xCB*2]
191 mov [xDI + BS3REGCTX.esp], xAX
192
193 mov [xDI + BS3REGCTX.cs], cs
194%if TMPL_BITS == 16
195 mov ax, [xBP - xCB*6]
196 mov [xDI + BS3REGCTX.ds], ax
197 mov ax, [xBP - xCB*5]
198 mov [xDI + BS3REGCTX.es], ax
199%else
200 mov [xDI + BS3REGCTX.ds], ds
201 mov [xDI + BS3REGCTX.es], es
202%endif
203
204 ;
205 ; Return.
206 ;
207.return:
208 BS3_ONLY_16BIT_STMT pop ds
209 BS3_ONLY_16BIT_STMT pop es
210 pop xDI
211 pop xCX
212 pop xAX
213 xPOPF
214 pop xBP
215 ret
216BS3_PROC_END_CMN Bs3RegCtxSave
217
Note: See TracBrowser for help on using the repository browser.

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