]>
Commit | Line | Data |
---|---|---|
da54941f RH |
1 | /* |
2 | * ARM v8.5-MemTag Operations | |
3 | * | |
4 | * Copyright (c) 2020 Linaro, Ltd. | |
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.1 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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "qemu/osdep.h" | |
21 | #include "cpu.h" | |
22 | #include "internals.h" | |
23 | #include "exec/exec-all.h" | |
24 | #include "exec/cpu_ldst.h" | |
25 | #include "exec/helper-proto.h" | |
26 | ||
27 | ||
28 | static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) | |
29 | { | |
30 | if (exclude == 0xffff) { | |
31 | return 0; | |
32 | } | |
33 | if (offset == 0) { | |
34 | while (exclude & (1 << tag)) { | |
35 | tag = (tag + 1) & 15; | |
36 | } | |
37 | } else { | |
38 | do { | |
39 | do { | |
40 | tag = (tag + 1) & 15; | |
41 | } while (exclude & (1 << tag)); | |
42 | } while (--offset > 0); | |
43 | } | |
44 | return tag; | |
45 | } | |
46 | ||
47 | uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm) | |
48 | { | |
49 | int rtag; | |
50 | ||
51 | /* | |
52 | * Our IMPDEF choice for GCR_EL1.RRND==1 is to behave as if | |
53 | * GCR_EL1.RRND==0, always producing deterministic results. | |
54 | */ | |
55 | uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16); | |
56 | int start = extract32(env->cp15.rgsr_el1, 0, 4); | |
57 | int seed = extract32(env->cp15.rgsr_el1, 8, 16); | |
58 | int offset, i; | |
59 | ||
60 | /* RandomTag */ | |
61 | for (i = offset = 0; i < 4; ++i) { | |
62 | /* NextRandomTagBit */ | |
63 | int top = (extract32(seed, 5, 1) ^ extract32(seed, 3, 1) ^ | |
64 | extract32(seed, 2, 1) ^ extract32(seed, 0, 1)); | |
65 | seed = (top << 15) | (seed >> 1); | |
66 | offset |= top << i; | |
67 | } | |
68 | rtag = choose_nonexcluded_tag(start, offset, exclude); | |
69 | env->cp15.rgsr_el1 = rtag | (seed << 8); | |
70 | ||
71 | return address_with_allocation_tag(rn, rtag); | |
72 | } | |
efbc78ad RH |
73 | |
74 | uint64_t HELPER(addsubg)(CPUARMState *env, uint64_t ptr, | |
75 | int32_t offset, uint32_t tag_offset) | |
76 | { | |
77 | int start_tag = allocation_tag_from_addr(ptr); | |
78 | uint16_t exclude = extract32(env->cp15.gcr_el1, 0, 16); | |
79 | int rtag = choose_nonexcluded_tag(start_tag, tag_offset, exclude); | |
80 | ||
81 | return address_with_allocation_tag(ptr + offset, rtag); | |
82 | } |