gem5 v24.0.0.0
Loading...
Searching...
No Matches
lupio_tty.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 The Regents of the University of California
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
30
31#include "base/trace.hh"
32#include "debug/LupioTTY.hh"
33#include "dev/platform.hh"
34#include "mem/packet_access.hh"
35#include "params/LupioTTY.hh"
36
37#define LUPIO_TTY_INVAL 0x80000000
38
39/* Same fields for CTRL and STAT registers */
40#define LUPIO_TTY_WBIT (1 << 0)
41#define LUPIO_TTY_RBIT (1 << 1)
42
43namespace gem5
44{
45
47 : BasicPioDevice(params, params.pio_size),
48 writChar(-1), readChar(-1), writIntrEn(false), readIntrEn(false),
49 terminal(params.terminal), platform(params.platform)
50{
51 // setup serial device callbacks
53}
54
55void
57{
58 unsigned int irq;
59
60 irq = (writIntrEn && writChar != -1)
61 || (readIntrEn && readChar != -1);
62
63 if (irq) {
64 DPRINTF(LupioTTY, "LupioTTY InterEvent, interrupting\n");
65 platform->postConsoleInt();
66 } else {
67 DPRINTF(LupioTTY, "LupioTTY InterEvent, not interrupting\n");
68 platform->clearConsoleInt();
69 }
70}
71
72void
74{
76
77 // prevent from overwritting an unread character
78 if (readChar != -1) {
79 fprintf(stderr, "Dropping characters\n");
80 } else {
81 // read data from the terminal
84 }
85}
86
87uint64_t
89{
90 uint32_t ret = LUPIO_TTY_INVAL;
91
92 switch (addr >> 2) {
93 case LUPIO_TTY_WRIT:
94 DPRINTF(LupioTTY, "Accessing LUPIO_TTY_WRIT\n");
95 if (writChar != -1) {
96 ret = writChar;
97 writChar = -1;
99 }
100 break;
101 case LUPIO_TTY_READ:
102 DPRINTF(LupioTTY, "Accessing LUPIO_TTY_READ\n");
103 if (readChar != -1) {
104 // return new character
105 ret = readChar;
106 readChar = -1;
108 }
109 break;
110 case LUPIO_TTY_CTRL:
111 DPRINTF(LupioTTY, "Accessing LUPIO_TTY_CTRL\n");
112 ret = 0;
113 if (writIntrEn) {
114 ret |= LUPIO_TTY_WBIT;
115 }
116 if (readIntrEn) {
117 ret |= LUPIO_TTY_RBIT;
118 }
119 break;
120 case LUPIO_TTY_STAT:
121 DPRINTF(LupioTTY, "Accessing LUPIO_TTY_STAT\n");
122 // always ready to write
123 ret = LUPIO_TTY_WBIT;
124 // ready to read if unread character available
125 if (readChar != -1) {
126 ret |= LUPIO_TTY_RBIT;
127 }
128 break;
129 default:
130 panic("Unexpected read to the LupioTTY device at address %d!",
131 addr);
132 break;
133 }
134
135 return ret;
136}
137
138void
139LupioTTY::lupioTTYWrite(uint8_t addr, uint64_t val64)
140{
141 uint32_t val = val64;
142 uint8_t c = val;
143
144 switch (addr >> 2) {
145 case LUPIO_TTY_WRIT:
146 DPRINTF(LupioTTY, "Accessing Write: LUPIO_TTY_WRIT: %d\n", c);
147 // write data to terminal
149 writChar = c;
151 break;
152 case LUPIO_TTY_CTRL:
153 // set interrupt enable bits
154 DPRINTF(LupioTTY, "Accessing LUPIO_TTY_CTRL\n");
158 break;
159 default:
160 panic("Unexpected write to the LupioTTY device at address %d!",
161 addr);
162 break;
163 }
164}
165
166Tick
168{
169 Addr tty_addr = pkt->getAddr() - pioAddr;
170
172 "Read request - addr: %#x, size: %#x\n", tty_addr, pkt->getSize());
173
174 uint64_t val = lupioTTYRead(tty_addr);
175 pkt->setUintX(val, byteOrder);
176
177 pkt->makeResponse();
178
179 return pioDelay;
180}
181
182Tick
184{
185 Addr tty_addr = pkt->getAddr() - pioAddr;
187 "Write request - addr: %#x pktAddr: %#x value: %c\n", tty_addr,
188 pkt->getAddr(), pkt->getUintX(byteOrder));
189
190 lupioTTYWrite(tty_addr, pkt->getUintX(byteOrder));
191
192 pkt->makeResponse();
193
194 return pioDelay;
195}
196
197} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
LupioTTY: The LupioTTY is a virtual terminal device that can both transmit characters to a screen,...
Definition lupio_tty.hh:48
Tick read(PacketPtr pkt) override
Implement BasicPioDevice virtual functions.
Definition lupio_tty.cc:167
int8_t readChar
Definition lupio_tty.hh:64
LupioTTY(const Params &p)
Definition lupio_tty.cc:46
SerialDevice * terminal
Definition lupio_tty.hh:75
uint64_t lupioTTYRead(const uint8_t addr)
Definition lupio_tty.cc:88
void dataAvailable()
Inform the LupIO-TTY there is data available.
Definition lupio_tty.cc:73
const ByteOrder byteOrder
Definition lupio_tty.hh:76
Platform * platform
Definition lupio_tty.hh:77
void lupioTTYWrite(const uint8_t addr, uint64_t c)
Definition lupio_tty.cc:139
int8_t writChar
Definition lupio_tty.hh:63
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition lupio_tty.cc:183
void lupioTTYUpdateIRQ()
IRQ management.
Definition lupio_tty.cc:56
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition packet.cc:361
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition packet.hh:1062
unsigned getSize() const
Definition packet.hh:817
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition packet.cc:352
PioDeviceParams Params
Definition io_device.hh:134
virtual uint8_t readData()=0
Read a character from the device.
virtual void writeData(uint8_t c)=0
Transmit a character from the host interface to the device.
void regInterfaceCallback(const std::function< void()> &callback)
Register a data available callback into the host interface layer.
Definition serial.cc:56
virtual bool dataAvailable() const =0
Check if there is pending data from the serial device.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:317
#define LUPIO_TTY_RBIT
Definition lupio_tty.cc:41
#define LUPIO_TTY_WBIT
Definition lupio_tty.cc:40
#define LUPIO_TTY_INVAL
Definition lupio_tty.cc:37
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 1 > irq
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
Generic interface for platforms.

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0