Skip to content

Commit dbd2e53

Browse files
committed
feat(data): add Zcmt instructions with IDL
Signed-off-by: Paul A. Clarke <[email protected]>
1 parent 22952a0 commit dbd2e53

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) Ventana Micro Systems
2+
# SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# yaml-language-server: $schema=../../../../schemas/inst_schema.json
5+
6+
$schema: "inst_schema.json#"
7+
kind: instruction
8+
name: cm.jalt
9+
long_name: Jump Via Table with Optional Link
10+
description: |
11+
Read an address from the Jump Vector Table and jump to it, linking to `ra`.
12+
definedBy: Zcmt
13+
assembly: index
14+
encoding:
15+
match: 101000--------10
16+
variables:
17+
- name: index
18+
location: 9-2
19+
# prettier-ignore
20+
not: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ]
21+
access:
22+
s: always
23+
u: always
24+
vs: always
25+
vu: always
26+
operation(): |
27+
# Ensure JVT readable
28+
XReg jvt = csr_sw_read(0x017);
29+
30+
if (CSR[jvt].MODE != 0) {
31+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
32+
}
33+
34+
# Skip over _this_ 16-bit instruction
35+
XReg return_addr = $pc + 2;
36+
X[1] = return_addr;
37+
38+
XReg jump_table_base = { CSR[jvt].BASE, 6'b000000 };
39+
XReg virtual_address = jump_table_base + index * (xlen() / 8);
40+
XReg addr;
41+
42+
# TODO
43+
# For a table jump instruction, the table entry that the instruction selects
44+
# is considered an extension of the instruction itself. Hence, the execution
45+
# of a table jump instruction involves two instruction fetches, the first to
46+
# read the instruction (cm.jt/cm.jalt) and the second to read from the jump
47+
# vector table (JVT). Both instruction fetches are implicit reads, and both
48+
# require execute permission; read permission is irrelevant. It is
49+
# recommended that the second fetch be ignored for hardware triggers and breakpoints.
50+
#
51+
# If an exception occurs on either instruction fetch, xEPC is set to the PC
52+
# of the table jump instruction, xCAUSE is set as expected for the type of
53+
# fault and xTVAL (if not set to zero) contains the fetch address which
54+
# caused the fault.
55+
56+
if (xlen() == 32) {
57+
addr = read_memory<32>(virtual_address, $encoding);
58+
} else {
59+
addr = read_memory<64>(virtual_address, $encoding);
60+
}
61+
62+
# Ensure low-order bit is clear
63+
addr = addr & $signed(2'b10);
64+
65+
jump(addr);
66+
67+
sail(): |

spec/std/isa/inst/Zcmt/cm.jt.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) Ventana Micro Systems
2+
# SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# yaml-language-server: $schema=../../../../schemas/inst_schema.json
5+
6+
$schema: "inst_schema.json#"
7+
kind: instruction
8+
name: cm.jt
9+
long_name: Jump Via Table
10+
description: |
11+
Read an address from the Jump Vector Table and jump to it.
12+
definedBy: Zcmt
13+
assembly: index
14+
encoding:
15+
match: 101000000-----10
16+
variables:
17+
- name: index
18+
location: 6-2
19+
access:
20+
s: always
21+
u: always
22+
vs: always
23+
vu: always
24+
operation(): |
25+
# Ensure JVT readable
26+
XReg jvt = csr_sw_read(0x017);
27+
28+
if (CSR[jvt].MODE != 0) {
29+
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
30+
}
31+
32+
XReg jump_table_base = { CSR[jvt].BASE, 6'b000000 };
33+
XReg virtual_address = jump_table_base + index `* (xlen() / 8);
34+
XReg addr;
35+
36+
# TODO
37+
# For a table jump instruction, the table entry that the instruction selects
38+
# is considered an extension of the instruction itself. Hence, the execution
39+
# of a table jump instruction involves two instruction fetches, the first to
40+
# read the instruction (cm.jt/cm.jalt) and the second to read from the jump
41+
# vector table (JVT). Both instruction fetches are implicit reads, and both
42+
# require execute permission; read permission is irrelevant. It is
43+
# recommended that the second fetch be ignored for hardware triggers and breakpoints.
44+
#
45+
# If an exception occurs on either instruction fetch, xEPC is set to the PC
46+
# of the table jump instruction, xCAUSE is set as expected for the type of
47+
# fault and xTVAL (if not set to zero) contains the fetch address which
48+
# caused the fault.
49+
50+
if (xlen() == 32) {
51+
addr = read_memory<32>(virtual_address, $encoding);
52+
} else {
53+
addr = read_memory<64>(virtual_address, $encoding);
54+
}
55+
56+
# Ensure low-order bit is clear
57+
addr = addr & $signed(2'b10);
58+
59+
jump(addr);
60+
61+
sail(): |

0 commit comments

Comments
 (0)