VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapRmV86Init.c@ 106215

Last change on this file since 106215 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: bs3-cmn-TrapRmV86Init.c 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3TrapRmV86Init
4 */
5
6/*
7 * Copyright (C) 2007-2024 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.h"
42
43
44/*********************************************************************************************************************************
45* Global Variables *
46*********************************************************************************************************************************/
47/* We ASSUME that BS3CLASS16CODE is 64KB aligned, so the low 16-bit of the
48 flat address matches. Also, these symbols are defined both with
49 and without underscore prefixes. */
50extern BS3_DECL(void) BS3_FAR_CODE Bs3TrapRmV86GenericEntries(void);
51
52/* These two are ugly. Need data access for patching purposes. */
53extern uint8_t BS3_FAR_DATA bs3TrapRmV86GenericTrapOrInt[];
54
55/* bs3-cmn-TrapRmV86Data.c: */
56#define g_fBs3RmIvtCopied BS3_DATA_NM(g_fBs3RmIvtCopied)
57extern bool g_fBs3RmIvtCopied;
58
59
60#undef Bs3TrapRmV86InitEx
61BS3_CMN_DEF(void, Bs3TrapRmV86InitEx,(bool f386Plus))
62{
63 RTFAR16 BS3_FAR *paIvt = Bs3XptrFlatToCurrent(0);
64 unsigned iIvt;
65
66 /*
67 * Copy the real mode IVT the first time we are here.
68 */
69 if (!g_fBs3RmIvtCopied)
70 {
71 Bs3MemCpy(g_aBs3RmIvtOriginal, paIvt, sizeof(g_aBs3RmIvtOriginal));
72 g_fBs3RmIvtCopied = true;
73 }
74 /*
75 * The rest of the times, we copy back the original and modify it.
76 */
77 else
78 Bs3MemCpy(paIvt, g_aBs3RmIvtOriginal, sizeof(g_aBs3RmIvtOriginal));
79
80
81 /*
82 * If 386 or later, patch the trap handler code to not jump to the 80286
83 * code but continue with the next instruction (the 386+ code).
84 */
85 if (f386Plus)
86 {
87 uint8_t BS3_FAR_DATA *pbFunction = &bs3TrapRmV86GenericTrapOrInt[0];
88#if ARCH_BITS == 16
89 if (g_bBs3CurrentMode != BS3_MODE_RM)
90 pbFunction = (uint8_t BS3_FAR_DATA *)BS3_FP_MAKE(BS3_SEL_TILED + 1, BS3_FP_OFF(pbFunction));
91#endif
92 pbFunction[1] = 0;
93 pbFunction[2] = 0;
94 }
95
96 /*
97 * Since we want to play with V86 mode as well as 8086 and 186 CPUs, we
98 * cannot move the IVT from its default location. So, modify it in place.
99 *
100 * Note! We must keep INT 10h working, which is easy since the CPU does
101 * use it (well, it's been reserved for 30+ years).
102 * Turns out we must not hook INT 6Dh either then, as some real VGA
103 * BIOS installs their INT 10h handler there as well, and seemingly
104 * must be using it internally or something.
105 *
106 * We also keep 15h working for memory interfaces (see bs3-mode-BiosInt15*).
107 */
108 for (iIvt = 0; iIvt < 256; iIvt++)
109 if (iIvt != 0x10 && iIvt != 0x15 && iIvt != 0x6d && iIvt != BS3_TRAP_SYSCALL)
110 {
111 paIvt[iIvt].off = (uint16_t)(uintptr_t)Bs3TrapRmV86GenericEntries + iIvt * 8;
112 paIvt[iIvt].sel = BS3_SEL_TEXT16;
113 }
114}
115
116
117#undef Bs3TrapRmV86Init
118BS3_CMN_DEF(void, Bs3TrapRmV86Init,(void))
119{
120 BS3_CMN_NM(Bs3TrapRmV86InitEx)((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386);
121}
122
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