Skip to content

Commit ae7f2ba

Browse files
committed
set the default option from ACLINT to CLINT
- Added a flag `ENABLE_ACLINT` in the Makefile, allowing users to choose whether to enable ACLINT. By default, ACLINT is disabled (inspired by QEMU). If enabled, ACLINT will be used instead of CLINT. - Introduced `OBJS_IR_CTRL` in the Makefile, including `plic.o` in it, and conditionally compiling either `aclint.o` or `clint.o` based on the state of the `ENABLE_ACLINT` flag. - Changed the default script for generating the device-tree configuration to the CLINT version, and adjusted the script selection based on whether ACLINT is enabled. - Remove the macro `SEMU_FEATURE_ACLINT` in feature.h
1 parent 86bdab9 commit ae7f2ba

File tree

4 files changed

+65
-57
lines changed

4 files changed

+65
-57
lines changed

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,27 @@ ifeq ($(call has, VIRTIONET), 1)
4343
OBJS_EXTRA += netdev.o
4444
endif
4545

46+
# Interrupt Controller
47+
OBJS_IR_CTRL := plic.o
48+
ENABLE_ACLINT ?= 0
49+
$(call set-feature, ACLINT)
50+
ifeq ($(call has, ACLINT), 1)
51+
OBJS_IR_CTRL += aclint.o
52+
else
53+
OBJS_IR_CTRL += clint.o
54+
endif
55+
4656
BIN = semu
4757
all: $(BIN) minimal.dtb
4858

4959
OBJS := \
5060
riscv.o \
5161
ram.o \
5262
utils.o \
53-
plic.o \
5463
uart.o \
5564
main.o \
56-
aclint.o \
57-
$(OBJS_EXTRA)
65+
$(OBJS_IR_CTRL) \
66+
$(OBJS_EXTRA)
5867

5968
deps := $(OBJS:%.o=.%.o.d)
6069

@@ -80,7 +89,11 @@ S := $E $E
8089
SMP ?= 1
8190
.PHONY: riscv-harts.dtsi
8291
riscv-harts.dtsi:
92+
ifeq ($(call has, ACLINT), 1)
93+
$(Q)python3 scripts/gen-aclint-dts.py $@ $(SMP) $(CLOCK_FREQ)
94+
else
8395
$(Q)python3 scripts/gen-hart-dts.py $@ $(SMP) $(CLOCK_FREQ)
96+
endif
8497

8598
minimal.dtb: minimal.dts riscv-harts.dtsi
8699
$(VECHO) " DTC\t$@\n"

feature.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,5 @@
1212
#define SEMU_FEATURE_VIRTIONET 1
1313
#endif
1414

15-
/* ACLINT */
16-
#ifndef SEMU_FEATURE_ACLINT
17-
#define SEMU_FEATURE_ACLINT 1
18-
#endif
19-
2015
/* Feature test macro */
2116
#define SEMU_HAS(x) SEMU_FEATURE_##x

scripts/gen-clint-dts.py renamed to scripts/gen-aclint-dts.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,26 @@ def plic_irq_format(nums):
2727
for i in range(nums):
2828
s += f"<&cpu{i}_intc 9>, "
2929
return s[:-2]
30-
31-
def clint_irq_format(nums):
30+
31+
def sswi_irq_format(nums):
32+
s = ""
33+
for i in range(nums):
34+
s += f"<&cpu{i}_intc 1>, " # 1 is the SSWI interrupt number (Supervisor Software Interrupt)
35+
return s[:-2]
36+
37+
def mswi_irq_format(nums):
38+
s = ""
39+
for i in range(nums):
40+
s += f"<&cpu{i}_intc 3>, " # 3 is the MSWI interrupt number (Machine Software Interrupt)
41+
return s[:-2]
42+
43+
def mtimer_irq_format(nums):
3244
s = ""
3345
for i in range(nums):
34-
s += f"<&cpu{i}_intc 3 &cpu{i}_intc 7>, "
46+
s += f"<&cpu{i}_intc 7>, " # 7 is the MTIMER interrupt number (Machine Timer Interrupt)
3547
return s[:-2]
3648

37-
def dtsi_template (cpu_list: str, plic_list, clint_list, clock_freq):
49+
def dtsi_template (cpu_list: str, plic_list, sswi_list, mtimer_list, mswi_list, clock_freq):
3850
return f"""/{{
3951
cpus {{
4052
#address-cells = <1>;
@@ -54,11 +66,28 @@ def dtsi_template (cpu_list: str, plic_list, clint_list, clock_freq):
5466
riscv,ndev = <31>;
5567
}};
5668
57-
clint0: clint@4300000 {{
58-
compatible = "riscv,clint0";
59-
interrupts-extended =
60-
{clint_list};
61-
reg = <0x4300000 0x10000>;
69+
sswi0: sswi@4500000 {{
70+
#interrupt-cells = <0>;
71+
#address-cells = <0>;
72+
interrupt-controller;
73+
interrupts-extended = {sswi_list};
74+
reg = <0x4500000 0x4000>;
75+
compatible = "riscv,aclint-sswi";
76+
}};
77+
78+
mswi0: mswi@4400000 {{
79+
#interrupt-cells = <0>;
80+
#address-cells = <0>;
81+
interrupt-controller;
82+
interrupts-extended = {mswi_list};
83+
reg = <0x4400000 0x4000>;
84+
compatible = "riscv,aclint-mswi";
85+
}};
86+
87+
mtimer0: mtimer@4300000 {{
88+
interrupts-extended = {mtimer_list};
89+
reg = <0x4300000 0x8000>;
90+
compatible = "riscv,aclint-mtimer";
6291
}};
6392
}};
6493
}};
@@ -69,4 +98,4 @@ def dtsi_template (cpu_list: str, plic_list, clint_list, clock_freq):
6998
clock_freq = int(sys.argv[3])
7099

71100
with open(dtsi, "w") as dts:
72-
dts.write(dtsi_template(cpu_format(harts), plic_irq_format(harts), clint_irq_format(harts), clock_freq))
101+
dts.write(dtsi_template(cpu_format(harts), plic_irq_format(harts), sswi_irq_format(harts), mswi_irq_format(harts), mtimer_irq_format(harts), clock_freq))

scripts/gen-hart-dts.py

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,14 @@ def plic_irq_format(nums):
2727
for i in range(nums):
2828
s += f"<&cpu{i}_intc 9>, "
2929
return s[:-2]
30-
31-
def sswi_irq_format(nums):
32-
s = ""
33-
for i in range(nums):
34-
s += f"<&cpu{i}_intc 1>, " # 1 is the SSWI interrupt number (Supervisor Software Interrupt)
35-
return s[:-2]
36-
37-
def mswi_irq_format(nums):
38-
s = ""
39-
for i in range(nums):
40-
s += f"<&cpu{i}_intc 3>, " # 3 is the MSWI interrupt number (Machine Software Interrupt)
41-
return s[:-2]
42-
43-
def mtimer_irq_format(nums):
30+
31+
def clint_irq_format(nums):
4432
s = ""
4533
for i in range(nums):
46-
s += f"<&cpu{i}_intc 7>, " # 7 is the MTIMER interrupt number (Machine Timer Interrupt)
34+
s += f"<&cpu{i}_intc 3 &cpu{i}_intc 7>, "
4735
return s[:-2]
4836

49-
def dtsi_template (cpu_list: str, plic_list, sswi_list, mtimer_list, mswi_list, clock_freq):
37+
def dtsi_template (cpu_list: str, plic_list, clint_list, clock_freq):
5038
return f"""/{{
5139
cpus {{
5240
#address-cells = <1>;
@@ -66,28 +54,11 @@ def dtsi_template (cpu_list: str, plic_list, sswi_list, mtimer_list, mswi_list,
6654
riscv,ndev = <31>;
6755
}};
6856
69-
sswi0: sswi@4500000 {{
70-
#interrupt-cells = <0>;
71-
#address-cells = <0>;
72-
interrupt-controller;
73-
interrupts-extended = {sswi_list};
74-
reg = <0x4500000 0x4000>;
75-
compatible = "riscv,aclint-sswi";
76-
}};
77-
78-
mswi0: mswi@4400000 {{
79-
#interrupt-cells = <0>;
80-
#address-cells = <0>;
81-
interrupt-controller;
82-
interrupts-extended = {mswi_list};
83-
reg = <0x4400000 0x4000>;
84-
compatible = "riscv,aclint-mswi";
85-
}};
86-
87-
mtimer0: mtimer@4300000 {{
88-
interrupts-extended = {mtimer_list};
89-
reg = <0x4300000 0x8000>;
90-
compatible = "riscv,aclint-mtimer";
57+
clint0: clint@4300000 {{
58+
compatible = "riscv,clint0";
59+
interrupts-extended =
60+
{clint_list};
61+
reg = <0x4300000 0x10000>;
9162
}};
9263
}};
9364
}};
@@ -98,4 +69,4 @@ def dtsi_template (cpu_list: str, plic_list, sswi_list, mtimer_list, mswi_list,
9869
clock_freq = int(sys.argv[3])
9970

10071
with open(dtsi, "w") as dts:
101-
dts.write(dtsi_template(cpu_format(harts), plic_irq_format(harts), sswi_irq_format(harts), mswi_irq_format(harts), mtimer_irq_format(harts), clock_freq))
72+
dts.write(dtsi_template(cpu_format(harts), plic_irq_format(harts), clint_irq_format(harts), clock_freq))

0 commit comments

Comments
 (0)