VirtualBox

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

Last change on this file since 60112 was 60088, checked in by vboxsync, 9 years ago

bs3kit: updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1; $Id: bs3-cmn-RegCtxSave.asm 60088 2016-03-18 00:07:33Z 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
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%if TMPL_BITS != 64
67 ;
68 ; Clear the whole structure first, unless 64-bit
69 ;
70 xor xAX, xAX
71 cld
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%endif
83
84 ;
85 ; Save the current mode.
86 ;
87 mov cl, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
88 mov [BS3_ONLY_16BIT(es:) xDI + BS3REGCTX.bMode], cl
89%if TMPL_BITS == 16
90
91 ;
92 ; In 16-bit mode we could be running on really ancient CPUs, so check
93 ; mode and detected CPU and proceed with care.
94 ;
95 cmp cl, BS3_MODE_PP16
96 jae .save_full
97
98 mov cl, [BS3_DATA16_WRT(g_uBs3CpuDetected)]
99 cmp cl, BS3CPU_80386
100 jae .save_full
101
102 ; load ES into DS so we can save some segment prefix bytes.
103 push es
104 pop ds
105
106 ; 16-bit GPRs not on the stack.
107 mov [xDI + BS3REGCTX.rdx], dx
108 mov [xDI + BS3REGCTX.rbx], bx
109 mov [xDI + BS3REGCTX.rsi], si
110
111 ; Join the common code.
112 cmp cl, BS3CPU_80286
113 jb .common_ancient
114
115 smsw [xDI + BS3REGCTX.cr0]
116 jmp .common_80286
117%endif
118
119
120.save_full:
121 ;
122 ; 80386 or later.
123 ;
124%if TMPL_BITS == 16
125 ; Load es into ds so we can save ourselves some segment prefix bytes.
126 push es
127 pop ds
128%endif
129
130 ; GPRs first.
131 mov [xDI + BS3REGCTX.rdx], sDX
132 mov [xDI + BS3REGCTX.rbx], sBX
133 mov [xDI + BS3REGCTX.rsi], sSI
134%if TMPL_BITS == 64
135 mov [xDI + BS3REGCTX.r8], r8
136 mov [xDI + BS3REGCTX.r9], r9
137 mov [xDI + BS3REGCTX.r10], r10
138 mov [xDI + BS3REGCTX.r11], r11
139 mov [xDI + BS3REGCTX.r12], r12
140 mov [xDI + BS3REGCTX.r13], r13
141 mov [xDI + BS3REGCTX.r14], r14
142 mov [xDI + BS3REGCTX.r15], r15
143%endif
144%if TMPL_BITS == 16 ; Save high bits.
145 mov [xDI + BS3REGCTX.rax], eax
146 mov [xDI + BS3REGCTX.rcx], ecx
147 mov [xDI + BS3REGCTX.rdi], edi
148 mov [xDI + BS3REGCTX.rbp], ebp
149 mov [xDI + BS3REGCTX.rsp], esp
150 pushfd
151 pop dword [xDI + BS3REGCTX.rflags]
152%endif
153
154 ; 386 segment registers.
155 mov [xDI + BS3REGCTX.fs], fs
156 mov [xDI + BS3REGCTX.gs], gs
157
158 ; Control registers.
159 mov sAX, cr0
160 mov [xDI + BS3REGCTX.cr0], sAX
161 mov sAX, cr2
162 mov [xDI + BS3REGCTX.cr2], sAX
163 mov sAX, cr3
164 mov [xDI + BS3REGCTX.cr3], sAX
165 mov sAX, cr4
166 mov [xDI + BS3REGCTX.cr4], sAX
167
168 ; 80286 control registers.
169.common_80286:
170 str [xDI + BS3REGCTX.tr]
171 sldt [xDI + BS3REGCTX.ldtr]
172
173 ; Common stuff - stuff on the stack, 286 segment registers.
174.common_ancient:
175 mov xAX, [xBP - xCB*1]
176 mov [xDI + BS3REGCTX.rflags], xAX
177 mov xAX, [xBP - xCB*2]
178 mov [xDI + BS3REGCTX.rax], xAX
179 mov xAX, [xBP - xCB*3]
180 mov [xDI + BS3REGCTX.rcx], xAX
181 mov xAX, [xBP - xCB*4]
182 mov [xDI + BS3REGCTX.rdi], xAX
183 mov xAX, [xBP]
184 mov [xDI + BS3REGCTX.rbp], xAX
185 mov xAX, [xBP + xCB]
186 mov [xDI + BS3REGCTX.rip], xAX
187 lea xAX, [xBP + xCB*2]
188 mov [xDI + BS3REGCTX.rsp], xAX
189
190 mov [xDI + BS3REGCTX.cs], cs
191%if TMPL_BITS == 16
192 mov ax, [xBP - xCB*6]
193 mov [xDI + BS3REGCTX.ds], ax
194 mov ax, [xBP - xCB*5]
195 mov [xDI + BS3REGCTX.es], ax
196%else
197 mov [xDI + BS3REGCTX.ds], ds
198 mov [xDI + BS3REGCTX.es], es
199%endif
200 mov [xDI + BS3REGCTX.ss], ss
201
202 ;
203 ; Return.
204 ;
205.return:
206 BS3_ONLY_16BIT_STMT pop ds
207 BS3_ONLY_16BIT_STMT pop es
208 pop xDI
209 pop xCX
210 pop xAX
211 xPOPF
212 pop xBP
213 ret
214BS3_PROC_END_CMN Bs3RegCtxSave
215
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