8 * Copyright (C) 1998 by the Board of Trustees
9 * of Leland Stanford Junior University.
10 * Copyright (C) 1998 Digital Equipment Corporation
12 * This file is part of the SimOS distribution.
13 * See LICENSE file for terms of the license.
20 #include "base/inifile.hh"
21 #include "base/str.hh" // for to_number
22 #include "base/trace.hh"
23 #include "dev/console.hh"
24 #include "dev/tsunami_uart.hh"
25 #include "mem/functional_mem/memory_control.hh"
26 #include "sim/builder.hh"
27 #include "targetarch/ev5.hh"
31 #define CONS_INT_TX 0x01 // interrupt enable / state bits
32 #define CONS_INT_RX 0x02
34 TsunamiUart::TsunamiUart(const string
&name
, SimConsole
*c
,
35 Addr addr
, Addr mask
, MemoryController
*mmu
)
36 : MmapDevice(name
, addr
, mask
, mmu
),
37 cons(c
), status_store(0), valid_char(false)
42 TsunamiUart::read(MemReqPtr
&req
, uint8_t *data
)
44 Addr daddr
= req
->paddr
& addr_mask
;
45 DPRINTF(TsunamiUart
, " read register %#x\n", daddr
);
48 case sizeof(uint64_t):
49 *(uint64_t *)data
= 0;
51 case sizeof(uint32_t):
52 *(uint32_t *)data
= 0;
54 case sizeof(uint16_t):
55 *(uint16_t *)data
= 0;
63 case 0xD: // Status Register
65 int status
= cons
->intStatus();
67 valid_char
= cons
->in(next_char
);
69 status
&= ~CONS_INT_RX
;
71 status
|= CONS_INT_RX
;
74 if (status_store
== 3) {
75 // RR3 stuff? Don't really understand it, btw
77 if (status
& CONS_INT_TX
) {
80 } else if (status
& CONS_INT_RX
) {
84 DPRINTF(TsunamiUart
, "spurious read\n");
88 int reg
= (1 << 2) | (1 << 5) | (1 << 6);
89 if (status
& CONS_INT_RX
)
97 case 0x8: // Data register (RX)
99 panic("Invalid character");
101 DPRINTF(TsunamiUart
, "read data register \'%c\' %#02x\n",
102 isprint(next_char
) ? next_char
: ' ', next_char
);
108 case 0x9: // Interrupt Enable Register
113 // panic("%s: read daddr=%#x type=read *data=%#x\n", name(), daddr, *data);
119 TsunamiUart::write(MemReqPtr
&req
, const uint8_t *data
)
121 Addr daddr
= req
->paddr
& addr_mask
;
123 DPRINTF(TsunamiUart
, " write register %#x value %#x\n", daddr
, *(uint8_t*)data
);
126 status_store
= *data
;
128 case 0x03: // going to read RR3
131 case 0x28: // Ack of TX
133 if ((cons
->intStatus() & CONS_INT_TX
) == 0)
134 panic("Ack of transmit, though there was no interrupt");
136 cons
->clearInt(CONS_INT_TX
);
143 // going to write data???
147 DPRINTF(TsunamiUart
, "writing status register %#x \n",
152 case 0x8: // Data register (TX)
153 cons
->out(*(uint64_t *)data
);
156 DPRINTF(TsunamiUart
, "writing to DLM/IER %#x\n", *(uint8_t*)data
);
159 DPRINTF(TsunamiUart
, "writing to MCR %#x\n", *(uint8_t*)data
);
168 TsunamiUart::serialize(ostream
&os
)
170 SERIALIZE_SCALAR(status_store
);
171 SERIALIZE_SCALAR(next_char
);
172 SERIALIZE_SCALAR(valid_char
);
176 TsunamiUart::unserialize(Checkpoint
*cp
, const std::string
§ion
)
178 UNSERIALIZE_SCALAR(status_store
);
179 UNSERIALIZE_SCALAR(next_char
);
180 UNSERIALIZE_SCALAR(valid_char
);
183 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiUart
)
185 SimObjectParam
<SimConsole
*> console
;
186 SimObjectParam
<MemoryController
*> mmu
;
190 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiUart
)
192 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiUart
)
194 INIT_PARAM(console
, "The console"),
195 INIT_PARAM(mmu
, "Memory Controller"),
196 INIT_PARAM(addr
, "Device Address"),
197 INIT_PARAM(mask
, "Address Mask")
199 END_INIT_SIM_OBJECT_PARAMS(TsunamiUart
)
201 CREATE_SIM_OBJECT(TsunamiUart
)
203 return new TsunamiUart(getInstanceName(), console
, addr
, mask
, mmu
);
206 REGISTER_SIM_OBJECT("TsunamiUart", TsunamiUart
)