3d369c177d9bf12ec54a602bdea367d91751e9be
[libreriscv.git] / isa_conflict_resolution / mvendor_march_mimplid.mdwn
1 # mvendorid/marchid/mimplid (mvendorid/marchid MRO, mimplid WARL)<a name="mvendor_marchid_mimplid"></a>
2
3 This proposal explores the possibility of adding a "mimplid" (or isamux) CSR
4 that acts as an extra bit of state that goes directly into instruction decoding.
5 It would be analogous to extending every single RISC-V instruction by a few bits
6 so as to guarantee that no conflicts may occur in either custom extensions or
7 future revisions of the RISC-V Standard, as well as permitting processors
8 to execute (rather than JIT decode) completely foreign architectures.
9
10 Implementors register (mvendorid-marchid-mimpl) tuples with the FSF
11 gcc and binutils teams, effectively making the FSF the de-facto atomic
12 arbiter responsible for maintaining the world-wide unique encoding
13 database as part of the gcc and binutils codebase.
14
15 Conflicting custom extensions thus become world-wide globally unique
16 such that assembly writers, gcc and binutils may have a high to 100%
17 degree of confidence that a given binary will not need recompiling from
18 source, if transferred from one architecture to another (that has the
19 exact same set of extensions).
20
21 # Ideas discussed so far
22
23 ## One hart, one ISA encoding
24
25 This idea is quite straightforward: on any given multi-core processor
26 it can have multiple mvendorid-marchid-mimplid tuples, where each core
27 (hart) has *one* and *only* one tuple. Thus, running different
28 encodings is a simple matter of selecting the correct core.
29
30 clarification from jacob:
31
32 > it solves the problem of one implementation needing to implement
33 > conflicting extensions, with some limitations, specifically that each of
34 > the conflicting extensions must be used in separate threads. The Rocket
35 > RoCC coprocessor interface, in a multi-tile SoC where different tiles
36 > have different coprocessors, provides a working example of this model.
37 > The overall system has both of two conflicting coprocessors.
38
39 There are a couple of issues with this approach:
40
41 * Single-core (single hart) implementations are not possible.
42 * Multi-core implementations are guaranteed, for high workloads,
43 to have "incompatible" cores sitting idle whilst "compatible"
44 cores are overloaded.
45
46 Aside from those limitations it is a workable and valid proposal that has the
47 potential to meet the requirements, that may turn out to be a legitimate
48 and simple and easy to implement subset of other ideas outlined in this
49 document.
50
51 ## Every hart, multiple ISA encodings, mimpl unchanged on traps
52
53 This idea allows every hart (core) to have the ability to select
54 any one of multiple ISA encodings, by setting mimpl *in U-mode*.
55 Implementation-wise the value in mimpl is passed to an out-muxer
56 that generates mutually-exclusive HIGH signals that are passed
57 as an additional input to the selection/enabler blocks of multiple
58 (conflicting) decoders. As an extra signal into the associated multi-input
59 AND gate the overhead is negligeable, and there is no possibility of
60 a conflict due to the out-mux outputs being mutually-exclusive.
61
62 Note that whilst this is very similar to setting MISA bits, MISA actively
63 disables instructions from being decoded (whereas whilst the above also
64 disables a certain subset of the opcode space it also *enables* some
65 in their place). Also - and this is extremely important - it is
66 **forbidden** for the encoding-switching to alter the actual state
67 of any Extensions (custom or othewise). Changing of mimplid **only**
68 affects the decoding, it does **not**, unlike MISA, actually switch on
69 or off the actual Extension and **cannot** be used to "power down" any
70 hardware.
71
72 The tricky bit for this idea is: what happens when a trap occurs,
73 to switch to M-Mode or S-Mode? If this is not taken care of properly
74 there is the possibility for a trap to be running instructions that
75 are completely alien and incompatible with the code and context from
76 which the trap occurred.
77
78 A cursory analysis of the situation came to the consensus that whilst in
79 a trap, it would both be highly unlikely that custom opcodes would be
80 used *in the trap*, or that even when the hart can support multiple
81 *approved* (present and future) variants of the *RV Base Standard*,
82 it would be so unusual for RV Base to change between (approved) variants
83 that the possibility of there actually being a conflict is extremely
84 remote. This is good as the code-path in an OS trap (supervisor mode)
85 needs to be kept as short as possible.
86
87 However, the possibility that there will be a critical difference cannot
88 be known or ruled out, and foreign ISAs will definitely be made much more
89 difficult to implement full OSes for (particularly proprietary ones) if
90 the M-Mode and S-Mode traps are running an incompatible ISA.
91
92 So the solution here is that whenever M-mode changes the mimplid/isamux CSR,
93 the underlying hardware switches mtvec, stvec and bstvec over to
94 *separate* and distint entries (stored on a per-hart, per-mimplid basis).
95 In the context of there being an OS, the OS would need to be running
96 in a "default" initial context. It would set up mtvec, stvec (and bstvec
97 if required), then change the mimplid/isamux, and set up *new* mtvec etc.
98 entries *as appropriate* for that particular (alternative) ISA (including
99 if it is a foreign architecture).
100
101 > I agree.. complete renumbering is a huge overhead. Guy's solution avoids
102 > that overhead and provides a fast-switching mechanism. We had already
103 > identified what happens on traps, flushes, caches, etc. Would prefer if
104 > we could review/critique that proposal.
105 >
106 > If someone wants to re-number the entire custom ISA even then Guy's
107 > solution will stand. Plus, in the heterogenous envrionemt, considering
108 > each hart/core has its own marcselect(mutable csr), the M mode (or
109 > user/supervisor) can simply choose to enable that hart/core by writing
110 > to the marchselect CSR.
111 >
112 > For compliance, yes we will need Jacob's idea of having a global database
113 > somewhere. Also, I believe that the compliance will check only if the
114 > core is RISC-V compliant and not worry about any other extensions present
115 > or not.
116 >
117 > By adding a new mutable csr in the MRW region even existing
118 > implementations will be compliant since accessing this CSR in current
119 > implementations would just trap.
120
121 ## Every hart, multiple ISA encodings, mimpl set to "default" on traps
122
123 This is effectively the same as the above except that when switching to
124 M-Mode or S-Mode, the ISA encoding is always automatically switched to
125 one and only one (default) ISA encoding. There are no complications for
126 the hardware, however for software - particularly OSes and in particular
127 for running foreign hardware ISAs - every single trap now has to work
128 out which ISA the U-mode was running, and branch accordingly. Running a
129 foreign OS thus becomes extremely challenging, although a case could be
130 made for the foreign ISA having its own entirely different orthogonal
131 trap-handling system.
132
133 ## Every hart, multiple ISA encodings, mimpl set to "supervisor-selectable"
134
135 This is again identical as far as mimplid/isamux is concerned, with, again,
136 a different kind of decision-making on traps. It was pointed out that
137 if the mimplid/isamux is left unaltered when a trap occurs, switching over
138 from one ISA to another inside a trap and dropping down to a different
139 ISA in U-Mode is made slightly challenging by virtue of the fact that, when
140 the trap changes the ISA, from that point onwards it *has to run that ISA
141 inside the trap*. This may involve extra code-paths (branches) to require
142 multiple different exit points from the trap.
143
144 Whilst again it is quite unlikely that this scenario will arise (due to
145 it being unlikely that the Base ISA will change significantly between
146 (stable, approved) revisions to the RV Standard, the possibility cannot
147 entirely be ruled out.
148
149 So this idea is a hybrid of the above two: there is a default ISA for
150 M-Mode and S-Mode, however in each it is possible to *set* that default.
151
152 The idea has not yet been fully analysed and needs further discussion.
153