gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
semihosting.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 2019 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  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_ARM_SEMIHOSTING_HH__
39 #define __ARCH_ARM_SEMIHOSTING_HH__
40 
41 #include <cstdio>
42 #include <functional>
43 #include <map>
44 #include <memory>
45 #include <utility>
46 #include <vector>
47 
48 #include "arch/arm/intregs.hh"
49 #include "arch/arm/utility.hh"
50 #include "cpu/thread_context.hh"
51 #include "mem/port_proxy.hh"
52 #include "sim/guest_abi.hh"
53 #include "sim/sim_object.hh"
54 
55 struct ArmSemihostingParams;
56 class SerialDevice;
57 
72 class ArmSemihosting : public SimObject
73 {
74  public:
75 
76  enum {
77  // Standard ARM immediate values which trigger semihosting.
78  T32Imm = 0xAB,
79  A32Imm = 0x123456,
80  A64Imm = 0xF000,
81 
82  // The immediate value which enables gem5 semihosting calls. Use the
83  // standard value for thumb.
84  Gem5Imm = 0x5D57
85  };
86 
87  static PortProxy &portProxy(ThreadContext *tc);
88 
89  struct AbiBase
90  {
91  template <typename Arg>
92  class StateBase
93  {
94  private:
96  ByteOrder endian;
97 
98  public:
99  StateBase(const ThreadContext *tc, Addr arg_pointer) :
100  argPointer(arg_pointer), endian(ArmISA::byteOrder(tc))
101  {}
102 
103  /*
104  * These two methods are used to both read an argument or its
105  * address, and to move position on to the next location. Normally
106  * State would be more passive, but since it behaves almost the
107  * same no matter what the argument type is we can simplify and
108  * consolidate a little bit by centralizing these methods.
109  */
110 
111  // Return the address of an argument slot and move past it.
112  Addr
114  {
115  Addr addr = argPointer;
116  argPointer += sizeof(Arg);
117  return addr;
118  }
119 
120  // Read the value in an argument slot and move past it.
121  Arg
123  {
124  Arg arg = ArmSemihosting::portProxy(tc).read<Arg>(
125  argPointer, endian);
126  argPointer += sizeof(Arg);
127  return arg;
128  }
129 
130  using ArgType = Arg;
131  };
132  };
133 
134  struct Abi64 : public AbiBase
135  {
136  using UintPtr = uint64_t;
137 
138  class State : public StateBase<uint64_t>
139  {
140  public:
141  // For 64 bit semihosting, the params are pointer to by X1.
142  explicit State(const ThreadContext *tc) :
143  StateBase<uint64_t>(tc, tc->readIntReg(ArmISA::INTREG_X1))
144  {}
145  };
146  };
147 
148  struct Abi32 : public AbiBase
149  {
150  using UintPtr = uint32_t;
151 
152  class State : public StateBase<uint64_t>
153  {
154  public:
155  // For 32 bit semihosting, the params are pointer to by R1.
156  explicit State(const ThreadContext *tc) :
157  StateBase<uint64_t>(tc, tc->readIntReg(ArmISA::INTREG_R1))
158  {}
159  };
160  };
161 
162  // Use this argument type when you need to modify an argument in place.
163  // This will give you the address of the argument itself and the size of
164  // each argument slot, rather than the actual value of the argument.
165  struct InPlaceArg
166  {
168  size_t size;
169 
170  InPlaceArg(Addr _addr, size_t _size) : addr(_addr), size(_size) {}
171 
172  // A helper function to read the argument since the guest ABI mechanism
173  // didn't do that for us.
174  uint64_t
175  read(ThreadContext *tc, ByteOrder endian)
176  {
177  auto &proxy = ArmSemihosting::portProxy(tc);
178  if (size == 8)
179  return proxy.read<uint64_t>(addr, endian);
180  else if (size == 4)
181  return proxy.read<uint32_t>(addr, endian);
182  else
183  panic("Unexpected semihosting argument size %d.", size);
184  }
185 
186  // A helper function to write to the argument's slot in the params.
187  void
188  write(ThreadContext *tc, uint64_t val, ByteOrder endian)
189  {
190  auto &proxy = ArmSemihosting::portProxy(tc);
191  if (size == 8)
192  proxy.write<uint64_t>(addr, val, endian);
193  else if (size == 4)
194  proxy.write<uint32_t>(addr, val, endian);
195  else
196  panic("Unexpected semihosting argument size %d.", size);
197  }
198  };
199 
200  enum Operation {
201  SYS_OPEN = 0x01,
202  SYS_CLOSE = 0x02,
203  SYS_WRITEC = 0x03,
204  SYS_WRITE0 = 0x04,
205  SYS_WRITE = 0x05,
206  SYS_READ = 0x06,
207  SYS_READC = 0x07,
208  SYS_ISERROR = 0x08,
209  SYS_ISTTY = 0x09,
210  SYS_SEEK = 0x0A,
211  SYS_FLEN = 0x0C,
212  SYS_TMPNAM = 0x0D,
213  SYS_REMOVE = 0x0E,
214  SYS_RENAME = 0x0F,
215  SYS_CLOCK = 0x10,
216  SYS_TIME = 0x11,
217  SYS_SYSTEM = 0x12,
218  SYS_ERRNO = 0x13,
220  SYS_HEAPINFO = 0x16,
221  SYS_EXIT = 0x18,
223  SYS_ELAPSED = 0x30,
224  SYS_TICKFREQ = 0x31,
225 
227 
229  };
230 
231  ArmSemihosting(const ArmSemihostingParams &p);
232 
234  bool call64(ThreadContext *tc, bool gem5_ops);
236  bool call32(ThreadContext *tc, bool gem5_ops);
237 
238  public: // SimObject and related interfaces
239  void serialize(CheckpointOut &cp) const override;
240  void unserialize(CheckpointIn &cp) override;
241 
242  protected: // Configuration
243  const std::string cmdLine;
246 
251  const time_t timeBase;
252 
254  const unsigned tickShift;
255 
256  protected: // Internal state
257  typedef uint64_t SemiErrno;
259 
260  protected: // File IO
274  class FileBase : public Serializable
275  {
276  public:
277  FileBase(ArmSemihosting &_parent, const char *name, const char *_mode)
278  : parent(_parent), _name(name), mode(_mode) {}
279  virtual ~FileBase() {};
280 
281  FileBase() = delete;
282  FileBase(FileBase &) = delete;
283 
284  static std::unique_ptr<FileBase> create(
285  ArmSemihosting &parent, const std::string &fname,
286  const char *mode);
287  static std::unique_ptr<FileBase> create(
288  ArmSemihosting &parent, CheckpointIn &cp, const std::string &sec);
289 
290  void serialize(CheckpointOut &cp) const override;
291  void unserialize(CheckpointIn &cp) override;
292 
293  const std::string &fileName() { return _name; }
294 
295  public:
311  virtual int64_t open() { return 0; }
312 
318  virtual int64_t close() { return 0; }
319 
325  virtual bool isTTY() const { return false; }
326 
332  virtual int64_t read(uint8_t *buffer, uint64_t size);
333 
339  virtual int64_t write(const uint8_t *buffer, uint64_t size);
340 
347  virtual int64_t seek(uint64_t pos);
348 
354  virtual int64_t flen();
355 
358  protected:
360  std::string _name;
361  std::string mode;
362  };
363 
365  class FileFeatures : public FileBase
366  {
367  public:
368  FileFeatures(ArmSemihosting &_parent,
369  const char *name, const char *mode);
370 
371  void serialize(CheckpointOut &cp) const override;
372  void unserialize(CheckpointIn &cp) override;
373 
374  int64_t read(uint8_t *buffer, uint64_t size) override;
375  int64_t seek(uint64_t pos) override;
376 
377  protected:
378  size_t pos;
379  };
380 
381  class File : public FileBase
382  {
383  public:
384  File(ArmSemihosting &_parent, const char *name, const char *mode);
385  ~File();
386 
387  void serialize(CheckpointOut &cp) const override;
388  void unserialize(CheckpointIn &cp) override;
389 
390  int64_t open() override { return openImpl(false); }
391  int64_t close() override;
392  bool isTTY() const override;
393  int64_t read(uint8_t *buffer, uint64_t size) override;
394  int64_t write(const uint8_t *buffer, uint64_t size) override;
395  int64_t seek(uint64_t pos) override;
396  int64_t flen() override;
397 
398  protected:
399  int64_t openImpl(bool unserialize);
400  bool needClose() const { return !isTTY(); }
401 
402  FILE *file;
403  };
404 
405  std::string filesRootDir;
407  using Handle = size_t;
408  FILE *stdin;
409  FILE *stdout;
410  FILE *stderr;
411 
412  protected: // Helper functions
413  unsigned
415  {
416  int msb = findMsbSet(SimClock::Frequency);
417  return msb > 31 ? msb - 31 : 0;
418  }
419  uint64_t
420  semiTick(Tick tick) const
421  {
422  return tick >> tickShift;
423  }
424  void semiExit(uint64_t code, uint64_t subcode);
425  std::string readString(ThreadContext *tc, Addr ptr, size_t len);
426 
427  public:
429 
430  private:
431  static RetErrno
433  {
434  return RetErrno((uint64_t)-1, e);
435  }
436 
437  static RetErrno
438  retOK(uint64_t r)
439  {
440  return RetErrno(r, 0);
441  }
442 
450  struct SemiCall
451  {
453  const char *name;
454 
455  // A type for member functions implementing semihosting calls.
456  template <typename ...Args>
457  using Implementation =
458  RetErrno (ArmSemihosting::*)(ThreadContext *tc, Args... args);
459 
460  // Since guest ABI doesn't know how to call member function pointers,
461  // this template builds a wrapper that takes care of that.
462  template <typename ...Args>
463  static inline std::function<RetErrno(ThreadContext *tc, Args... args)>
465  {
466  return [sh, impl](ThreadContext *tc, Args... args) {
467  return (sh->*impl)(tc, args...);
468  };
469  }
470 
471  // A type for functions which dispatch semihosting calls through the
472  // guest ABI mechanism.
473  using Dispatcher =
474  std::function<RetErrno(ArmSemihosting *sh, ThreadContext *tc)>;
475  using Dumper = std::function<std::string(ThreadContext *tc)>;
476 
477  // Dispatchers for 32 and 64 bits.
480 
481  // Dumpers which print semihosting calls and their arguments.
484 
485  // A function which builds a dispatcher for a semihosting call.
486  template <typename Abi, typename ...Args>
487  static inline Dispatcher
489  {
490  // This lambda is the dispatcher we're building.
491  return [impl](ArmSemihosting *sh, ThreadContext *tc) {
492  auto wrapper = wrapImpl(sh, impl);
493  return invokeSimcall<Abi>(tc, wrapper);
494  };
495  }
496 
497  // A function which builds a dumper for a semihosting call.
498  template <typename Abi, typename ...Args>
499  static inline Dumper
501  {
502  // This lambda is the dumper we're building.
503  return [name](ThreadContext *tc) -> std::string {
504  return dumpSimcall<Abi, RetErrno, Args...>(name, tc);
505  };
506  }
507 
508  // When there's one implementation, use it for both 32 and 64 bits.
509  template <typename ...Args>
510  SemiCall(const char *_name, Implementation<Args...> common) :
511  name(_name), call32(buildDispatcher<Abi32>(common)),
512  call64(buildDispatcher<Abi64>(common)),
513  dump32(buildDumper<Abi32>(_name, common)),
514  dump64(buildDumper<Abi64>(_name, common))
515  {}
516 
517  // When there are two, use one for 32 bits and one for 64 bits.
518  template <typename ...Args32, typename ...Args64>
519  SemiCall(const char *_name, Implementation<Args32...> impl32,
520  Implementation<Args64...> impl64) :
521  name(_name), call32(buildDispatcher<Abi32>(impl32)),
522  call64(buildDispatcher<Abi64>(impl64)),
523  dump32(buildDumper<Abi32>(_name, impl32)),
524  dump64(buildDumper<Abi64>(_name, impl64))
525  {}
526  };
527 
528  RetErrno callOpen(ThreadContext *tc, const Addr name_base,
529  int fmode, size_t name_size);
530  RetErrno callClose(ThreadContext *tc, Handle handle);
531  RetErrno callWriteC(ThreadContext *tc, InPlaceArg c);
532  RetErrno callWrite0(ThreadContext *tc, InPlaceArg str);
534  Addr buffer, size_t size);
536  Addr buffer, size_t size);
539  RetErrno callIsTTY(ThreadContext *tc, Handle handle);
540  RetErrno callSeek(ThreadContext *tc, Handle handle, uint64_t pos);
541  RetErrno callFLen(ThreadContext *tc, Handle handle);
543  uint64_t id, size_t size);
544  RetErrno callRemove(ThreadContext *tc, Addr name_base, size_t name_size);
545  RetErrno callRename(ThreadContext *tc, Addr from_addr, size_t from_size,
546  Addr to_addr, size_t to_size);
549  RetErrno callSystem(ThreadContext *tc, Addr cmd_addr, size_t cmd_size);
551  RetErrno callGetCmdLine(ThreadContext *tc, Addr addr, InPlaceArg size_arg);
552 
553  void gatherHeapInfo(ThreadContext *tc, bool aarch64,
554  Addr &heap_base, Addr &heap_limit,
555  Addr &stack_base, Addr &stack_limit);
556  RetErrno callHeapInfo32(ThreadContext *tc, Addr block_addr);
557  RetErrno callHeapInfo64(ThreadContext *tc, Addr block_addr);
558  RetErrno callExit32(ThreadContext *tc, InPlaceArg code);
559  RetErrno callExit64(ThreadContext *tc, uint64_t code, uint64_t subcode);
560  RetErrno callExitExtended(ThreadContext *tc, uint64_t code,
561  uint64_t subcode);
562 
563  RetErrno callElapsed32(ThreadContext *tc, InPlaceArg low, InPlaceArg high);
564  RetErrno callElapsed64(ThreadContext *tc, InPlaceArg ticks);
566 
567  RetErrno callGem5PseudoOp32(ThreadContext *tc, uint32_t encoded_func);
568  RetErrno callGem5PseudoOp64(ThreadContext *tc, uint64_t encoded_func);
569 
570  template <typename Abi>
571  void
572  unrecognizedCall(ThreadContext *tc, const char *format, uint64_t op)
573  {
574  warn(format, op);
575  std::function<RetErrno(ThreadContext *tc)> retErr =
576  [](ThreadContext *tc) { return retError(EINVAL); };
577  invokeSimcall<Abi>(tc, retErr);
578  }
579 
580  static FILE *getSTDIO(const char *stream_name,
581  const std::string &name, const char *mode);
582 
583  static const std::map<uint32_t, SemiCall> calls;
585  static const std::map<uint64_t, const char *> exitCodes;
587  static const std::map<const std::string, FILE *> stdioMap;
588 
589  // used in callTmpNam() to deterministically generate a temp filename
590  uint16_t tmpNameIndex = 0;
591 
592 };
593 
594 std::ostream &operator << (
595  std::ostream &os, const ArmSemihosting::InPlaceArg &ipa);
596 
597 namespace GuestABI
598 {
599 
600 template <typename Arg>
601 struct Argument<ArmSemihosting::Abi64, Arg,
602  typename std::enable_if_t<std::is_integral<Arg>::value>>
603 {
604  static Arg
606  {
607  return state.get(tc);
608  }
609 };
610 
611 template <typename Arg>
612 struct Argument<ArmSemihosting::Abi32, Arg,
613  typename std::enable_if_t<std::is_integral<Arg>::value>>
614 {
615  static Arg
617  {
618  if (std::is_signed<Arg>::value)
619  return sext<32>(state.get(tc));
620  else
621  return state.get(tc);
622  }
623 };
624 
625 template <typename Abi>
626 struct Argument<Abi, ArmSemihosting::InPlaceArg, typename std::enable_if_t<
627  std::is_base_of<ArmSemihosting::AbiBase, Abi>::value>>
628 {
630  get(ThreadContext *tc, typename Abi::State &state)
631  {
633  state.getAddr(), sizeof(typename Abi::State::ArgType));
634  }
635 };
636 
637 template <>
639 {
640  static void
642  {
643  tc->setIntReg(ArmISA::INTREG_R0, err.first);
644  }
645 };
646 
647 template <>
649 {
650  static void
652  {
653  tc->setIntReg(ArmISA::INTREG_X0, err.first);
654  }
655 };
656 
657 } // namespace GuestABI
658 
659 #endif // __ARCH_ARM_SEMIHOSTING_HH__
ArmSemihosting::gatherHeapInfo
void gatherHeapInfo(ThreadContext *tc, bool aarch64, Addr &heap_base, Addr &heap_limit, Addr &stack_base, Addr &stack_limit)
Definition: semihosting.cc:547
ArmSemihosting::FileFeatures
Implementation of the ':semihosting-features' magic file.
Definition: semihosting.hh:365
ArmSemihosting::FileBase::create
static std::unique_ptr< FileBase > create(ArmSemihosting &parent, const std::string &fname, const char *mode)
Definition: semihosting.cc:765
ArmSemihosting::retError
static RetErrno retError(SemiErrno e)
Definition: semihosting.hh:432
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
ArmSemihosting::callWrite0
RetErrno callWrite0(ThreadContext *tc, InPlaceArg str)
Definition: semihosting.cc:345
ArmSemihosting::callWrite
RetErrno callWrite(ThreadContext *tc, Handle handle, Addr buffer, size_t size)
Definition: semihosting.cc:357
ArmSemihosting::SYS_WRITE
@ SYS_WRITE
Definition: semihosting.hh:205
ArmSemihosting::Abi32
Definition: semihosting.hh:148
ArmSemihosting::semiErrno
SemiErrno semiErrno
Definition: semihosting.hh:258
ArmSemihosting::callExit64
RetErrno callExit64(ThreadContext *tc, uint64_t code, uint64_t subcode)
Definition: semihosting.cc:624
ArmSemihosting::FileBase::flen
virtual int64_t flen()
Get the length of a file in bytes.
Definition: semihosting.cc:832
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
warn
#define warn(...)
Definition: logging.hh:239
ArmSemihosting::SYS_TMPNAM
@ SYS_TMPNAM
Definition: semihosting.hh:212
ArmSemihosting::SYS_HEAPINFO
@ SYS_HEAPINFO
Definition: semihosting.hh:220
ArmSemihosting::callElapsed32
RetErrno callElapsed32(ThreadContext *tc, InPlaceArg low, InPlaceArg high)
Definition: semihosting.cc:651
ArmSemihosting::stdioMap
static const std::map< const std::string, FILE * > stdioMap
Definition: semihosting.hh:587
ArmISA::sh
Bitfield< 8, 7 > sh
Definition: miscregs_types.hh:654
ArmSemihosting::callTickFreq
RetErrno callTickFreq(ThreadContext *tc)
Definition: semihosting.cc:673
ArmSemihosting::Gem5Imm
@ Gem5Imm
Definition: semihosting.hh:84
ArmSemihosting::callRename
RetErrno callRename(ThreadContext *tc, Addr from_addr, size_t from_size, Addr to_addr, size_t to_size)
Definition: semihosting.cc:487
ArmSemihosting::SYS_SEEK
@ SYS_SEEK
Definition: semihosting.hh:210
ArmSemihosting::filesRootDir
std::string filesRootDir
Definition: semihosting.hh:405
ArmSemihosting::retOK
static RetErrno retOK(uint64_t r)
Definition: semihosting.hh:438
ArmSemihosting::callElapsed64
RetErrno callElapsed64(ThreadContext *tc, InPlaceArg ticks)
Definition: semihosting.cc:665
ArmSemihosting::SYS_READC
@ SYS_READC
Definition: semihosting.hh:207
ArmSemihosting::callWriteC
RetErrno callWriteC(ThreadContext *tc, InPlaceArg c)
Definition: semihosting.cc:334
GuestABI::Argument< ArmSemihosting::Abi64, Arg, typename std::enable_if_t< std::is_integral< Arg >::value > >::get
static Arg get(ThreadContext *tc, ArmSemihosting::Abi64::State &state)
Definition: semihosting.hh:605
ArmISA::byteOrder
ByteOrder byteOrder(const ThreadContext *tc)
Definition: utility.hh:430
ArmSemihosting::File::~File
~File()
Definition: semihosting.cc:889
ArmSemihosting::SemiCall::Dispatcher
std::function< RetErrno(ArmSemihosting *sh, ThreadContext *tc)> Dispatcher
Definition: semihosting.hh:474
ArmSemihosting::Abi64::UintPtr
uint64_t UintPtr
Definition: semihosting.hh:136
Serializable
Basic support for object serialization.
Definition: serialize.hh:175
ArmSemihosting::callOpen
RetErrno callOpen(ThreadContext *tc, const Addr name_base, int fmode, size_t name_size)
Definition: semihosting.cc:284
GuestABI::Argument< ArmSemihosting::Abi32, Arg, typename std::enable_if_t< std::is_integral< Arg >::value > >::get
static Arg get(ThreadContext *tc, ArmSemihosting::Abi32::State &state)
Definition: semihosting.hh:616
ArmSemihosting::File::openImpl
int64_t openImpl(bool unserialize)
Definition: semihosting.cc:896
ArmSemihosting::semiTick
uint64_t semiTick(Tick tick) const
Definition: semihosting.hh:420
ArmSemihosting::cmdLine
const std::string cmdLine
Definition: semihosting.hh:243
ArmSemihosting::File
Definition: semihosting.hh:381
ArmSemihosting::features
static const std::vector< uint8_t > features
Definition: semihosting.hh:586
ArmSemihosting::SemiCall::buildDumper
static Dumper buildDumper(const char *name, Implementation< Args... > impl)
Definition: semihosting.hh:500
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
ArmSemihosting::SYS_OPEN
@ SYS_OPEN
Definition: semihosting.hh:201
GuestABI::Argument< Abi, ArmSemihosting::InPlaceArg, typename std::enable_if_t< std::is_base_of< ArmSemihosting::AbiBase, Abi >::value > >::get
static ArmSemihosting::InPlaceArg get(ThreadContext *tc, typename Abi::State &state)
Definition: semihosting.hh:630
ArmSemihosting::SYS_ERRNO
@ SYS_ERRNO
Definition: semihosting.hh:218
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
ArmSemihosting::fmodes
static const std::vector< const char * > fmodes
Definition: semihosting.hh:584
ArmSemihosting::callErrno
RetErrno callErrno(ThreadContext *tc)
Definition: semihosting.cc:523
ArmSemihosting::callRemove
RetErrno callRemove(ThreadContext *tc, Addr name_base, size_t name_size)
Definition: semihosting.cc:475
ArmSemihosting::AbiBase::StateBase
Definition: semihosting.hh:92
ArmSemihosting::FileBase::seek
virtual int64_t seek(uint64_t pos)
Seek to an absolute position in the file.
Definition: semihosting.cc:826
X86ISA::op
Bitfield< 4 > op
Definition: types.hh:79
ArmSemihosting::FileBase::FileBase
FileBase()=delete
ArmSemihosting::callExit32
RetErrno callExit32(ThreadContext *tc, InPlaceArg code)
Definition: semihosting.cc:617
ArmSemihosting::callClock
RetErrno callClock(ThreadContext *tc)
Definition: semihosting.cc:501
std::vector
STL vector class.
Definition: stl.hh:37
ArmSemihosting::AbiBase::StateBase::get
Arg get(ThreadContext *tc)
Definition: semihosting.hh:122
ArmSemihosting::FileBase::open
virtual int64_t open()
Open the the file.
Definition: semihosting.hh:311
ArmSemihosting::call32
bool call32(ThreadContext *tc, bool gem5_ops)
Perform an Arm Semihosting call from aarch32 code.
Definition: semihosting.cc:193
ArmSemihosting::FileBase::fileName
const std::string & fileName()
Definition: semihosting.hh:293
ArmSemihosting::FileBase::_name
std::string _name
Definition: semihosting.hh:360
ArmSemihosting::SYS_EXIT
@ SYS_EXIT
Definition: semihosting.hh:221
ArmSemihosting::SYS_CLOCK
@ SYS_CLOCK
Definition: semihosting.hh:215
ArmSemihosting::SYS_ISERROR
@ SYS_ISERROR
Definition: semihosting.hh:208
ArmSemihosting::callGetCmdLine
RetErrno callGetCmdLine(ThreadContext *tc, Addr addr, InPlaceArg size_arg)
Definition: semihosting.cc:530
ArmSemihosting::InPlaceArg::write
void write(ThreadContext *tc, uint64_t val, ByteOrder endian)
Definition: semihosting.hh:188
ArmSemihosting::SYS_TIME
@ SYS_TIME
Definition: semihosting.hh:216
ArmSemihosting::callSeek
RetErrno callSeek(ThreadContext *tc, Handle handle, uint64_t pos)
Definition: semihosting.cc:425
ArmISA
Definition: ccregs.hh:41
ArmSemihosting::SemiCall::dump32
Dumper dump32
Definition: semihosting.hh:482
ArmSemihosting::SYS_RENAME
@ SYS_RENAME
Definition: semihosting.hh:214
ArmSemihosting::callTime
RetErrno callTime(ThreadContext *tc)
Definition: semihosting.cc:507
ArmSemihosting::Abi32::State::State
State(const ThreadContext *tc)
Definition: semihosting.hh:156
ArmSemihosting::File::flen
int64_t flen() override
Get the length of a file in bytes.
Definition: semihosting.cc:989
ArmSemihosting::FileFeatures::pos
size_t pos
Definition: semihosting.hh:378
ArmSemihosting::callHeapInfo32
RetErrno callHeapInfo32(ThreadContext *tc, Addr block_addr)
Definition: semihosting.cc:588
ArmSemihosting::ArmSemihosting
ArmSemihosting(const ArmSemihostingParams &p)
Definition: semihosting.cc:141
ArmSemihosting::tmpNameIndex
uint16_t tmpNameIndex
Definition: semihosting.hh:590
SimClock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:43
ArmSemihosting::A32Imm
@ A32Imm
Definition: semihosting.hh:79
ArmISA::aarch64
Bitfield< 34 > aarch64
Definition: types.hh:90
ArmSemihosting::SemiCall::buildDispatcher
static Dispatcher buildDispatcher(Implementation< Args... > impl)
Definition: semihosting.hh:488
ArmSemihosting::FileFeatures::read
int64_t read(uint8_t *buffer, uint64_t size) override
Read data from file.
Definition: semihosting.cc:845
ArmSemihosting::File::open
int64_t open() override
Open the the file.
Definition: semihosting.hh:390
ArmSemihosting::SYS_REMOVE
@ SYS_REMOVE
Definition: semihosting.hh:213
ArmSemihosting::File::File
File(ArmSemihosting &_parent, const char *name, const char *mode)
Definition: semihosting.cc:882
cp
Definition: cprintf.cc:37
ArmSemihosting::FileBase::FileBase
FileBase(ArmSemihosting &_parent, const char *name, const char *_mode)
Definition: semihosting.hh:277
ArmSemihosting::FileBase::read
virtual int64_t read(uint8_t *buffer, uint64_t size)
Read data from file.
Definition: semihosting.cc:814
ArmSemihosting::SYS_GET_CMDLINE
@ SYS_GET_CMDLINE
Definition: semihosting.hh:219
ArmSemihosting::SemiCall::wrapImpl
static std::function< RetErrno(ThreadContext *tc, Args... args)> wrapImpl(ArmSemihosting *sh, Implementation< Args... > impl)
Definition: semihosting.hh:464
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
ArmISA::INTREG_R0
@ INTREG_R0
Definition: intregs.hh:54
ArmSemihosting::stderr
FILE * stderr
Definition: semihosting.hh:410
ArmSemihosting::SYS_EXIT_EXTENDED
@ SYS_EXIT_EXTENDED
Definition: semihosting.hh:222
MipsISA::impl
Bitfield< 19, 16 > impl
Definition: mt_constants.hh:87
sim_object.hh
GuestABI
Definition: aapcs32.hh:66
ArmSemihosting::call64
bool call64(ThreadContext *tc, bool gem5_ops)
Perform an Arm Semihosting call from aarch64 code.
Definition: semihosting.cc:167
ArmSemihosting::Abi32::State
Definition: semihosting.hh:152
ArmSemihosting::File::isTTY
bool isTTY() const override
Check if a file corresponds to a TTY device.
Definition: semihosting.cc:938
ArmSemihosting::calls
static const std::map< uint32_t, SemiCall > calls
Definition: semihosting.hh:583
ArmSemihosting::callSystem
RetErrno callSystem(ThreadContext *tc, Addr cmd_addr, size_t cmd_size)
Definition: semihosting.cc:513
ArmISA::INTREG_R1
@ INTREG_R1
Definition: intregs.hh:55
ArmSemihosting::InPlaceArg::size
size_t size
Definition: semihosting.hh:168
ArmSemihosting::readString
std::string readString(ThreadContext *tc, Addr ptr, size_t len)
Definition: semihosting.cc:273
ArmSemihosting::callIsTTY
RetErrno callIsTTY(ThreadContext *tc, Handle handle)
Definition: semihosting.cc:411
ArmSemihosting::callHeapInfo64
RetErrno callHeapInfo64(ThreadContext *tc, Addr block_addr)
Definition: semihosting.cc:603
ArmSemihosting::exitCodes
static const std::map< uint64_t, const char * > exitCodes
Definition: semihosting.hh:585
ArmSemihosting::stackSize
const Addr stackSize
Definition: semihosting.hh:245
MipsISA::r
r
Definition: pra_constants.hh:95
ArmSemihosting::tickShift
const unsigned tickShift
Number of bits to right shift gem5 ticks to fit in a uint32_t.
Definition: semihosting.hh:254
ArmSemihosting::stdout
FILE * stdout
Definition: semihosting.hh:409
ArmSemihosting::SemiCall::SemiCall
SemiCall(const char *_name, Implementation< Args32... > impl32, Implementation< Args64... > impl64)
Definition: semihosting.hh:519
ArmSemihosting::AbiBase::StateBase::endian
ByteOrder endian
Definition: semihosting.hh:96
GuestABI::Argument
Definition: definition.hh:93
port_proxy.hh
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
ArmSemihosting::SYS_SYSTEM
@ SYS_SYSTEM
Definition: semihosting.hh:217
ArmSemihosting::File::close
int64_t close() override
Close the file.
Definition: semihosting.cc:925
ArmSemihosting::semiExit
void semiExit(uint64_t code, uint64_t subcode)
Definition: semihosting.cc:639
ArmSemihosting::AbiBase::StateBase::StateBase
StateBase(const ThreadContext *tc, Addr arg_pointer)
Definition: semihosting.hh:99
intregs.hh
ArmSemihosting::FileBase::isTTY
virtual bool isTTY() const
Check if a file corresponds to a TTY device.
Definition: semihosting.hh:325
ArmSemihosting::InPlaceArg::addr
Addr addr
Definition: semihosting.hh:167
ArmSemihosting::SYS_GEM5_PSEUDO_OP
@ SYS_GEM5_PSEUDO_OP
Definition: semihosting.hh:228
ArmISA::INTREG_X0
@ INTREG_X0
Definition: intregs.hh:127
ArmSemihosting::SemiCall::SemiCall
SemiCall(const char *_name, Implementation< Args... > common)
Definition: semihosting.hh:510
ArmSemihosting::File::seek
int64_t seek(uint64_t pos) override
Seek to an absolute position in the file.
Definition: semihosting.cc:977
ArmSemihosting::SemiErrno
uint64_t SemiErrno
Definition: semihosting.hh:257
std::pair
STL pair class.
Definition: stl.hh:58
ArmSemihosting::SYS_CLOSE
@ SYS_CLOSE
Definition: semihosting.hh:202
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
ArmSemihosting::SemiCall::Implementation
RetErrno(ArmSemihosting::*)(ThreadContext *tc, Args... args) Implementation
Definition: semihosting.hh:458
ArmSemihosting::SYS_WRITE0
@ SYS_WRITE0
Definition: semihosting.hh:204
ArmSemihosting::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: semihosting.cc:219
ArmSemihosting::getSTDIO
static FILE * getSTDIO(const char *stream_name, const std::string &name, const char *mode)
Definition: semihosting.cc:748
ArmSemihosting::A64Imm
@ A64Imm
Definition: semihosting.hh:80
ArmSemihosting::SYS_TICKFREQ
@ SYS_TICKFREQ
Definition: semihosting.hh:224
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
ArmSemihosting::InPlaceArg
Definition: semihosting.hh:165
ArmSemihosting::FileFeatures::seek
int64_t seek(uint64_t pos) override
Seek to an absolute position in the file.
Definition: semihosting.cc:856
ArmSemihosting::SYS_ELAPSED
@ SYS_ELAPSED
Definition: semihosting.hh:223
utility.hh
ArmSemihosting::InPlaceArg::read
uint64_t read(ThreadContext *tc, ByteOrder endian)
Definition: semihosting.hh:175
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
ArmISA::INTREG_X1
@ INTREG_X1
Definition: intregs.hh:128
ArmSemihosting::memReserve
const Addr memReserve
Definition: semihosting.hh:244
GuestABI::Result< ArmSemihosting::Abi64, ArmSemihosting::RetErrno >::store
static void store(ThreadContext *tc, const ArmSemihosting::RetErrno &err)
Definition: semihosting.hh:651
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
ArmSemihosting::File::file
FILE * file
Definition: semihosting.hh:402
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
ArmSemihosting::SYS_FLEN
@ SYS_FLEN
Definition: semihosting.hh:211
ArmSemihosting::callGem5PseudoOp32
RetErrno callGem5PseudoOp32(ThreadContext *tc, uint32_t encoded_func)
Definition: semihosting.cc:722
ArmSemihosting::FileBase::mode
std::string mode
Definition: semihosting.hh:361
ArmSemihosting::callExitExtended
RetErrno callExitExtended(ThreadContext *tc, uint64_t code, uint64_t subcode)
Definition: semihosting.cc:631
ArmSemihosting::SemiCall::call64
Dispatcher call64
Definition: semihosting.hh:479
ArmSemihosting::stdin
FILE * stdin
Definition: semihosting.hh:408
ArmSemihosting::Abi64::State
Definition: semihosting.hh:138
SerialDevice
Base class for serial devices such as terminals.
Definition: serial.hh:91
findMsbSet
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:240
ArmSemihosting::InPlaceArg::InPlaceArg
InPlaceArg(Addr _addr, size_t _size)
Definition: semihosting.hh:170
ArmSemihosting::portProxy
static PortProxy & portProxy(ThreadContext *tc)
Definition: semihosting.cc:246
ArmSemihosting::Handle
size_t Handle
Definition: semihosting.hh:407
ArmSemihosting::MaxStandardOp
@ MaxStandardOp
Definition: semihosting.hh:226
ArmSemihosting::SYS_WRITEC
@ SYS_WRITEC
Definition: semihosting.hh:203
GuestABI::Result
Definition: definition.hh:58
ArmSemihosting::SemiCall::Dumper
std::function< std::string(ThreadContext *tc)> Dumper
Definition: semihosting.hh:475
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
ArmSemihosting::SemiCall
Semihosting call information structure.
Definition: semihosting.hh:450
ArmSemihosting::File::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: semihosting.cc:1011
PortProxy::read
T read(Addr address) const
Read sizeof(T) bytes from address and return as object T.
Definition: port_proxy.hh:282
ArmSemihosting::FileBase::close
virtual int64_t close()
Close the file.
Definition: semihosting.hh:318
ArmSemihosting::File::read
int64_t read(uint8_t *buffer, uint64_t size) override
Read data from file.
Definition: semihosting.cc:946
ArmSemihosting::FileBase::~FileBase
virtual ~FileBase()
Definition: semihosting.hh:279
ArmSemihosting::SYS_READ
@ SYS_READ
Definition: semihosting.hh:206
ArmSemihosting::callFLen
RetErrno callFLen(ThreadContext *tc, Handle handle)
Definition: semihosting.cc:439
ArmSemihosting::File::needClose
bool needClose() const
Definition: semihosting.hh:400
ArmSemihosting::callReadC
RetErrno callReadC(ThreadContext *tc)
Definition: semihosting.cc:399
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
guest_abi.hh
ArmSemihosting::FileFeatures::FileFeatures
FileFeatures(ArmSemihosting &_parent, const char *name, const char *mode)
Definition: semihosting.cc:838
ArmSemihosting::T32Imm
@ T32Imm
Definition: semihosting.hh:78
ArmSemihosting::FileBase::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: semihosting.cc:807
ArmSemihosting::File::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: semihosting.cc:1023
ArmSemihosting::unrecognizedCall
void unrecognizedCall(ThreadContext *tc, const char *format, uint64_t op)
Definition: semihosting.hh:572
ArmSemihosting::File::write
int64_t write(const uint8_t *buffer, uint64_t size) override
Write data to file.
Definition: semihosting.cc:961
ArmSemihosting::FileBase::write
virtual int64_t write(const uint8_t *buffer, uint64_t size)
Write data to file.
Definition: semihosting.cc:820
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
ArmSemihosting::AbiBase::StateBase::getAddr
Addr getAddr()
Definition: semihosting.hh:113
GuestABI::Result< ArmSemihosting::Abi32, ArmSemihosting::RetErrno >::store
static void store(ThreadContext *tc, const ArmSemihosting::RetErrno &err)
Definition: semihosting.hh:641
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
ArmSemihosting::SemiCall::name
const char * name
Call name.
Definition: semihosting.hh:453
ArmISA::format
Bitfield< 31, 29 > format
Definition: miscregs_types.hh:640
ArmSemihosting::SemiCall::dump64
Dumper dump64
Definition: semihosting.hh:483
ArmSemihosting::AbiBase::StateBase::argPointer
Addr argPointer
Definition: semihosting.hh:95
ArmISA::err
Bitfield< 6 > err
Definition: miscregs_types.hh:744
ArmSemihosting::calcTickShift
unsigned calcTickShift() const
Definition: semihosting.hh:414
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmSemihosting::callClose
RetErrno callClose(ThreadContext *tc, Handle handle)
Definition: semihosting.cc:312
ArmSemihosting::SYS_ISTTY
@ SYS_ISTTY
Definition: semihosting.hh:209
ArmSemihosting::files
std::vector< std::unique_ptr< FileBase > > files
Definition: semihosting.hh:406
CheckpointIn
Definition: serialize.hh:68
ArmSemihosting::AbiBase
Definition: semihosting.hh:89
ArmSemihosting::SemiCall::call32
Dispatcher call32
Definition: semihosting.hh:478
ArmSemihosting::timeBase
const time_t timeBase
Base time when the simulation started.
Definition: semihosting.hh:251
ArmSemihosting
Semihosting for AArch32 and AArch64.
Definition: semihosting.hh:72
ArmSemihosting::callTmpNam
RetErrno callTmpNam(ThreadContext *tc, Addr buffer, uint64_t id, size_t size)
Definition: semihosting.cc:453
ArmSemihosting::Operation
Operation
Definition: semihosting.hh:200
ArmSemihosting::callRead
RetErrno callRead(ThreadContext *tc, Handle handle, Addr buffer, size_t size)
Definition: semihosting.cc:378
ArmSemihosting::Abi64::State::State
State(const ThreadContext *tc)
Definition: semihosting.hh:142
ArmSemihosting::FileBase::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: semihosting.cc:800
ArmSemihosting::callIsError
RetErrno callIsError(ThreadContext *tc, int64_t status)
Definition: semihosting.cc:405
ArmSemihosting::RetErrno
std::pair< uint64_t, SemiErrno > RetErrno
Definition: semihosting.hh:428
ArmSemihosting::FileFeatures::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: semihosting.cc:867
thread_context.hh
operator<<
std::ostream & operator<<(std::ostream &os, const ArmSemihosting::InPlaceArg &ipa)
Definition: semihosting.cc:1041
ArmSemihosting::FileBase::parent
ArmSemihosting & parent
Definition: semihosting.hh:359
ArmSemihosting::Abi64
Definition: semihosting.hh:134
dumpSimcall
std::string dumpSimcall(std::string name, ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target=std::function< Ret(ThreadContext *, Args...)>())
Definition: guest_abi.hh:107
ArmSemihosting::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: semihosting.cc:234
ArmSemihosting::FileBase
Internal state for open files.
Definition: semihosting.hh:274
ArmSemihosting::Abi32::UintPtr
uint32_t UintPtr
Definition: semihosting.hh:150
ArmSemihosting::callGem5PseudoOp64
RetErrno callGem5PseudoOp64(ThreadContext *tc, uint64_t encoded_func)
Definition: semihosting.cc:735
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ArmSemihosting::AbiBase::StateBase::ArgType
Arg ArgType
Definition: semihosting.hh:130
ArmSemihosting::FileFeatures::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: semihosting.cc:874
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:20 for gem5 by doxygen 1.8.17