Miguel Young de la Sota | 3b5a9f5 | 2022-03-24 16:11:42 -0400 | [diff] [blame] | 1 | # 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 Frantz | 7d962c8 | 2022-05-03 07:39:44 -0700 | [diff] [blame] | 7 | OPENTITAN_CPU = "@platforms//cpu:riscv32" |
Timothy Trippel | 41b46fe | 2022-08-17 23:01:25 -0700 | [diff] [blame] | 8 | OPENTITAN_PLATFORM = "@crt//platforms/riscv32:opentitan" |
Miguel Young de la Sota | 3b5a9f5 | 2022-03-24 16:11:42 -0400 | [diff] [blame] | 9 | |
| 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 Vogel | 9fc1ec9 | 2023-02-16 19:18:42 +0100 | [diff] [blame] | 12 | # simulation platforms (DV and Verilator), and two FPGA platforms (CW305 |
Miguel Young de la Sota | 3b5a9f5 | 2022-03-24 16:11:42 -0400 | [diff] [blame] | 13 | # and CW310). |
| 14 | PER_DEVICE_DEPS = { |
| 15 | "sim_verilator": ["//sw/device/lib/arch:sim_verilator"], |
| 16 | "sim_dv": ["//sw/device/lib/arch:sim_dv"], |
Pirmin Vogel | 9fc1ec9 | 2023-02-16 19:18:42 +0100 | [diff] [blame] | 17 | "fpga_cw305": ["//sw/device/lib/arch:fpga_cw305"], |
Miguel Young de la Sota | 3b5a9f5 | 2022-03-24 16:11:42 -0400 | [diff] [blame] | 18 | "fpga_cw310": ["//sw/device/lib/arch:fpga_cw310"], |
| 19 | } |
| 20 | |
| 21 | def _opentitan_transition_impl(settings, attr): |
| 22 | return {"//command_line_option:platforms": attr.platform} |
| 23 | |
| 24 | opentitan_transition = transition( |
| 25 | implementation = _opentitan_transition_impl, |
| 26 | inputs = [], |
| 27 | outputs = ["//command_line_option:platforms"], |
| 28 | ) |
| 29 | |
| 30 | def rv_rule(**kwargs): |
| 31 | """ |
Timothy Trippel | 36f9654 | 2022-08-02 18:31:20 -0700 | [diff] [blame] | 32 | A wrapper over rule() for painlessly creating rules that trigger the |
| 33 | opentitan transition. |
Miguel Young de la Sota | 3b5a9f5 | 2022-03-24 16:11:42 -0400 | [diff] [blame] | 34 | """ |
| 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 | ) |