Skip to content

Commit 45b37e9

Browse files
authored
Merge pull request #54 from glguida/sysemu/cleanup_best_effort
Bulk erbium emulator update
2 parents 9431369 + 661da32 commit 45b37e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2061
-109
lines changed
Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <vector>
1717
#include <unistd.h>
1818

19+
#include "emu_defines.h"
1920
#include "memory/memory_error.h"
2021
#include "memory/memory_region.h"
2122
#include "system.h"
@@ -31,6 +32,9 @@ struct PLIC_Interrupt_Target {
3132
PLIC_Target_Notify notify;
3233
};
3334

35+
//
36+
// A generic PLIC device.
37+
//
3438
// S = #sources, T = #targets
3539
template <unsigned long long Base, size_t N, size_t S, size_t T>
3640
struct PLIC : public MemoryRegion
@@ -205,10 +209,10 @@ struct PLIC : public MemoryRegion
205209

206210
if ((pos % 0x1000) == 0) { // Threshold registers
207211
*result32 = threshold[name_id];
208-
} else if ((pos % 0x1000) == 4) { // MaxID registers
212+
} else if ((pos % 0x1000) == 4) { // Claim/Complete registers
209213
// Read current MaxID
210214
*result32 = max_id[name_id];
211-
// To claim an interrupt, the target reads its MaxID register
215+
// To claim an interrupt, the target reads its Claim register
212216
if (max_id[name_id] > 0) {
213217
in_flight[max_id[name_id]] = true;
214218
// Save the ID of the Target that claimed the source interrupt
@@ -279,66 +283,6 @@ struct PLIC : public MemoryRegion
279283
std::array<uint32_t, T> max_id; // Interrupt MaxID (per target)
280284
};
281285

282-
template <unsigned long long Base, size_t N>
283-
struct PU_PLIC : public PLIC<Base, N, 41, 12>
284-
{
285-
static void Target_Minion_Machine_external_interrupt(System* system, bool raise) {
286-
for (int i = 0; i < EMU_NUM_MINION_SHIRES; i++) {
287-
if (raise) {
288-
system->raise_machine_external_interrupt(i);
289-
} else {
290-
system->clear_machine_external_interrupt(i);
291-
}
292-
}
293-
}
294-
295-
static void Target_Minion_Supervisor_external_interrupt(System* system, bool raise) {
296-
for (int i = 0; i < EMU_NUM_MINION_SHIRES; i++) {
297-
if (raise) {
298-
system->raise_supervisor_external_interrupt(i);
299-
} else {
300-
system->clear_supervisor_external_interrupt(i);
301-
}
302-
}
303-
}
304-
305-
const std::vector<PLIC_Interrupt_Target> &get_target_list() const {
306-
static const std::vector<PLIC_Interrupt_Target> targets = {
307-
{10, 0x21, Target_Minion_Machine_external_interrupt},
308-
{11, 0x20, Target_Minion_Supervisor_external_interrupt},
309-
};
310-
return targets;
311-
}
312-
};
313-
314-
template <unsigned long long Base, size_t N>
315-
struct SP_PLIC : public PLIC<Base, N, 148, 2>
316-
{
317-
static void Target_SP_Machine_external_interrupt(System* system, bool raise) {
318-
if (raise) {
319-
system->raise_machine_external_interrupt(IO_SHIRE_ID);
320-
} else {
321-
system->clear_machine_external_interrupt(IO_SHIRE_ID);
322-
}
323-
}
324-
325-
static void Target_SP_Supervisor_external_interrupt(System* system, bool raise) {
326-
if (raise) {
327-
system->raise_supervisor_external_interrupt(IO_SHIRE_ID);
328-
} else {
329-
system->clear_supervisor_external_interrupt(IO_SHIRE_ID);
330-
}
331-
}
332-
333-
const std::vector<PLIC_Interrupt_Target> &get_target_list() const {
334-
static const std::vector<PLIC_Interrupt_Target> targets = {
335-
{0, 0, Target_SP_Machine_external_interrupt},
336-
{1, 1, Target_SP_Supervisor_external_interrupt},
337-
};
338-
return targets;
339-
}
340-
};
341-
342286
} // namespace bemu
343287

344288
#endif // BEMU_PLIC_H

sw-sysemu/devices/plic_er.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-------------------------------------------------------------------------
2+
* Copyright (c) 2025 Ainekko, Co.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*-------------------------------------------------------------------------*/
5+
6+
#ifndef BEMU_PLIC_ER_H
7+
#define BEMU_PLIC_ER_H
8+
9+
#include "plic_dev.h"
10+
11+
namespace bemu {
12+
13+
//
14+
// Erbium PLIC Implementation.
15+
//
16+
template <unsigned long long Base, size_t N>
17+
struct ER_PLIC : public PLIC<Base, N, 32, 2>
18+
{
19+
static void Target_Machine_external_interrupt(System* system, bool raise) {
20+
if (raise) {
21+
system->raise_machine_external_interrupt(0);
22+
} else {
23+
system->clear_machine_external_interrupt(0);
24+
}
25+
}
26+
27+
static void Target_Supervisor_external_interrupt(System* system, bool raise) {
28+
if (raise) {
29+
system->raise_supervisor_external_interrupt(0);
30+
} else {
31+
system->clear_supervisor_external_interrupt(0);
32+
}
33+
}
34+
35+
const std::vector<PLIC_Interrupt_Target> &get_target_list() const override {
36+
static const std::vector<PLIC_Interrupt_Target> targets = {
37+
{0, 0, Target_Machine_external_interrupt},
38+
{1, 1, Target_Supervisor_external_interrupt},
39+
};
40+
return targets;
41+
}
42+
};
43+
44+
} // namespace bemu
45+
46+
#endif // BEMU_PLIC_ERBIUM_H

sw-sysemu/devices/plic_pu.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*-------------------------------------------------------------------------
2+
* Copyright (c) 2025 Ainekko, Co.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*-------------------------------------------------------------------------*/
5+
6+
#ifndef BEMU_PLIC_PU_H
7+
#define BEMU_PLIC_PU_H
8+
9+
#include "plic_dev.h"
10+
11+
12+
namespace bemu {
13+
14+
//
15+
// Peripheral PLIC Implementation.
16+
//
17+
template <unsigned long long Base, size_t N>
18+
struct PU_PLIC : public PLIC<Base, N, 41, 12>
19+
{
20+
static void Target_Minion_Machine_external_interrupt(System* system, bool raise) {
21+
for (int i = 0; i < EMU_NUM_MINION_SHIRES; i++) {
22+
if (raise) {
23+
system->raise_machine_external_interrupt(i);
24+
} else {
25+
system->clear_machine_external_interrupt(i);
26+
}
27+
}
28+
}
29+
30+
static void Target_Minion_Supervisor_external_interrupt(System* system, bool raise) {
31+
for (int i = 0; i < EMU_NUM_MINION_SHIRES; i++) {
32+
if (raise) {
33+
system->raise_supervisor_external_interrupt(i);
34+
} else {
35+
system->clear_supervisor_external_interrupt(i);
36+
}
37+
}
38+
}
39+
40+
const std::vector<PLIC_Interrupt_Target> &get_target_list() const {
41+
static const std::vector<PLIC_Interrupt_Target> targets = {
42+
{10, 0x21, Target_Minion_Machine_external_interrupt},
43+
{11, 0x20, Target_Minion_Supervisor_external_interrupt},
44+
};
45+
return targets;
46+
}
47+
};
48+
49+
} // namespace bemu
50+
51+
#endif // BEMU_PLIC_H

sw-sysemu/devices/plic_sp.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-------------------------------------------------------------------------
2+
* Copyright (c) 2025 Ainekko, Co.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*-------------------------------------------------------------------------*/
5+
6+
#ifndef BEMU_PLIC_SP_H
7+
#define BEMU_PLIC_SP_H
8+
9+
#include "plic_dev.h"
10+
11+
namespace bemu {
12+
13+
//
14+
// ETSOC-1 Service Processor PLIC
15+
//
16+
template <unsigned long long Base, size_t N>
17+
struct SP_PLIC : public PLIC<Base, N, 148, 2>
18+
{
19+
static void Target_SP_Machine_external_interrupt(System* system, bool raise) {
20+
if (raise) {
21+
system->raise_machine_external_interrupt(IO_SHIRE_ID);
22+
} else {
23+
system->clear_machine_external_interrupt(IO_SHIRE_ID);
24+
}
25+
}
26+
27+
static void Target_SP_Supervisor_external_interrupt(System* system, bool raise) {
28+
if (raise) {
29+
system->raise_supervisor_external_interrupt(IO_SHIRE_ID);
30+
} else {
31+
system->clear_supervisor_external_interrupt(IO_SHIRE_ID);
32+
}
33+
}
34+
35+
const std::vector<PLIC_Interrupt_Target> &get_target_list() const {
36+
static const std::vector<PLIC_Interrupt_Target> targets = {
37+
{0, 0, Target_SP_Machine_external_interrupt},
38+
{1, 1, Target_SP_Supervisor_external_interrupt},
39+
};
40+
return targets;
41+
}
42+
};
43+
44+
} // namespace bemu
45+
46+
#endif // BEMU_PLIC_H

sw-sysemu/emu_defines.h

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,51 @@ namespace bemu {
2020
#endif
2121

2222
#if EMU_ERBIUM
23-
#define EMU_NUM_SHIRES 1
23+
//
24+
// Erbium
25+
//
26+
27+
// Basic Topology
28+
#define EMU_NUM_SHIRES 1
2429
#define EMU_NUM_MINION_SHIRES (EMU_NUM_SHIRES)
2530
#define EMU_NUM_COMPUTE_SHIRES (EMU_NUM_MINION_SHIRES)
26-
#define EMU_THREADS_PER_MINION 2
27-
#define EMU_MINIONS_PER_NEIGH 8
31+
#define EMU_THREADS_PER_MINION 2
32+
#define EMU_MINIONS_PER_NEIGH 8
2833
#define EMU_THREADS_PER_NEIGH (EMU_THREADS_PER_MINION * EMU_MINIONS_PER_NEIGH)
29-
#define EMU_NEIGH_PER_SHIRE 1
34+
#define EMU_NEIGH_PER_SHIRE 1
3035
#define EMU_MINIONS_PER_SHIRE (EMU_MINIONS_PER_NEIGH * EMU_NEIGH_PER_SHIRE)
3136
#define EMU_THREADS_PER_SHIRE (EMU_THREADS_PER_NEIGH * EMU_NEIGH_PER_SHIRE)
3237
#define EMU_NUM_NEIGHS (EMU_NUM_MINION_SHIRES * EMU_NEIGH_PER_SHIRE)
3338
#define EMU_NUM_MINIONS (EMU_NUM_MINION_SHIRES * EMU_MINIONS_PER_SHIRE)
3439
#define EMU_NUM_THREADS (EMU_NUM_MINION_SHIRES * EMU_THREADS_PER_SHIRE)
3540

41+
// Tensor Reduce Configuartion
42+
#define EMU_TREDUCE_MAX_MINION (EMU_NUM_MINIONS - 1)
43+
#define EMU_TREDUCE_MAX_HEIGHT 2
44+
45+
// System Features
3646
#define EMU_HAS_WDT 1
47+
#define EMU_HAS_RVTIMER 1
3748
#define EMU_HAS_L2 0
3849
#define EMU_HAS_SVCPROC 0
3950
#define EMU_HAS_MEMSHIRE 0
4051
#define EMU_HAS_SPIO 0
4152
#define EMU_HAS_PU 0
42-
#define EMU_HAS_PMA 0
4353
#define EMU_HAS_PTW 0
54+
#define EMU_HAS_GFX 0
55+
#define EMU_HAS_MSG_PORTS 0
4456

4557
// Main memory size (16MB of MRAM)
4658
#define EMU_DRAM_SIZE (16ULL*1024ULL*1024ULL)
4759

60+
#define PA_SIZE 32
61+
4862
#elif EMU_ETSOC1
63+
//
64+
// ETSOC-1
65+
//
4966

50-
// Maximum number of threads
67+
// Basic Topology
5168
#define EMU_NUM_SHIRES 35
5269
#define EMU_NUM_MINION_SHIRES (EMU_NUM_SHIRES - 1)
5370
#define EMU_NUM_COMPUTE_SHIRES (EMU_NUM_MINION_SHIRES - 2)
@@ -62,6 +79,10 @@ namespace bemu {
6279
#define EMU_NUM_MINIONS ((EMU_NUM_MINION_SHIRES * EMU_MINIONS_PER_SHIRE) + 1)
6380
#define EMU_NUM_THREADS ((EMU_NUM_MINION_SHIRES * EMU_THREADS_PER_SHIRE) + 1)
6481

82+
// Tensor Reduce configuration.
83+
#define EMU_TREDUCE_MAX_MINION (0x1FFF) // ET-SOC1 TENSOR_REDUCE send/recv: up to 8k minions. (!)
84+
#define EMU_TREDUCE_MAX_HEIGHT 0xF // ET-SOC1 TENSOR_REDUCE bcast/reduce: up to 64k minions. (!)
85+
6586
//
6687
// IO-Shire (and Service Processor) Configuration.
6788
//
@@ -111,24 +132,31 @@ namespace bemu {
111132
#define SCP_REGION_BASE 0x80000000ULL
112133
#define SCP_REGION_SIZE 0x80000000ULL
113134

114-
//
115-
// PMA Configuration
116-
//
117-
#define EMU_HAS_PMA 1
118-
119135
//
120136
// PTW Configuration
121137
//
122138
// Note: ET-SOC-1 PTW is presumably broken, but is left
123139
// enabled in the emulator to support the code that expects it.
124140
#define EMU_HAS_PTW 1
125141

142+
//
143+
// Graphics (tex_send CSR)
144+
//
145+
#define EMU_HAS_GFX 1
146+
147+
//
148+
// Message ports (portctrl, porthead CSRs)
149+
//
150+
#define EMU_HAS_MSG_PORTS 1
151+
126152
//
127153
// Main memory size (up to 32GiB)
128154
//
129155
#define EMU_DRAM_SIZE (32ULL*1024ULL*1024ULL*1024ULL)
130156
#define EMU_HAS_HIGH_MEMORY 1
131157

158+
#define PA_SIZE 40
159+
132160
#else
133161
#error "Architecture unspecified."
134162
#endif
@@ -154,8 +182,6 @@ namespace bemu {
154182
#define EMU_NUM_FCC_COUNTERS_PER_THREAD 2
155183

156184
// VA to PA translation
157-
// TODO: Different for Erbium.
158-
#define PA_SIZE 40
159185
#define PA_M ((((uint64_t)1) << PA_SIZE) - 1)
160186
#define VA_SIZE 48
161187
#define VA_M ((((uint64_t)1) << VA_SIZE) - 1)

sw-sysemu/esrs_er.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,12 @@ uint64_t System::esr_read(const Agent& agent, uint64_t addr)
359359
case ESR_FAST_LOCAL_BARRIER31:
360360
return shire_other_esrs[shire].fast_local_barrier[(esr - ESR_FAST_LOCAL_BARRIER0)>>3];
361361
case ESR_MTIME:
362-
return 0;
363-
// TODO: implement actual timer (restore PU)
364-
//return memory.timer_read_mtime();
362+
return memory.rvtimer_read_mtime();
365363
case ESR_MTIMECMP:
366-
return 0;
367-
// TODO: implement actual timer (restore PU)
368-
// return memory.timer_read_mtimecmp();
364+
return memory.rvtimer_read_mtimecmp();
369365
case ESR_TIME_CONFIG:
366+
// TODO: undefined
370367
return 0;
371-
// TODO: implement actual timer (restore PU)
372-
// return memory.timer_read_mtimecmp();
373368
case ESR_MTIME_LOCAL_TARGET:
374369
return shire_other_esrs[shire].mtime_local_target;
375370
case ESR_THREAD0_DISABLE:
@@ -639,13 +634,13 @@ void System::esr_write(const Agent& agent, uint64_t addr, uint64_t value)
639634
shire_other_esrs[shire].fast_local_barrier[(esr - ESR_FAST_LOCAL_BARRIER0)>>3]);
640635
return;
641636
case ESR_MTIME:
642-
// TODO: implement actual timer (restore PU)
637+
memory.rvtimer_write_mtime(agent, value);
643638
return;
644639
case ESR_MTIMECMP:
645-
// TODO: implement actual timer (restore PU)
640+
memory.rvtimer_write_mtimecmp(agent, value);
646641
return;
647642
case ESR_TIME_CONFIG:
648-
// TODO: implement actual timer
643+
// TODO: undefined
649644
// shire_other_esrs[shire].time_config = uint16_t(value & 0x3ff);
650645
// LOG_AGENT(DEBUG, agent, "S%u:time_config = 0x%" PRIx16,
651646
// shireid(shire), shire_other_esrs[shire].time_config);

0 commit comments

Comments
 (0)