mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
efbc78ad97
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20200626033144.790098-12-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
83 lines
2.5 KiB
C
83 lines
2.5 KiB
C
/*
|
|
* ARM v8.5-MemTag Operations
|
|
*
|
|
* Copyright (c) 2020 Linaro, Ltd.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "cpu.h"
|
|
#include "internals.h"
|
|
#include "exec/exec-all.h"
|
|
#include "exec/cpu_ldst.h"
|
|
#include "exec/helper-proto.h"
|
|
|
|
|
|
static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
|
|
{
|
|
if (exclude == 0xffff) {
|
|
return 0;
|
|
}
|
|
if (offset == 0) {
|
|
while (exclude & (1 << tag)) {
|
|
tag = (tag + 1) & 15;
|
|
}
|
|
} else {
|
|
do {
|
|
do {
|
|
tag = (tag + 1) & 15;
|
|
} while (exclude & (1 << tag));
|
|
} while (--offset > 0);
|
|
}
|
|
return tag;
|
|
}
|
|
|
|
uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm)
|
|
{
|
|
int rtag;
|
|
|
|
/*
|
|
* Our IMPDEF choice for GCR_EL1.RRND==1 is to behave as if
|
|
* GCR_EL1.RRND==0, always producing deterministic results.
|
|
*/
|
|
uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16);
|
|
int start = extract32(env->cp15.rgsr_el1, 0, 4);
|
|
int seed = extract32(env->cp15.rgsr_el1, 8, 16);
|
|
int offset, i;
|
|
|
|
/* RandomTag */
|
|
for (i = offset = 0; i < 4; ++i) {
|
|
/* NextRandomTagBit */
|
|
int top = (extract32(seed, 5, 1) ^ extract32(seed, 3, 1) ^
|
|
extract32(seed, 2, 1) ^ extract32(seed, 0, 1));
|
|
seed = (top << 15) | (seed >> 1);
|
|
offset |= top << i;
|
|
}
|
|
rtag = choose_nonexcluded_tag(start, offset, exclude);
|
|
env->cp15.rgsr_el1 = rtag | (seed << 8);
|
|
|
|
return address_with_allocation_tag(rn, rtag);
|
|
}
|
|
|
|
uint64_t HELPER(addsubg)(CPUARMState *env, uint64_t ptr,
|
|
int32_t offset, uint32_t tag_offset)
|
|
{
|
|
int start_tag = allocation_tag_from_addr(ptr);
|
|
uint16_t exclude = extract32(env->cp15.gcr_el1, 0, 16);
|
|
int rtag = choose_nonexcluded_tag(start_tag, tag_offset, exclude);
|
|
|
|
return address_with_allocation_tag(ptr + offset, rtag);
|
|
}
|