xref: /qemu/target/i386/tcg/bpt_helper.c (revision d0fb9657)
1 /*
2  *  i386 breakpoint 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.1 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 "qemu/osdep.h"
21 #include "cpu.h"
22 #include "exec/helper-proto.h"
23 #include "helper-tcg.h"
24 
25 void QEMU_NORETURN helper_single_step(CPUX86State *env)
26 {
27 #ifndef CONFIG_USER_ONLY
28     check_hw_breakpoints(env, true);
29     env->dr[6] |= DR6_BS;
30 #endif
31     raise_exception(env, EXCP01_DB);
32 }
33 
34 void helper_rechecking_single_step(CPUX86State *env)
35 {
36     if ((env->eflags & TF_MASK) != 0) {
37         helper_single_step(env);
38     }
39 }
40 
41 target_ulong helper_get_dr(CPUX86State *env, int reg)
42 {
43     switch (reg) {
44     case 0: case 1: case 2: case 3: case 6: case 7:
45         return env->dr[reg];
46     case 4:
47         if (env->cr[4] & CR4_DE_MASK) {
48             break;
49         } else {
50             return env->dr[6];
51         }
52     case 5:
53         if (env->cr[4] & CR4_DE_MASK) {
54             break;
55         } else {
56             return env->dr[7];
57         }
58     }
59     raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
60 }
61