~ubuntu-branches/ubuntu/vivid/qemu/vivid

« back to all changes in this revision

Viewing changes to cputlb.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-25 22:31:43 UTC
  • mfrom: (1.8.5)
  • Revision ID: package-import@ubuntu.com-20140225223143-odhqxfc60wxrjl15
Tags: 2.0.0~rc1+dfsg-0ubuntu1
* Merge 2.0.0-rc1
* debian/rules: consolidate ppc filter entries.
* Move qemu-system-arch64 into qemu-system-arm
* debian/patches/define-trusty-machine-type.patch: define a trusty machine
  type, currently the same as pc-i440fx-2.0, to put is in a better position
  to enable live migrations from trusty onward.  (LP: #1294823)
* debian/control: build-dep on libfdt >= 1.4.0  (LP: #1295072)
* Merge latest upstream git to commit dc9528f
* Debian/rules:
  - remove -enable-uname-release=2.6.32
  - don't make the aarch64 target Ubuntu-specific.
* Remove patches which are now upstream:
  - fix-smb-security-share.patch
  - slirp-smb-redirect-port-445-too.patch 
  - linux-user-Implement-sendmmsg-syscall.patch (better version is upstream)
  - signal-added-a-wrapper-for-sigprocmask-function.patch
  - ubuntu/signal-sigsegv-protection-on-do_sigprocmask.patch
  - ubuntu/Don-t-block-SIGSEGV-at-more-places.patch
  - ubuntu/ppc-force-cpu-threads-count-to-be-power-of-2.patch
* add link for /usr/share/qemu/bios-256k.bin
* Remove all linaro patches.
* Remove all arm64/ patches.  Many but not all are upstream.
* Remove CVE-2013-4377.patch which is upstream.
* debian/control-in: don't make qemu-system-aarch64 ubuntu-specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "exec/cputlb.h"
27
27
 
28
28
#include "exec/memory-internal.h"
 
29
#include "exec/ram_addr.h"
29
30
 
30
31
//#define DEBUG_TLB
31
32
//#define DEBUG_TLB_CHECK
33
34
/* statistics */
34
35
int tlb_flush_count;
35
36
 
36
 
static const CPUTLBEntry s_cputlb_empty_entry = {
37
 
    .addr_read  = -1,
38
 
    .addr_write = -1,
39
 
    .addr_code  = -1,
40
 
    .addend     = -1,
41
 
};
42
 
 
43
37
/* NOTE:
44
38
 * If flush_global is true (the usual case), flush all tlb entries.
45
39
 * If flush_global is false, flush (at least) all tlb entries not
52
46
 * entries from the TLB at any time, so flushing more entries than
53
47
 * required is only an efficiency issue, not a correctness issue.
54
48
 */
55
 
void tlb_flush(CPUArchState *env, int flush_global)
 
49
void tlb_flush(CPUState *cpu, int flush_global)
56
50
{
57
 
    CPUState *cpu = ENV_GET_CPU(env);
58
 
    int i;
 
51
    CPUArchState *env = cpu->env_ptr;
59
52
 
60
53
#if defined(DEBUG_TLB)
61
54
    printf("tlb_flush:\n");
64
57
       links while we are modifying them */
65
58
    cpu->current_tb = NULL;
66
59
 
67
 
    for (i = 0; i < CPU_TLB_SIZE; i++) {
68
 
        int mmu_idx;
69
 
 
70
 
        for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) {
71
 
            env->tlb_table[mmu_idx][i] = s_cputlb_empty_entry;
72
 
        }
73
 
    }
74
 
 
75
 
    memset(env->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof (void *));
 
60
    memset(env->tlb_table, -1, sizeof(env->tlb_table));
 
61
    memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache));
76
62
 
77
63
    env->tlb_flush_addr = -1;
78
64
    env->tlb_flush_mask = 0;
87
73
                 (TARGET_PAGE_MASK | TLB_INVALID_MASK)) ||
88
74
        addr == (tlb_entry->addr_code &
89
75
                 (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
90
 
        *tlb_entry = s_cputlb_empty_entry;
 
76
        memset(tlb_entry, -1, sizeof(*tlb_entry));
91
77
    }
92
78
}
93
79
 
94
 
void tlb_flush_page(CPUArchState *env, target_ulong addr)
 
80
void tlb_flush_page(CPUState *cpu, target_ulong addr)
95
81
{
96
 
    CPUState *cpu = ENV_GET_CPU(env);
 
82
    CPUArchState *env = cpu->env_ptr;
97
83
    int i;
98
84
    int mmu_idx;
99
85
 
107
93
               TARGET_FMT_lx "/" TARGET_FMT_lx ")\n",
108
94
               env->tlb_flush_addr, env->tlb_flush_mask);
109
95
#endif
110
 
        tlb_flush(env, 1);
 
96
        tlb_flush(cpu, 1);
111
97
        return;
112
98
    }
113
99
    /* must reset current TB so that interrupts cannot modify the
120
106
        tlb_flush_entry(&env->tlb_table[mmu_idx][i], addr);
121
107
    }
122
108
 
123
 
    tb_flush_jmp_cache(env, addr);
 
109
    tb_flush_jmp_cache(cpu, addr);
124
110
}
125
111
 
126
112
/* update the TLBs so that writes to code in the virtual page 'addr'
127
113
   can be detected */
128
114
void tlb_protect_code(ram_addr_t ram_addr)
129
115
{
130
 
    cpu_physical_memory_reset_dirty(ram_addr,
131
 
                                    ram_addr + TARGET_PAGE_SIZE,
132
 
                                    CODE_DIRTY_FLAG);
 
116
    cpu_physical_memory_reset_dirty(ram_addr, TARGET_PAGE_SIZE,
 
117
                                    DIRTY_MEMORY_CODE);
133
118
}
134
119
 
135
120
/* update the TLB so that writes in physical page 'phys_addr' are no longer
136
121
   tested for self modifying code */
137
 
void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr,
 
122
void tlb_unprotect_code_phys(CPUState *cpu, ram_addr_t ram_addr,
138
123
                             target_ulong vaddr)
139
124
{
140
 
    cpu_physical_memory_set_dirty_flags(ram_addr, CODE_DIRTY_FLAG);
 
125
    cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_CODE);
141
126
}
142
127
 
143
128
static bool tlb_is_dirty_ram(CPUTLBEntry *tlbe)
236
221
/* Add a new TLB entry. At most one entry for a given virtual address
237
222
   is permitted. Only a single TARGET_PAGE_SIZE region is mapped, the
238
223
   supplied size is only used by tlb_flush_page.  */
239
 
void tlb_set_page(CPUArchState *env, target_ulong vaddr,
 
224
void tlb_set_page(CPUState *cpu, target_ulong vaddr,
240
225
                  hwaddr paddr, int prot,
241
226
                  int mmu_idx, target_ulong size)
242
227
{
 
228
    CPUArchState *env = cpu->env_ptr;
243
229
    MemoryRegionSection *section;
244
230
    unsigned int index;
245
231
    target_ulong address;
254
240
    }
255
241
 
256
242
    sz = size;
257
 
    section = address_space_translate_for_iotlb(&address_space_memory, paddr,
 
243
    section = address_space_translate_for_iotlb(cpu->as, paddr,
258
244
                                                &xlat, &sz);
259
245
    assert(sz >= TARGET_PAGE_SIZE);
260
246
 
275
261
    }
276
262
 
277
263
    code_address = address;
278
 
    iotlb = memory_region_section_get_iotlb(env, section, vaddr, paddr, xlat,
 
264
    iotlb = memory_region_section_get_iotlb(cpu, section, vaddr, paddr, xlat,
279
265
                                            prot, &address);
280
266
 
281
267
    index = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
299
285
            /* Write access calls the I/O callback.  */
300
286
            te->addr_write = address | TLB_MMIO;
301
287
        } else if (memory_region_is_ram(section->mr)
302
 
                   && !cpu_physical_memory_is_dirty(section->mr->ram_addr + xlat)) {
 
288
                   && cpu_physical_memory_is_clean(section->mr->ram_addr
 
289
                                                   + xlat)) {
303
290
            te->addr_write = address | TLB_NOTDIRTY;
304
291
        } else {
305
292
            te->addr_write = address;
319
306
    int mmu_idx, page_index, pd;
320
307
    void *p;
321
308
    MemoryRegion *mr;
 
309
    CPUState *cpu = ENV_GET_CPU(env1);
322
310
 
323
311
    page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
324
312
    mmu_idx = cpu_mmu_index(env1);
327
315
        cpu_ldub_code(env1, addr);
328
316
    }
329
317
    pd = env1->iotlb[mmu_idx][page_index] & ~TARGET_PAGE_MASK;
330
 
    mr = iotlb_to_region(pd);
 
318
    mr = iotlb_to_region(cpu->as, pd);
331
319
    if (memory_region_is_unassigned(mr)) {
332
 
        CPUState *cpu = ENV_GET_CPU(env1);
333
320
        CPUClass *cc = CPU_GET_CLASS(cpu);
334
321
 
335
322
        if (cc->do_unassigned_access) {
336
323
            cc->do_unassigned_access(cpu, addr, false, true, 0, 4);
337
324
        } else {
338
 
            cpu_abort(env1, "Trying to execute code outside RAM or ROM at 0x"
 
325
            cpu_abort(cpu, "Trying to execute code outside RAM or ROM at 0x"
339
326
                      TARGET_FMT_lx "\n", addr);
340
327
        }
341
328
    }