From 2463e2a99137533ad59d179e32ed4c937d1b01ec Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Fri, 15 Sep 2023 17:59:31 -0700 Subject: [PATCH] Add Zimop/Zcmop draft --- src/images/wavedrom/c-mop.adoc | 12 ++++++ src/images/wavedrom/mop-r.adoc | 15 +++++++ src/images/wavedrom/mop-rr.adoc | 15 +++++++ src/riscv-unprivileged.adoc | 1 + src/zimop.adoc | 72 +++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 src/images/wavedrom/c-mop.adoc create mode 100644 src/images/wavedrom/mop-r.adoc create mode 100644 src/images/wavedrom/mop-rr.adoc create mode 100644 src/zimop.adoc diff --git a/src/images/wavedrom/c-mop.adoc b/src/images/wavedrom/c-mop.adoc new file mode 100644 index 000000000..c66e80c55 --- /dev/null +++ b/src/images/wavedrom/c-mop.adoc @@ -0,0 +1,12 @@ +[wavedrom, ,svg] +.... +{reg:[ + { bits: 2, name: 0x1, type: 8 }, + { bits: 5, name: 0x0 }, + { bits: 1, name: 0x1, type: 4 }, + { bits: 3, name: 'n[2:0]', type: 4 }, + { bits: 1, name: 0x0, type: 4 }, + { bits: 1, name: 0x0 }, + { bits: 3, name: 0x3 }, +]} +.... diff --git a/src/images/wavedrom/mop-r.adoc b/src/images/wavedrom/mop-r.adoc new file mode 100644 index 000000000..713b37c48 --- /dev/null +++ b/src/images/wavedrom/mop-r.adoc @@ -0,0 +1,15 @@ +[wavedrom, ,svg] +.... +{reg:[ + { bits: 7, name: 0x73, attr: ['SYSTEM'], type: 8 }, + { bits: 5, name: 'rd', type: 2 }, + { bits: 3, name: 0x4 }, + { bits: 5, name: 'rs1', type: 4 }, + { bits: 2, name: 'n[1:0]' }, + { bits: 4, name: 0x7 }, + { bits: 2, name: 'n[3:2]' }, + { bits: 2, name: 0x0 }, + { bits: 1, name: 'n[4]' }, + { bits: 1, name: 0x1 }, +], config: {fontsize: 11}} +.... diff --git a/src/images/wavedrom/mop-rr.adoc b/src/images/wavedrom/mop-rr.adoc new file mode 100644 index 000000000..b70f8543d --- /dev/null +++ b/src/images/wavedrom/mop-rr.adoc @@ -0,0 +1,15 @@ +[wavedrom, ,svg] +.... +{reg:[ + { bits: 7, name: 0x73, attr: ['SYSTEM'], type: 8 }, + { bits: 5, name: 'rd', type: 2 }, + { bits: 3, name: 0x4 }, + { bits: 5, name: 'rs1', type: 4 }, + { bits: 5, name: 'rs2', type: 4 }, + { bits: 1, name: 0x1 }, + { bits: 2, name: 'n[1:0]' }, + { bits: 2, name: 0x0 }, + { bits: 1, name: 'n[2]' }, + { bits: 1, name: 0x1 }, +], config: {fontsize: 11}} +.... diff --git a/src/riscv-unprivileged.adoc b/src/riscv-unprivileged.adoc index b9c164dfc..48aebcd07 100644 --- a/src/riscv-unprivileged.adoc +++ b/src/riscv-unprivileged.adoc @@ -111,6 +111,7 @@ include::rvwmo.adoc[] //rvwmo.tex include::c-st-ext.adoc[] //c.tex +include::zimop.adoc[] include::b-st-ext.adoc[] //b.tex include::j-st-ext.adoc[] diff --git a/src/zimop.adoc b/src/zimop.adoc new file mode 100644 index 000000000..a1d64f359 --- /dev/null +++ b/src/zimop.adoc @@ -0,0 +1,72 @@ +[[zimop]] +== "Zimop" May-Be-Operations Extension, Version 0.1 +This chapter defines the "Zimop" extension, which introduces the concept of +instructions that _may be operations_ (MOPs). MOPs are initially defined to +perform no useful operation and raise no exceptions, but might be redefined by +later extensions to perform some other action. The Zimop extension defines an +encoding space for 40 MOPs. + +[NOTE] +==== +It is sometimes desirable to define instruction-set extensions whose +instructions do not raise illegal-instruction exceptions when the extension is +not implemented. For example, programs with control-flow integrity checks can +execute correctly on implementations without the corresponding extension, +provided the checks are simply ignored. Implementing these checks as MOPs +allows the same programs to run on implementations with or without the +corresponding extension. + +Although similar in some respects to HINTs, most MOPs cannot be encoded as +HINTs, because MOPs might sometimes alter architectural state, which HINTs are +forbidden from doing. +==== + +The Zimop extension defines 32 MOP instructions named `mop.r.__n__`, where +__n__ is an integer between 0 and 31, inclusive. +Unless redefined by another extension, these instructions simply write 0 to +`x[rd]`. Their encoding allows future extensions to define them to read `x[rs1]`, +as well as write `x[rd]`. + +include::images/wavedrom/mop-r.adoc[] +[[mop-r]] + +The Zimop extension additionally defines 8 MOP instructions named +`mop.rr.__n__`, where __n__ is an integer between 0 and 7, inclusive. +Unless redefined by another extension, these instructions simply +write 0 to `x[rd]`. Their encoding allows future extensions to define them to +read `x[rs1]` and `x[rs2]`, as well as write `x[rd]`. + +include::images/wavedrom/mop-rr.adoc[] +[[mop-rr]] + +NOTE: These MOPs are encoded in the SYSTEM major opcode in part because it is +expected their behavior will be modulated by privileged CSR state. + +NOTE: These MOPs are defined to write `x[rd]`, rather than performing no +operation, to simplify instruction decoding and to allow testing the presence +of features by branching on the zeroness of the result. + +The MOPs defined in the Zimop extension are not guaranteed to carry +a syntactic dependency from `x[rs1]` or `x[rs2]` to `x[rd]`. + +NOTE: Not carrying a syntactic dependence relieves straightforward +implementations of reading `x[rs1]` and `x[rs2]`. + +<<< + +=== "Zcmop" Compressed May-Be-Operations Extension, Version 0.1 + +This section defines the "Zcmop" extension, which defines eight 16-bit MOP +instructions named `c.mop.__n__`, where __n__ is an integer between 0 and 7, +inclusive. `c.mop.__n__` is encoded in the reserved encoding space +corresponding to `c.lui x__m__, 0`, where __m__=2__n__+1. These instructions +are defined to not write any register. Their encoding allows future extensions +to define them to read register `x[__m__]`. + +include::images/wavedrom/c-mop.adoc[] +[[c-mop]] + + +NOTE: The expectation is that each Zcmop instruction is equivalent to some +Zimop instruction, but the choice of expansion (if any) is left to the +extension that redefines the MOP.