keys.py
1 from dataclasses import dataclass 2 from typing import TYPE_CHECKING, Callable, Concatenate 3 4 from transactron.utils import MethodStruct 5 from transactron.lib.dependencies import SimpleKey, UnifierKey, ListKey 6 from transactron.lib.transformers import MethodProduct 7 from transactron import Method, TModule 8 from coreblocks.peripherals.bus_adapter import BusMasterInterface 9 from coreblocks.func_blocks.csr.csr_protocol import RegisteredCSRProtocol 10 from amaranth import Signal 11 12 if TYPE_CHECKING: 13 from coreblocks.priv.csr.csr_instances import CSRInstances # noqa: F401 14 15 __all__ = [ 16 "CommonBusDataKey", 17 "InstructionPrecommitKey", 18 "BranchVerifyKey", 19 "PredictedJumpTargetKey", 20 "UnsafeInstructionResolvedKey", 21 "ExceptionReportKey", 22 "CSRInstancesKey", 23 "AsyncInterruptInsertSignalKey", 24 "WaitForInterruptResumeKey", 25 "MretKey", 26 "SretKey", 27 "CoreStateKey", 28 "CSRListKey", 29 "FlushICacheKey", 30 "RollbackKey", 31 "InstructionTaggedCounterKey", 32 ] 33 34 35 @dataclass(frozen=True) 36 class CommonBusDataKey(SimpleKey[BusMasterInterface]): 37 pass 38 39 40 @dataclass(frozen=True) 41 class InstructionPrecommitKey(SimpleKey[Method]): 42 pass 43 44 45 @dataclass(frozen=True) 46 class BranchVerifyKey(SimpleKey[Method]): 47 pass 48 49 50 @dataclass(frozen=True) 51 class PredictedJumpTargetKey(SimpleKey[tuple[Method, Method]]): 52 pass 53 54 55 @dataclass(frozen=True) 56 class UnsafeInstructionResolvedKey(SimpleKey[Method]): 57 """ 58 Represents a method that is called by functional units when 59 an unsafe instruction is executed and the core should be resumed. 60 """ 61 62 pass 63 64 65 @dataclass(frozen=True) 66 class ExceptionReportKey(SimpleKey[Callable[[], Callable[Concatenate[TModule, ...], MethodStruct]]]): 67 """ 68 Used to report exception details to the `ExceptionInformationRegister`. 69 Needs to be called once in the component's constructor. The callable 70 returned acts like a method call and can be used multiple times 71 in `elaborate`. 72 """ 73 74 pass 75 76 77 @dataclass(frozen=True) 78 class CSRInstancesKey(SimpleKey["CSRInstances"]): 79 pass 80 81 82 @dataclass(frozen=True) 83 class AsyncInterruptInsertSignalKey(SimpleKey[Signal]): 84 pass 85 86 87 @dataclass(frozen=True) 88 class WaitForInterruptResumeKey(SimpleKey[Signal]): 89 pass 90 91 92 @dataclass(frozen=True) 93 class MretKey(SimpleKey[Method]): 94 pass 95 96 97 @dataclass(frozen=True) 98 class SretKey(SimpleKey[Method]): 99 pass 100 101 102 @dataclass(frozen=True) 103 class CoreStateKey(SimpleKey[Method]): 104 pass 105 106 107 @dataclass(frozen=True) 108 class CSRListKey(ListKey[tuple[int, RegisteredCSRProtocol]]): 109 """DependencyManager key collecting CSR registers globally as a list. 110 Requires tuple of architectural CSR number to register and the register itself.""" 111 112 pass 113 114 115 @dataclass(frozen=True) 116 class FlushICacheKey(SimpleKey[Method]): 117 pass 118 119 120 @dataclass(frozen=True) 121 class RollbackKey(UnifierKey, unifier=MethodProduct.create): 122 """ 123 Collects method that want to be notifed about tag rollback event. 124 Expected layout is `RATLayouts.rollback_in`. 125 """ 126 127 pass 128 129 130 @dataclass(frozen=True) 131 class InstructionTaggedCounterKey(ListKey[tuple[str, Method]]): 132 """ 133 Collects methods called on instruction issue, paired with FU name. 134 The method must have a tag argument, which will be passed to a `TaggedCounter`. 135 A separate counter will be created for different tag types. 136 """ 137 138 pass