Skip to content

Commit

Permalink
added linker as an argument of cva6.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fatimasaleem committed May 24, 2022
1 parent a62b4d8 commit 006449b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cva6/regress/dv-riscv-arch-test.sh
Expand Up @@ -28,5 +28,5 @@ if ! [ -n "$DV_SIMULATORS" ]; then
fi

cd cva6/sim
python3 cva6.py --testlist=../tests/testlist_riscv-arch-test-$DV_TARGET.yaml --target $DV_TARGET --iss_yaml=cva6.yaml --iss=$DV_SIMULATORS $DV_OPTS
python3 cva6.py --testlist=../tests/testlist_riscv-arch-test-$DV_TARGET.yaml --target $DV_TARGET --iss_yaml=cva6.yaml --iss=$DV_SIMULATORS $DV_OPTS --linker=../tests/riscv-isa-sim/arch_test_target/spike/link.ld
cd -
2 changes: 1 addition & 1 deletion cva6/regress/install-cva6.sh
Expand Up @@ -37,7 +37,7 @@ export NUM_JOBS=24
if ! [ -n "$CVA6_REPO" ]; then
CVA6_REPO="https://github.com/openhwgroup/cva6.git"
CVA6_BRANCH="master"
CVA6_HASH="34f63b44873148d371133bfa8642d2b7d388f39b"
CVA6_HASH="75807530f26ba9a0ca501e9d3a6575ec375ed7ab"
CVA6_PATCH=
fi
echo $CVA6_REPO
Expand Down
42 changes: 25 additions & 17 deletions cva6/sim/cva6.py
Expand Up @@ -329,7 +329,7 @@ def elf2bin(elf, binary, debug_cmd):
run_cmd_output(cmd.split(), debug_cmd = debug_cmd)


def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd):
def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd, linker):
"""Use riscv gcc toolchain to compile the assembly program
Args:
Expand All @@ -338,6 +338,7 @@ def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd):
isa : ISA variant passed to GCC
mabi : MABI variant passed to GCC
debug_cmd : Produce the debug cmd log without running
linker : Path to the linker
"""
cwd = os.path.dirname(os.path.realpath(__file__))
for test in test_list:
Expand All @@ -357,8 +358,8 @@ def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd):
-fvisibility=hidden -nostdlib \
-nostartfiles %s \
-I%s/dv/user_extension \
-T%s/link.ld %s -o %s " % \
(get_env_var("RISCV_GCC", debug_cmd = debug_cmd), asm, cwd, cwd, opts, elf))
-T%s %s -o %s " % \
(get_env_var("RISCV_GCC", debug_cmd = debug_cmd), asm, cwd, linker, opts, elf))
if 'gcc_opts' in test:
cmd += test['gcc_opts']
if 'gen_opts' in test:
Expand All @@ -377,7 +378,7 @@ def gcc_compile(test_list, output_dir, isa, mabi, opts, debug_cmd):


def run_assembly(asm_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir,
setting_dir, debug_cmd):
setting_dir, debug_cmd, linker):
"""Run a directed assembly test with ISS
Args:
Expand All @@ -390,6 +391,7 @@ def run_assembly(asm_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, outp
output_dir : Output directory of compiled test files
setting_dir : Generator setting directory
debug_cmd : Produce the debug cmd log without running
linker : Path to the linker
"""
if not asm_test.endswith(".S"):
logging.error("%s is not an assembly .S file" % asm_test)
Expand All @@ -413,9 +415,9 @@ def run_assembly(asm_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, outp
-fvisibility=hidden -nostdlib \
-nostartfiles %s \
-I%s/dv/user_extension \
-T%s/link.ld %s -o %s " % \
(get_env_var("RISCV_GCC", debug_cmd = debug_cmd), asm_test, cwd,
cwd, gcc_opts, elf))
-T%s %s -o %s " % \
(get_env_var("RISCV_GCC", debug_cmd = debug_cmd), asm_test, cwd, linker,
gcc_opts, elf))
cmd += (" -march=%s" % isa)
cmd += (" -mabi=%s" % mabi)
run_cmd_output(cmd.split(), debug_cmd = debug_cmd)
Expand Down Expand Up @@ -457,7 +459,7 @@ def run_assembly_from_dir(asm_test_dir, iss_yaml, isa, mabi, gcc_opts, iss,
(len(asm_list), asm_test_dir))
for asm_file in asm_list:
run_assembly(asm_file, iss_yaml, isa, target, mabi, gcc_opts, iss, output_dir,
setting_dir, debug_cmd)
setting_dir, debug_cmd, linker)
if "," in iss:
report = ("%s/iss_regr.log" % output_dir).rstrip()
save_regr_report(report)
Expand Down Expand Up @@ -514,7 +516,7 @@ def run_elf(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir,


def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir,
setting_dir, debug_cmd):
setting_dir, debug_cmd, linker):
"""Run a directed c test with ISS
Args:
Expand All @@ -527,6 +529,7 @@ def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir,
output_dir : Output directory of compiled test files
setting_dir : Generator setting directory
debug_cmd : Produce the debug cmd log without running
linker : Path to the linker
"""
if not c_test.endswith(".c"):
logging.error("%s is not a .c file" % c_test)
Expand All @@ -547,9 +550,9 @@ def run_c(c_test, iss_yaml, isa, target, mabi, gcc_opts, iss_opts, output_dir,
cmd = ("%s -mcmodel=medany -nostdlib \
-nostartfiles %s \
-I%s/dv/user_extension \
-T%s/link.ld %s -o %s " % \
-T%s %s -o %s " % \
(get_env_var("RISCV_GCC", debug_cmd = debug_cmd), c_test, cwd,
cwd, gcc_opts, elf))
linker, gcc_opts, elf))
cmd += (" -march=%s" % isa)
cmd += (" -mabi=%s" % mabi)
run_cmd_output(cmd.split(), debug_cmd = debug_cmd)
Expand Down Expand Up @@ -591,7 +594,7 @@ def run_c_from_dir(c_test_dir, iss_yaml, isa, mabi, gcc_opts, iss,
(len(c_list), c_test_dir))
for c_file in c_list:
run_c(c_file, iss_yaml, isa, target, mabi, gcc_opts, iss, output_dir,
setting_dir, debug_cmd)
setting_dir, debug_cmd, linker)
if "," in iss:
report = ("%s/iss_regr.log" % output_dir).rstrip()
save_regr_report(report)
Expand Down Expand Up @@ -811,6 +814,8 @@ def setup_parser():
help="Generate debug command log file")
parser.add_argument("--hwconfig_opts", type=str, default="",
help="custom configuration options, to be passed in config_pkg_generator.py in cva6")
parser.add_argument("-l", "--linker", type=str, default="",
help="Path for the link.ld")
return parser


Expand All @@ -833,6 +838,9 @@ def load_config(args, cwd):
if not args.simulator_yaml:
args.simulator_yaml = cwd + "/cva6-simulator.yaml"

if not args.linker:
args.linker = cwd + "/link.ld"

# Keep the core_setting_dir option to be backward compatible, suggest to use
# --custom_target
if args.core_setting_dir:
Expand Down Expand Up @@ -958,7 +966,7 @@ def main():
# path_asm_test is an assembly file
elif os.path.isfile(full_path) or args.debug:
run_assembly(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts,
args.iss, output_dir, args.core_setting_dir, args.debug)
args.iss, output_dir, args.core_setting_dir, args.debug, args.linker)
else:
logging.error('%s does not exist' % full_path)
sys.exit(RET_FAIL)
Expand All @@ -977,7 +985,7 @@ def main():
# path_c_test is a c file
elif os.path.isfile(full_path) or args.debug:
run_c(full_path, args.iss_yaml, args.isa, args.target, args.mabi, args.gcc_opts,
args.iss, output_dir, args.core_setting_dir, args.debug)
args.iss, output_dir, args.core_setting_dir, args.debug, args.linker)
else:
logging.error('%s does not exist' % full_path)
sys.exit(RET_FAIL)
Expand Down Expand Up @@ -1068,7 +1076,7 @@ def main():
# path_asm_test is an assembly file
elif os.path.isfile(path_asm_test):
run_assembly(path_asm_test, args.iss_yaml, args.isa, args.target, args.mabi, gcc_opts,
args.iss, output_dir, args.core_setting_dir, args.debug)
args.iss, output_dir, args.core_setting_dir, args.debug, args.linker)
else:
if not args.debug:
logging.error('%s does not exist' % path_asm_test)
Expand All @@ -1089,7 +1097,7 @@ def main():
# path_c_test is a C file
elif os.path.isfile(path_c_test):
run_c(path_c_test, args.iss_yaml, args.isa, args.target, args.mabi, gcc_opts,
args.iss, output_dir, args.core_setting_dir, args.debug)
args.iss, output_dir, args.core_setting_dir, args.debug, args.linker)
else:
if not args.debug:
logging.error('%s does not exist' % path_c_test)
Expand All @@ -1102,7 +1110,7 @@ def main():
# Compile the assembly program to ELF, convert to plain binary
if args.steps == "all" or re.match(".*gcc_compile.*", args.steps):
gcc_compile(matched_list, output_dir, args.isa, args.mabi,
args.gcc_opts, args.debug)
args.gcc_opts, args.debug, args.linker)

# Run ISS simulation
if args.steps == "all" or re.match(".*iss_sim.*", args.steps):
Expand Down
4 changes: 1 addition & 3 deletions cva6/sim/link.ld
Expand Up @@ -14,7 +14,7 @@
*/

OUTPUT_ARCH( "riscv" )
ENTRY(rvtest_entry_point)
ENTRY(_start)

SECTIONS
{
Expand All @@ -30,8 +30,6 @@ SECTIONS
.kernel_data : { *(.kernel_data) }
.kernel_stack : { *(.kernel_stack) }
.data : { *(.data) }
.data.string : { *(.data.string)}
.bss : { *(.bss) }
_end = .;
}

0 comments on commit 006449b

Please sign in to comment.