1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NATIVE_BRIDGE_SUPPORT_ARM_GUEST_STATE_GUEST_STATE_CPU_STATE_H_
18 #define NATIVE_BRIDGE_SUPPORT_ARM_GUEST_STATE_GUEST_STATE_CPU_STATE_H_
19 
20 #include <climits>
21 #include <cstdint>
22 
23 namespace berberis {
24 
25 using GuestAddr = uintptr_t;
26 using Reservation = uint64_t;
27 
28 // Guest CPU state.
29 struct CPUState {
30   // General registers, except PC (r15).
31   uint32_t r[15];
32 
33   // ATTENTION: flag values should only be 0 or 1, for bitwise computations!
34   // This is different from 'bool', where 'true' can be any non-zero value!
35   struct Flags {
36     uint8_t negative;
37     uint8_t zero;
38     uint8_t carry;
39     uint8_t overflow;
40     uint32_t saturation;
41     // Greater than or equal flags in SIMD-friendly format: 4 bytes, each either 0x00 or 0xff.
42     // That's format produced by SIMD instructions (e.g. PCMPGTB/etc on x86 and VCGT/etc on ARM).
43     uint32_t ge;
44   } flags;
45 
46   // Current insn address, +1 if Thumb.
47   uint32_t insn_addr;
48 
49   // Advanced SIMD and floating-point registers (s, d, q).
50   // Have to be aligned (relative to structure start) to allow optimizer
51   // determine 128-bit container for 64-bit element.
52   alignas(128 / CHAR_BIT) uint64_t d[32];
53 
54   // See intrinsics/guest_fp_flags.h for the information about that word.
55   // Intrinsics touch separate bits of that word, the rest uses it as opaque 32-bit data structure.
56   //
57   // Exception: SemanticsDecoder::VMRS accesses four bits directly without intrinsics.
58   uint32_t fpflags;
59 
60   GuestAddr reservation_address;
61   Reservation reservation_value;
62 };
63 
64 }
65 #endif  // NATIVE_BRIDGE_SUPPORT_ARM_GUEST_STATE_GUEST_STATE_CPU_STATE_H_
66