]>
Commit | Line | Data |
---|---|---|
f6bb84d5 EC |
1 | /* |
2 | * Copyright (C) 2017, Emilio G. Cota <cota@braap.org> | |
3 | * | |
4 | * License: GNU GPL, version 2 or later. | |
5 | * See the COPYING file in the top-level directory. | |
6 | */ | |
7 | #ifndef EXEC_TB_LOOKUP_H | |
8 | #define EXEC_TB_LOOKUP_H | |
9 | ||
f6bb84d5 EC |
10 | #ifdef NEED_CPU_H |
11 | #include "cpu.h" | |
12 | #else | |
13 | #include "exec/poison.h" | |
14 | #endif | |
15 | ||
16 | #include "exec/exec-all.h" | |
17 | #include "exec/tb-hash.h" | |
18 | ||
19 | /* Might cause an exception, so have a longjmp destination ready */ | |
20 | static inline TranslationBlock * | |
21 | tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base, | |
4e2ca83e | 22 | uint32_t *flags, uint32_t cf_mask) |
f6bb84d5 EC |
23 | { |
24 | CPUArchState *env = (CPUArchState *)cpu->env_ptr; | |
25 | TranslationBlock *tb; | |
26 | uint32_t hash; | |
27 | ||
28 | cpu_get_tb_cpu_state(env, pc, cs_base, flags); | |
29 | hash = tb_jmp_cache_hash_func(*pc); | |
30 | tb = atomic_rcu_read(&cpu->tb_jmp_cache[hash]); | |
9fd9b7de PM |
31 | |
32 | cf_mask &= ~CF_CLUSTER_MASK; | |
33 | cf_mask |= cpu->cluster_index << CF_CLUSTER_SHIFT; | |
34 | ||
f6bb84d5 EC |
35 | if (likely(tb && |
36 | tb->pc == *pc && | |
37 | tb->cs_base == *cs_base && | |
38 | tb->flags == *flags && | |
39 | tb->trace_vcpu_dstate == *cpu->trace_dstate && | |
4e2ca83e | 40 | (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == cf_mask)) { |
f6bb84d5 EC |
41 | return tb; |
42 | } | |
4e2ca83e | 43 | tb = tb_htable_lookup(cpu, *pc, *cs_base, *flags, cf_mask); |
f6bb84d5 EC |
44 | if (tb == NULL) { |
45 | return NULL; | |
46 | } | |
47 | atomic_set(&cpu->tb_jmp_cache[hash], tb); | |
48 | return tb; | |
49 | } | |
50 | ||
51 | #endif /* EXEC_TB_LOOKUP_H */ |