Fix elf loader range checking
[qemu] / target-microblaze / mmu.h
1 /*
2  *  Microblaze MMU emulation for qemu.
3  *
4  *  Copyright (c) 2009 Edgar E. Iglesias
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, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
19  */
20
21 #define MMU_R_PID    0
22 #define MMU_R_ZPR    1
23 #define MMU_R_TLBX   2
24 #define MMU_R_TLBLO  3
25 #define MMU_R_TLBHI  4
26 #define MMU_R_TLBSX  5
27
28 #define RAM_DATA     1
29 #define RAM_TAG      0
30
31 /* Tag portion */
32 #define TLB_EPN_MASK          0xFFFFFC00 /* Effective Page Number */
33 #define TLB_PAGESZ_MASK       0x00000380
34 #define TLB_PAGESZ(x)         (((x) & 0x7) << 7)
35 #define PAGESZ_1K             0
36 #define PAGESZ_4K             1
37 #define PAGESZ_16K            2
38 #define PAGESZ_64K            3
39 #define PAGESZ_256K           4
40 #define PAGESZ_1M             5
41 #define PAGESZ_4M             6
42 #define PAGESZ_16M            7
43 #define TLB_VALID             0x00000040 /* Entry is valid */
44
45 /* Data portion */
46 #define TLB_RPN_MASK          0xFFFFFC00 /* Real Page Number */
47 #define TLB_PERM_MASK         0x00000300
48 #define TLB_EX                0x00000200 /* Instruction execution allowed */
49 #define TLB_WR                0x00000100 /* Writes permitted */
50 #define TLB_ZSEL_MASK         0x000000F0
51 #define TLB_ZSEL(x)           (((x) & 0xF) << 4)
52 #define TLB_ATTR_MASK         0x0000000F
53 #define TLB_W                 0x00000008 /* Caching is write-through */
54 #define TLB_I                 0x00000004 /* Caching is inhibited */
55 #define TLB_M                 0x00000002 /* Memory is coherent */
56 #define TLB_G                 0x00000001 /* Memory is guarded from prefetch */
57
58 #define TLB_ENTRIES    64
59
60 struct microblaze_mmu
61 {
62     /* Data and tag brams.  */
63     uint32_t rams[2][TLB_ENTRIES];
64     /* We keep a separate ram for the tids to avoid the 48 bit tag width.  */
65     uint8_t tids[TLB_ENTRIES];
66     /* Control flops.  */
67     uint32_t regs[8];;
68 };
69
70 struct microblaze_mmu_lookup
71 {
72     uint32_t paddr;
73     uint32_t vaddr;
74     unsigned int size;
75     unsigned int idx;
76     int prot;
77     enum {
78         ERR_PROT, ERR_MISS, ERR_HIT
79     } err;
80 };
81
82 void mmu_flip_um(CPUState *env, unsigned int um);
83 unsigned int mmu_translate(struct microblaze_mmu *mmu,
84                            struct microblaze_mmu_lookup *lu,
85                            target_ulong vaddr, int rw, int mmu_idx);
86 uint32_t mmu_read(CPUState *env, uint32_t rn);
87 void mmu_write(CPUState *env, uint32_t rn, uint32_t v);
88 void mmu_init(struct microblaze_mmu *mmu);