1 | ; $Id: bootsector2-common-traprec.mac 64529 2016-11-03 14:01:30Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Boot sector 2 - Trap Records.
|
---|
4 | ;
|
---|
5 | ; @note Don't forget to cinldue bootsector2-common-traprec-end.mac!
|
---|
6 | ;
|
---|
7 |
|
---|
8 | ;
|
---|
9 | ; Copyright (C) 2007-2016 Oracle Corporation
|
---|
10 | ;
|
---|
11 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
13 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | ; General Public License (GPL) as published by the Free Software
|
---|
15 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | ;
|
---|
19 | ; The contents of this file may alternatively be used under the terms
|
---|
20 | ; of the Common Development and Distribution License Version 1.0
|
---|
21 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
22 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
23 | ; CDDL are applicable instead of those of the GPL.
|
---|
24 | ;
|
---|
25 | ; You may elect to license modified versions of this file under the
|
---|
26 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
27 | ;
|
---|
28 |
|
---|
29 | %ifndef ___bootsector2_common_traprec_mac___
|
---|
30 | %define ___bootsector2_common_traprec_mac___
|
---|
31 |
|
---|
32 |
|
---|
33 | ;*******************************************************************************
|
---|
34 | ;* Header Files *
|
---|
35 | ;*******************************************************************************
|
---|
36 | %include "iprt/x86.mac"
|
---|
37 |
|
---|
38 |
|
---|
39 | ;*******************************************************************************
|
---|
40 | ;* Defined Constants And Macros *
|
---|
41 | ;*******************************************************************************
|
---|
42 | ;;
|
---|
43 | ; The base address for the records (only important for 64-bit code
|
---|
44 | ; loaded above 4GB).
|
---|
45 | ; We use 0 by default so we don't create too complex expressions for YASM.
|
---|
46 | %ifndef BS2_TRAP_RECS_BASE
|
---|
47 | %define BS2_TRAP_RECS_BASE 0
|
---|
48 | %endif
|
---|
49 |
|
---|
50 | ;;
|
---|
51 | ; Macro to emit an trapping instruction.
|
---|
52 | ;
|
---|
53 | ; @param 1 The trap number (X86_XCPT_XXX).
|
---|
54 | ; @param 2 The error code, 0 if none.
|
---|
55 | ; @param 3+ The instruction.
|
---|
56 | ;
|
---|
57 | ; @sa BS2_TRAP_BRANCH_INSTR
|
---|
58 | ;
|
---|
59 | %macro BS2_TRAP_INSTR 3+,
|
---|
60 | [section .traprecs]
|
---|
61 | istruc BS2TRAPREC
|
---|
62 | at BS2TRAPREC.offWhere, dd (%%trapinstr - BS2_TRAP_RECS_BASE)
|
---|
63 | at BS2TRAPREC.offResumeAddend, db (%%resume - %%trapinstr)
|
---|
64 | at BS2TRAPREC.u8TrapNo, db %1
|
---|
65 | at BS2TRAPREC.u16ErrCd, dw %2
|
---|
66 | iend
|
---|
67 | __SECT__
|
---|
68 | %if %1 != X86_XCPT_BP
|
---|
69 | %%trapinstr:
|
---|
70 | %3
|
---|
71 | %else
|
---|
72 | %3
|
---|
73 | %%trapinstr:
|
---|
74 | %endif
|
---|
75 | call TMPL_NM_CMN(TestFailedMissingTrap_ %+ %1)
|
---|
76 | %%resume:
|
---|
77 | %endmacro
|
---|
78 |
|
---|
79 | ;;
|
---|
80 | ; Macro to emit an trapping instruction.
|
---|
81 | ;
|
---|
82 | ; @param 1 The trap number (X86_XCPT_XXX).
|
---|
83 | ; @param 2 The error code, 0 if none.
|
---|
84 | ; @param 3 The name of the branch label.
|
---|
85 | ; @param 4+ The instruction.
|
---|
86 | ;
|
---|
87 | %macro BS2_TRAP_BRANCH_INSTR 4+,
|
---|
88 | [section .traprecs]
|
---|
89 | istruc BS2TRAPREC
|
---|
90 | at BS2TRAPREC.offWhere, dd (%%trapinstr - BS2_TRAP_RECS_BASE)
|
---|
91 | at BS2TRAPREC.offResumeAddend, db (%%resume - %%trapinstr)
|
---|
92 | at BS2TRAPREC.u8TrapNo, db %1
|
---|
93 | at BS2TRAPREC.u16ErrCd, dw %2
|
---|
94 | iend
|
---|
95 | __SECT__
|
---|
96 | %%trapinstr:
|
---|
97 | %4
|
---|
98 | %3:
|
---|
99 | call TMPL_NM_CMN(TestFailedMissingTrap_ %+ %1)
|
---|
100 | %%resume:
|
---|
101 | %endmacro
|
---|
102 |
|
---|
103 | ;;
|
---|
104 | ; Sets up the trap records section.
|
---|
105 | ; @internal
|
---|
106 | %macro BS2_TRAP_RECS_BEGIN 0,
|
---|
107 | [section .traprecs] ; Declared in bootsector2-common-init-code.mac
|
---|
108 | dq 0ffffffffeeeeeeeeh
|
---|
109 | g_aTrapRecs:
|
---|
110 | __SECT__
|
---|
111 | %endmacro
|
---|
112 |
|
---|
113 | ;;
|
---|
114 | ; Terminates the trap records section.
|
---|
115 | ; @internal
|
---|
116 | %macro BS2_TRAP_RECS_END 0,
|
---|
117 | [section .traprecs]
|
---|
118 | g_aTrapRecsEnd:
|
---|
119 | dq 0ddddddddcccccccch
|
---|
120 | __SECT__
|
---|
121 | %endmacro
|
---|
122 |
|
---|
123 |
|
---|
124 | ;;
|
---|
125 | ; Macro for installing the trap records.
|
---|
126 | ;
|
---|
127 | ; This must be invoked prior to the traps.
|
---|
128 | ;
|
---|
129 | ; @uses Stack
|
---|
130 | ;
|
---|
131 | %macro BS2_TRAP_RECS_INSTALL 0,
|
---|
132 | push sAX
|
---|
133 | push sDX
|
---|
134 | push sCX
|
---|
135 |
|
---|
136 | mov sAX, NAME(g_aTrapRecs)
|
---|
137 | mov edx, NAME(g_aTrapRecsEnd) - NAME(g_aTrapRecs)
|
---|
138 | shr edx, BS2TRAPREC_SIZE_SHIFT
|
---|
139 | mov sCX, BS2_TRAP_RECS_BASE
|
---|
140 | call TMPL_NM_CMN(TestInstallTrapRecs)
|
---|
141 |
|
---|
142 | pop sAX
|
---|
143 | pop sDX
|
---|
144 | pop sCX
|
---|
145 | %endmacro
|
---|
146 |
|
---|
147 |
|
---|
148 | ;;
|
---|
149 | ; Macro for uninstalling the trap records.
|
---|
150 | ;
|
---|
151 | ; @uses Stack
|
---|
152 | ;
|
---|
153 | %macro BS2_TRAP_RECS_UNINSTALL 0,
|
---|
154 | push sAX
|
---|
155 | push sDX
|
---|
156 | push sCX
|
---|
157 |
|
---|
158 | xor sAX, sAX
|
---|
159 | xor edx, edx
|
---|
160 | xor sCX, sCX
|
---|
161 | call TMPL_NM_CMN(TestInstallTrapRecs)
|
---|
162 |
|
---|
163 | pop sAX
|
---|
164 | pop sDX
|
---|
165 | pop sCX
|
---|
166 | %endmacro
|
---|
167 |
|
---|
168 |
|
---|
169 | ;
|
---|
170 | ; Setup the trap record segment.
|
---|
171 | ;
|
---|
172 | BS2_TRAP_RECS_BEGIN
|
---|
173 | BEGINCODELOW
|
---|
174 |
|
---|
175 |
|
---|
176 | ;
|
---|
177 | ; Instantiate code templates.
|
---|
178 | ;
|
---|
179 | %ifdef BS2_INC_CMN_R86
|
---|
180 | %define TMPL_RM
|
---|
181 | %include "bootsector2-common-traprec-template.mac"
|
---|
182 | %endif
|
---|
183 | %ifdef BS2_INC_CMN_P16
|
---|
184 | %define TMPL_PE16
|
---|
185 | %include "bootsector2-common-traprec-template.mac"
|
---|
186 | %endif
|
---|
187 | %ifdef BS2_INC_CMN_P32
|
---|
188 | %define TMPL_PE32
|
---|
189 | %include "bootsector2-common-traprec-template.mac"
|
---|
190 | %endif
|
---|
191 | %ifdef BS2_INC_LM64
|
---|
192 | %define TMPL_LM64
|
---|
193 | %include "bootsector2-common-traprec-template.mac"
|
---|
194 | %endif
|
---|
195 |
|
---|
196 | BEGINCODELOW
|
---|
197 |
|
---|
198 | %endif
|
---|
199 |
|
---|