gem5  v22.1.0.0
se_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include "arch/sparc/process.hh"
31 #include "arch/sparc/regs/int.hh"
32 #include "arch/sparc/regs/misc.hh"
33 #include "arch/sparc/types.hh"
34 #include "base/logging.hh"
35 #include "cpu/thread_context.hh"
37 
38 namespace gem5
39 {
40 
41 namespace SparcISA
42 {
43 
47 };
48 
49 bool
51 {
52  return dynamic_cast<Sparc64Process *>(tc->getProcessPtr());
53 }
54 
55 void
57 {
58  auto &pc = tc->pcState().as<PCState>();
59  switch (trapNum) {
60  case 0x01: // Software breakpoint
61  warn("Software breakpoint encountered at pc %#x.", pc.pc());
62  break;
63  case 0x02: // Division by zero
64  warn("Software signaled a division by zero at pc %#x.", pc.pc());
65  break;
66  case 0x03: // Flush window trap
67  flushWindows(tc);
68  break;
69  case 0x04: // Clean windows
70  warn("Ignoring process request for clean register "
71  "windows at pc %#x.", pc.pc());
72  break;
73  case 0x05: // Range check
74  warn("Software signaled a range check at pc %#x.", pc.pc());
75  break;
76  case 0x06: // Fix alignment
77  warn("Ignoring process request for os assisted unaligned accesses "
78  "at pc %#x.", pc.pc());
79  break;
80  case 0x07: // Integer overflow
81  warn("Software signaled an integer overflow at pc %#x.", pc.pc());
82  break;
83  case 0x32: // Get integer condition codes
84  warn("Ignoring process request to get the integer condition codes "
85  "at pc %#x.", pc.pc());
86  break;
87  case 0x33: // Set integer condition codes
88  warn("Ignoring process request to set the integer condition codes "
89  "at pc %#x.", pc.pc());
90  break;
91  default:
92  panic("Unimplemented trap to operating system: trap number %#x.",
93  trapNum);
94  }
95 }
96 
97 void
99 {
103  RegVal CWP = tc->readMiscReg(MISCREG_CWP);
104  RegVal origCWP = CWP;
105 
106  const bool is_64 = is64(tc);
107  const size_t reg_bytes = is_64 ? 8 : 4;
108  uint8_t bytes[8];
109 
110  SETranslatingPortProxy proxy(tc);
111 
112  CWP = (CWP + Cansave + 2) % NWindows;
113  while (NWindows - 2 - Cansave != 0) {
114  panic_if(Otherwin, "Otherwin non-zero.");
115 
116  tc->setMiscReg(MISCREG_CWP, CWP);
117  // Do the stores
119 
120  Addr addr = is_64 ? sp + 2047 : sp;
121  for (int index = 16; index < 32; index++) {
123  if (is_64) {
124  uint64_t regVal = htobe<uint64_t>(tc->getReg(reg));
125  memcpy(bytes, &regVal, reg_bytes);
126  } else {
127  uint32_t regVal = htobe<uint32_t>(tc->getReg(reg));
128  memcpy(bytes, &regVal, reg_bytes);
129  }
130  if (!proxy.tryWriteBlob(addr, bytes, reg_bytes)) {
131  warn("Failed to save register to the stack when "
132  "flushing windows.");
133  }
134  addr += reg_bytes;
135  }
136  Canrestore--;
137  Cansave++;
138  CWP = (CWP + 1) % NWindows;
139  }
140 
143  tc->setMiscReg(MISCREG_CWP, origCWP);
144 }
145 
146 } // namespace SparcISA
147 } // namespace gem5
Target & as()
Definition: pcstate.hh:72
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
virtual void handleTrap(ThreadContext *tc, int trapNum)
Definition: se_workload.cc:56
bool is64(ThreadContext *tc)
Definition: se_workload.cc:50
virtual void flushWindows(ThreadContext *tc)
Definition: se_workload.cc:98
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscReg(RegIndex misc_reg)=0
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
virtual RegVal getReg(const RegId &reg) const
virtual const PCStateBase & pcState() const =0
virtual void setReg(const RegId &reg, RegVal val)
virtual Process * getProcessPtr()=0
bool tryWriteBlob(Addr addr, const void *p, int size) const override
Version of tryWriteBlob that translates virt->phys and deals with page boundries.
STL vector class.
Definition: stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
#define warn(...)
Definition: logging.hh:246
Bitfield< 0 > sp
Definition: misc_types.hh:75
Bitfield< 4 > pc
Bitfield< 30, 0 > index
constexpr RegId O5
Definition: int.hh:106
constexpr RegId O1
Definition: int.hh:102
constexpr RegId O0
Definition: int.hh:101
constexpr RegId O4
Definition: int.hh:105
constexpr RegId O3
Definition: int.hh:104
constexpr RegId Cansave
Definition: int.hh:133
constexpr RegId Otherwin
Definition: int.hh:136
constexpr RegId Canrestore
Definition: int.hh:134
constexpr RegId O2
Definition: int.hh:103
@ MISCREG_CWP
Definition: misc.hh:70
constexpr RegClass intRegClass
Definition: int.hh:78
constexpr auto & StackPointerReg
Definition: int.hh:170
const int NWindows
Definition: sparc_traits.hh:44
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t RegVal
Definition: types.hh:173
static const std::vector< RegId > ArgumentRegs
Definition: se_workload.hh:69

Generated on Wed Dec 21 2022 10:22:25 for gem5 by doxygen 1.9.1