gem5  v22.1.0.0
isa.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 RISC-V Foundation
3  * Copyright (c) 2016 The University of Virginia
4  * Copyright (c) 2020 Barkhausen Institut
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "arch/riscv/isa.hh"
32 
33 #include <ctime>
34 #include <set>
35 #include <sstream>
36 
37 #include "arch/riscv/interrupts.hh"
38 #include "arch/riscv/mmu.hh"
39 #include "arch/riscv/pagetable.hh"
40 #include "arch/riscv/pmp.hh"
41 #include "arch/riscv/regs/float.hh"
42 #include "arch/riscv/regs/int.hh"
43 #include "arch/riscv/regs/misc.hh"
44 #include "base/bitfield.hh"
45 #include "base/compiler.hh"
46 #include "base/logging.hh"
47 #include "base/trace.hh"
48 #include "cpu/base.hh"
49 #include "debug/Checkpoint.hh"
50 #include "debug/LLSC.hh"
51 #include "debug/RiscvMisc.hh"
52 #include "mem/packet.hh"
53 #include "mem/request.hh"
54 #include "params/RiscvISA.hh"
55 #include "sim/pseudo_inst.hh"
56 
57 namespace gem5
58 {
59 
60 namespace RiscvISA
61 {
62 
63 [[maybe_unused]] const std::array<const char *, NUM_MISCREGS> MiscRegNames = {{
64  [MISCREG_PRV] = "PRV",
65  [MISCREG_ISA] = "ISA",
66  [MISCREG_VENDORID] = "VENDORID",
67  [MISCREG_ARCHID] = "ARCHID",
68  [MISCREG_IMPID] = "IMPID",
69  [MISCREG_HARTID] = "HARTID",
70  [MISCREG_STATUS] = "STATUS",
71  [MISCREG_IP] = "IP",
72  [MISCREG_IE] = "IE",
73  [MISCREG_CYCLE] = "CYCLE",
74  [MISCREG_TIME] = "TIME",
75  [MISCREG_INSTRET] = "INSTRET",
76  [MISCREG_HPMCOUNTER03] = "HPMCOUNTER03",
77  [MISCREG_HPMCOUNTER04] = "HPMCOUNTER04",
78  [MISCREG_HPMCOUNTER05] = "HPMCOUNTER05",
79  [MISCREG_HPMCOUNTER06] = "HPMCOUNTER06",
80  [MISCREG_HPMCOUNTER07] = "HPMCOUNTER07",
81  [MISCREG_HPMCOUNTER08] = "HPMCOUNTER08",
82  [MISCREG_HPMCOUNTER09] = "HPMCOUNTER09",
83  [MISCREG_HPMCOUNTER10] = "HPMCOUNTER10",
84  [MISCREG_HPMCOUNTER11] = "HPMCOUNTER11",
85  [MISCREG_HPMCOUNTER12] = "HPMCOUNTER12",
86  [MISCREG_HPMCOUNTER13] = "HPMCOUNTER13",
87  [MISCREG_HPMCOUNTER14] = "HPMCOUNTER14",
88  [MISCREG_HPMCOUNTER15] = "HPMCOUNTER15",
89  [MISCREG_HPMCOUNTER16] = "HPMCOUNTER16",
90  [MISCREG_HPMCOUNTER17] = "HPMCOUNTER17",
91  [MISCREG_HPMCOUNTER18] = "HPMCOUNTER18",
92  [MISCREG_HPMCOUNTER19] = "HPMCOUNTER19",
93  [MISCREG_HPMCOUNTER20] = "HPMCOUNTER20",
94  [MISCREG_HPMCOUNTER21] = "HPMCOUNTER21",
95  [MISCREG_HPMCOUNTER22] = "HPMCOUNTER22",
96  [MISCREG_HPMCOUNTER23] = "HPMCOUNTER23",
97  [MISCREG_HPMCOUNTER24] = "HPMCOUNTER24",
98  [MISCREG_HPMCOUNTER25] = "HPMCOUNTER25",
99  [MISCREG_HPMCOUNTER26] = "HPMCOUNTER26",
100  [MISCREG_HPMCOUNTER27] = "HPMCOUNTER27",
101  [MISCREG_HPMCOUNTER28] = "HPMCOUNTER28",
102  [MISCREG_HPMCOUNTER29] = "HPMCOUNTER29",
103  [MISCREG_HPMCOUNTER30] = "HPMCOUNTER30",
104  [MISCREG_HPMCOUNTER31] = "HPMCOUNTER31",
105  [MISCREG_HPMEVENT03] = "HPMEVENT03",
106  [MISCREG_HPMEVENT04] = "HPMEVENT04",
107  [MISCREG_HPMEVENT05] = "HPMEVENT05",
108  [MISCREG_HPMEVENT06] = "HPMEVENT06",
109  [MISCREG_HPMEVENT07] = "HPMEVENT07",
110  [MISCREG_HPMEVENT08] = "HPMEVENT08",
111  [MISCREG_HPMEVENT09] = "HPMEVENT09",
112  [MISCREG_HPMEVENT10] = "HPMEVENT10",
113  [MISCREG_HPMEVENT11] = "HPMEVENT11",
114  [MISCREG_HPMEVENT12] = "HPMEVENT12",
115  [MISCREG_HPMEVENT13] = "HPMEVENT13",
116  [MISCREG_HPMEVENT14] = "HPMEVENT14",
117  [MISCREG_HPMEVENT15] = "HPMEVENT15",
118  [MISCREG_HPMEVENT16] = "HPMEVENT16",
119  [MISCREG_HPMEVENT17] = "HPMEVENT17",
120  [MISCREG_HPMEVENT18] = "HPMEVENT18",
121  [MISCREG_HPMEVENT19] = "HPMEVENT19",
122  [MISCREG_HPMEVENT20] = "HPMEVENT20",
123  [MISCREG_HPMEVENT21] = "HPMEVENT21",
124  [MISCREG_HPMEVENT22] = "HPMEVENT22",
125  [MISCREG_HPMEVENT23] = "HPMEVENT23",
126  [MISCREG_HPMEVENT24] = "HPMEVENT24",
127  [MISCREG_HPMEVENT25] = "HPMEVENT25",
128  [MISCREG_HPMEVENT26] = "HPMEVENT26",
129  [MISCREG_HPMEVENT27] = "HPMEVENT27",
130  [MISCREG_HPMEVENT28] = "HPMEVENT28",
131  [MISCREG_HPMEVENT29] = "HPMEVENT29",
132  [MISCREG_HPMEVENT30] = "HPMEVENT30",
133  [MISCREG_HPMEVENT31] = "HPMEVENT31",
134  [MISCREG_TSELECT] = "TSELECT",
135  [MISCREG_TDATA1] = "TDATA1",
136  [MISCREG_TDATA2] = "TDATA2",
137  [MISCREG_TDATA3] = "TDATA3",
138  [MISCREG_DCSR] = "DCSR",
139  [MISCREG_DPC] = "DPC",
140  [MISCREG_DSCRATCH] = "DSCRATCH",
141 
142  [MISCREG_MEDELEG] = "MEDELEG",
143  [MISCREG_MIDELEG] = "MIDELEG",
144  [MISCREG_MTVEC] = "MTVEC",
145  [MISCREG_MCOUNTEREN] = "MCOUNTEREN",
146  [MISCREG_MSCRATCH] = "MSCRATCH",
147  [MISCREG_MEPC] = "MEPC",
148  [MISCREG_MCAUSE] = "MCAUSE",
149  [MISCREG_MTVAL] = "MTVAL",
150  [MISCREG_PMPCFG0] = "PMPCFG0",
151  // pmpcfg1 rv32 only
152  [MISCREG_PMPCFG2] = "PMPCFG2",
153  // pmpcfg3 rv32 only
154  [MISCREG_PMPADDR00] = "PMPADDR00",
155  [MISCREG_PMPADDR01] = "PMPADDR01",
156  [MISCREG_PMPADDR02] = "PMPADDR02",
157  [MISCREG_PMPADDR03] = "PMPADDR03",
158  [MISCREG_PMPADDR04] = "PMPADDR04",
159  [MISCREG_PMPADDR05] = "PMPADDR05",
160  [MISCREG_PMPADDR06] = "PMPADDR06",
161  [MISCREG_PMPADDR07] = "PMPADDR07",
162  [MISCREG_PMPADDR08] = "PMPADDR08",
163  [MISCREG_PMPADDR09] = "PMPADDR09",
164  [MISCREG_PMPADDR10] = "PMPADDR10",
165  [MISCREG_PMPADDR11] = "PMPADDR11",
166  [MISCREG_PMPADDR12] = "PMPADDR12",
167  [MISCREG_PMPADDR13] = "PMPADDR13",
168  [MISCREG_PMPADDR14] = "PMPADDR14",
169  [MISCREG_PMPADDR15] = "PMPADDR15",
170 
171  [MISCREG_SEDELEG] = "SEDELEG",
172  [MISCREG_SIDELEG] = "SIDELEG",
173  [MISCREG_STVEC] = "STVEC",
174  [MISCREG_SCOUNTEREN] = "SCOUNTEREN",
175  [MISCREG_SSCRATCH] = "SSCRATCH",
176  [MISCREG_SEPC] = "SEPC",
177  [MISCREG_SCAUSE] = "SCAUSE",
178  [MISCREG_STVAL] = "STVAL",
179  [MISCREG_SATP] = "SATP",
180 
181  [MISCREG_UTVEC] = "UTVEC",
182  [MISCREG_USCRATCH] = "USCRATCH",
183  [MISCREG_UEPC] = "UEPC",
184  [MISCREG_UCAUSE] = "UCAUSE",
185  [MISCREG_UTVAL] = "UTVAL",
186  [MISCREG_FFLAGS] = "FFLAGS",
187  [MISCREG_FRM] = "FRM",
188 
189  [MISCREG_NMIVEC] = "NMIVEC",
190  [MISCREG_NMIE] = "NMIE",
191  [MISCREG_NMIP] = "NMIP",
192 }};
193 
194 namespace
195 {
196 
197 /* Not applicable to RISCV */
198 RegClass vecRegClass(VecRegClass, VecRegClassName, 1, debug::IntRegs);
201  debug::IntRegs);
202 RegClass ccRegClass(CCRegClass, CCRegClassName, 0, debug::IntRegs);
203 
204 } // anonymous namespace
205 
206 ISA::ISA(const Params &p) :
207  BaseISA(p), checkAlignment(p.check_alignment)
208 {
209  _regClasses.push_back(&intRegClass);
210  _regClasses.push_back(&floatRegClass);
211  _regClasses.push_back(&vecRegClass);
212  _regClasses.push_back(&vecElemClass);
213  _regClasses.push_back(&vecPredRegClass);
214  _regClasses.push_back(&ccRegClass);
215  _regClasses.push_back(&miscRegClass);
216 
217  miscRegFile.resize(NUM_MISCREGS);
218  clear();
219 }
220 
221 bool ISA::inUserMode() const
222 {
223  return miscRegFile[MISCREG_PRV] == PRV_U;
224 }
225 
226 void
228 {
229  // First loop through the integer registers.
230  for (auto &id: intRegClass)
231  tc->setReg(id, src->getReg(id));
232 
233  // Second loop through the float registers.
234  for (auto &id: floatRegClass)
235  tc->setReg(id, src->getReg(id));
236 
237  // Lastly copy PC/NPC
238  tc->pcState(src->pcState());
239 }
240 
242 {
243  std::fill(miscRegFile.begin(), miscRegFile.end(), 0);
244 
246  miscRegFile[MISCREG_ISA] = (2ULL << MXL_OFFSET) | 0x14112D;
250  miscRegFile[MISCREG_STATUS] = (2ULL << UXL_OFFSET) | (2ULL << SXL_OFFSET) |
251  (1ULL << FS_OFFSET);
254  // don't set it to zero; software may try to determine the supported
255  // triggers, starting at zero. simply set a different value here.
257  // NMI is always enabled.
259 }
260 
261 bool
262 ISA::hpmCounterEnabled(int misc_reg) const
263 {
264  int hpmcounter = misc_reg - MISCREG_CYCLE;
265  if (hpmcounter < 0 || hpmcounter > 31)
266  panic("Illegal HPM counter %d\n", hpmcounter);
267  int counteren;
268  switch (readMiscRegNoEffect(MISCREG_PRV)) {
269  case PRV_M:
270  return true;
271  case PRV_S:
272  counteren = MISCREG_MCOUNTEREN;
273  break;
274  case PRV_U:
275  counteren = MISCREG_SCOUNTEREN;
276  break;
277  default:
278  panic("Unknown privilege level %d\n", miscRegFile[MISCREG_PRV]);
279  return false;
280  }
281  return (miscRegFile[counteren] & (1ULL << (hpmcounter))) > 0;
282 }
283 
284 RegVal
286 {
287  // Illegal CSR
288  panic_if(idx > NUM_MISCREGS, "Illegal CSR index %#x\n", idx);
289  DPRINTF(RiscvMisc, "Reading MiscReg %s (%d): %#x.\n",
290  MiscRegNames[idx], idx, miscRegFile[idx]);
291  return miscRegFile[idx];
292 }
293 
294 RegVal
296 {
297  switch (idx) {
298  case MISCREG_HARTID:
299  return tc->contextId();
300  case MISCREG_CYCLE:
302  DPRINTF(RiscvMisc, "Cycle counter at: %llu.\n",
303  tc->getCpuPtr()->curCycle());
304  return tc->getCpuPtr()->curCycle();
305  } else {
306  warn("Cycle counter disabled.\n");
307  return 0;
308  }
309  case MISCREG_TIME:
311  DPRINTF(RiscvMisc, "Wall-clock counter at: %llu.\n",
312  std::time(nullptr));
314  } else {
315  warn("Wall clock disabled.\n");
316  return 0;
317  }
318  case MISCREG_INSTRET:
320  DPRINTF(RiscvMisc, "Instruction counter at: %llu.\n",
321  tc->getCpuPtr()->totalInsts());
322  return tc->getCpuPtr()->totalInsts();
323  } else {
324  warn("Instruction counter disabled.\n");
325  return 0;
326  }
327  case MISCREG_IP:
328  {
329  auto ic = dynamic_cast<RiscvISA::Interrupts *>(
331  return ic->readIP();
332  }
333  case MISCREG_IE:
334  {
335  auto ic = dynamic_cast<RiscvISA::Interrupts *>(
337  return ic->readIE();
338  }
339  case MISCREG_SEPC:
340  case MISCREG_MEPC:
341  {
342  auto misa = readMiscRegNoEffect(MISCREG_ISA);
343  auto val = readMiscRegNoEffect(idx);
344  // if compressed instructions are disabled, epc[1] is set to 0
345  if ((misa & ISA_EXT_C_MASK) == 0)
346  return mbits(val, 63, 2);
347  // epc[0] is always 0
348  else
349  return mbits(val, 63, 1);
350  }
351  case MISCREG_STATUS:
352  {
353  // Updating the SD bit.
354  // . Per RISC-V ISA Manual, vol II, section 3.1.6.6, page 26,
355  // the SD bit is a read-only bit indicating whether any of
356  // FS, VS, and XS fields being in the respective dirty state.
357  // . Per section 3.1.6, page 20, the SD bit is the most
358  // significant bit of the MSTATUS CSR for both RV32 and RV64.
359  // . Per section 3.1.6.6, page 29, the explicit formula for
360  // updating the SD is,
361  // SD = ((FS==DIRTY) | (XS==DIRTY) | (VS==DIRTY))
362  // . Ideally, we want to update the SD after every relevant
363  // instruction, however, lazily updating the Status register
364  // upon its read produces the same effect as well.
365  STATUS status = readMiscRegNoEffect(idx);
366  uint64_t sd_bit = \
367  (status.xs == 3) || (status.fs == 3) || (status.vs == 3);
368  // We assume RV64 here, updating the SD bit at index 63.
369  status.sd = sd_bit;
371 
372  return readMiscRegNoEffect(idx);
373  }
374  default:
375  // Try reading HPM counters
376  // As a placeholder, all HPM counters are just cycle counters
377  if (idx >= MISCREG_HPMCOUNTER03 &&
378  idx <= MISCREG_HPMCOUNTER31) {
379  if (hpmCounterEnabled(idx)) {
380  DPRINTF(RiscvMisc, "HPM counter %d: %llu.\n",
381  idx - MISCREG_CYCLE, tc->getCpuPtr()->curCycle());
382  return tc->getCpuPtr()->curCycle();
383  } else {
384  warn("HPM counter %d disabled.\n", idx - MISCREG_CYCLE);
385  return 0;
386  }
387  }
388  return readMiscRegNoEffect(idx);
389  }
390 }
391 
392 void
394 {
395  // Illegal CSR
396  panic_if(idx > NUM_MISCREGS, "Illegal CSR index %#x\n", idx);
397  DPRINTF(RiscvMisc, "Setting MiscReg %s (%d) to %#x.\n",
398  MiscRegNames[idx], idx, val);
399  miscRegFile[idx] = val;
400 }
401 
402 void
404 {
405  if (idx >= MISCREG_CYCLE && idx <= MISCREG_HPMCOUNTER31) {
406  // Ignore writes to HPM counters for now
407  warn("Ignoring write to %s.\n", CSRData.at(idx).name);
408  } else {
409  switch (idx) {
410 
411  // From section 3.7.1 of RISCV priv. specs
412  // V1.12, the odd-numbered configuration
413  // registers are illegal for RV64 and
414  // each 64 bit CFG register hold configurations
415  // for 8 PMP entries.
416 
417  case MISCREG_PMPCFG0:
418  case MISCREG_PMPCFG2:
419  {
420  // PMP registers should only be modified in M mode
422 
423  // Specs do not seem to mention what should be
424  // configured first, cfg or address regs!
425  // qemu seems to update the tables when
426  // pmp addr regs are written (with the assumption
427  // that cfg regs are already written)
428 
429  for (int i=0; i < sizeof(val); i++) {
430 
431  uint8_t cfg_val = (val >> (8*i)) & 0xff;
432  auto mmu = dynamic_cast<RiscvISA::MMU *>
433  (tc->getMMUPtr());
434 
435  // Form pmp_index using the index i and
436  // PMPCFG register number
437  // Note: MISCREG_PMPCFG2 - MISCREG_PMPCFG0 = 1
438  // 8*(idx-MISCREG_PMPCFG0) will be useful
439  // if a system contains more than 16 PMP entries
440  uint32_t pmp_index = i+(8*(idx-MISCREG_PMPCFG0));
441  mmu->getPMP()->pmpUpdateCfg(pmp_index,cfg_val);
442  }
443 
444  setMiscRegNoEffect(idx, val);
445  }
446  break;
448  {
449  // PMP registers should only be modified in M mode
451 
452  auto mmu = dynamic_cast<RiscvISA::MMU *>
453  (tc->getMMUPtr());
454  uint32_t pmp_index = idx-MISCREG_PMPADDR00;
455  mmu->getPMP()->pmpUpdateAddr(pmp_index, val);
456 
457  setMiscRegNoEffect(idx, val);
458  }
459  break;
460 
461  case MISCREG_IP:
462  {
463  auto ic = dynamic_cast<RiscvISA::Interrupts *>(
465  ic->setIP(val);
466  }
467  break;
468  case MISCREG_IE:
469  {
470  auto ic = dynamic_cast<RiscvISA::Interrupts *>(
472  ic->setIE(val);
473  }
474  break;
475  case MISCREG_SATP:
476  {
477  // we only support bare and Sv39 mode; setting a different mode
478  // shall have no effect (see 4.1.12 in priv ISA manual)
479  SATP cur_val = readMiscRegNoEffect(idx);
480  SATP new_val = val;
481  if (new_val.mode != AddrXlateMode::BARE &&
482  new_val.mode != AddrXlateMode::SV39)
483  new_val.mode = cur_val.mode;
484  setMiscRegNoEffect(idx, new_val);
485  }
486  break;
487  case MISCREG_TSELECT:
488  {
489  // we don't support debugging, so always set a different value
490  // than written
491  setMiscRegNoEffect(idx, val + 1);
492  }
493  break;
494  case MISCREG_ISA:
495  {
496  auto cur_val = readMiscRegNoEffect(idx);
497  // only allow to disable compressed instructions
498  // if the following instruction is 4-byte aligned
499  if ((val & ISA_EXT_C_MASK) == 0 &&
501  2, 0) != 0) {
502  val |= cur_val & ISA_EXT_C_MASK;
503  }
504  setMiscRegNoEffect(idx, val);
505  }
506  break;
507  case MISCREG_STATUS:
508  {
509  // SXL and UXL are hard-wired to 64 bit
510  auto cur = readMiscRegNoEffect(idx);
512  val |= cur & (STATUS_SXL_MASK | STATUS_UXL_MASK);
513  setMiscRegNoEffect(idx, val);
514  }
515  break;
516  default:
517  setMiscRegNoEffect(idx, val);
518  }
519  }
520 }
521 
522 void
524 {
525  DPRINTF(Checkpoint, "Serializing Riscv Misc Registers\n");
527 }
528 
529 void
531 {
532  DPRINTF(Checkpoint, "Unserializing Riscv Misc Registers\n");
534 }
535 
536 const int WARN_FAILURE = 10000;
537 
539 std::unordered_map<int, Addr> load_reservation_addrs;
540 
541 void
543 {
544  Addr& load_reservation_addr = load_reservation_addrs[tc->contextId()];
545 
546  if (load_reservation_addr == INVALID_RESERVATION_ADDR)
547  return;
548  Addr snoop_addr = pkt->getAddr() & cacheBlockMask;
549  DPRINTF(LLSC, "Locked snoop on address %x.\n", snoop_addr);
550  if ((load_reservation_addr & cacheBlockMask) == snoop_addr)
551  load_reservation_addr = INVALID_RESERVATION_ADDR;
552 }
553 
554 
555 void
557 {
558  Addr& load_reservation_addr = load_reservation_addrs[tc->contextId()];
559 
560  load_reservation_addr = req->getPaddr() & ~0xF;
561  DPRINTF(LLSC, "[cid:%d]: Reserved address %x.\n",
562  req->contextId(), req->getPaddr() & ~0xF);
563 }
564 
565 bool
566 ISA::handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask)
567 {
568  Addr& load_reservation_addr = load_reservation_addrs[tc->contextId()];
569  bool lr_addr_empty = (load_reservation_addr == INVALID_RESERVATION_ADDR);
570 
571  // Normally RISC-V uses zero to indicate success and nonzero to indicate
572  // failure (right now only 1 is reserved), but in gem5 zero indicates
573  // failure and one indicates success, so here we conform to that (it should
574  // be switched in the instruction's implementation)
575 
576  DPRINTF(LLSC, "[cid:%d]: load_reservation_addrs empty? %s.\n",
577  req->contextId(),
578  lr_addr_empty ? "yes" : "no");
579  if (!lr_addr_empty) {
580  DPRINTF(LLSC, "[cid:%d]: addr = %x.\n", req->contextId(),
581  req->getPaddr() & ~0xF);
582  DPRINTF(LLSC, "[cid:%d]: last locked addr = %x.\n", req->contextId(),
583  load_reservation_addr);
584  }
585  if (lr_addr_empty
586  || load_reservation_addr != ((req->getPaddr() & ~0xF))) {
587  req->setExtraData(0);
588  int stCondFailures = tc->readStCondFailures();
589  tc->setStCondFailures(++stCondFailures);
590  if (stCondFailures % WARN_FAILURE == 0) {
591  warn("%i: context %d: %d consecutive SC failures.\n",
592  curTick(), tc->contextId(), stCondFailures);
593  }
594  return false;
595  }
596  if (req->isUncacheable()) {
597  req->setExtraData(2);
598  }
599 
600  return true;
601 }
602 
603 void
605 {
606  tc->getCpuPtr()->wakeup(tc->threadId());
607 }
608 
609 } // namespace RiscvISA
610 } // namespace gem5
611 
612 std::ostream &
614 {
615  switch (pm) {
617  return os << "PRV_U";
619  return os << "PRV_S";
621  return os << "PRV_M";
622  }
623  return os << "PRV_<invalid>";
624 }
#define DPRINTF(x,...)
Definition: trace.hh:186
virtual Counter totalInsts() const =0
virtual void wakeup(ThreadID tid)=0
BaseInterrupts * getInterruptController(ThreadID tid)
Definition: base.hh:224
ThreadContext * tc
Definition: isa.hh:65
RegClasses _regClasses
Definition: isa.hh:67
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Target & as()
Definition: pcstate.hh:72
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
void setMiscReg(RegIndex idx, RegVal val) override
Definition: isa.cc:403
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
Definition: isa.cc:542
RegVal readMiscReg(RegIndex idx) override
Definition: isa.cc:295
void globalClearExclusive() override
Definition: isa.cc:604
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: isa.cc:523
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
Definition: isa.cc:393
RegVal readMiscRegNoEffect(RegIndex idx) const override
Definition: isa.cc:285
bool hpmCounterEnabled(int counter) const
Definition: isa.cc:262
void copyRegsFrom(ThreadContext *src) override
Definition: isa.cc:227
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
Definition: isa.cc:566
void clear() override
Definition: isa.cc:241
std::vector< RegVal > miscRegFile
Definition: isa.hh:73
bool inUserMode() const override
Definition: isa.cc:221
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: isa.cc:530
RiscvISAParams Params
Definition: isa.hh:79
ISA(const Params &p)
Definition: isa.cc:206
void handleLockedRead(const RequestPtr &req) override
Definition: isa.cc:556
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId &reg) const
virtual const PCStateBase & pcState() const =0
virtual void setReg(const RegId &reg, RegVal val)
virtual BaseCPU * getCpuPtr()=0
virtual void setStCondFailures(unsigned sc_failures)=0
virtual unsigned readStCondFailures() const =0
virtual int threadId() const =0
virtual ContextID contextId() const =0
virtual BaseMMU * getMMUPtr()=0
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
constexpr T mbits(T val, unsigned first, unsigned last)
Mask off the given bits in place like bits() but without shifting.
Definition: bitfield.hh:103
#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 UNSERIALIZE_CONTAINER(member)
Definition: serialize.hh:634
#define SERIALIZE_CONTAINER(member)
Definition: serialize.hh:626
#define warn(...)
Definition: logging.hh:246
constexpr RegClass ccRegClass(CCRegClass, CCRegClassName, cc_reg::NumRegs, debug::CCRegs)
constexpr RegClass vecElemClass
Definition: vec.hh:105
Bitfield< 5, 0 > status
Definition: misc_types.hh:429
constexpr RegClass vecPredRegClass
Definition: vec.hh:109
constexpr RegClass vecRegClass
Definition: vec.hh:101
Bitfield< 0 > p
constexpr RegClass floatRegClass(FloatRegClass, FloatRegClassName, float_reg::NumRegs, debug::FloatRegs)
const off_t UXL_OFFSET
Definition: misc.hh:595
const off_t SXL_OFFSET
Definition: misc.hh:594
const int WARN_FAILURE
Definition: isa.cc:536
const off_t FS_OFFSET
Definition: misc.hh:596
Bitfield< 2 > i
const RegVal STATUS_SXL_MASK
Definition: misc.hh:605
const RegVal STATUS_UXL_MASK
Definition: misc.hh:606
const std::unordered_map< int, CSRMetadata > CSRData
Definition: misc.hh:381
constexpr RegClass intRegClass(IntRegClass, IntRegClassName, int_reg::NumRegs, debug::IntRegs)
const std::array< const char *, NUM_MISCREGS > MiscRegNames
Definition: isa.cc:63
const RegVal ISA_EXT_C_MASK
Definition: misc.hh:601
@ MISCREG_PMPADDR11
Definition: misc.hh:168
@ MISCREG_HPMCOUNTER09
Definition: misc.hh:85
@ MISCREG_MTVEC
Definition: misc.hh:147
@ MISCREG_HPMEVENT31
Definition: misc.hh:136
@ MISCREG_IMPID
Definition: misc.hh:71
@ MISCREG_HPMEVENT07
Definition: misc.hh:112
@ MISCREG_UTVEC
Definition: misc.hh:184
@ MISCREG_HPMCOUNTER16
Definition: misc.hh:92
@ MISCREG_HPMCOUNTER19
Definition: misc.hh:95
@ MISCREG_PMPADDR12
Definition: misc.hh:169
@ MISCREG_HPMCOUNTER07
Definition: misc.hh:83
@ MISCREG_HPMEVENT29
Definition: misc.hh:134
@ MISCREG_HPMCOUNTER26
Definition: misc.hh:102
@ MISCREG_PMPADDR05
Definition: misc.hh:162
@ MISCREG_HPMCOUNTER13
Definition: misc.hh:89
@ MISCREG_PMPADDR10
Definition: misc.hh:167
@ MISCREG_SIDELEG
Definition: misc.hh:175
@ MISCREG_NMIE
Definition: misc.hh:198
@ MISCREG_PMPADDR14
Definition: misc.hh:171
@ MISCREG_PMPADDR09
Definition: misc.hh:166
@ MISCREG_HPMEVENT06
Definition: misc.hh:111
@ MISCREG_TSELECT
Definition: misc.hh:137
@ MISCREG_MSCRATCH
Definition: misc.hh:149
@ MISCREG_ISA
Definition: misc.hh:68
@ MISCREG_NMIVEC
Definition: misc.hh:196
@ MISCREG_STVEC
Definition: misc.hh:176
@ MISCREG_HPMEVENT21
Definition: misc.hh:126
@ MISCREG_SCAUSE
Definition: misc.hh:180
@ MISCREG_UEPC
Definition: misc.hh:186
@ MISCREG_STATUS
Definition: misc.hh:73
@ MISCREG_HPMEVENT12
Definition: misc.hh:117
@ MISCREG_HPMCOUNTER25
Definition: misc.hh:101
@ MISCREG_SATP
Definition: misc.hh:182
@ MISCREG_PMPADDR04
Definition: misc.hh:161
@ MISCREG_MCOUNTEREN
Definition: misc.hh:148
@ MISCREG_UTVAL
Definition: misc.hh:188
@ MISCREG_PMPADDR00
Definition: misc.hh:157
@ MISCREG_HPMCOUNTER22
Definition: misc.hh:98
@ MISCREG_HPMEVENT17
Definition: misc.hh:122
@ MISCREG_MCAUSE
Definition: misc.hh:151
@ MISCREG_UCAUSE
Definition: misc.hh:187
@ MISCREG_HPMEVENT20
Definition: misc.hh:125
@ MISCREG_MEDELEG
Definition: misc.hh:145
@ MISCREG_USCRATCH
Definition: misc.hh:185
@ MISCREG_HPMEVENT25
Definition: misc.hh:130
@ MISCREG_HPMCOUNTER11
Definition: misc.hh:87
@ MISCREG_HPMEVENT03
Definition: misc.hh:108
@ MISCREG_PRV
Definition: misc.hh:67
@ MISCREG_IP
Definition: misc.hh:74
@ MISCREG_TDATA3
Definition: misc.hh:140
@ MISCREG_HPMEVENT13
Definition: misc.hh:118
@ MISCREG_PMPADDR13
Definition: misc.hh:170
@ MISCREG_HPMCOUNTER12
Definition: misc.hh:88
@ MISCREG_MTVAL
Definition: misc.hh:152
@ MISCREG_HPMEVENT04
Definition: misc.hh:109
@ MISCREG_HPMEVENT08
Definition: misc.hh:113
@ MISCREG_IE
Definition: misc.hh:75
@ MISCREG_HPMEVENT19
Definition: misc.hh:124
@ MISCREG_DSCRATCH
Definition: misc.hh:143
@ NUM_MISCREGS
Definition: misc.hh:202
@ MISCREG_HPMEVENT30
Definition: misc.hh:135
@ MISCREG_SEDELEG
Definition: misc.hh:174
@ MISCREG_PMPADDR06
Definition: misc.hh:163
@ MISCREG_HPMCOUNTER21
Definition: misc.hh:97
@ MISCREG_PMPADDR03
Definition: misc.hh:160
@ MISCREG_SCOUNTEREN
Definition: misc.hh:177
@ MISCREG_HPMCOUNTER06
Definition: misc.hh:82
@ MISCREG_HPMCOUNTER28
Definition: misc.hh:104
@ MISCREG_PMPADDR02
Definition: misc.hh:159
@ MISCREG_MIDELEG
Definition: misc.hh:146
@ MISCREG_HPMCOUNTER30
Definition: misc.hh:106
@ MISCREG_HPMCOUNTER14
Definition: misc.hh:90
@ MISCREG_HPMEVENT10
Definition: misc.hh:115
@ MISCREG_HPMEVENT26
Definition: misc.hh:131
@ MISCREG_HPMEVENT18
Definition: misc.hh:123
@ MISCREG_MEPC
Definition: misc.hh:150
@ MISCREG_HPMEVENT23
Definition: misc.hh:128
@ MISCREG_INSTRET
Definition: misc.hh:78
@ MISCREG_HARTID
Definition: misc.hh:72
@ MISCREG_FFLAGS
Definition: misc.hh:189
@ MISCREG_HPMCOUNTER20
Definition: misc.hh:96
@ MISCREG_HPMEVENT09
Definition: misc.hh:114
@ MISCREG_HPMCOUNTER04
Definition: misc.hh:80
@ MISCREG_PMPADDR07
Definition: misc.hh:164
@ MISCREG_TDATA1
Definition: misc.hh:138
@ MISCREG_HPMEVENT16
Definition: misc.hh:121
@ MISCREG_HPMCOUNTER18
Definition: misc.hh:94
@ MISCREG_TIME
Definition: misc.hh:77
@ MISCREG_SSCRATCH
Definition: misc.hh:178
@ MISCREG_HPMEVENT14
Definition: misc.hh:119
@ MISCREG_HPMCOUNTER05
Definition: misc.hh:81
@ MISCREG_SEPC
Definition: misc.hh:179
@ MISCREG_HPMCOUNTER17
Definition: misc.hh:93
@ MISCREG_HPMCOUNTER27
Definition: misc.hh:103
@ MISCREG_HPMCOUNTER24
Definition: misc.hh:100
@ MISCREG_HPMCOUNTER23
Definition: misc.hh:99
@ MISCREG_CYCLE
Definition: misc.hh:76
@ MISCREG_HPMCOUNTER15
Definition: misc.hh:91
@ MISCREG_HPMEVENT24
Definition: misc.hh:129
@ MISCREG_HPMCOUNTER10
Definition: misc.hh:86
@ MISCREG_HPMCOUNTER29
Definition: misc.hh:105
@ MISCREG_STVAL
Definition: misc.hh:181
@ MISCREG_VENDORID
Definition: misc.hh:69
@ MISCREG_PMPADDR01
Definition: misc.hh:158
@ MISCREG_HPMEVENT27
Definition: misc.hh:132
@ MISCREG_HPMEVENT15
Definition: misc.hh:120
@ MISCREG_HPMEVENT05
Definition: misc.hh:110
@ MISCREG_ARCHID
Definition: misc.hh:70
@ MISCREG_DCSR
Definition: misc.hh:141
@ MISCREG_HPMEVENT11
Definition: misc.hh:116
@ MISCREG_HPMCOUNTER31
Definition: misc.hh:107
@ MISCREG_TDATA2
Definition: misc.hh:139
@ MISCREG_PMPADDR08
Definition: misc.hh:165
@ MISCREG_HPMCOUNTER03
Definition: misc.hh:79
@ MISCREG_PMPADDR15
Definition: misc.hh:172
@ MISCREG_HPMEVENT28
Definition: misc.hh:133
@ MISCREG_HPMEVENT22
Definition: misc.hh:127
@ MISCREG_PMPCFG0
Definition: misc.hh:153
@ MISCREG_HPMCOUNTER08
Definition: misc.hh:84
@ MISCREG_NMIP
Definition: misc.hh:200
@ MISCREG_PMPCFG2
Definition: misc.hh:155
const Addr INVALID_RESERVATION_ADDR
Definition: isa.cc:538
std::unordered_map< int, Addr > load_reservation_addrs
Definition: isa.cc:539
constexpr RegClass miscRegClass(MiscRegClass, MiscRegClassName, NUM_MISCREGS, debug::MiscRegs)
Bitfield< 17 > os
Definition: misc.hh:810
Bitfield< 63 > val
Definition: misc.hh:776
bool ic(TxDesc *d)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
constexpr char CCRegClassName[]
Definition: reg_class.hh:78
uint16_t RegIndex
Definition: types.hh:176
constexpr char VecPredRegClassName[]
Definition: reg_class.hh:77
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
constexpr char VecRegClassName[]
Definition: reg_class.hh:75
uint64_t RegVal
Definition: types.hh:173
@ VecPredRegClass
Definition: reg_class.hh:66
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:67
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:65
constexpr char VecElemClassName[]
Definition: reg_class.hh:76
Declaration of the Packet class.
PMP header file.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::ostream & operator<<(std::ostream &os, gem5::RiscvISA::PrivilegeMode pm)
Definition: isa.cc:613

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