Skip to content

Commit

Permalink
Cleanup automatic generation
Browse files Browse the repository at this point in the history
  • Loading branch information
slgth authored and ASintzoff committed Oct 25, 2024
1 parent e45766f commit 02f3d08
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 135 deletions.
9 changes: 0 additions & 9 deletions config/gen_from_riscv_config/cv32a65x/isa/isa.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
|M | RV32M Multiplication and Division Instructions | the standard integer multiplication and division instruction extension, which is named “M” and contains instructions that multiply or divide values held in two integer registers.
|C | RV32C Compressed Instructions | RVC uses a simple compression scheme that offers shorter 16-bit versions of common 32-bit RISC-V instructions when: the immediate or address offset is small; one of the registers is the zero register (x0), the ABI link register (x1), or the ABI stack pointer (x2); the destination register and the first source register are identical; the registers used are the 8 most popular ones.The C extension is compatible with all other standard instruction extensions. The C extension allows 16-bit instructions to be freely intermixed with 32-bit instructions, with the latter now able to start on any 16-bit boundary. With the addition of the C extension, JAL and JALR instructions will no longer raise an instruction misaligned exception
|Zicsr | RV32Zicsr Control and Status Register Instructions | All CSR instructions atomically read-modify-write a single CSR, whose CSR specifier is encoded in the 12-bit csr field of the instruction held in bits 31–20. The immediate forms use a 5-bit zero-extended immediate encoded in the rs1 field.
|Zifencei | RVZifencei Instruction Fetch Fence | FENCE.I instruction that provides explicit synchronization between writes to instruction memory and instruction fetches on the same hart.Currently, this instruction is the only standard mechanism to ensure that stores visible to a hart will also be visible to it instruction fetches.
|Zcb | RV32Zcb Code Size Reduction Instructions | Zcb belongs to the group of extensions called RISC-V Code Size Reduction Extension (Zc*). Zc* has become the superset of the Standard C extension adding more 16-bit instructions to the ISA. Zcb includes the 16-bit version of additional Integer (I), Multiply (M), and Bit-Manipulation (Zbb) Instructions. All the Zcb instructions require at least standard C extension support as a prerequisite, along with M and Zbb extensions for the 16-bit version of the respective instructions.
|Zba | RVZba Address generation instructions | The Zba instructions can be used to accelerate the generation of addresses that index into arrays of basic types (halfword, word, doubleword) using both unsigned word-sized and XLEN-sized indices: a shifted index is added to a base address. The shift and add instructions do a left shift of 1, 2, or 3 because these are commonly found in real-world code and because they can be implemented with a minimal amount of additional hardware beyond that of the simple adder. This avoids lengthening the critical path in implementations. While the shift and add instructions are limited to a maximum left shift of 3, the slli instruction (from the base ISA) can be used to perform similar shifts for indexing into arrays of wider elements. The slli.uw added in this extension can be used when the index is to be interpreted as an unsigned word.
|Zbb | RVZbb Basic bit-manipulation | The bit-manipulation (bitmanip) extension collection is comprised of several component extensions to the base RISC-V architecture that are intended to provide some combination of code size reduction, performance improvement, and energy reduction. While the instructions are intended to have general use, some instructions are more useful in some domains than others. Hence, several smaller bitmanip extensions are provided. Each of these smaller extensions is grouped by common function and use case, and each has its own Zb*-extension name.
Expand Down Expand Up @@ -133,14 +132,6 @@
| CSRRCI | csrrci rd, csr, uimm[4:0] | t = CSRs[csr]; CSRs[csr] = t & ∼zext(uimm[4:0]); x[rd] = t | NONE | Attempts to access a non-existent CSR raise an illegal instruction exception. Attempts to access a CSR without appropriate privilege level or to write a read-only register also raise illegal instruction exceptions. | Reads the value of the CSR, zero-extends the value to 32 bits, and writes it to integer register rd. The zero-extends immediate value is treated as a bit mask that specifies bit positions to be cleared in the CSR. Any bit that is high in zero-extends immediate will cause the corresponding bit to be set in the CSR, if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might have side effects when written). If the uimm[4:0] field is zero, then these instructions will not write to the CSR, and shall not cause any of the side effects that might otherwise occur on a CSR write. | Control and Status Register Operations
|===
==== RVZifencei Instruction Fetch Fence
|===
| Name | Format | Pseudocode|Invalid_values | Exception_raised | Description| Op Name
| FENCE.I | fence.i | Fence(Store, Fetch) | NONE | NONE | The FENCE.I instruction is used to synchronize the instruction and data streams. RISC-V does not guarantee that stores to instruction memory will be made visible to instruction fetches on the same RISC-V hart until a FENCE.I instruction is executed. A FENCE.I instruction only ensures that a subsequent instruction fetch on a RISC-V hart will see any previous data stores already visible to the same RISC-V hart. | Fetch Fence Operations
|===
==== RV32Zcb Code Size Reduction Instructions
|===
Expand Down
1 change: 0 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
/_build
*.swp
*.html
generated
2 changes: 0 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
all: prepare sphinx

prepare:
python3 scripts/spec_builder.py 04_cv32a65x
make -C 04_cv32a65x/riscv priv-html unpriv-html
make -C 04_cv32a65x/design design-html

python3 scripts/spec_builder.py 06_cv64a6_mmu
make -C 06_cv64a6_mmu/riscv priv-html unpriv-html

sphinx:
Expand Down
15 changes: 10 additions & 5 deletions docs/design/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ ifeq ($(CONFIG),)
$(error CONFIG must be defined)
endif

current_dir = $(shell pwd)

# Path of current file, intended to be included by a configuration subfolder
design_dir := $(dir $(lastword $(MAKEFILE_LIST)))

all: design-pdf design-html

setup:
mkdir -p build
pwd
echo $(design_dir)

cp -r $(design_dir)/design-manual/* build
cp -r $(design_dir)/../../config/gen_from_riscv_config/$(CONFIG)/* build/source
cp -r $(design_dir)/../riscv-isa/riscv-isa-manual/docs-resources build
cp $(design_dir)/../common/*.adoc build/source
cp ../generated/config.adoc build/source
cp -rf generated/* build/source

cp -rf source/* build/source

cd ../../../config/gen_from_riscv_config && python3 scripts/riscv_config_gen.py -s ../riscv-config/cv32a65x/generated/isa_gen.yaml -i templates/isa_template.yaml -m updaters/cv32a65x/isa_updater.yaml -t cv32a65x -f adoc
cd ../../../config/gen_from_riscv_config && python3 scripts/riscv_config_gen.py -s ../riscv-config/cv32a65x/generated/isa_gen.yaml -c ../riscv-config/cv32a65x/generated/custom_gen.yaml -m updaters/cv32a65x/csr_updater.yaml -t cv32a65x -f adoc
cp -r $(design_dir)/../../config/gen_from_riscv_config/$(CONFIG)/* build/source

cd ../.. && python3 scripts/spec_builder.py --target $(CONFIG) --gen-config $(current_dir)/build/source/config.adoc --gen-parameters $(current_dir)/build/source/parameters.adoc --gen-ports $(current_dir)/build/source

design-pdf: setup
cd build; make SKIP_DOCKER=true build/design.pdf
cp ./build/build/design.pdf design-$(CONFIG).pdf
Expand Down
8 changes: 6 additions & 2 deletions docs/riscv-isa/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ ifeq ($(CONFIG),)
$(error CONFIG must be defined)
endif

current_dir = $(shell pwd)

# Path of current file, intended to be included by a configuration subfolder
riscv-isa_dir := $(dir $(lastword $(MAKEFILE_LIST)))

all: priv-pdf priv-html unpriv-pdf unpriv-html

setup:
mkdir -p build/riscv-isa-manual

cp -r $(riscv-isa_dir)/riscv-isa-manual/* build/riscv-isa-manual
cp -r $(riscv-isa_dir)/src build/riscv-isa-manual
cp -r $(riscv-isa_dir)/../common/*.adoc build/riscv-isa-manual/src
cp ../generated/config.adoc build/riscv-isa-manual/src
cp $(riscv-isa_dir)/../common/*.adoc build/riscv-isa-manual/src

cd ../.. && python3 scripts/spec_builder.py --target $(CONFIG) --gen-config $(current_dir)/build/riscv-isa-manual/src/config.adoc

priv-pdf: setup
cd build/riscv-isa-manual; make SKIP_DOCKER=true build/riscv-privileged.pdf
Expand Down
2 changes: 1 addition & 1 deletion docs/scripts/parameters_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
sys.path.append(os.getcwd() + "/../util")
from user_config import get_config

def parameters_extractor(spec_number, target):
def parameters_extractor(target):

parameters = {}
file_in = "../core/include/config_pkg.sv"
Expand Down
222 changes: 107 additions & 115 deletions docs/scripts/spec_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,141 +144,133 @@ def main():
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("config_folder")
parser.add_argument("--target", required=True)
parser.add_argument("--gen-config", help="Generate target variables documentation file")
parser.add_argument("--gen-parameters", help="Generate target parameters files")
parser.add_argument("--gen-ports-folder", help="Generate target ports files")
args = parser.parse_args()

[spec_number, target] = args.config_folder.split("_", 1)
generate_file_type = "adoc"
target = args.target

# Parameters
parameters = parameters_extractor(spec_number, target)

pathout = f"./{spec_number}_{target}/design/source"
if generate_file_type in ['rst']:
fileout = f"{pathout}/parameters_{target}.rst"
writeout_parameter_table(fileout, parameters, target)
elif generate_file_type in ['adoc']:
pathout_design = f"./{spec_number}_{target}/design/generated"
os.makedirs(pathout_design, exist_ok=True)
fileout = f"{pathout_design}/parameters.adoc"
writeout_parameter_table_adoc(fileout, parameters, target)
else:
raise Exception("Format de sortie %s non pris en charge"%generate_file_type)

# Config
pathout_common = f"./{spec_number}_{target}/generated"
os.makedirs(pathout_common, exist_ok=True)
with open(f"{pathout_common}/config.adoc", "w") as fout:
fout.write(f":ohg-config: {target.upper()}\n")
for name, value in DEFAULT_PARAMS.items():
fout.write(_format_parameter_adoc(name, value))
for name, parameter in parameters.items():
fout.write(_format_parameter_adoc(name, parameter.value))
parameters = parameters_extractor(target)

# User_cfg
export_user_cfg_doc("01_cva6_user/user_cfg_doc.rst", parameters)

# Parameters
if args.gen_parameters is not None:
os.makedirs(os.path.dirname(args.gen_parameters), exist_ok=True)
writeout_parameter_table_adoc(args.gen_parameters, parameters, target)
print(f"File {args.gen_parameters} written")

# Config
if args.gen_config is not None:
os.makedirs(os.path.dirname(args.gen_config), exist_ok=True)
with open(args.gen_config, "w") as fout:
fout.write(f":ohg-config: {target.upper()}\n")
for name, value in DEFAULT_PARAMS.items():
fout.write(_format_parameter_adoc(name, value))
for name, parameter in parameters.items():
fout.write(_format_parameter_adoc(name, parameter.value))
print(f"File {args.gen_config} written")

# Ports
file = []
file.append("../core/cva6.sv")
file.append("../core/frontend/frontend.sv")
file.append("../core/frontend/bht.sv")
file.append("../core/frontend/btb.sv")
file.append("../core/frontend/ras.sv")
file.append("../core/frontend/instr_queue.sv")
file.append("../core/frontend/instr_scan.sv")
file.append("../core/instr_realign.sv")
file.append("../core/id_stage.sv")
file.append("../core/issue_stage.sv")
file.append("../core/ex_stage.sv")
file.append("../core/commit_stage.sv")
file.append("../core/controller.sv")
file.append("../core/csr_regfile.sv")
file.append("../core/decoder.sv")
file.append("../core/compressed_decoder.sv")
file.append("../core/scoreboard.sv")
file.append("../core/issue_read_operands.sv")
file.append("../core/alu.sv")
file.append("../core/branch_unit.sv")
file.append("../core/csr_buffer.sv")
file.append("../core/mult.sv")
file.append("../core/multiplier.sv")
file.append("../core/serdiv.sv")
file.append("../core/load_store_unit.sv")
file.append("../core/load_unit.sv")
file.append("../core/store_unit.sv")
file.append("../core/lsu_bypass.sv")
file.append("../core/cvxif_fu.sv")
file.append("../core/cache_subsystem/cva6_hpdcache_subsystem.sv")

black_list = define_blacklist(parameters)

for filein in file:
comments = []
a = re.match(r".*\/(.*).sv", filein)
module = a.group(1)
print("Input file " + filein)
ports = []
with open(filein, "r", encoding="utf-8") as fin:
description = "none"
connexion = "none"
for line in fin:
e = re.match(r"^ +(?:(in|out))put +([\S]*(?: +.* *|)) ([\S]*)\n", line)
d = re.match(r"^ +\/\/ (.*) - ([\S]*)\n", line)
if d:
description = d.group(1)
connexion = d.group(2)
if e:
name = e.group(3)
name = name.replace(",", "")
data_type = e.group(2)
data_type = data_type.replace(" ", "")
if connexion in black_list:
for i, comment in enumerate(comments):
if black_list[connexion][0] == comment[0]:
comment[1] = (
comment[1]
+ f"\n| ``{name}`` {e.group(1)}put is tied to {black_list[connexion][1]}"
)
break
else:
comments.append(
[
black_list[connexion][0],
f"``{name}`` {e.group(1)}put is tied to {black_list[connexion][1]}",
]
)
else:
if name in black_list:
if args.gen_ports_folder is not None:
file = []
file.append("../core/cva6.sv")
file.append("../core/frontend/frontend.sv")
file.append("../core/frontend/bht.sv")
file.append("../core/frontend/btb.sv")
file.append("../core/frontend/ras.sv")
file.append("../core/frontend/instr_queue.sv")
file.append("../core/frontend/instr_scan.sv")
file.append("../core/instr_realign.sv")
file.append("../core/id_stage.sv")
file.append("../core/issue_stage.sv")
file.append("../core/ex_stage.sv")
file.append("../core/commit_stage.sv")
file.append("../core/controller.sv")
file.append("../core/csr_regfile.sv")
file.append("../core/decoder.sv")
file.append("../core/compressed_decoder.sv")
file.append("../core/scoreboard.sv")
file.append("../core/issue_read_operands.sv")
file.append("../core/alu.sv")
file.append("../core/branch_unit.sv")
file.append("../core/csr_buffer.sv")
file.append("../core/mult.sv")
file.append("../core/multiplier.sv")
file.append("../core/serdiv.sv")
file.append("../core/load_store_unit.sv")
file.append("../core/load_unit.sv")
file.append("../core/store_unit.sv")
file.append("../core/lsu_bypass.sv")
file.append("../core/cvxif_fu.sv")
file.append("../core/cache_subsystem/cva6_hpdcache_subsystem.sv")

black_list = define_blacklist(parameters)

for filein in file:
comments = []
a = re.match(r".*\/(.*).sv", filein)
module = a.group(1)
print("Input file " + filein)
ports = []
with open(filein, "r", encoding="utf-8") as fin:
description = "none"
connexion = "none"
for line in fin:
e = re.match(r"^ +(?:(in|out))put +([\S]*(?: +.* *|)) ([\S]*)\n", line)
d = re.match(r"^ +\/\/ (.*) - ([\S]*)\n", line)
if d:
description = d.group(1)
connexion = d.group(2)
if e:
name = e.group(3)
name = name.replace(",", "")
data_type = e.group(2)
data_type = data_type.replace(" ", "")
if connexion in black_list:
for i, comment in enumerate(comments):
if black_list[name][0] == comment[0]:
if black_list[connexion][0] == comment[0]:
comment[1] = (
comment[1]
+ f"\n| ``{name}`` {e.group(1)}put is tied to {black_list[name][1]}"
+ f"\n| ``{name}`` {e.group(1)}put is tied to {black_list[connexion][1]}"
)
break
else:
comments.append(
[
black_list[name][0],
f"``{name}`` {e.group(1)}put is tied to {black_list[name][1]}",
black_list[connexion][0],
f"``{name}`` {e.group(1)}put is tied to {black_list[connexion][1]}",
]
)
else:
ports.append(
PortIO(
name, e.group(1), data_type, description, connexion
if name in black_list:
for i, comment in enumerate(comments):
if black_list[name][0] == comment[0]:
comment[1] = (
comment[1]
+ f"\n| ``{name}`` {e.group(1)}put is tied to {black_list[name][1]}"
)
break
else:
comments.append(
[
black_list[name][0],
f"``{name}`` {e.group(1)}put is tied to {black_list[name][1]}",
]
)
else:
ports.append(
PortIO(
name, e.group(1), data_type, description, connexion
)
)
)
description = "none"
connexion = "none"

if generate_file_type in ['rst']:
print_to_rst(pathout, target, module, ports, comments)
elif generate_file_type in ['adoc']:
print_to_adoc(pathout_design, target, module, ports, comments)
else:
raise Exception("Format de sortie %s non pris en charge"%generate_file_type)
description = "none"
connexion = "none"

print_to_adoc(args.gen_ports_folder, target, module, ports, comments)

def export_user_cfg_doc(out_path, params):
with open(out_path, "w", encoding="utf-8") as f:
Expand Down

0 comments on commit 02f3d08

Please sign in to comment.