4cf87261caabecaec40b2413fe06d6bafa325daf
[libreriscv.git] / isa_conflict_resolution / isamux_isans.mdwn
1 # Note-form on ISAMUX (aka "ISANS")
2
3 Links:
4
5 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2020-February/004190.html>
6 * bugreport <http://bugs.libre-riscv.org/show_bug.cgi?id=214>
7
8 A fixed number of additional (hidden) bits, conceptually a "namespace",
9 set by way of a CSR or other out-of-band mechanism,
10 that go directly and non-optionally
11 into the instruction decode phase, extending (in each implementation) the
12 opcode length to 16+N, 32+N, 48+N, where N is a hard fixed quantity on
13 a per-implementor basis.
14
15 Where the opcode is normally loaded from the location at the PC, the extra
16 bits, set via a CSR, are mandatorially appended to every instruction: hence why they are described as "hidden" opcode bits, and as a "namespace".
17
18 The parallels with c++ "using namespace" are direct and clear.
19 Alternative conceptual ways to understand this concept include
20 "escape-sequencing".
21
22 TODO: reserve some bits which permit the namespace (escape-sequence) to
23 be relevant for a fixed number of instructions at a time. Caveat:
24 allowing such a countdown to cross branch-points is unwise (illegal
25 instruction?)
26
27 An example of a pre-existing "namespace" switch that has been in
28 prevalent use for several decades (SPARC and other architectures):
29 dynamic runtime selectability of littel-endian / big-endian "meaning"
30 of instructions by way of a "mode switch" instruction (of some kind).
31
32 That "switch" is in effect a 33rd (hidden) bit that is part of the opcode,
33 going directly into the mux / decode phase of instruction decode, and
34 thus qualifies categorically as a "namespace". This proposal both formalises
35 and generalises that concept.
36
37 # Hypothetical Format
38
39 Note that this is a hypothetical format, yet TBD, where particular attention
40 needs to be paid to the fact that there is an "immediate" version of CSRRW
41 (with 5 bits of immediate) that could save a lot of space in binaries.
42
43 <pre>
44 3 2 1
45 |1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0|
46 |------------------------------ |-------|---------------------|-|
47 |1 custom custom custom custom custom | foreignarch |1|
48 |0 reserved reserved reserved reserved reserved | foreignarch |1|
49 |custom | reserved | official|B| rvcpage |0|
50 </pre>
51
52 RV Mode
53
54 * when bit 0 is 0, "RV" mode is selected.
55 * in RV mode, bits 1 thru 5 provide up to 16 possible alternative meanings (namespaces) for 16 Bit opcodes. "pages" if you will. The top bit indicates custom meanings. When set to 0, the top bit is for official usage.
56 * Bits 15 thru 23 are reserved.
57 * Bits 24 thru 31 are for custom usage.
58 * bit 6 ("B") is endian-selection: LE/BE
59
60 16 bit page examples:
61
62 * 0b0000 STANDARD (2019) RVC
63 * 0b0001 RVCv2
64 * 0b0010 RV16
65 * 0b0011 RVCv3
66 * ...
67 * 0b1000 custom 16 bit opcode meanings 1
68 * 0b1001 custom 16 bit opcode meanings 2
69 * .....
70
71 Foreign Arch Mode
72
73 * when bit 0 is 1, "Foreign arch" mode is selected.
74 * Bits 1 thru 7 are a table of foreign arches.
75 * when the MSB is 1, this is for custom use.
76 * when the MSB is 0, bits 1 thru 6 are reserved for 64 possible official foreign archs.
77
78 Foreign archs could be (examples):
79
80 * 0b0000000 x86_32
81 * 0b0000001 x86_64
82 * 0b0000010 MIPS32
83 * 0b0000011 MIPS64
84 * ....
85 * 0b0010000 Java Bytecode
86 * 0b0010001 N.E.Other Bytecode
87 * ....
88 * 0b1000000 custom foreign arch 1
89 * 0b1000001 custom foreign arch 2
90 * ....
91
92 Note that "official" foreign archs have a binary value where the MSB is zero,
93 and custom foreign archs have a binary value where the MSB is 1.
94
95 # Namespaces are permitted to swap to new state <a name="stateswap"></a>
96
97 In each privilege level, on a change of ISANS (whether through manual setting of ISANS or through trap entry or exit changing the ISANS CSR), an implementation is permitted to completely and arbitrarily switch not only the instruction set, it is permitted to switch to a new bank of CSRs (or a subset of the same), and even to switch to a new PC.
98
99 This to occur immediately and atomically at the point at which the change in ISANS occurs.
100
101 The most obvious application of this is for Foreign Archs, which may have their own completely separate PC. Thus, foreign assembly code and RISCV assembly code need not be mixed in the same binary.
102
103 Further use-cases may be envisaged however great care needs to be taken to not cause massive complications for JIT emulation, as the RV ISANS is unary encoded (2^31 permutations).
104
105 In addition, the state information of *all* namespaces has to be saved and restored on a context-switch (unless the SP is also switched as part of the state!) which is quite severely burdensome and getting exceptionally complex.
106
107 Switching CSR, PC (and potentially SP) and other state on a NS change in the RISCV unary NS therefore needs to be done wisely and responsibly, i.e. minimised!
108
109 To be discussed. Context <https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/x-uFZDXiOxY/27QDW5KvBQAJ>
110
111 # Privileged Modes / Traps <a name="privtraps"></a>
112
113 An additional WLRL CSR per priv-level named "LAST-ISANS" is required, and
114 another called "TRAP-ISANS"
115 These mirrors the ISANS CSR, and, on a trap, the current ISANS in
116 that privilege level is atomically
117 transferred into LAST-ISANS by the hardware, and ISANS in that trap
118 is set to TRAP-ISANS. Hardware is *only then* permitted to modify the PC to
119 begin execution of the trap.
120
121 On exit from the trap, LAST-ISANS is copied into the ISANS CSR, and
122 LAST-ISANS is set to TRAP-ISANS. *Only then* is the hardware permitted
123 to modify the PC to begin execution where the trap left off.
124
125 This is identical to how xepc is handled.
126
127 Note 1: in the case of Supervisor Mode (context switches in particular),
128 saving and changing of LAST-ISANS (to and from the stack) must be done
129 atomically and under the protection of the SIE bit. Failure to do so
130 could result in corruption of LAST-ISANS when multiple traps occur in
131 the same privilege level.
132
133 Note 2: question - should the trap due to illegal (unsupported) values
134 written into LAST-ISANS occur when the *software* writes to LAST-ISANS,
135 or when the *trap* (on exit) writes into LAST-ISANS? this latter seems
136 fraught: a trap, on exit, causing another trap??
137
138 Per-privilege-level pseudocode (there exists UISANS, UTRAPISANS, ULASTISANS,
139 MISANS, MTRAPISANS, MLASTISANS and so on):
140
141 <pre>
142 trap_entry()
143 {
144     LAST-ISANS = ISANS // record the old NS
145     ISANS = TRAP_ISANS // traps are executed in "trap" NS
146 }
147
148 and trap_exit:
149
150 trap_exit():
151 {
152     ISANS = LAST-ISANS
153     LAST-ISANS = TRAP_ISANS
154 }
155 </pre>
156
157 # Alternative RVC 16 Bit Opcode meanings
158
159 Here is appropriate to raise an idea how to cover RVC and future
160 variants, including RV16.
161
162 Just as with foreign archs, and you quite rightly highlight above, it
163 makes absolutely no sense to try to select both RVCv1, v2, v3 and so on,
164 all simultaneously. An unary bit vector for RVC modes, changing the 16
165 BIT opcode space meaning, is wasteful and again has us believe that WARL
166 is the "solution".
167
168 The correct thing to do is, again, just like with foreign archs, to
169 treat RVCs as a *binary* namespace selector. Bits 1 thru 3 would give
170 8 possible completely new alternative meanings, just like how the Z80
171 and the 286 and 386 used to do bank switching.
172
173 All zeros is clearly reserved for the present RVC. 0b001 for RVCv2. 0b010
174 for RV16 (look it up) and there should definitely be room reserved here
175 for custom reencodings of the 16 bit opcode space.
176
177 # FAQ
178
179 ## Why not have TRAP-ISANS as a vector table, matching mtvec? <a name="trap-isans-vec"></a>
180
181 Use case to be determined. Rather than be a global per-priv-level value,
182 TRAP-ISANS is a table of length exactly equal to the mtvec/utvec/stvec table,
183 with corresponding entries that specify the assembly-code namespace in which
184 the trap handler routine is written.
185
186 Open question: see <https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/IAhyOqEZoWA/BM0G3J2zBgAJ>
187
188 <pre>
189 trap_entry(x_cause)
190 {
191     LAST-ISANS = ISANS // record the old NS
192     ISANS = TRAP_ISANS_VEC[xcause] // traps are executed in "trap" NS
193 }
194
195 and trap_exit:
196
197 trap_exit(x_cause):
198 {
199     ISANS = LAST-ISANS
200     LAST-ISANS = TRAP_ISANS_VEC[x_cause]
201 }
202 </pre>
203
204 ## Is this like MISA? <a name="misa"></a>
205
206 No.
207
208 * MISA's space is entirely taken up (and running out).
209 * There is no allocation (provision) for custom extensions.
210 * MISA switches on and off entire extensions: ISAMUX/NS may be used to switch multiple opcodes (present and future), to alternate meanings.
211 * MISA is WARL and is inaccessible from everything but M-Mode (not even readable).
212
213 MISA is therefore wholly unsuited to U-Mode usage; ISANS is specifically permitted to be called by userspace to switch (with no stalling) between namespaces, repeatedly and in quick succession.
214
215 ## What happens if this scheme is not adopted? Why is it better than leaving things well alone? <a name="laissezfaire"></a>
216
217 At the first sign of an emergency non-backwards compatible and unavoidable
218 change to the *frozen* RISCV *official* Standards, the entire RISCV
219 community is fragmented and divided into two:
220
221 * Those vendors that are hardware compatible with the legacy standard.
222 * Those that are compatible with the new standard.
223
224 *These two communities would be mutually exclusively incompatible*. If
225 a second emergency occurs, RISCV becomes even less tenable.
226
227 Hardware that wished to be "compatible" with either flavour would require
228 JIT or offline static binary recompilation. No vendor would willingly
229 accept this as a condition of the standards divergence in the first place,
230 locking up decision making to the detriment of RISCV as a whole.
231
232 By providing a "safety valve" in the form of a hidden namespace, at least
233 newer hardware has the option to implement both (or more) variations,
234 *and still apply for Certification*.
235
236 However to also allow "legacy" hardware to at least be JIT soft
237 compatible, some very strict rules *must* be adhered to, that appear at
238 first sight not to make any sense.
239
240 It's complicated in other words!
241
242 ## Surely it's okay to just tell people to use 48-bit encodings? <a name="use48bit"></a>
243
244 Short answer: it doesn't help resolve conflicts, and costs hardware and
245 redesigns to do so. Softcores in cost-sensitive embedded applications may
246 even not actually be able to fit the required 48 bit instruction decode engine
247 into a (small, ICE40) FPGA. 48-bit instruction decoding is much more complex
248 than straight 32-bit decoding, requiring a queue.
249
250 Second answer: conflicts can still occur in the (unregulated, custom) 48-bit
251 space, which *could* be resolved by ISAMUX/ISANS as applied to the *48* bit
252 space in exactly the same way. And the 64-bit space.
253
254 ## Why not leave this to individual custom vendors to solve on a case by case basis? <a name="case-by-case"></a>
255
256 The suggestion was raised that a custom extension vendor could create
257 their own CSR that selects between conflicting namespaces that resolve
258 the meaning of the exact same opcode. This to be done by all and any
259 vendors, as they see fit, with little to no collaboration or coordination
260 towards standardisation in any form.
261
262 The problems with this approach are numerous, when presented to a
263 worldwide context that the UNIX Platform, in particular, has to face
264 (where the embedded platform does not)
265
266 First: lack of coordination, in the proliferation of arbitrary solutions,
267 has to primarily be borne by gcc, binutils, LLVM and other compilers.
268
269 Secondly: CSR space is precious. With each vendor likely needing only one
270 or two bits to express the namespace collision avoidance, if they make
271 even a token effort to use worldwide unique CSRs (an effort that would
272 benefit compiler writers), the CSR register space is quickly exhausted.
273
274 Thirdly: JIT Emulation of such an unregulated space becomes just as
275 much hell as it is for compiler writers. In addition, if two vendors
276 use conflicting CSR addresses, the only sane way to tell the emulator
277 what to do is to give the emulator a runtime commandline argument.
278
279 Fourthly: with each vendor coming up with their own way of handling
280 conflicts, not only are the chances of mistakes higher, it is against the
281 very principles of collaboration and cooperation that save vendors money
282 on development and ongoing maintenance. Each custom vendor will have
283 to maintain their own separate hard fork of the toolchain and software,
284 which is well known to result in security vulnerabilities.
285
286 By coordinating and managing the allocation of namespace bits (unary
287 or binary) the above issues are solved. CSR space is no longer wasted,
288 compiler and JIT software writers have an easier time, clashes are
289 avoided, and RISCV is stabilised and has a trustable long term future.
290
291 ## Why ISAMUX / ISANS has to be WLRL and mandatory trap on illegal writes <a name="wlrlmandatorytrap"></a>
292
293 The namespaces, set by bits in the CSR, are functionally directly
294 equivalent to c++ namespaces, even down to the use of braces.
295
296 WARL, by allowing implementors to choose the value, prevents and prohibits
297 the critical and necessary raising of an exception that would begin the
298 JIT process in the case of ongoing standards evolution.
299
300 Without this opportunity, an implementation has no reliable guaranteed way of knowing
301 when to drop into full JIT mode,
302 which is the only guaranteed way to distinguish
303 any given conflicting opcode. It is as if the c++
304 standard was given a similar optional
305 opportunity to completely ignore the
306 "using namespace" prefix!
307
308 --
309
310 Ok so I trust it's now clear why WLRL (thanks Allen) is needed.
311
312 When Dan raised the WARL concern initially a situation was masked by
313 the conflict, that if gone unnoticed would jeapordise ISAMUX/ISANS
314 entirely. Actually, two separate errors. So thank you for raising the
315 question.
316
317 The situation arises when foreign archs are to be given their own NS
318 bit. MIPS is allocated bit 8, x86 bit 9, whilst LE/BE is given bit 0,
319 RVCv2 bit 1 andso on. All of this potential rather than actual, clearly.
320
321 Imagine then that software tries to write and set not just bit 8 and
322 bit 9, it also tries to set bit 0 and 1 as well.
323
324 This *IS* on the face of it a legitimate reason to make ISAMUX/ISANS WARL.
325
326 However it masks a fundamental flaw that has to be addressed, which
327 brings us back much closer to the original design of 18 months ago,
328 and it's highlighted thus:
329
330 x86 and simultaneous RVCv2 modes are total nonsense in the first place!
331
332 The solution instead is to have a NS bit (bit0) that SPECIFICALLY
333 determines if the arch is RV or not. If 0, the rest of the ISAMUX/ISANS
334 is very specifically RV *only*, and if 1, the ISAMUX/ISANS is a *binary*
335 table of foreign architectures and foreign architectures only.
336
337 Exactly how many bits are used for the foreign arch table, is to
338 be determined. 7 bits, one of which is reserved for custom usage,
339 leaving a whopping 64 possible "official" foreign instruction sets to
340 be hardware-supported/JIT-emulated seems to be sufficiently gratuitous,
341 to me.
342
343 One of those could even be Java Bytecode!
344
345 Now, it could *hypothetically* be argued that the permutation of setting
346 LE/BE and MIPS for example is desirable. A simple analysis shows this
347 not to be the case: once in the MIPS foreign NS, it is the MIPS hardware
348 implementation that should have its own way of setting and managing its
349 LE/BE mode, because to do otherwise drastically interferes with MIPS
350 binary compatibility.
351
352 Thus, it is officially Not Our Problem: only flipping into one foreign
353 arch at a time makes sense, thus this has to be reflected in the
354 ISAMUX/ISANS CSR itself, completely side-stepping the (apparent) need
355 to make the NS CSR WARL (which would not work anyway, as previously
356 mentioned).
357
358 So, thank you, again, Dan, for raising this. It would have completely
359 jeapordised ISAMUX/NS if not spotted.
360
361 The second issue is: how does any hardware system, whether it support
362 ISANS or not, and whether any future hardware supports some Namespaces
363 and, in a transitive fashion, has to support *more* future namespaces,
364 through JIT emulation, if this is not planned properly in advance?
365
366 Let us take the simple case first: a current 2019 RISCV fully compliant
367 RV64GC UNIX capable system (with mandatory traps on all unsupported CSRs).
368
369 Fast forward 20 years, there are now 5 ISAMUX/NS unary bits, and 3
370 foreign arch binary table entries.
371
372 Such a system is perfectly possible of software JIT emulating ALL of these
373 options because the write to the (illegal, for that system) ISAMUX/NS
374 CSR generates the trap that is needed for that system ti begin JIT mode.
375
376 (This again emphasises exactly why the trap is mandatory).
377
378 Now let us take the case of a hypothetical system from say 2021 that
379 implements RVCv2 at the hardware level.
380
381 Fast forward 20 years: if the CSR were made WARL, that system would be
382 absolutely screwed. The implementor would be under the false impression
383 that ignoring setting of "illegal" bits was acceptable, making the
384 transition to JIT mode flat-out impossible to detect.
385
386 When this is considered transitively, considering all future additions to
387 the NS, and all permutations, it can be logically deduced that there is
388 a need to reserve a *full* set of bits in the ISAMUX/NS CSR *in advance*.
389
390 i.e. that *right now*, in the year 2019, the entire ISAMUX/NS CSR cannot
391 be added to piecemeal, the full 32 (or 64) bits *has* to be reserved,
392 and reserved bits set at zero.
393
394 Furthermore, if any software attempts to write to those reserved bits,
395 it *must* be treated just as if those bits were distinct and nonexistent
396 CSRs, and a trap raised.
397
398 It makes more sense to consider each NS as having its own completely
399 separate CSR, which, if it does not exist, clearly it should be obvious
400 that, as an unsupported CSR, a trap should be raised (and JIT emulation
401 activated).
402
403 However given that only the one bit is needed (in RV NS Mode, not
404 Foreign NS Mode), it would be terribly wasteful of the CSRs to do this,
405 despite it being technically correct and much easier to understand why
406 trap raising is so essential (mandatory).
407
408 This again should emphasise how to mentally get one's head round this
409 mind-bendingly complex problem space: think of each NS bit as its own
410 totally separate CSR that every implementor is free and clear to implement
411 (or leave to JIT Emulation) as they see fit.
412
413 Only then does the mandatory need to trap on write really start to hit
414 home, as does the need to preallocate a full set of reserved zero values
415 in the RV ISAMUX/NS.
416
417 Lastly, I *think* it's ok to only reserve say 32 bits, and, in 50 years
418 time if that genuinely is not enough, start the process all over again
419 with a new CSR. ISAMUX2/NS2.
420
421 Subdivision of the RV NS (support for RVCv3/4/5/RV16 without wasting
422 precious CSR bits) best left for discussion another time, the above is
423 a heck of a lot to absorb, already.
424
425 ## Why WARL will not work and why WLRL is required
426
427 WARL requires a follow-up read of the CSR to ascertain what heuristic
428 the hardware *might* have applied, and if that procedure is followed in
429 this proposal, performance even on hardware would be severely compromised.
430
431 In addition when switching to foreign architectures, the switch has to
432 be done atomically and guaranteed to occur.
433
434 In the case of JIT emulation, the WARL "detection" code will be in an
435 assembly language that is alien to hardware.
436
437 Support for both assembly languages immediately after the CSR write
438 is clearly impossible, this leaves no other option but to have the CSR
439 be WLRL (on all platforms) and for traps to be mandatory (on the UNIX
440 Platform).
441
442 ## Is it strictly necessary for foreign archs to switch back? <a name="foreignswitch"></a>
443
444 No, because LAST-ISANS handles the setting and unsetting of the ISANS CSR
445 in a completely transparent fashion as far as the foreign arch is concerned.
446 Supervisor or Hypervisor traps take care of the context switch in a way
447 that the user mode (or guest) need not be aware of, in any way.
448
449 Thus, in e.g. Hypervisor Mode, the foreign guest arch has no knowledge
450 or need to know that the hypervisor is flipping back to RV at the time of
451 a trap.
452
453 Note however that this is **not** the same as the foreign arch executing
454 *foreign* traps! Foreign architecture trap and interrupt handling mechanisms
455 are **out of scope** of this document and MUST be handled by the foreign
456 architecture implementation in a completely transparent fashion that in
457 no way interacts or interferes with this proposal.
458
459 ## Can we have dynamic declaration and runtime declaration of capabilities? <a name="dynamic"></a>
460
461 Answer: don't know (yet). Quoted from Rogier:
462
463 > "A SOC may have several devices that one may want to directly control
464 > with custom instructions. If independent vendors use the same opcodes you
465 > either have to change the encodings for every different chip (not very
466 > nice for software) or you can give the device an ID which is defined in
467 > some device tree or something like that and use that."
468
469 dynamic detection wasn't originally planned: static
470 compilation was envisaged to solve the need, with a table of
471 mvendorid-marchid-isamux/isans being maintained inside gcc / binutils /
472 llvm (or separate library?) that, like the linux kernel ARCH table,
473 requires a world-wide atomic "git commit" to add globally-unique
474 registered entries that map functionality to actual namespaces.
475
476 where that goes wrong is if there is ever a pair (or more) of vendors
477 that use the exact same custom feature that maps to different opcodes,
478 a statically-compiled binary has no hope of executing natively on both
479 systems.
480
481 at that point: yes, something akin to device-tree would be needed.
482
483 # Open Questions <a name="open-questions"></a>
484
485 This section from a post by Rogier Bruisse
486 <http://hands.com/~lkcl/gmail_re_isadev_isamux.html>
487
488 ## is the ISANS CSR a 32 or XLEN bit value? <a name="isans-32-or-xlen"></a>
489
490 This is partly answered in another FAQ above: if 32 bits is not enough
491 for a full suite of official, custom-with-atomic-registration and custom-without
492 then a second CSR group (ISANS2) may be added at a future date (10-20 years
493 hence).
494
495 32 bits would not inconvenience RV32, and implementors wishing to
496 make significant altnernative modifications to opcodes in the RV32 ISA space
497 could do so without the burden of having to support a split 32/LO 32/HI
498 CSR across two locations.
499
500 ## is the ISANS a flat number space or should some bits be reserved for use as flags?
501
502 See 16-bit RV namespace "page" concept, above. Some bits have to be unary
503 (multiple simultaneous features such as LE/BE in one bit, and augmented
504 Floating-point rounding / clipping in another), whilst others definitely
505 need to be binary (the most obvious one being "paging" in the space currently
506 occupied by RVC).
507
508 ## should the ISANS space be partitioned between reserved, custom with registration guaranteed non clashing, custom, very likely non clashing?
509
510 Yes. Format TBD.
511
512 ## should only compiler visible/generated constant setting with CSRRWI and/or using a clearly recognisable LI/LUI be accommodated or should dynamic setting be accommodated as well?
513
514 This is almost certainly a software design issue, not so much a hardware
515 issue.
516
517 ## How should the ISANS be (re)stored in a trap and in context switch?
518
519 See section above on privilege mode: LAST-ISANS has been introduced that
520 mirrors (x)CAUSE and (x)EPC pretty much exactly. Context switches change
521 uepc just before exit from the trap, in order to change the user-mode PC
522 to switch to a new process, and ulast-isans can - must - be treated in
523 exactly the same way. When the context switch sets ulast-isans (and uepc),
524 the hardware flips both ulast-isans into uisans and uepc into pc (atomically):
525 both the new NS and the new PC activate immediately, on return to usermode.
526
527 Quite simple.
528
529 ## Should the mechanism accommodate "foreign ISA's" and if so how does one restore the ISA.
530
531 See section above on LAST-ISANS. With the introduction of LAST-ISANS, the
532 change is entirely transparent, and handled by the Supervisor (or Hypervisor)
533 trap, in a fashion that the foreign ISA need not even know of the existence
534 of ISANS. At all.
535
536 ## Where is the default ISA stored and what is responsible for what it is after
537
538 Options:
539 * start up
540 * starting a program
541 * calling into a dynamically linked library
542 * taking a trap
543 * changing privilege levels
544
545 These first four are entirely at the discretion of (and the
546 responsibility of) the software. There is precedent for most of these
547 having been implemented, historically, at some point, in relation to
548 LE/BE mode CSRs in other hardware (MIPSEL vs MIPS distros for example).
549
550 Traps are responsible for saving LAST-ISANS on the stack, exactly as they
551 are also responsible for saving other context-sensitive information such
552 as the registers and xEPC.
553
554 The hardware is responsible for atomically switching out ISANS into the
555 relevant xLAST-ISANS (and back again on exit). See Privileged Traps,
556 above.
557
558 ## If the ISANS is just bits of an instruction that are to be prefixed by the cpu, can those bits contain immediates? Register numbers?
559
560 The concept of a CSR containing an immediate makes no sense. The concept
561 of a CSR containing a register number, the contents of which would, presumably,
562 be inserted into the NS, would immediately make that register a permanent
563 and irrevocably reserved register that could not be utilised for any other
564 purpose.
565
566 This is what the CSRs are supposed to be for!
567
568 It would be better just to have a second CSR - ISANS2 - potentially even ISANS3
569 in 60+ years time, rather than try to use a GPR for the purposes for which CSRs
570 are intended.
571
572 ## How does the system indicate a namespace is not recognised? Does it trap or can/must a recoverable mechanism be provided?
573
574 It doesn't "indicate" that a namespace is not recognised. WLRL fields only
575 hold supported values. If the hardware cannot hold the value, a trap
576 **MUST** be thrown (in the UNIX platform), and at that point it becomes the
577 responsibility of software to deal with it.
578
579 ## What are the security implications? Can some ISA namespaces be set by user space?
580
581 Of course they can. It becomes the responsibility of the Supervisor Mode
582 (the kernel) to treat ISANS in a fashion orthogonal to the PC. If the OS
583 is not capable of properly context-switching securely by setting the right
584 PC, it's not going to be capable of properly looking after changes to ISANS.
585
586 ## Does the validity of an ISA namespace depend on privilege level? If so how?
587
588 The question does not exactly make sense, and may need a re-reading of the
589 section on how Privilege Modes, above. In RISC-V, privilege modes do not
590 actually change very much state of the system: the absolute minimum changes
591 are made (swapped out) - xEPC, xSTATUS and so on - and the privilege mode
592 is expected to handle the context switching (or other actions) itself.
593
594 ISANS - through LAST-ISANS - is absolutely no different. The trap and the
595 kernel (Supervisor or Hypervisor) are provided the *mechanism* by which
596 ISA Namespace *may* be set: it is up to the software to use that mechanism
597 correctly, just as the software is expected to use the mechanisms provided
598 to correctly implement context-switching by saving and restoring register
599 files, the PC, and other state. The NS effectively becomes just another
600 part of that state.
601
602