VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-Trap64Init.c

Last change on this file 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.1 KB
Line 
1/* $Id: bs3-cmn-Trap64Init.c 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3Trap64Init
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#undef Bs3Trap64Init
45BS3_CMN_DEF(void, Bs3Trap64Init,(void))
46{
47 Bs3Trap64InitEx(false);
48}
49
50#undef Bs3Trap64InitEx
51BS3_CMN_DEF(void, Bs3Trap64InitEx,(bool fMoreIstUsage))
52{
53 static const uint8_t s_aAssignments[] =
54 {
55 /* [X86_XCPT_DE] = */ 3,
56 /* [X86_XCPT_DB] = */ 2,
57 /* [X86_XCPT_NMI] = */ 0,
58 /* [X86_XCPT_BP] = */ 2,
59 /* [X86_XCPT_OF] = */ 3,
60 /* [X86_XCPT_BR] = */ 3,
61 /* [X86_XCPT_UD] = */ 4,
62 /* [X86_XCPT_NM] = */ 3,
63 /* [X86_XCPT_DF] = */ 1,
64 /* [0x09] = */ 0,
65 /* [X86_XCPT_TS] = */ 1,
66 /* [X86_XCPT_NP] = */ 5,
67 /* [X86_XCPT_SS] = */ 5,
68 /* [X86_XCPT_GP] = */ 6,
69 /* [X86_XCPT_PF] = */ 7,
70 /* [0x0f] = */ 0,
71 /* [X86_XCPT_MF] = */ 0,
72 /* [X86_XCPT_AC] = */ 3,
73 /* [X86_XCPT_MC] = */ 0,
74 /* [X86_XCPT_XF] = */ 0,
75 /* [X86_XCPT_VE] = */ 0,
76 /* [X86_XCPT_CP] = */ 6,
77 };
78#ifdef _MSC_VER /* No-SSE hack */
79 X86TSS64 BS3_FAR volatile *pTss;
80#else
81 X86TSS64 BS3_FAR *pTss;
82#endif
83 unsigned iIdt;
84
85 /*
86 * IDT entries, except the system call gate.
87 * The #DF entry get IST=1, all others IST=0.
88 */
89 for (iIdt = 0; iIdt < BS3_TRAP_SYSCALL; iIdt++)
90 Bs3Trap64SetGate(iIdt, AMD64_SEL_TYPE_SYS_INT_GATE, 0 /*bDpl*/,
91 BS3_SEL_R0_CS64, g_Bs3Trap64GenericEntriesFlatAddr + iIdt * 8,
92 !fMoreIstUsage ? iIdt == X86_XCPT_DF : iIdt < RT_ELEMENTS(s_aAssignments) ? s_aAssignments[iIdt] : 0);
93 for (iIdt = BS3_TRAP_SYSCALL + 1; iIdt < 256; iIdt++)
94 Bs3Trap64SetGate(iIdt, AMD64_SEL_TYPE_SYS_INT_GATE, 0 /*bDpl*/,
95 BS3_SEL_R0_CS64, g_Bs3Trap64GenericEntriesFlatAddr + iIdt * 8, 0);
96
97 /*
98 * Initialize the normal TSS so we can do ring transitions via the IDT.
99 */
100 pTss = &Bs3Tss64;
101 Bs3MemZero(pTss, sizeof(*pTss));
102 pTss->rsp0 = BS3_ADDR_STACK_R0;
103 pTss->rsp1 = BS3_ADDR_STACK_R1;
104 pTss->rsp2 = BS3_ADDR_STACK_R2;
105 pTss->ist1 = BS3_ADDR_STACK_R0_IST1;
106 pTss->ist2 = BS3_ADDR_STACK_R0_IST2;
107 pTss->ist3 = BS3_ADDR_STACK_R0_IST3;
108 pTss->ist4 = BS3_ADDR_STACK_R0_IST4;
109 pTss->ist5 = BS3_ADDR_STACK_R0_IST5;
110 pTss->ist6 = BS3_ADDR_STACK_R0_IST6;
111 pTss->ist7 = BS3_ADDR_STACK_R0_IST7;
112}
113
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