aarch64: simplify armv8_read_ttbcr

Read registers based on current EL instead of PE mode.

Change-Id: I05d3219ac1bf8585e9f4f024a7e8599fea0913b6
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
This commit is contained in:
Matthias Welwarsky 2016-10-06 16:36:29 +02:00
parent a76e88daa6
commit 2539a32308
1 changed files with 47 additions and 50 deletions

View File

@ -431,56 +431,53 @@ static __unused int armv8_read_ttbcr(struct target *target)
memset(&armv8->armv8_mmu.ttbr1_used, 0, sizeof(armv8->armv8_mmu.ttbr1_used)); memset(&armv8->armv8_mmu.ttbr1_used, 0, sizeof(armv8->armv8_mmu.ttbr1_used));
memset(&armv8->armv8_mmu.ttbr0_mask, 0, sizeof(armv8->armv8_mmu.ttbr0_mask)); memset(&armv8->armv8_mmu.ttbr0_mask, 0, sizeof(armv8->armv8_mmu.ttbr0_mask));
switch (arm->core_mode) { switch (armv8_curel_from_core_mode(arm)) {
case ARMV8_64_EL3H: case SYSTEM_CUREL_EL3:
case ARMV8_64_EL3T: retval = dpm->instr_read_data_r0(dpm,
retval = dpm->instr_read_data_r0(dpm, ARMV8_MRS(SYSTEM_TCR_EL3, 0),
ARMV8_MRS(SYSTEM_TCR_EL3, 0), &ttbcr);
&ttbcr); retval += dpm->instr_read_data_r0_64(dpm,
retval += dpm->instr_read_data_r0_64(dpm, ARMV8_MRS(SYSTEM_TTBR0_EL3, 0),
ARMV8_MRS(SYSTEM_TTBR0_EL3, 0), &armv8->ttbr_base);
&armv8->ttbr_base); if (retval != ERROR_OK)
if (retval != ERROR_OK) goto done;
goto done; armv8->va_size = 64 - (ttbcr & 0x3F);
armv8->va_size = 64 - (ttbcr & 0x3F); armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7);
armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7); armv8->page_size = (ttbcr >> 14) & 3;
armv8->page_size = (ttbcr >> 14) & 3; break;
break; case SYSTEM_CUREL_EL2:
case ARMV8_64_EL2T: retval = dpm->instr_read_data_r0(dpm,
case ARMV8_64_EL2H: ARMV8_MRS(SYSTEM_TCR_EL2, 0),
retval = dpm->instr_read_data_r0(dpm, &ttbcr);
ARMV8_MRS(SYSTEM_TCR_EL2, 0), retval += dpm->instr_read_data_r0_64(dpm,
&ttbcr); ARMV8_MRS(SYSTEM_TTBR0_EL2, 0),
retval += dpm->instr_read_data_r0_64(dpm, &armv8->ttbr_base);
ARMV8_MRS(SYSTEM_TTBR0_EL2, 0), if (retval != ERROR_OK)
&armv8->ttbr_base); goto done;
if (retval != ERROR_OK) armv8->va_size = 64 - (ttbcr & 0x3F);
goto done; armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7);
armv8->va_size = 64 - (ttbcr & 0x3F); armv8->page_size = (ttbcr >> 14) & 3;
armv8->pa_size = armv8_pa_size((ttbcr >> 16) & 7); break;
armv8->page_size = (ttbcr >> 14) & 3; case SYSTEM_CUREL_EL0:
break; case SYSTEM_CUREL_EL1:
case ARMV8_64_EL0T: retval = dpm->instr_read_data_r0_64(dpm,
case ARMV8_64_EL1T: ARMV8_MRS(SYSTEM_TCR_EL1, 0),
case ARMV8_64_EL1H: &ttbcr_64);
retval = dpm->instr_read_data_r0_64(dpm, armv8->va_size = 64 - (ttbcr_64 & 0x3F);
ARMV8_MRS(SYSTEM_TCR_EL1, 0), armv8->pa_size = armv8_pa_size((ttbcr_64 >> 32) & 7);
&ttbcr_64); armv8->page_size = (ttbcr_64 >> 14) & 3;
armv8->va_size = 64 - (ttbcr_64 & 0x3F); armv8->armv8_mmu.ttbr1_used = (((ttbcr_64 >> 16) & 0x3F) != 0) ? 1 : 0;
armv8->pa_size = armv8_pa_size((ttbcr_64 >> 32) & 7); armv8->armv8_mmu.ttbr0_mask = 0x0000FFFFFFFFFFFF;
armv8->page_size = (ttbcr_64 >> 14) & 3; retval += dpm->instr_read_data_r0_64(dpm,
armv8->armv8_mmu.ttbr1_used = (((ttbcr_64 >> 16) & 0x3F) != 0) ? 1 : 0; ARMV8_MRS(SYSTEM_TTBR0_EL1 | (armv8->armv8_mmu.ttbr1_used), 0),
armv8->armv8_mmu.ttbr0_mask = 0x0000FFFFFFFFFFFF; &armv8->ttbr_base);
retval += dpm->instr_read_data_r0_64(dpm, if (retval != ERROR_OK)
ARMV8_MRS(SYSTEM_TTBR0_EL1 | (armv8->armv8_mmu.ttbr1_used), 0), goto done;
&armv8->ttbr_base); break;
if (retval != ERROR_OK) default:
goto done; LOG_ERROR("unknow core state");
break; retval = ERROR_FAIL;
default: break;
LOG_ERROR("unknow core state");
retval = ERROR_FAIL;
break;
} }
if (retval != ERROR_OK) if (retval != ERROR_OK)
goto done; goto done;