Skip to content

Commit 5e3cced

Browse files
committed
target/loongarch: Change return value type with loongarch_tlb_search_cb()
With function loongarch_tlb_search_cb(), change return value type from bool type to pointer LoongArchTLB *, the pointer type can be use directly in future. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Song Gao <gaosong@loongson.cn>
1 parent 58c5522 commit 5e3cced

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

target/loongarch/tcg/tlb_helper.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ static uint32_t get_random_tlb(uint32_t low, uint32_t high)
203203
* field in tlb entry contains bit[47:13], so need adjust.
204204
* virt_vpn = vaddr[47:13]
205205
*/
206-
static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
207-
int *index, int csr_asid, tlb_match func)
206+
static LoongArchTLB *loongarch_tlb_search_cb(CPULoongArchState *env,
207+
vaddr vaddr, int csr_asid,
208+
tlb_match func)
208209
{
209210
LoongArchTLB *tlb;
210211
uint16_t tlb_asid, stlb_idx;
@@ -229,8 +230,7 @@ static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
229230

230231
if (func(tlb_g, csr_asid, tlb_asid) &&
231232
(vpn == (tlb_vppn >> compare_shift))) {
232-
*index = i * 256 + stlb_idx;
233-
return true;
233+
return tlb;
234234
}
235235
}
236236
}
@@ -248,23 +248,29 @@ static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
248248
vpn = (vaddr & TARGET_VIRT_MASK) >> (tlb_ps + 1);
249249
if (func(tlb_g, csr_asid, tlb_asid) &&
250250
(vpn == (tlb_vppn >> compare_shift))) {
251-
*index = i;
252-
return true;
251+
return tlb;
253252
}
254253
}
255254
}
256-
return false;
255+
return NULL;
257256
}
258257

259258
static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
260259
int *index)
261260
{
262261
int csr_asid;
263262
tlb_match func;
263+
LoongArchTLB *tlb;
264264

265265
func = tlb_match_any;
266266
csr_asid = FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID);
267-
return loongarch_tlb_search_cb(env, vaddr, index, csr_asid, func);
267+
tlb = loongarch_tlb_search_cb(env, vaddr, csr_asid, func);
268+
if (tlb) {
269+
*index = tlb - env->tlb;
270+
return true;
271+
}
272+
273+
return false;
268274
}
269275

270276
void helper_tlbsrch(CPULoongArchState *env)

0 commit comments

Comments
 (0)