root / softmmu_header.h @ 6e59c1db
History | View | Annotate | Download (4 kB)
1 | b92e5a22 | bellard | /*
|
---|---|---|---|
2 | b92e5a22 | bellard | * Software MMU support
|
3 | b92e5a22 | bellard | *
|
4 | b92e5a22 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | b92e5a22 | bellard | *
|
6 | b92e5a22 | bellard | * This library is free software; you can redistribute it and/or
|
7 | b92e5a22 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | b92e5a22 | bellard | * License as published by the Free Software Foundation; either
|
9 | b92e5a22 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | b92e5a22 | bellard | *
|
11 | b92e5a22 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | b92e5a22 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | b92e5a22 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | b92e5a22 | bellard | * Lesser General Public License for more details.
|
15 | b92e5a22 | bellard | *
|
16 | b92e5a22 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | b92e5a22 | bellard | * License along with this library; if not, write to the Free Software
|
18 | b92e5a22 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | b92e5a22 | bellard | */
|
20 | b92e5a22 | bellard | #if DATA_SIZE == 8 |
21 | b92e5a22 | bellard | #define SUFFIX q
|
22 | 61382a50 | bellard | #define USUFFIX q
|
23 | b92e5a22 | bellard | #define DATA_TYPE uint64_t
|
24 | b92e5a22 | bellard | #elif DATA_SIZE == 4 |
25 | b92e5a22 | bellard | #define SUFFIX l
|
26 | 61382a50 | bellard | #define USUFFIX l
|
27 | b92e5a22 | bellard | #define DATA_TYPE uint32_t
|
28 | b92e5a22 | bellard | #elif DATA_SIZE == 2 |
29 | b92e5a22 | bellard | #define SUFFIX w
|
30 | 61382a50 | bellard | #define USUFFIX uw
|
31 | b92e5a22 | bellard | #define DATA_TYPE uint16_t
|
32 | b92e5a22 | bellard | #define DATA_STYPE int16_t
|
33 | b92e5a22 | bellard | #elif DATA_SIZE == 1 |
34 | b92e5a22 | bellard | #define SUFFIX b
|
35 | 61382a50 | bellard | #define USUFFIX ub
|
36 | b92e5a22 | bellard | #define DATA_TYPE uint8_t
|
37 | b92e5a22 | bellard | #define DATA_STYPE int8_t
|
38 | b92e5a22 | bellard | #else
|
39 | b92e5a22 | bellard | #error unsupported data size
|
40 | b92e5a22 | bellard | #endif
|
41 | b92e5a22 | bellard | |
42 | 61382a50 | bellard | #if ACCESS_TYPE == 0 |
43 | 61382a50 | bellard | |
44 | 61382a50 | bellard | #define CPU_MEM_INDEX 0 |
45 | 61382a50 | bellard | #define MMUSUFFIX _mmu
|
46 | 61382a50 | bellard | |
47 | 61382a50 | bellard | #elif ACCESS_TYPE == 1 |
48 | 61382a50 | bellard | |
49 | 61382a50 | bellard | #define CPU_MEM_INDEX 1 |
50 | 61382a50 | bellard | #define MMUSUFFIX _mmu
|
51 | 61382a50 | bellard | |
52 | 61382a50 | bellard | #elif ACCESS_TYPE == 2 |
53 | 61382a50 | bellard | |
54 | 61382a50 | bellard | #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3) |
55 | 61382a50 | bellard | #define MMUSUFFIX _mmu
|
56 | 61382a50 | bellard | |
57 | 61382a50 | bellard | #elif ACCESS_TYPE == 3 |
58 | 61382a50 | bellard | |
59 | 61382a50 | bellard | #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3) |
60 | 61382a50 | bellard | #define MMUSUFFIX _cmmu
|
61 | 61382a50 | bellard | |
62 | b92e5a22 | bellard | #else
|
63 | 61382a50 | bellard | #error invalid ACCESS_TYPE
|
64 | b92e5a22 | bellard | #endif
|
65 | b92e5a22 | bellard | |
66 | b92e5a22 | bellard | #if DATA_SIZE == 8 |
67 | b92e5a22 | bellard | #define RES_TYPE uint64_t
|
68 | b92e5a22 | bellard | #else
|
69 | b92e5a22 | bellard | #define RES_TYPE int |
70 | b92e5a22 | bellard | #endif
|
71 | b92e5a22 | bellard | |
72 | b92e5a22 | bellard | |
73 | 61382a50 | bellard | DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(unsigned long addr, |
74 | 61382a50 | bellard | int is_user);
|
75 | 61382a50 | bellard | void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(unsigned long addr, DATA_TYPE v, int is_user); |
76 | b92e5a22 | bellard | |
77 | 61382a50 | bellard | static inline int glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr) |
78 | b92e5a22 | bellard | { |
79 | b92e5a22 | bellard | int index;
|
80 | b92e5a22 | bellard | RES_TYPE res; |
81 | b92e5a22 | bellard | unsigned long addr, physaddr; |
82 | 61382a50 | bellard | int is_user;
|
83 | 61382a50 | bellard | |
84 | b92e5a22 | bellard | addr = (unsigned long)ptr; |
85 | b92e5a22 | bellard | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
86 | 61382a50 | bellard | is_user = CPU_MEM_INDEX; |
87 | 61382a50 | bellard | if (__builtin_expect(env->tlb_read[is_user][index].address !=
|
88 | b92e5a22 | bellard | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) { |
89 | 61382a50 | bellard | res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user); |
90 | b92e5a22 | bellard | } else {
|
91 | 61382a50 | bellard | physaddr = addr + env->tlb_read[is_user][index].addend; |
92 | 61382a50 | bellard | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr); |
93 | b92e5a22 | bellard | } |
94 | b92e5a22 | bellard | return res;
|
95 | b92e5a22 | bellard | } |
96 | b92e5a22 | bellard | |
97 | b92e5a22 | bellard | #if DATA_SIZE <= 2 |
98 | b92e5a22 | bellard | static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(void *ptr) |
99 | b92e5a22 | bellard | { |
100 | b92e5a22 | bellard | int res, index;
|
101 | b92e5a22 | bellard | unsigned long addr, physaddr; |
102 | 61382a50 | bellard | int is_user;
|
103 | 61382a50 | bellard | |
104 | b92e5a22 | bellard | addr = (unsigned long)ptr; |
105 | b92e5a22 | bellard | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
106 | 61382a50 | bellard | is_user = CPU_MEM_INDEX; |
107 | 61382a50 | bellard | if (__builtin_expect(env->tlb_read[is_user][index].address !=
|
108 | b92e5a22 | bellard | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) { |
109 | 61382a50 | bellard | res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user); |
110 | b92e5a22 | bellard | } else {
|
111 | 61382a50 | bellard | physaddr = addr + env->tlb_read[is_user][index].addend; |
112 | b92e5a22 | bellard | res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr); |
113 | b92e5a22 | bellard | } |
114 | b92e5a22 | bellard | return res;
|
115 | b92e5a22 | bellard | } |
116 | b92e5a22 | bellard | #endif
|
117 | b92e5a22 | bellard | |
118 | b92e5a22 | bellard | static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(void *ptr, RES_TYPE v) |
119 | b92e5a22 | bellard | { |
120 | b92e5a22 | bellard | int index;
|
121 | b92e5a22 | bellard | unsigned long addr, physaddr; |
122 | 61382a50 | bellard | int is_user;
|
123 | 61382a50 | bellard | |
124 | b92e5a22 | bellard | addr = (unsigned long)ptr; |
125 | b92e5a22 | bellard | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
126 | 61382a50 | bellard | is_user = CPU_MEM_INDEX; |
127 | 61382a50 | bellard | if (__builtin_expect(env->tlb_write[is_user][index].address !=
|
128 | b92e5a22 | bellard | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) { |
129 | 61382a50 | bellard | glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user); |
130 | b92e5a22 | bellard | } else {
|
131 | 61382a50 | bellard | physaddr = addr + env->tlb_write[is_user][index].addend; |
132 | b92e5a22 | bellard | glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v); |
133 | b92e5a22 | bellard | } |
134 | b92e5a22 | bellard | } |
135 | b92e5a22 | bellard | |
136 | b92e5a22 | bellard | #undef RES_TYPE
|
137 | b92e5a22 | bellard | #undef DATA_TYPE
|
138 | b92e5a22 | bellard | #undef DATA_STYPE
|
139 | b92e5a22 | bellard | #undef SUFFIX
|
140 | 61382a50 | bellard | #undef USUFFIX
|
141 | b92e5a22 | bellard | #undef DATA_SIZE
|
142 | 61382a50 | bellard | #undef CPU_MEM_INDEX
|
143 | 61382a50 | bellard | #undef MMUSUFFIX |