1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
; $Id: bs3-cmn-TrapSetJmp.asm $
;; @file
; BS3Kit - Bs3TrapSetJmp.
;
;
; Copyright (C) 2007-2019 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) as published by the Free Software
; Foundation, in version 2 as it comes in the "COPYING" file of the
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
; VirtualBox OSE distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
;*********************************************************************************************************************************
;* Header Files *
;*********************************************************************************************************************************
%include "bs3kit-template-header.mac"
;*********************************************************************************************************************************
;* External Symbols *
;*********************************************************************************************************************************
BS3_EXTERN_CMN Bs3RegCtxSave
%if TMPL_BITS == 16
BS3_EXTERN_CMN_FAR Bs3SelFar32ToFlat32
%endif
BS3_EXTERN_DATA16 g_Bs3TrapSetJmpCtx
BS3_EXTERN_DATA16 g_pBs3TrapSetJmpFrame
TMPL_BEGIN_TEXT
;;
; Sets up a one-shot set-jmp-on-trap.
;
; @uses See, applicable C calling convention.
;
BS3_PROC_BEGIN_CMN Bs3TrapSetJmp, BS3_PBC_HYBRID
BS3_CALL_CONV_PROLOG 1
push xBP
mov xBP, xSP
push xBX
BONLY64 sub xSP, 20h
;
; Save the current register context.
;
BONLY16 push ds
BS3_LEA_MOV_WRT_RIP(xAX, BS3_DATA16_WRT(g_Bs3TrapSetJmpCtx))
push xAX
BS3_CALL Bs3RegCtxSave, 1
add xSP, sCB
;
; Adjust the return context a little.
;
BS3_LEA_MOV_WRT_RIP(xBX, BS3_DATA16_WRT(g_Bs3TrapSetJmpCtx))
mov xAX, [xBP + xCB] ; The return address of this function
mov [xBX + BS3REGCTX.rip], xAX
%if TMPL_BITS == 16
mov xAX, [xBP + xCB+2] ; The return address CS of this function.
mov [xBX + BS3REGCTX.cs], xAX
%endif
mov xAX, [xBP]
mov [xBX + BS3REGCTX.rbp], xAX
lea xAX, [xBP + xCB + cbCurRetAddr]
mov [xBX + BS3REGCTX.rsp], xAX
mov xAX, [xBP - xCB]
mov [xBX + BS3REGCTX.rbx], xAX
xor xAX, xAX
mov [xBX + BS3REGCTX.rax], xAX ; the return value.
;
; Fill the trap frame return structure.
;
push xDI
%if TMPL_BITS == 16
push es
les di, [xBP + xCB + cbCurRetAddr]
mov cx, BS3TRAPFRAME_size / 2
mov ax, 0faceh
rep stosw
pop es
%else
mov xDI, [xBP + xCB*2]
mov ecx, BS3TRAPFRAME_size / 4
mov xAX, 0feedfaceh
rep stosd
%endif
pop xDI
;
; Save the (flat) pointer to the trap frame return structure.
;
%if TMPL_BITS == 16
xor ax, ax
push word [xBP + xCB + cbCurRetAddr + 2]
push ax
push word [xBP + xCB + cbCurRetAddr]
push cs
call Bs3SelFar32ToFlat32
add sp, 6h
mov [BS3_DATA16_WRT(g_pBs3TrapSetJmpFrame)], ax
mov [2 + BS3_DATA16_WRT(g_pBs3TrapSetJmpFrame)], dx
%else
mov xAX, [xBP + xCB*2]
mov [BS3_DATA16_WRT(g_pBs3TrapSetJmpFrame)], eax
%endif
;
; Return 'true'.
;
mov xAX, 1
BONLY64 add xSP, 20h
pop xBX
pop xBP
BS3_CALL_CONV_EPILOG 1
BS3_HYBRID_RET
BS3_PROC_END_CMN Bs3TrapSetJmp
|