blob: ecb4a2aaac0ca96b1cd5d87fd2354ee61a83e3d4 [file] [log] [blame]
Miguel Young de la Sota3b5a9f52022-03-24 16:11:42 -04001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5"""Helpers for transitioning to the RISC-V target."""
6
Chris Frantz7d962c82022-05-03 07:39:44 -07007OPENTITAN_CPU = "@platforms//cpu:riscv32"
Timothy Trippel41b46fe2022-08-17 23:01:25 -07008OPENTITAN_PLATFORM = "@crt//platforms/riscv32:opentitan"
Miguel Young de la Sota3b5a9f52022-03-24 16:11:42 -04009
10# This constant holds a dictionary of per-device dependencies which are used to
11# generate slightly different binaries for each hardware target, including two
Pirmin Vogel9fc1ec92023-02-16 19:18:42 +010012# simulation platforms (DV and Verilator), and two FPGA platforms (CW305
Miguel Young de la Sota3b5a9f52022-03-24 16:11:42 -040013# and CW310).
14PER_DEVICE_DEPS = {
15 "sim_verilator": ["//sw/device/lib/arch:sim_verilator"],
16 "sim_dv": ["//sw/device/lib/arch:sim_dv"],
Pirmin Vogel9fc1ec92023-02-16 19:18:42 +010017 "fpga_cw305": ["//sw/device/lib/arch:fpga_cw305"],
Miguel Young de la Sota3b5a9f52022-03-24 16:11:42 -040018 "fpga_cw310": ["//sw/device/lib/arch:fpga_cw310"],
19}
20
21def _opentitan_transition_impl(settings, attr):
22 return {"//command_line_option:platforms": attr.platform}
23
24opentitan_transition = transition(
25 implementation = _opentitan_transition_impl,
26 inputs = [],
27 outputs = ["//command_line_option:platforms"],
28)
29
30def rv_rule(**kwargs):
31 """
Timothy Trippel36f96542022-08-02 18:31:20 -070032 A wrapper over rule() for painlessly creating rules that trigger the
33 opentitan transition.
Miguel Young de la Sota3b5a9f52022-03-24 16:11:42 -040034 """
35
36 attrs = kwargs.pop("attrs", {})
37 if "platform" not in attrs:
38 attrs["platform"] = attr.string(default = OPENTITAN_PLATFORM)
39 attrs["_allowlist_function_transition"] = attr.label(
40 default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
41 )
42
43 return rule(
44 cfg = opentitan_transition,
45 attrs = attrs,
46 **kwargs
47 )