1 | ; $Id: bs3-c16-Trap16Generic.asm 59984 2016-03-11 00:56:10Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Trap, 16-bit assembly handlers.
|
---|
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 | ;*********************************************************************************************************************************
|
---|
28 | ;* Header Files *
|
---|
29 | ;*********************************************************************************************************************************
|
---|
30 | %include "bs3kit-template-header.mac"
|
---|
31 |
|
---|
32 | %ifndef TMPL_16BIT
|
---|
33 | %error "16-bit only template"
|
---|
34 | %endif
|
---|
35 |
|
---|
36 |
|
---|
37 | ;*********************************************************************************************************************************
|
---|
38 | ;* External Symbols *
|
---|
39 | ;*********************************************************************************************************************************
|
---|
40 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
41 | BS3_EXTERN_SYSTEM16 Bs3Gdt
|
---|
42 | TMPL_BEGIN_TEXT
|
---|
43 | BS3_EXTERN_CMN Bs3TrapDefaultHandler
|
---|
44 | BS3_EXTERN_CMN Bs3RegCtxRestore
|
---|
45 | TMPL_BEGIN_TEXT
|
---|
46 |
|
---|
47 |
|
---|
48 | ;*********************************************************************************************************************************
|
---|
49 | ;* Global Variables *
|
---|
50 | ;*********************************************************************************************************************************
|
---|
51 | BS3_BEGIN_DATA16
|
---|
52 | ;; Pointer C trap handlers (BS3TEXT16).
|
---|
53 | BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c16, 512
|
---|
54 | resw 256
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | ;;
|
---|
59 | ; Generic entry points for IDT handlers, 8 byte spacing.
|
---|
60 | ;
|
---|
61 | BS3_PROC_BEGIN _Bs3Trap16GenericEntries
|
---|
62 | BS3_PROC_BEGIN Bs3Trap16GenericEntries
|
---|
63 | %macro Bs3Trap16GenericEntry 1
|
---|
64 | db 06ah, i ; push imm8 - note that this is a signextended value.
|
---|
65 | hlt
|
---|
66 | jmp %1
|
---|
67 | ALIGNCODE(8)
|
---|
68 | %assign i i+1
|
---|
69 | %endmacro
|
---|
70 |
|
---|
71 | %assign i 0 ; start counter.
|
---|
72 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 0
|
---|
73 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1
|
---|
74 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 2
|
---|
75 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 3
|
---|
76 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 4
|
---|
77 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 5
|
---|
78 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 6
|
---|
79 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 7
|
---|
80 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; 8
|
---|
81 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 9
|
---|
82 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; a
|
---|
83 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; b
|
---|
84 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; c
|
---|
85 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; d
|
---|
86 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; e
|
---|
87 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; f (reserved)
|
---|
88 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 10
|
---|
89 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; 11
|
---|
90 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 12
|
---|
91 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 13
|
---|
92 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 14
|
---|
93 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 15 (reserved)
|
---|
94 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 16 (reserved)
|
---|
95 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 17 (reserved)
|
---|
96 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 18 (reserved)
|
---|
97 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 19 (reserved)
|
---|
98 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1a (reserved)
|
---|
99 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1b (reserved)
|
---|
100 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1c (reserved)
|
---|
101 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1d (reserved)
|
---|
102 | Bs3Trap16GenericEntry bs3Trap16GenericTrapErrCode ; 1e
|
---|
103 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt ; 1f (reserved)
|
---|
104 | %rep 224
|
---|
105 | Bs3Trap16GenericEntry bs3Trap16GenericTrapOrInt
|
---|
106 | %endrep
|
---|
107 | BS3_PROC_END Bs3Trap16GenericEntries
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | ;;
|
---|
113 | ; 80386+: Trap or interrupt (no error code).
|
---|
114 | ;
|
---|
115 | BS3_PROC_BEGIN _bs3Trap16GenericTrapOrInt
|
---|
116 | BS3_PROC_BEGIN bs3Trap16GenericTrapOrInt
|
---|
117 | CPU 386
|
---|
118 | jmp near bs3Trap16GenericTrapOrInt80286 ; Bs3Trap16Init adjusts this on 80386+
|
---|
119 | push ebp
|
---|
120 | mov bp, sp
|
---|
121 | push ebx
|
---|
122 | pushfd
|
---|
123 | cli
|
---|
124 | cld
|
---|
125 |
|
---|
126 | ; Reserve space for the the register and trap frame.
|
---|
127 | mov bx, (BS3TRAPFRAME_size + 7) / 8
|
---|
128 | .more_zeroed_space:
|
---|
129 | push 0
|
---|
130 | push 0
|
---|
131 | push 0
|
---|
132 | push 0
|
---|
133 | dec bx
|
---|
134 | jz .more_zeroed_space
|
---|
135 | movzx ebx, sp
|
---|
136 |
|
---|
137 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
|
---|
138 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], edx
|
---|
139 | mov edx, [bp]
|
---|
140 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], edx
|
---|
141 | mov edx, [bp - 4]
|
---|
142 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], edx
|
---|
143 |
|
---|
144 | mov edx, [bp - 8]
|
---|
145 | mov [ss:bx + BS3TRAPFRAME.fHandlerRfl], edx
|
---|
146 |
|
---|
147 | mov dl, [bp + 4]
|
---|
148 | mov [ss:bx + BS3TRAPFRAME.bXcpt], dl
|
---|
149 |
|
---|
150 | add bp, 4 ; adjust so it points to the word before the iret frame.
|
---|
151 | jmp bs3Trap16GenericCommon
|
---|
152 | BS3_PROC_END bs3Trap16GenericTrapOrInt
|
---|
153 |
|
---|
154 |
|
---|
155 | ;;
|
---|
156 | ; 80286: Trap or interrupt (no error code)
|
---|
157 | ;
|
---|
158 | BS3_PROC_BEGIN bs3Trap16GenericTrapOrInt80286
|
---|
159 | CPU 286
|
---|
160 | push bp
|
---|
161 | mov bp, sp
|
---|
162 | push bx
|
---|
163 | pushf
|
---|
164 | cli
|
---|
165 | cld
|
---|
166 |
|
---|
167 | ; Reserve space for the the register and trap frame.
|
---|
168 | mov bx, (BS3TRAPFRAME_size + 7) / 8
|
---|
169 | .more_zeroed_space:
|
---|
170 | push 0
|
---|
171 | push 0
|
---|
172 | push 0
|
---|
173 | push 0
|
---|
174 | dec bx
|
---|
175 | jz .more_zeroed_space
|
---|
176 | mov bx, sp
|
---|
177 |
|
---|
178 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], ax
|
---|
179 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], dx
|
---|
180 | mov dx, [bp]
|
---|
181 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], dx
|
---|
182 | mov dx, [bp - 2]
|
---|
183 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], dx
|
---|
184 |
|
---|
185 | mov dl, [bp - 4]
|
---|
186 | mov [ss:bx + BS3TRAPFRAME.fHandlerRfl], dl
|
---|
187 |
|
---|
188 | mov al, byte [bp + 4]
|
---|
189 | mov [ss:bx + BS3TRAPFRAME.bXcpt], al
|
---|
190 |
|
---|
191 | add bp, 4 ; adjust so it points to the word before the iret frame.
|
---|
192 | jmp bs3Trap16GenericCommon
|
---|
193 | BS3_PROC_END bs3Trap16GenericTrapOrInt80286
|
---|
194 |
|
---|
195 |
|
---|
196 | ;;
|
---|
197 | ; Trap with error code.
|
---|
198 | ;
|
---|
199 | BS3_PROC_BEGIN _bs3Trap16GenericTrapErrCode
|
---|
200 | BS3_PROC_BEGIN bs3Trap16GenericTrapErrCode
|
---|
201 | CPU 386
|
---|
202 | jmp near bs3Trap16GenericTrapOrInt80286 ; Bs3Trap16Init adjusts this on 80386+
|
---|
203 | push ebp
|
---|
204 | mov bp, sp
|
---|
205 | push ebx
|
---|
206 | pushfd
|
---|
207 | cli
|
---|
208 | cld
|
---|
209 |
|
---|
210 | ; Reserve space for the the register and trap frame.
|
---|
211 | mov bx, (BS3TRAPFRAME_size + 7) / 8
|
---|
212 | .more_zeroed_space:
|
---|
213 | push 0
|
---|
214 | push 0
|
---|
215 | push 0
|
---|
216 | push 0
|
---|
217 | dec bx
|
---|
218 | jz .more_zeroed_space
|
---|
219 | movzx ebx, sp
|
---|
220 |
|
---|
221 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
|
---|
222 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], edx
|
---|
223 | mov edx, [bp]
|
---|
224 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], edx
|
---|
225 | mov edx, [bp - 4]
|
---|
226 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], ebx
|
---|
227 |
|
---|
228 | mov edx, [bp - 8]
|
---|
229 | mov [ss:bx + BS3TRAPFRAME.fHandlerRfl], edx
|
---|
230 |
|
---|
231 | mov dl, [bp + 4]
|
---|
232 | mov [ss:bx + BS3TRAPFRAME.bXcpt], dl
|
---|
233 |
|
---|
234 | mov dx, [bp + 6]
|
---|
235 | ;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
|
---|
236 | mov [ss:bx + BS3TRAPFRAME.uErrCd], dx
|
---|
237 |
|
---|
238 | add bp, 6 ; adjust so it points to the word before the iret frame.
|
---|
239 | jmp bs3Trap16GenericCommon
|
---|
240 | BS3_PROC_END bs3Trap16GenericTrapErrCode
|
---|
241 |
|
---|
242 | ;;
|
---|
243 | ; Trap with error code - 80286 code variant.
|
---|
244 | ;
|
---|
245 | BS3_PROC_BEGIN bs3Trap16GenericTrapErrCode80286
|
---|
246 | CPU 286
|
---|
247 | push bp
|
---|
248 | mov bp, sp
|
---|
249 | push bx
|
---|
250 | pushf
|
---|
251 | cli
|
---|
252 | cld
|
---|
253 |
|
---|
254 | ; Reserve space for the the register and trap frame.
|
---|
255 | mov bx, (BS3TRAPFRAME_size + 7) / 8
|
---|
256 | .more_zeroed_space:
|
---|
257 | push 0
|
---|
258 | push 0
|
---|
259 | push 0
|
---|
260 | push 0
|
---|
261 | dec bx
|
---|
262 | jz .more_zeroed_space
|
---|
263 | mov bx, sp
|
---|
264 |
|
---|
265 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], ax
|
---|
266 | mov [bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], dx
|
---|
267 | mov dx, [bp]
|
---|
268 | mov [bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], dx
|
---|
269 | mov dx, [bp - 2]
|
---|
270 | mov [bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], bx
|
---|
271 |
|
---|
272 | mov dx, [bp - 4]
|
---|
273 | mov [bx + BS3TRAPFRAME.fHandlerRfl], dx
|
---|
274 |
|
---|
275 | mov dl, [bp + 2]
|
---|
276 | mov [bx + BS3TRAPFRAME.bXcpt], dl
|
---|
277 |
|
---|
278 | mov dx, [bp + 4]
|
---|
279 | ;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
|
---|
280 | mov [ss:bx + BS3TRAPFRAME.uErrCd], dx
|
---|
281 |
|
---|
282 | add bp, 4 ; adjust so it points to the word before the iret frame.
|
---|
283 | jmp bs3Trap16GenericCommon
|
---|
284 | BS3_PROC_END bs3Trap16GenericTrapErrCode80286
|
---|
285 |
|
---|
286 |
|
---|
287 | ;;
|
---|
288 | ; Common context saving code and dispatching.
|
---|
289 | ;
|
---|
290 | ; @param bx Pointer to the trap frame. The following members have been
|
---|
291 | ; filled in by the previous code:
|
---|
292 | ; - bXcpt
|
---|
293 | ; - uErrCd
|
---|
294 | ; - fHandlerRFL
|
---|
295 | ; - Ctx.eax (except upper stuff)
|
---|
296 | ; - Ctx.edx (except upper stuff)
|
---|
297 | ; - Ctx.ebx (except upper stuff)
|
---|
298 | ; - Ctx.ebp (except upper stuff)
|
---|
299 | ; - All other bytes are zeroed.
|
---|
300 | ;
|
---|
301 | ; @param bp Pointer to the word before the iret frame, i.e. where bp
|
---|
302 | ; would be saved if this was a normal near call.
|
---|
303 | ; @param dx zero (0) if 286, set (1) if 386
|
---|
304 | ;
|
---|
305 | BS3_PROC_BEGIN bs3Trap16GenericCommon
|
---|
306 | CPU 286
|
---|
307 | ;
|
---|
308 | ; Fake EBP frame.
|
---|
309 | ;
|
---|
310 | mov ax, [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
|
---|
311 | mov [bp], ax
|
---|
312 |
|
---|
313 | ;
|
---|
314 | ; Save the remaining GPRs and segment registers.
|
---|
315 | ;
|
---|
316 | test dx, dx
|
---|
317 | jz .save_word_grps
|
---|
318 | CPU 386
|
---|
319 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], ecx
|
---|
320 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], edi
|
---|
321 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], esi
|
---|
322 | jmp .save_segment_registers
|
---|
323 | .save_word_grps:
|
---|
324 | CPU 286
|
---|
325 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], cx
|
---|
326 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], di
|
---|
327 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], si
|
---|
328 | .save_segment_registers:
|
---|
329 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], ds
|
---|
330 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.es], es
|
---|
331 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], fs
|
---|
332 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], gs
|
---|
333 |
|
---|
334 | ;
|
---|
335 | ; Load 16-bit data selector for the DPL we're executing at into DS and ES.
|
---|
336 | ; Save the handler SS and CS values first.
|
---|
337 | ;
|
---|
338 | mov ax, cs
|
---|
339 | mov [ss:bx + BS3TRAPFRAME.uHandlerCs], ax
|
---|
340 | mov ax, ss
|
---|
341 | mov [ss:bx + BS3TRAPFRAME.uHandlerSs], ax
|
---|
342 | and ax, 3
|
---|
343 | mov cx, ax
|
---|
344 | shl ax, BS3_SEL_RING_SHIFT
|
---|
345 | or ax, cx
|
---|
346 | add ax, BS3_SEL_R0_DS32
|
---|
347 | mov ds, ax
|
---|
348 | mov es, ax
|
---|
349 |
|
---|
350 | ;
|
---|
351 | ; Copy and update the mode now that we've got a flat DS.
|
---|
352 | ;
|
---|
353 | mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
|
---|
354 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], al
|
---|
355 | and al, ~BS3_MODE_CODE_MASK
|
---|
356 | or al, BS3_MODE_CODE_32
|
---|
357 | mov [BS3_DATA16_WRT(g_bBs3CurrentMode)], al
|
---|
358 |
|
---|
359 | ;
|
---|
360 | ; Copy iret info.
|
---|
361 | ;
|
---|
362 | mov cx, [bp + 2]
|
---|
363 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], cx
|
---|
364 | mov cx, [bp + 6]
|
---|
365 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], cx
|
---|
366 | mov cx, [bp + 4]
|
---|
367 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx
|
---|
368 |
|
---|
369 | mov al, [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode]
|
---|
370 | and al, BS3_MODE_CODE_MASK
|
---|
371 | cmp al, BS3_MODE_CODE_V86
|
---|
372 | je .iret_frame_v8086
|
---|
373 |
|
---|
374 | mov ax, ss
|
---|
375 | and al, 3
|
---|
376 | and cl, 3
|
---|
377 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl
|
---|
378 | cmp cl, al
|
---|
379 | je .iret_frame_same_cpl
|
---|
380 |
|
---|
381 | .ret_frame_different_cpl:
|
---|
382 | mov cx, [bp + 10]
|
---|
383 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
|
---|
384 | test dx, dx
|
---|
385 | jz .ret_frame_different_cpl_286
|
---|
386 | .ret_frame_different_cpl_386:
|
---|
387 | CPU 386
|
---|
388 | mov ecx, esp
|
---|
389 | mov cx, [bp + 8]
|
---|
390 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
|
---|
391 | lea eax, [ebp + 12]
|
---|
392 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], eax
|
---|
393 | jmp .iret_frame_done
|
---|
394 | .ret_frame_different_cpl_286:
|
---|
395 | CPU 286
|
---|
396 | mov cx, [bp + 8]
|
---|
397 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], cx
|
---|
398 | lea ax, [bp + 12]
|
---|
399 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], ax
|
---|
400 | jmp .iret_frame_done
|
---|
401 |
|
---|
402 | .iret_frame_same_cpl:
|
---|
403 | mov cx, ss
|
---|
404 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
|
---|
405 | test dx, dx
|
---|
406 | jz .iret_frame_same_cpl_286
|
---|
407 | .iret_frame_same_cpl_386:
|
---|
408 | CPU 386
|
---|
409 | mov ecx, esp
|
---|
410 | lea cx, [bp + 8]
|
---|
411 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
|
---|
412 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], ecx
|
---|
413 | jmp .iret_frame_done
|
---|
414 | .iret_frame_same_cpl_286:
|
---|
415 | CPU 286
|
---|
416 | lea cx, [bp + 8]
|
---|
417 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], cx
|
---|
418 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], cx
|
---|
419 | jmp .iret_frame_done
|
---|
420 |
|
---|
421 | .iret_frame_v8086:
|
---|
422 | CPU 386
|
---|
423 | mov byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], 3
|
---|
424 | or byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], BS3_MODE_CODE_V86 ; paranoia ^ 2
|
---|
425 | movzx ecx, word [ebp + 16]
|
---|
426 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
|
---|
427 | mov cx, [ebp + 20]
|
---|
428 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
|
---|
429 | mov cx, [ebp + 24]
|
---|
430 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.es], cx
|
---|
431 | mov cx, [ebp + 28]
|
---|
432 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], cx
|
---|
433 | mov cx, [ebp + 32]
|
---|
434 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], cx
|
---|
435 | mov cx, [ebp + 36]
|
---|
436 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], cx
|
---|
437 | lea eax, [ebp + 40]
|
---|
438 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], eax
|
---|
439 | jmp .iret_frame_done
|
---|
440 |
|
---|
441 | .iret_frame_done:
|
---|
442 | ;
|
---|
443 | ; Control registers.
|
---|
444 | ;
|
---|
445 | str [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr]
|
---|
446 | sldt [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr]
|
---|
447 | test dx, dx
|
---|
448 | jz .save_286_control_registers
|
---|
449 | .save_386_control_registers:
|
---|
450 | CPU 386
|
---|
451 | mov eax, cr0
|
---|
452 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], eax
|
---|
453 | mov eax, cr2
|
---|
454 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], eax
|
---|
455 | mov eax, cr3
|
---|
456 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], eax
|
---|
457 | mov eax, cr4
|
---|
458 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], eax
|
---|
459 | jmp .dispatch_to_handler
|
---|
460 | CPU 286
|
---|
461 | .save_286_control_registers:
|
---|
462 | smsw [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0]
|
---|
463 |
|
---|
464 | ;
|
---|
465 | ; Dispatch it to C code.
|
---|
466 | ;
|
---|
467 | .dispatch_to_handler: ; The double fault code joins us here.
|
---|
468 | mov di, bx
|
---|
469 | mov bl, byte [ss:bx + BS3TRAPFRAME.bXcpt]
|
---|
470 | mov bh, 0
|
---|
471 | shl bx, 1
|
---|
472 | mov bx, [bx + BS3_DATA16_WRT(_g_apfnBs3TrapHandlers_c16)]
|
---|
473 | or bx, bx
|
---|
474 | jnz .call_handler
|
---|
475 | mov bx, Bs3TrapDefaultHandler
|
---|
476 | .call_handler:
|
---|
477 | push ss
|
---|
478 | push di
|
---|
479 | call bx
|
---|
480 |
|
---|
481 | ;
|
---|
482 | ; Resume execution using trap frame.
|
---|
483 | ;
|
---|
484 | push 0
|
---|
485 | push ss
|
---|
486 | add di, BS3TRAPFRAME.Ctx
|
---|
487 | push di
|
---|
488 | call Bs3RegCtxRestore
|
---|
489 | .panic:
|
---|
490 | hlt
|
---|
491 | jmp .panic
|
---|
492 | BS3_PROC_END bs3Trap16GenericCommon
|
---|
493 |
|
---|
494 |
|
---|
495 | ;;
|
---|
496 | ; Helper.
|
---|
497 | ;
|
---|
498 | ; @retruns Flat address in es:di.
|
---|
499 | ; @param di
|
---|
500 | ; @uses eax
|
---|
501 | ;
|
---|
502 | bs3Trap16TssInDiToFar1616InEsDi:
|
---|
503 | CPU 286
|
---|
504 | push ax
|
---|
505 |
|
---|
506 | ; ASSUME Bs3Gdt is being used.
|
---|
507 | push BS3_SEL_SYSTEM16
|
---|
508 | pop es
|
---|
509 | and di, 0fff8h
|
---|
510 | add di, Bs3Gdt wrt BS3SYSTEM16
|
---|
511 |
|
---|
512 | ; Load the TSS base into ax:di (di is low, ax high)
|
---|
513 | mov al, [es:di + (X86DESCGENERIC_BIT_OFF_BASE_HIGH1 / 8)]
|
---|
514 | mov ah, [es:di + (X86DESCGENERIC_BIT_OFF_BASE_HIGH2 / 8)]
|
---|
515 | mov di, [es:di + (X86DESCGENERIC_BIT_OFF_BASE_LOW / 8)]
|
---|
516 |
|
---|
517 | ; Convert ax to tiled selector, if not within the tiling area we read
|
---|
518 | ; random BS3SYSTEM16 bits as that's preferable to #GP'ing.
|
---|
519 | shl ax, X86_SEL_SHIFT
|
---|
520 | cmp ax, BS3_SEL_TILED_LAST - BS3_SEL_TILED
|
---|
521 | %ifdef BS3_STRICT
|
---|
522 | jbe .tiled
|
---|
523 | int3
|
---|
524 | %endif
|
---|
525 | ja .return ; don't crash again.
|
---|
526 | .tiled:
|
---|
527 | add ax, BS3_SEL_TILED
|
---|
528 | mov es, ax
|
---|
529 | .return:
|
---|
530 | pop ax
|
---|
531 | ret
|
---|
532 |
|
---|
533 |
|
---|
534 | ;;
|
---|
535 | ; Double fault handler.
|
---|
536 | ;
|
---|
537 | ; We don't have to load any selectors or clear anything in EFLAGS because the
|
---|
538 | ; TSS specified sane values which got loaded during the task switch.
|
---|
539 | ;
|
---|
540 | ; @param dx Zero (1) (for 386+).
|
---|
541 | ;
|
---|
542 | BS3_PROC_BEGIN _Bs3Trap16DoubleFaultHandler80386
|
---|
543 | BS3_PROC_BEGIN Bs3Trap16DoubleFaultHandler80386
|
---|
544 | CPU 386
|
---|
545 | push 0 ; We'll copy the rip from the other TSS here later to create a more sensible call chain.
|
---|
546 | push ebp
|
---|
547 | mov bp, sp
|
---|
548 | pushfd ; Handler flags.
|
---|
549 |
|
---|
550 | ; Reserve space for the the register and trap frame.
|
---|
551 | mov bx, (BS3TRAPFRAME_size + 15) / 16
|
---|
552 | .more_zeroed_space:
|
---|
553 | push dword 0
|
---|
554 | push dword 0
|
---|
555 | push dword 0
|
---|
556 | push dword 0
|
---|
557 | dec bx
|
---|
558 | jz .more_zeroed_space
|
---|
559 | mov bx, sp
|
---|
560 |
|
---|
561 | ;
|
---|
562 | ; Fill in the high GRP register words before we mess them up.
|
---|
563 | ;
|
---|
564 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
|
---|
565 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], ebx
|
---|
566 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], ecx
|
---|
567 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], edx
|
---|
568 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], esi
|
---|
569 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], edi
|
---|
570 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], ebp
|
---|
571 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], esp
|
---|
572 |
|
---|
573 | ;
|
---|
574 | ; FS and GS are not part of the 16-bit TSS because they are 386+ specfic.
|
---|
575 | ;
|
---|
576 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], fs
|
---|
577 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], gs
|
---|
578 |
|
---|
579 | ;
|
---|
580 | ; Fill in the non-context trap frame bits.
|
---|
581 | ;
|
---|
582 | mov ecx, [bp - 4]
|
---|
583 | mov [ss:bx + BS3TRAPFRAME.fHandlerRfl], ecx
|
---|
584 | mov byte [ss:bx + BS3TRAPFRAME.bXcpt], X86_XCPT_DF
|
---|
585 | mov [ss:bx + BS3TRAPFRAME.uHandlerCs], cs
|
---|
586 | mov [ss:bx + BS3TRAPFRAME.uHandlerSs], ss
|
---|
587 | mov ecx, esp
|
---|
588 | lea cx, [bp + 8]
|
---|
589 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], ecx
|
---|
590 | mov cx, [bp + 6]
|
---|
591 | mov [ss:bx + BS3TRAPFRAME.uErrCd], cx
|
---|
592 |
|
---|
593 | ;
|
---|
594 | ; Copy 80386+ control registers.
|
---|
595 | ;
|
---|
596 | mov ecx, cr0
|
---|
597 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], ecx
|
---|
598 | mov ecx, cr2
|
---|
599 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], ecx
|
---|
600 | mov ecx, cr3
|
---|
601 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], ecx
|
---|
602 | mov ecx, cr4
|
---|
603 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], ecx
|
---|
604 |
|
---|
605 | ;
|
---|
606 | ; Copy the register state from the previous task segment.
|
---|
607 | ; The 80286 code with join us here.
|
---|
608 | ;
|
---|
609 | .common:
|
---|
610 | CPU 286
|
---|
611 | ; Find our TSS.
|
---|
612 | str di
|
---|
613 | call bs3Trap16TssInDiToFar1616InEsDi
|
---|
614 |
|
---|
615 | ; Find the previous TSS.
|
---|
616 | mov di, [es:di + X86TSS32.selPrev]
|
---|
617 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr], ax
|
---|
618 | call bs3Trap16TssInDiToFar1616InEsDi
|
---|
619 |
|
---|
620 | ; Do the copying.
|
---|
621 | mov cx, [es:di + X86TSS16.ax]
|
---|
622 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], cx
|
---|
623 | mov cx, [es:di + X86TSS16.cx]
|
---|
624 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], cx
|
---|
625 | mov cx, [es:di + X86TSS16.dx]
|
---|
626 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], cx
|
---|
627 | mov cx, [es:di + X86TSS16.bx]
|
---|
628 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], cx
|
---|
629 | mov cx, [es:di + X86TSS16.sp]
|
---|
630 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], cx
|
---|
631 | mov cx, [es:di + X86TSS16.bp]
|
---|
632 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], cx
|
---|
633 | mov [bp], cx ; For better call stacks.
|
---|
634 | mov cx, [es:di + X86TSS16.si]
|
---|
635 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], cx
|
---|
636 | mov cx, [es:di + X86TSS16.di]
|
---|
637 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], cx
|
---|
638 | mov cx, [es:di + X86TSS16.si]
|
---|
639 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], cx
|
---|
640 | mov cx, [es:di + X86TSS16.flags]
|
---|
641 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], cx
|
---|
642 | mov cx, [es:di + X86TSS16.ip]
|
---|
643 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], cx
|
---|
644 | mov [ebp + 2], cx ; For better call stacks.
|
---|
645 | mov cx, [eax + X86TSS16.cs]
|
---|
646 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx
|
---|
647 | mov cx, [eax + X86TSS16.ds]
|
---|
648 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], cx
|
---|
649 | mov cx, [eax + X86TSS16.es]
|
---|
650 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.es], cx
|
---|
651 | mov cx, [eax + X86TSS16.ss]
|
---|
652 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
|
---|
653 | mov cx, [eax + X86TSS16.selLdt] ; Note! This isn't necessarily the ldtr at the time of the fault.
|
---|
654 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr], cx
|
---|
655 |
|
---|
656 | ;
|
---|
657 | ; Set CPL; copy and update mode.
|
---|
658 | ;
|
---|
659 | mov cl, [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
|
---|
660 | and cl, 3
|
---|
661 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl
|
---|
662 |
|
---|
663 | mov cl, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
|
---|
664 | mov [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], cl
|
---|
665 | and cl, ~BS3_MODE_CODE_MASK
|
---|
666 | or cl, BS3_MODE_CODE_32
|
---|
667 | mov [BS3_DATA16_WRT(g_bBs3CurrentMode)], cl
|
---|
668 |
|
---|
669 | ;
|
---|
670 | ; Join code paths with the generic handler code.
|
---|
671 | ;
|
---|
672 | jmp bs3Trap16GenericCommon.dispatch_to_handler
|
---|
673 | BS3_PROC_END Bs3Trap16DoubleFaultHandler
|
---|
674 |
|
---|
675 |
|
---|
676 | ;;
|
---|
677 | ; Double fault handler.
|
---|
678 | ;
|
---|
679 | ; We don't have to load any selectors or clear anything in EFLAGS because the
|
---|
680 | ; TSS specified sane values which got loaded during the task switch.
|
---|
681 | ;
|
---|
682 | ; @param dx Zero (0) (for 286).
|
---|
683 | ;
|
---|
684 | BS3_PROC_BEGIN _Bs3Trap16DoubleFaultHandler80286
|
---|
685 | BS3_PROC_BEGIN Bs3Trap16DoubleFaultHandler80286
|
---|
686 | CPU 286
|
---|
687 | push 0 ; We'll copy the rip from the other TSS here later to create a more sensible call chain.
|
---|
688 | push bp
|
---|
689 | mov bp, sp
|
---|
690 | pushf ; Handler flags.
|
---|
691 |
|
---|
692 | ; Reserve space for the the register and trap frame.
|
---|
693 | mov bx, (BS3TRAPFRAME_size + 7) / 8
|
---|
694 | .more_zeroed_space:
|
---|
695 | push 0
|
---|
696 | push 0
|
---|
697 | push 0
|
---|
698 | push 0
|
---|
699 | dec bx
|
---|
700 | jz .more_zeroed_space
|
---|
701 | mov bx, sp
|
---|
702 |
|
---|
703 | ;
|
---|
704 | ; Fill in the non-context trap frame bits.
|
---|
705 | ;
|
---|
706 | mov cx, [bp - 2]
|
---|
707 | mov [ss:bx + BS3TRAPFRAME.fHandlerRfl], cx
|
---|
708 | mov byte [ss:bx + BS3TRAPFRAME.bXcpt], X86_XCPT_DF
|
---|
709 | mov [ss:bx + BS3TRAPFRAME.uHandlerCs], cs
|
---|
710 | mov [ss:bx + BS3TRAPFRAME.uHandlerSs], ss
|
---|
711 | lea cx, [bp + 8]
|
---|
712 | mov [ss:bx + BS3TRAPFRAME.uHandlerRsp], cx
|
---|
713 | mov cx, [bp + 6]
|
---|
714 | mov [ss:bx + BS3TRAPFRAME.uErrCd], cx
|
---|
715 |
|
---|
716 | ;
|
---|
717 | ; Copy 80286 specific control register.
|
---|
718 | ;
|
---|
719 | smsw [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0]
|
---|
720 |
|
---|
721 | jmp Bs3Trap16DoubleFaultHandler80386.common
|
---|
722 | BS3_PROC_END Bs3Trap16DoubleFaultHandler80286
|
---|
723 |
|
---|
724 |
|
---|