utility.hh (6759:98101a5f7ee4) utility.hh (7111:ee902ae075bb)
1/*
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2007-2008 The Florida State University
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Korey Sewell
30 * Stephen Hines
31 */
32
33#ifndef __ARCH_ARM_UTILITY_HH__
34#define __ARCH_ARM_UTILITY_HH__
35
36#include "arch/arm/miscregs.hh"
37#include "arch/arm/types.hh"
38#include "base/hashmap.hh"
39#include "base/types.hh"
40#include "cpu/thread_context.hh"
41
42namespace __hash_namespace {
43 template<>
44 struct hash<ArmISA::ExtMachInst> : public hash<uint32_t> {
45 size_t operator()(const ArmISA::ExtMachInst &emi) const {
46 return hash<uint32_t>::operator()((uint32_t)emi);
47 };
48 };
49}
50
51namespace ArmISA {
52
53 inline bool
54 testPredicate(CPSR cpsr, ConditionCode code)
55 {
56 switch (code)
57 {
58 case COND_EQ: return cpsr.z;
59 case COND_NE: return !cpsr.z;
60 case COND_CS: return cpsr.c;
61 case COND_CC: return !cpsr.c;
62 case COND_MI: return cpsr.n;
63 case COND_PL: return !cpsr.n;
64 case COND_VS: return cpsr.v;
65 case COND_VC: return !cpsr.v;
66 case COND_HI: return (cpsr.c && !cpsr.z);
67 case COND_LS: return !(cpsr.c && !cpsr.z);
68 case COND_GE: return !(cpsr.n ^ cpsr.v);
69 case COND_LT: return (cpsr.n ^ cpsr.v);
70 case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z);
71 case COND_LE: return (cpsr.n ^ cpsr.v || cpsr.z);
72 case COND_AL: return true;
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Korey Sewell
42 * Stephen Hines
43 */
44
45#ifndef __ARCH_ARM_UTILITY_HH__
46#define __ARCH_ARM_UTILITY_HH__
47
48#include "arch/arm/miscregs.hh"
49#include "arch/arm/types.hh"
50#include "base/hashmap.hh"
51#include "base/types.hh"
52#include "cpu/thread_context.hh"
53
54namespace __hash_namespace {
55 template<>
56 struct hash<ArmISA::ExtMachInst> : public hash<uint32_t> {
57 size_t operator()(const ArmISA::ExtMachInst &emi) const {
58 return hash<uint32_t>::operator()((uint32_t)emi);
59 };
60 };
61}
62
63namespace ArmISA {
64
65 inline bool
66 testPredicate(CPSR cpsr, ConditionCode code)
67 {
68 switch (code)
69 {
70 case COND_EQ: return cpsr.z;
71 case COND_NE: return !cpsr.z;
72 case COND_CS: return cpsr.c;
73 case COND_CC: return !cpsr.c;
74 case COND_MI: return cpsr.n;
75 case COND_PL: return !cpsr.n;
76 case COND_VS: return cpsr.v;
77 case COND_VC: return !cpsr.v;
78 case COND_HI: return (cpsr.c && !cpsr.z);
79 case COND_LS: return !(cpsr.c && !cpsr.z);
80 case COND_GE: return !(cpsr.n ^ cpsr.v);
81 case COND_LT: return (cpsr.n ^ cpsr.v);
82 case COND_GT: return !(cpsr.n ^ cpsr.v || cpsr.z);
83 case COND_LE: return (cpsr.n ^ cpsr.v || cpsr.z);
84 case COND_AL: return true;
73 case COND_NV: return false;
85 case COND_UC: return true;
74 default:
75 panic("Unhandled predicate condition: %d\n", code);
76 }
77 }
78
79 /**
80 * Function to insure ISA semantics about 0 registers.
81 * @param tc The thread context.
82 */
83 template <class TC>
84 void zeroRegisters(TC *tc);
85
86 // Instruction address compression hooks
87 static inline Addr realPCToFetchPC(const Addr &addr) {
88 return addr;
89 }
90
91 static inline Addr fetchPCToRealPC(const Addr &addr) {
92 return addr;
93 }
94
95 // the size of "fetched" instructions
96 static inline size_t fetchInstSize() {
97 return sizeof(MachInst);
98 }
99
100 static inline MachInst makeRegisterCopy(int dest, int src) {
101 panic("makeRegisterCopy not implemented");
102 return 0;
103 }
104
105 inline void startupCPU(ThreadContext *tc, int cpuId)
106 {
107 tc->activate(0);
108 }
109
110 template <class XC>
111 Fault
112 checkFpEnableFault(XC *xc)
113 {
114 return NoFault;
115 }
116
117 static inline void
118 copyRegs(ThreadContext *src, ThreadContext *dest)
119 {
120 panic("Copy Regs Not Implemented Yet\n");
121 }
122
123 static inline void
124 copyMiscRegs(ThreadContext *src, ThreadContext *dest)
125 {
126 panic("Copy Misc. Regs Not Implemented Yet\n");
127 }
128
129 void initCPU(ThreadContext *tc, int cpuId);
130
131 static inline bool
132 inUserMode(ThreadContext *tc)
133 {
134 return (tc->readMiscRegNoEffect(MISCREG_CPSR) & 0x1f) == MODE_USER;
135 }
136
137uint64_t getArgument(ThreadContext *tc, int number, bool fp);
138
139Fault setCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
140Fault readCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
141
142};
143
144
145#endif
86 default:
87 panic("Unhandled predicate condition: %d\n", code);
88 }
89 }
90
91 /**
92 * Function to insure ISA semantics about 0 registers.
93 * @param tc The thread context.
94 */
95 template <class TC>
96 void zeroRegisters(TC *tc);
97
98 // Instruction address compression hooks
99 static inline Addr realPCToFetchPC(const Addr &addr) {
100 return addr;
101 }
102
103 static inline Addr fetchPCToRealPC(const Addr &addr) {
104 return addr;
105 }
106
107 // the size of "fetched" instructions
108 static inline size_t fetchInstSize() {
109 return sizeof(MachInst);
110 }
111
112 static inline MachInst makeRegisterCopy(int dest, int src) {
113 panic("makeRegisterCopy not implemented");
114 return 0;
115 }
116
117 inline void startupCPU(ThreadContext *tc, int cpuId)
118 {
119 tc->activate(0);
120 }
121
122 template <class XC>
123 Fault
124 checkFpEnableFault(XC *xc)
125 {
126 return NoFault;
127 }
128
129 static inline void
130 copyRegs(ThreadContext *src, ThreadContext *dest)
131 {
132 panic("Copy Regs Not Implemented Yet\n");
133 }
134
135 static inline void
136 copyMiscRegs(ThreadContext *src, ThreadContext *dest)
137 {
138 panic("Copy Misc. Regs Not Implemented Yet\n");
139 }
140
141 void initCPU(ThreadContext *tc, int cpuId);
142
143 static inline bool
144 inUserMode(ThreadContext *tc)
145 {
146 return (tc->readMiscRegNoEffect(MISCREG_CPSR) & 0x1f) == MODE_USER;
147 }
148
149uint64_t getArgument(ThreadContext *tc, int number, bool fp);
150
151Fault setCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
152Fault readCp15Register(uint32_t &Rd, int CRn, int opc1, int CRm, int opc2);
153
154};
155
156
157#endif