Deleted Added
sdiff udiff text old ( 12533:a5b047f55eb6 ) new ( 12698:cef1e0e7a368 )
full compact
1/*
2 * Copyright (c) 2018 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

--- 107 unchanged lines hidden (view full) ---

116};
117
118
119const std::vector<uint8_t> ArmSemihosting::features{
120 0x53, 0x48, 0x46, 0x42, // Magic
121 0x3, // EXT_EXIT_EXTENDED, EXT_STDOUT_STDERR
122};
123
124const std::map<const std::string, FILE *> ArmSemihosting::stdioMap{
125 {"cin", ::stdin},
126 {"stdin", ::stdin},
127 {"cout", ::stdout},
128 {"stdout", ::stdout},
129 {"cerr", ::stderr},
130 {"stderr", ::stderr},
131};
132
133ArmSemihosting::ArmSemihosting(const ArmSemihostingParams *p)
134 : SimObject(p),
135 cmdLine(p->cmd_line),
136 memReserve(p->mem_reserve),
137 stackSize(p->stack_size),
138 timeBase([p]{ struct tm t = p->time; return mkutctime(&t); }()),
139 tickShift(calcTickShift()),
140 semiErrno(0),
141 stdin(getSTDIO("stdin", p->stdin, "r")),
142 stdout(getSTDIO("stdout", p->stdout, "w")),
143 stderr(p->stderr == p->stdout ?
144 stdout : getSTDIO("stderr", p->stderr, "w"))
145{
146 // Create an empty place-holder file for position 0 as semi-hosting
147 // calls typically expect non-zero file handles.
148 files.push_back(nullptr);
149
150 if (tickShift > 0)
151 inform("Semihosting: Shifting elapsed ticks by %i bits.",
152 tickShift);

--- 536 unchanged lines hidden (view full) ---

689 auto it = calls.find(op);
690 if (it == calls.end())
691 return nullptr;
692 else {
693 return &it->second;
694 }
695}
696
697FILE *
698ArmSemihosting::getSTDIO(const char *stream_name,
699 const std::string &name, const char *mode)
700{
701 auto it = stdioMap.find(name);
702 if (it == stdioMap.end()) {
703 FILE *f = fopen(name.c_str(), mode);
704 if (!f) {
705 fatal("Failed to open %s (%s): %s\n",
706 stream_name, name, strerror(errno));
707 }
708 return f;
709 } else {
710 return it->second;
711 }
712}
713
714std::unique_ptr<ArmSemihosting::FileBase>
715ArmSemihosting::FileBase::create(
716 ArmSemihosting &parent, const std::string &fname, const char *mode)
717{
718 std::unique_ptr<FileBase> file;
719 if (fname == ":semihosting-features") {
720 file.reset(new FileFeatures(parent, fname.c_str(), mode));
721 } else {

--- 122 unchanged lines hidden (view full) ---

844
845int64_t
846ArmSemihosting::File::openImpl(bool in_cpt)
847{
848 panic_if(file, "Trying to open an already open file.\n");
849
850 if (_name == ":tt") {
851 if (mode[0] == 'r') {
852 file = parent.stdin;
853 } else if (mode[0] == 'w') {
854 file = parent.stdout;
855 } else if (mode[0] == 'a') {
856 file = parent.stderr;
857 } else {
858 warn("Unknown file mode for the ':tt' special file");
859 return -EINVAL;
860 }
861 } else {
862 std::string real_mode(this->mode);
863 // Avoid truncating the file if we are restoring from a
864 // checkpoint.

--- 17 unchanged lines hidden (view full) ---

882 file = nullptr;
883
884 return 0;
885}
886
887bool
888ArmSemihosting::File::isTTY() const
889{
890 return file == parent.stdout ||
891 file == parent.stderr ||
892 file == parent.stdin;
893}
894
895int64_t
896ArmSemihosting::File::read(uint8_t *buffer, uint64_t size)
897{
898 panic_if(!file, "Trying to read from a closed file");
899
900 size_t ret = fread(buffer, 1, size, file);

--- 95 unchanged lines hidden ---