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