1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_V2_ARM_HELPERS_H
8 : #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_V2_ARM_HELPERS_H
9 :
10 : /* This file defines arm helper functions that are used by the
11 : method definitions in armv7.table. They exists because either
12 : (a) ARM specifications use them, or (b) the limitations of
13 : (dgen) bit expressions (defined in dgen_input.py) do not allow us
14 : to specify the function explicitly.
15 : */
16 :
17 : #include "native_client/src/trusted/validator_arm/model.h"
18 :
19 : namespace nacl_arm_dec {
20 :
21 : // Function to get the number of general purpose registers in
22 : // a register list.
23 0 : inline uint32_t NumGPRs(RegisterList registers) {
24 0 : return registers.numGPRs();
25 0 : }
26 :
27 : // Function to return the smallest general purpose register in
28 : // a register list.
29 0 : inline uint32_t SmallestGPR(RegisterList registers) {
30 0 : return registers.SmallestGPR();
31 0 : }
32 :
33 : // Function that returns true if the general purpose register
34 : // in in the register list.
35 0 : inline bool Contains(RegisterList registers, Register r) {
36 0 : return registers.Contains(r);
37 0 : }
38 :
39 : // Function that unions together to register lists.
40 0 : inline RegisterList Union(RegisterList r1, RegisterList r2) {
41 0 : return r1.Union(r2);
42 0 : }
43 :
44 : // Function returning the register index of a register.
45 0 : inline Register::Number RegIndex(Register r) {
46 0 : return r.number();
47 0 : }
48 :
49 : // Function that expands an immediate value, corresponding
50 : // to ARMExpandImm, as described in section A5.2.4 of the manual.
51 0 : inline uint32_t ARMExpandImm(uint32_t imm12) {
52 0 : uint32_t unrotated_value = imm12 & 0xFF;
53 0 : uint32_t ror_amount = ((imm12 >> 8) & 0xF) << 1;
54 : return (ror_amount == 0) ?
55 : unrotated_value :
56 : ((unrotated_value >> ror_amount) |
57 0 : (unrotated_value << (32 - ror_amount)));
58 0 : }
59 :
60 : // Function ARMExpandImm_C, less the carry, as described in
61 : // section A5.2.4 of the manual.
62 0 : inline uint32_t ARMExpandImm_C(uint32_t imm12) {
63 0 : return ARMExpandImm(imm12);
64 0 : }
65 :
66 : // Function that expands an imm8 to a corresponding floating point
67 : // value with the given (n) number of bits, where n is 32 or 64.
68 : uint64_t VFPExpandImm(uint32_t imm8, int n);
69 :
70 : // Returns the bits used as a literal pool head.
71 0 : inline uint32_t LiteralPoolHeadConstant() {
72 0 : return kLiteralPoolHead;
73 0 : }
74 :
75 : // Returns true if the UDF instruction matches encoding values we've chosen
76 : // to be safe.
77 0 : inline bool IsUDFNaClSafe(uint32_t inst_bits) {
78 0 : return inst_bits == kHaltFill || inst_bits == kAbortNow;
79 0 : }
80 :
81 : } // namespace nacl_arm_dec
82 :
83 : #endif // NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_ARM_V2_ARM_HELPERS_H
|