47#if defined(__FreeBSD__)
51#include <sys/termios.h>
71#include "debug/Terminal.hh"
72#include "debug/TerminalVerbose.hh"
115 else if (revent & POLLNVAL)
131 outfile->stream()->setf(std::ios::unitbuf);
153 case TerminalDump::none:
155 case TerminalDump::stdoutput:
156 return simout.findOrCreate(
"stdout");
157 case TerminalDump::stderror:
158 return simout.findOrCreate(
"stderr");
159 case TerminalDump::file:
160 return simout.findOrCreate(
p.name);
162 panic(
"Invalid option\n");
174 warn_once(
"Sockets disabled, not accepting terminal connections");
188 panic(
"%s: cannot accept a connection if not listening!",
name());
192 char message[] =
"terminal already attached!\n";
202 std::stringstream stream;
209 write((
const uint8_t *)stream.str().c_str(), stream.str().size());
213 for (
size_t i = 0;
i <
txbuf.size();
i +=
sizeof(buf)) {
214 const size_t chunk_len(std::min(
txbuf.size() -
i,
sizeof(buf)));
215 txbuf.peek(buf,
i, chunk_len);
216 write((
const uint8_t *)buf, chunk_len);
252 panic(
"Terminal not properly attached.\n");
257 }
while (ret == -1 && errno == EINTR);
276 panic(
"Terminal not properly attached.\n");
285#define MORE_PENDING (1ULL << 61)
286#define RECEIVE_SUCCESS (0ULL << 62)
287#define RECEIVE_NONE (2ULL << 62)
288#define RECEIVE_ERROR (3ULL << 62)
295 assert(!
rxbuf.empty());
296 rxbuf.read((
char *)&
c, 1);
298 DPRINTF(TerminalVerbose,
"in: \'%c\' %#02x more: %d\n",
299 isprint(
c) ?
c :
' ',
c, !
rxbuf.empty());
317 DPRINTF(TerminalVerbose,
"console_in: return: %#x\n", value);
326 if (debug::Terminal) {
327 static char last =
'\0';
329 if ((
c !=
'\n' &&
c !=
'\r') || (last !=
'\n' && last !=
'\r')) {
330 if (
c ==
'\n' ||
c ==
'\r') {
331 int size = linebuf.size();
332 char *buffer =
new char[size + 1];
333 linebuf.read(buffer, size);
338 linebuf.write(&
c, 1);
354 DPRINTF(TerminalVerbose,
"out: \'%c\' %#02x\n",
355 isprint(
c) ?
c :
' ', (
int)
c);
static bool allDisabled()
virtual std::string name() const
void notifyInterface()
Notify the host interface of pending data.
SerialDevice(const SerialDeviceParams &p)
DataEvent(Terminal *t, int fd, int e)
ListenEvent(Terminal *t, int fd, int e)
OutputStream * terminalDump(const TerminalParams &p)
uint8_t readData() override
Read a character from the device.
Terminal(const Params &p)
void writeData(uint8_t c) override
Transmit a character from the host interface to the device.
ListenEvent * listenEvent
bool dataAvailable() const override
Check if there is pending data from the serial device.
#define panic(...)
This implements a cprintf based panic() function.
PollEvent(int fd, int event)
Copyright (c) 2024 Arm Limited All rights reserved.
ssize_t atomic_write(int fd, const void *s, size_t n)
void ccprintf(cp::Print &print)