]> Git Repo - qemu.git/blob - target-i386/excp_helper.c
Merge remote-tracking branch 'remotes/rth/tags/pull-tile-20151030' into staging
[qemu.git] / target-i386 / excp_helper.c
1 /*
2  *  x86 exception helpers
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "cpu.h"
21 #include "qemu/log.h"
22 #include "sysemu/sysemu.h"
23 #include "exec/helper-proto.h"
24
25 void helper_raise_interrupt(CPUX86State *env, int intno, int next_eip_addend)
26 {
27     raise_interrupt(env, intno, 1, 0, next_eip_addend);
28 }
29
30 void helper_raise_exception(CPUX86State *env, int exception_index)
31 {
32     raise_exception(env, exception_index);
33 }
34
35 /*
36  * Check nested exceptions and change to double or triple fault if
37  * needed. It should only be called, if this is not an interrupt.
38  * Returns the new exception number.
39  */
40 static int check_exception(CPUX86State *env, int intno, int *error_code)
41 {
42     int first_contributory = env->old_exception == 0 ||
43                               (env->old_exception >= 10 &&
44                                env->old_exception <= 13);
45     int second_contributory = intno == 0 ||
46                                (intno >= 10 && intno <= 13);
47
48     qemu_log_mask(CPU_LOG_INT, "check_exception old: 0x%x new 0x%x\n",
49                 env->old_exception, intno);
50
51 #if !defined(CONFIG_USER_ONLY)
52     if (env->old_exception == EXCP08_DBLE) {
53         if (env->hflags & HF_SVMI_MASK) {
54             cpu_vmexit(env, SVM_EXIT_SHUTDOWN, 0); /* does not return */
55         }
56
57         qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
58
59         qemu_system_reset_request();
60         return EXCP_HLT;
61     }
62 #endif
63
64     if ((first_contributory && second_contributory)
65         || (env->old_exception == EXCP0E_PAGE &&
66             (second_contributory || (intno == EXCP0E_PAGE)))) {
67         intno = EXCP08_DBLE;
68         *error_code = 0;
69     }
70
71     if (second_contributory || (intno == EXCP0E_PAGE) ||
72         (intno == EXCP08_DBLE)) {
73         env->old_exception = intno;
74     }
75
76     return intno;
77 }
78
79 /*
80  * Signal an interruption. It is executed in the main CPU loop.
81  * is_int is TRUE if coming from the int instruction. next_eip is the
82  * env->eip value AFTER the interrupt instruction. It is only relevant if
83  * is_int is TRUE.
84  */
85 static void QEMU_NORETURN raise_interrupt2(CPUX86State *env, int intno,
86                                            int is_int, int error_code,
87                                            int next_eip_addend,
88                                            uintptr_t retaddr)
89 {
90     CPUState *cs = CPU(x86_env_get_cpu(env));
91
92     if (!is_int) {
93         cpu_svm_check_intercept_param(env, SVM_EXIT_EXCP_BASE + intno,
94                                       error_code);
95         intno = check_exception(env, intno, &error_code);
96     } else {
97         cpu_svm_check_intercept_param(env, SVM_EXIT_SWINT, 0);
98     }
99
100     cs->exception_index = intno;
101     env->error_code = error_code;
102     env->exception_is_int = is_int;
103     env->exception_next_eip = env->eip + next_eip_addend;
104     cpu_loop_exit_restore(cs, retaddr);
105 }
106
107 /* shortcuts to generate exceptions */
108
109 void QEMU_NORETURN raise_interrupt(CPUX86State *env, int intno, int is_int,
110                                    int error_code, int next_eip_addend)
111 {
112     raise_interrupt2(env, intno, is_int, error_code, next_eip_addend, 0);
113 }
114
115 void raise_exception_err(CPUX86State *env, int exception_index,
116                          int error_code)
117 {
118     raise_interrupt2(env, exception_index, 0, error_code, 0, 0);
119 }
120
121 void raise_exception_err_ra(CPUX86State *env, int exception_index,
122                             int error_code, uintptr_t retaddr)
123 {
124     raise_interrupt2(env, exception_index, 0, error_code, 0, retaddr);
125 }
126
127 void raise_exception(CPUX86State *env, int exception_index)
128 {
129     raise_interrupt2(env, exception_index, 0, 0, 0, 0);
130 }
131
132 void raise_exception_ra(CPUX86State *env, int exception_index, uintptr_t retaddr)
133 {
134     raise_interrupt2(env, exception_index, 0, 0, 0, retaddr);
135 }
This page took 0.032202 seconds and 4 git commands to generate.