Skip to content

Commit 3f86a09

Browse files
committed
Atualizando leaf
1 parent 33500fb commit 3f86a09

File tree

4 files changed

+72
-50
lines changed

4 files changed

+72
-50
lines changed

config/leaf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"include_dirs": [],
5252
"repository": "https://github.com/daniel-santos-7/leaf",
53-
"top_module": "core",
53+
"top_module": "leaf",
5454
"extra_flags": [],
5555
"language_version": "08",
5656
"march": "rv32i",

rtl/kronos.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ kronos_core #(
165165
.data_addr (data_mem_addr),
166166
.data_rd_data (data_mem),
167167
.data_wr_data (data_mem_data_out),
168-
.data_mask (),
168+
.data_mask (data_mem_wstrb),
169169
.data_wr_en (data_mem_we),
170170
.data_req (data_mem_stb),
171171
.data_ack (data_ack),

rtl/leaf.sv

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
`include "processor_ci_defines.vh"
55
`endif
66

7-
`define ENABLE_SECOND_MEMORY 1 // Habilita o segundo barramento de memória
7+
//`define ENABLE_SECOND_MEMORY 1 // Habilita o segundo barramento de memória
88

99
module processorci_top (
1010
input logic sys_clk, // Clock de sistema
@@ -140,7 +140,7 @@ Controller #(
140140
// Core space
141141

142142
logic read_en, write_en;
143-
143+
/*
144144
core #(
145145
.RESET_ADDR(32'h0)
146146
) u_dut (
@@ -155,13 +155,30 @@ core #(
155155
.dmrd_en (read_en),
156156
.dmwr_en (write_en),
157157
.dmrw_addr (data_mem_addr),
158-
.dm_byte_en (), // mask
158+
.dm_byte_en (data_mem_wstrb), // mask
159159
160160
.ex_irq (0),
161161
.sw_irq (0),
162162
.tm_irq (0)
163163
);
164+
*/
165+
166+
leaf u_leaf (
167+
.clk_i (clk_core), // Clock de entrada
168+
.rst_i (rst_core), // Reset de entrada
169+
.ack_i (core_ack), // Acknowledgment de entrada
170+
.dat_i (core_data_in), // Dados de entrada
171+
172+
.cyc_o (core_cyc), // Ciclo de saída
173+
.stb_o (core_stb), // Strobe de saída
174+
.we_o (core_we), // Write enable de saída
175+
.sel_o (core_wstrb), // Seleção de byte de saída
176+
.adr_o (core_addr), // Endereço de saída
177+
.dat_o (core_data_out) // Dados de saída
178+
);
164179

180+
181+
/*
165182
assign core_cyc = 1'b1; // Always active for now
166183
assign core_stb = core_cyc;
167184
assign core_we = 1'b0; // Always read for now
@@ -170,5 +187,5 @@ assign core_data_out = 32'h0; // No data to write
170187
assign data_mem_we = write_en;
171188
assign data_mem_cyc = read_en | write_en;
172189
assign data_mem_stb = data_mem_cyc;
173-
190+
*/
174191
endmodule

simulate.py

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,53 @@
1313
BUILD_DIR = BASE_DIR / "build"
1414
PROCESSADOR_BASE = Path("/eda/processadores")
1515

16-
def analyze_all_vhdl_files(vhdl_files):
17-
"""Analisar todos os arquivos VHDL de uma vez."""
18-
print(f"[INFO] Analisando arquivos VHDL:")
19-
for f in vhdl_files:
20-
print(f" {f}")
21-
cmd = ["ghdl", "-a", *map(str, vhdl_files)]
16+
def run_ghdl_import(cpu_name, vhdl_files):
17+
"""Importar todos os arquivos VHDL com GHDL -i."""
18+
print("[INFO] Importando arquivos VHDL com GHDL (-i)...")
19+
cmd = [
20+
"ghdl", "-i", "--std=08",
21+
f"--work={cpu_name}",
22+
f"--workdir={BUILD_DIR}",
23+
f"-P{BUILD_DIR}"
24+
] + list(map(str, vhdl_files))
2225
print(f"[CMD] {' '.join(cmd)}")
2326
subprocess.run(cmd, check=True)
2427

25-
def synthesize_vhdl_entity(entity_name, output_file):
26-
"""Sintetizar a entidade principal para Verilog."""
27-
print(f"[INFO] Sintetizando entidade VHDL: {entity_name}")
28+
def run_ghdl_elaborate(cpu_name, top_module):
29+
"""Elaborar com GHDL -m."""
30+
print("[INFO] Elaborando projeto com GHDL (-m)...")
2831
cmd = [
29-
"ghdl", "--synth", entity_name,
30-
"--out=verilog", "-o", str(output_file)
32+
"ghdl", "-m", "--std=08",
33+
f"--work={cpu_name}",
34+
f"--workdir={BUILD_DIR}",
35+
f"-P{BUILD_DIR}",
36+
f"{top_module}"
3137
]
3238
print(f"[CMD] {' '.join(cmd)}")
3339
subprocess.run(cmd, check=True)
3440

41+
def synthesize_to_verilog(cpu_name, output_file, top_module):
42+
"""Sintetizar o VHDL com GHDL para Verilog."""
43+
print(f"[INFO] Sintetizando {cpu_name} para Verilog...")
44+
cmd = [
45+
"ghdl", "synth", "--latches", "--std=08",
46+
f"--work={cpu_name}",
47+
f"--workdir={BUILD_DIR}",
48+
f"-P{BUILD_DIR}",
49+
"--out=verilog", top_module
50+
]
51+
print(f"[CMD] {' '.join(cmd)} > {output_file}")
52+
with open(output_file, "w") as f:
53+
subprocess.run(cmd, stdout=f, check=True)
54+
3555
def main():
3656
if len(sys.argv) != 2:
3757
print("Uso: simulate.py <nome_do_processador>")
3858
sys.exit(1)
3959

4060
cpu_name = sys.argv[1]
4161

42-
# Mensagens informativas
43-
print("[INFO] Iniciando simulação do processador...")
44-
print("[INFO] Processador:", cpu_name)
45-
print("[INFO] Diretório base:", BASE_DIR)
46-
print("[INFO] Diretório RTL:", RTL_DIR)
47-
print("[INFO] Diretório de configuração:", CONFIG_DIR)
48-
print("[INFO] Diretório interno:", INTERNAL_DIR)
49-
print("[INFO] Diretório de build:", BUILD_DIR)
50-
print("[INFO] Verificando arquivos...")
62+
print("[INFO] Iniciando simulação do processador:", cpu_name)
5163

5264
config_file = CONFIG_DIR / f"{cpu_name}.json"
5365
top_module_file = RTL_DIR / f"{cpu_name}.sv"
@@ -57,16 +69,16 @@ def main():
5769
sys.exit(1)
5870

5971
if not top_module_file.exists():
60-
print(f"[ERRO] Top module do processador não encontrado: {top_module_file}")
72+
print(f"[ERRO] Top module não encontrado: {top_module_file}")
6173
sys.exit(1)
6274

6375
with open(config_file) as f:
6476
config = json.load(f)
6577

6678
file_list = config.get("files", [])
6779
include_dirs = config.get("include_dirs", [])
80+
top_module = config.get("top_module", cpu_name)
6881

69-
# Separar arquivos VHDL e outros
7082
vhdl_files = []
7183
other_files = []
7284

@@ -75,35 +87,31 @@ def main():
7587
if not src_file.exists():
7688
print(f"[AVISO] Arquivo não encontrado: {src_file}")
7789
continue
78-
7990
if src_file.suffix.lower() in [".vhdl", ".vhd"]:
8091
vhdl_files.append(src_file)
8192
else:
8293
other_files.append(str(src_file))
8394

84-
# Analisa todos os arquivos VHDL juntos (na ordem que apareceram)
8595
if vhdl_files:
86-
analyze_all_vhdl_files(vhdl_files)
87-
# Supondo que o nome da entidade VHDL principal é igual ao nome do processador
88-
verilog_output = PROCESSADOR_BASE / cpu_name / f"{cpu_name}.v"
89-
synthesize_vhdl_entity(cpu_name, verilog_output)
96+
BUILD_DIR.mkdir(exist_ok=True)
97+
run_ghdl_import(cpu_name, vhdl_files)
98+
run_ghdl_elaborate(cpu_name, top_module)
99+
100+
verilog_output = BUILD_DIR / f"{cpu_name}.v"
101+
synthesize_to_verilog(cpu_name, verilog_output, top_module)
90102
other_files.append(str(verilog_output))
91103

92-
# Adiciona tops e arquivos fixos
93104
other_files.append(str(top_module_file))
94-
other_files.append(str(INTERNAL_DIR / "verification_top.sv"))
95-
other_files.append(str(INTERNAL_DIR / "memory.sv"))
96-
other_files.append(str(INTERNAL_DIR / "axi4_to_wishbone.sv"))
97-
other_files.append(str(INTERNAL_DIR / "axi4lite_to_wishbone.sv"))
98-
other_files.append(str(INTERNAL_DIR / "ahblite_to_wishbone.sv"))
99-
100-
# Prepara diretório de build
101-
BUILD_DIR.mkdir(exist_ok=True)
105+
other_files += [
106+
str(INTERNAL_DIR / "verification_top.sv"),
107+
str(INTERNAL_DIR / "memory.sv"),
108+
str(INTERNAL_DIR / "axi4_to_wishbone.sv"),
109+
str(INTERNAL_DIR / "axi4lite_to_wishbone.sv"),
110+
str(INTERNAL_DIR / "ahblite_to_wishbone.sv")
111+
]
102112

103-
# Monta lista de -I para include_dirs
104113
include_flags = []
105114
for inc_dir in include_dirs:
106-
# Monta caminho absoluto dos include dirs
107115
inc_path = PROCESSADOR_BASE / cpu_name / inc_dir
108116
if inc_path.exists():
109117
include_flags.append(f"-I{inc_path}")
@@ -112,9 +120,7 @@ def main():
112120

113121
verilator_cmd = [
114122
"verilator", "--cc", "--exe", "--build",
115-
"--trace", # habilita trace
116-
"-Wno-fatal",
117-
"-DSIMULATION",
123+
"--trace", "-Wno-fatal", "-DSIMULATION",
118124
"--top-module", "verification_top",
119125
str(INTERNAL_DIR / "soc_main.cpp"),
120126
*include_flags,
@@ -123,12 +129,11 @@ def main():
123129
]
124130

125131
print(f"[CMD] {' '.join(verilator_cmd)}")
126-
print("[INFO] Rodando Verilator...")
127132
subprocess.run(verilator_cmd, check=True, cwd=BUILD_DIR)
128133

129134
sim_executable = BUILD_DIR / "obj_dir" / "Vverification_top"
130135
if sim_executable.exists():
131-
print("[INFO] Iniciando simulação...")
136+
print("[INFO] Executando simulação...")
132137
subprocess.run([str(sim_executable)], check=True)
133138
else:
134139
print("[ERRO] Executável de simulação não encontrado.")

0 commit comments

Comments
 (0)