Skip to content

Commit 15b5029

Browse files
committed
Add support for Zcmt extension
1 parent 97b7ed5 commit 15b5029

8 files changed

+121
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Supported RISC-V ISA features
109109
- Zfa extension for additional floating-point instructions, v1.0
110110
- Zfinx, Zdinx, and Zhinx extensions for floating-point in integer registers, v1.0
111111
- C extension for compressed instructions, v2.0
112-
- Zca, Zcf, Zcd, and Zcb extensions for code size reduction, v1.0
112+
- Zca, Zcf, Zcd, Zcb, and Zcmt extensions for code size reduction, v1.0
113113
- Zcmop extension for compressed May-Be-Operations, v1.0
114114
- B (Zba, Zbb, Zbs) and Zbc extensions for bit manipulation, v1.0
115115
- Zbkb, Zbkc, and Zbkx extensions for bit manipulation for cryptography, v1.0

config/default.json

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
"Zcb" : {
120120
"supported" : true
121121
},
122+
"Zcmt" : {
123+
"supported" : false
124+
},
122125
"Zcmop" : {
123126
"supported" : true
124127
},

model/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ foreach (xlen IN ITEMS 32 64)
7272
"riscv_insts_zba.sail"
7373
"riscv_insts_zbb.sail"
7474
"riscv_insts_zbc.sail"
75+
"riscv_insts_zcmt.sail"
7576
"riscv_insts_zbs.sail"
7677
"riscv_insts_zcb.sail"
7778
"riscv_insts_zfh.sail"

model/riscv_addr_checks.sail

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function ext_data_get_addr(base : regidx, offset : xlenbits, acc : AccessType(ex
5959
let addr = Virtaddr(X(base) + offset) in
6060
Ext_DataAddr_OK(addr)
6161

62+
function ext_data_get_addr_from_bits(addr_ext : xlenbits, acc : AccessType(ext_access_type), width : mem_access_width)
63+
-> Ext_DataAddr_Check(ext_data_addr_error) =
64+
let addr = Virtaddr(addr_ext) in
65+
Ext_DataAddr_OK(addr)
66+
6267
function ext_handle_data_check_error(err : ext_data_addr_error) -> unit =
6368
()
6469

model/riscv_extensions.sail

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ function clause hartSupports(Ext_Zca) = config extensions.Zca.supported
108108
// Code Size Reduction: additional 16-bit aliases
109109
enum clause extension = Ext_Zcb
110110
function clause hartSupports(Ext_Zcb) = config extensions.Zcb.supported
111+
// Code Size Reduction: compressed table jump instructions
112+
enum clause extension = Ext_Zcmt
113+
function clause hartSupports(Ext_Zcmt) = config extensions.Zcmt.supported
111114
// Code Size Reduction: compressed double precision floating point loads and stores
112115
enum clause extension = Ext_Zcd
113116
function clause hartSupports(Ext_Zcd) = config extensions.Zcd.supported

model/riscv_insts_zcd.sail

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* SPDX-License-Identifier: BSD-2-Clause */
77
/*=======================================================================================*/
88

9-
function clause currentlyEnabled(Ext_Zcd) = hartSupports(Ext_Zcd) & currentlyEnabled(Ext_D) & currentlyEnabled(Ext_Zca) & (currentlyEnabled(Ext_C) | not(hartSupports(Ext_C)))
9+
function clause currentlyEnabled(Ext_Zcd) = hartSupports(Ext_Zcd) & currentlyEnabled(Ext_D) & currentlyEnabled(Ext_Zca) & not(currentlyEnabled(Ext_Zcmt)) & (currentlyEnabled(Ext_C) | not(hartSupports(Ext_C)))
1010

1111
union clause ast = C_FLDSP : (bits(6), fregidx)
1212

model/riscv_insts_zcmt.sail

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*=======================================================================================*/
2+
/* This Sail RISC-V architecture model, comprising all files and */
3+
/* directories except where otherwise noted is subject the BSD */
4+
/* two-clause license in the LICENSE file. */
5+
/* */
6+
/* SPDX-License-Identifier: BSD-2-Clause */
7+
/*=======================================================================================*/
8+
9+
function clause currentlyEnabled(Ext_Zcmt) = hartSupports(Ext_Zcmt) & currentlyEnabled(Ext_Zca) & not(currentlyEnabled(Ext_Zcd))
10+
11+
type target_address = xlenbits
12+
13+
function fetch_jump_table(table_address : xlenbits) -> result(target_address, unit) = {
14+
/* Executable permission required to fetch jump table address */
15+
match ext_data_get_addr_from_bits(table_address, Execute(), xlen_bytes) {
16+
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); Err() },
17+
Ext_DataAddr_OK(vaddr) => {
18+
if check_misaligned(vaddr, size_bytes(xlen_bytes))
19+
then { handle_mem_exception(vaddr, E_Load_Addr_Align()); Err() }
20+
else match translateAddr(vaddr, Execute()) {
21+
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); Err() },
22+
TR_Address(paddr, _) =>
23+
match mem_read(Execute(), paddr, xlen_bytes, false, false, false) {
24+
Ok(result) => { Ok(result) },
25+
Err(e) => { handle_mem_exception(vaddr, e); Err() },
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
union clause ast = CM_JALT : (bits(8))
33+
34+
mapping clause encdec_compressed = CM_JALT(index)
35+
<-> 0b101 @ 0b000 @ index : bits(8) @ 0b10
36+
when currentlyEnabled(Ext_Zcmt) & 32 <= unsigned(index)
37+
38+
function clause execute (CM_JALT(index)) = {
39+
let base : bits(xlen) = jvt[base] @ 0b000000;
40+
let index : bits(xlen) = zero_extend(index);
41+
if jvt[mode] == 0b000000 then {
42+
let table_address = base + (index << log2_xlen_bytes);
43+
match fetch_jump_table(table_address) {
44+
Err(_) => { RETIRE_FAIL },
45+
Ok(target_address) => {
46+
X(ra) = get_next_pc();
47+
set_next_pc([target_address with 0 = bitzero]);
48+
RETIRE_SUCCESS
49+
}
50+
};
51+
} else {
52+
handle_illegal();
53+
RETIRE_FAIL
54+
};
55+
}
56+
57+
mapping clause assembly = CM_JALT(index)
58+
<-> "cm.jalt" ^ spc() ^ hex_bits_8(index)
59+
60+
/* ****************************************************************** */
61+
union clause ast = CM_JT : (bits(8))
62+
63+
mapping clause encdec_compressed = CM_JT(index)
64+
<-> 0b101 @ 0b000 @ index : bits(8) @ 0b10
65+
when currentlyEnabled(Ext_Zcmt) & unsigned(index) < 32
66+
67+
function clause execute (CM_JT(index)) = {
68+
let base : bits(xlen) = jvt[base] @ 0b000000;
69+
let index : bits(xlen) = zero_extend(index);
70+
if jvt[mode] == 0b000000 then {
71+
let table_address = base + (index << log2_xlen_bytes);
72+
match fetch_jump_table(table_address) {
73+
Err(_) => { RETIRE_FAIL },
74+
Ok(target_address) => {
75+
set_next_pc([target_address with 0 = bitzero]);
76+
RETIRE_SUCCESS
77+
}
78+
};
79+
} else {
80+
handle_illegal();
81+
RETIRE_FAIL
82+
};
83+
}
84+
85+
mapping clause assembly = CM_JT(index)
86+
<-> "cm.jt" ^ spc() ^ hex_bits_8(index)

model/riscv_sys_regs.sail

+21
Original file line numberDiff line numberDiff line change
@@ -978,3 +978,24 @@ function get_vtype_vma() = decode_agtype(vtype[vma])
978978

979979
val get_vtype_vta : unit -> agtype
980980
function get_vtype_vta() = decode_agtype(vtype[vta])
981+
982+
/* Zcmt register */
983+
984+
bitfield Jvt : xlenbits = {
985+
base : xlen - 1 .. 6,
986+
mode : 5 .. 0
987+
}
988+
register jvt : Jvt
989+
990+
function legalize_jvt(o : Jvt, v : xlenbits) -> Jvt = {
991+
let v = Mk_Jvt(v);
992+
[o with
993+
base = v[base],
994+
mode = 0b000000
995+
]
996+
}
997+
998+
mapping clause csr_name_map = 0x017 <-> "jvt"
999+
function clause is_CSR_defined (0x017) = currentlyEnabled(Ext_Zcmt)
1000+
function clause write_CSR(0x017, value) = { jvt = legalize_jvt(jvt, value); jvt.bits }
1001+
function clause read_CSR(0x017) = jvt.bits

0 commit comments

Comments
 (0)