Skip to content

Commit 1643f21

Browse files
committed
feat(cpu): add Sstc CSRs
1 parent b2005b4 commit 1643f21

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

arch/csr/stimecmp.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# yaml-language-server: $schema=../../schemas/csr_schema.json
2+
3+
$schema: "csr_schema.json#"
4+
kind: csr
5+
name: stimecmp
6+
long_name: Supervisor Timer Compare Register
7+
virtual_address: 0x14D
8+
address: 0x14D
9+
priv_mode: S
10+
definedBy: Sstc
11+
length: 64
12+
13+
description:
14+
- id: csr-stimecmp-purpose
15+
normative: true
16+
text: |
17+
The stimecmp CSR is a 64-bit register and provides 64-bit precision on all RV32 and RV64 systems.
18+
On RV32, accesses to the stimecmp CSR access the low 32 bits, while accesses to the stimecmph CSR
19+
access the high 32 bits of stimecmp.
20+
The CSR numbers for stimecmp and stimecmph are 0x14D and 0x15D, respectively, within the Supervisor Trap Setup block.
21+
22+
- id: csr-stimecmp-interrupt
23+
normative: true
24+
text: |
25+
A supervisor timer interrupt becomes pending, as reflected in the STIP bit in the mip and sip registers,
26+
whenever the time register contains a value greater than or equal to stimecmp, treating the values as unsigned integers.
27+
If the result of this comparison changes, it is guaranteed to be reflected in STIP eventually,
28+
but not necessarily immediately.
29+
The interrupt remains posted until stimecmp becomes greater than time, typically due to writing a new value to stimecmp.
30+
The interrupt is taken based on standard interrupt enable and delegation rules.
31+
32+
- id: csr-stimecmp-spurious
33+
normative: false
34+
text: |
35+
A spurious timer interrupt might occur if an interrupt handler advances stimecmp and immediately returns,
36+
because STIP might not yet have fallen. All software should be written to account for this possibility,
37+
although it is generally rare. It is usually more efficient to tolerate occasional spurious timer interrupts
38+
than to poll STIP until it clears.
39+
40+
- id: csr-stimecmp-sbi
41+
normative: false
42+
text: |
43+
In systems where a Supervisor Execution Environment (SEE) provides timer services via an SBI call,
44+
the SBI will continue to support scheduling timer interrupts. The SEE updates stimecmp as needed.
45+
This ensures compatibility with existing S-mode software, while newer software can interact with stimecmp directly.
46+
47+
fields:
48+
STIMECMP:
49+
long_name: Supervisor timer compare value
50+
location_rv32: 31-0
51+
location_rv64: 63-0
52+
type: RW
53+
reset_value: 0
54+
sw_write(csr_value): |
55+
return csr_value.STIMECMP;
56+
description: |
57+
The value in stimecmp is compared against the current value of the time CSR.
58+
If time is greater than or equal to stimecmp, a supervisor timer interrupt (STIP) is posted.

arch/csr/vstimecmp.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# yaml-language-server: $schema=../../schemas/csr_schema.json
2+
3+
$schema: "csr_schema.json#"
4+
kind: csr
5+
name: vstimecmp
6+
long_name: Virtual Supervisor Timer Register
7+
virtual_address: 0x24D
8+
address: 0x24D
9+
priv_mode: VS
10+
definedBy: H
11+
length: SXLEN
12+
13+
description:
14+
- id: csr-vstimecmp-purpose
15+
normative: true
16+
text: |
17+
The vstimecmp CSR is a 64-bit register and has 64-bit precision on all RV32 and RV64 systems.
18+
In RV32 only, accesses to the vstimecmp CSR access the low 32 bits, while accesses to the vstimecmph CSR
19+
access the high 32 bits of vstimecmp.
20+
21+
- id: csr-vstimecmp-csr-numbers
22+
normative: true
23+
text: |
24+
The proposed CSR numbers for vstimecmp / vstimecmph are 0x24D / 0x25D (within the Virtual Supervisor
25+
Registers block of CSRs, and mirroring the CSR numbers for stimecmp/stimecmph).
26+
27+
- id: csr-vstimecmp-interrupt
28+
normative: true
29+
text: |
30+
A virtual supervisor timer interrupt becomes pending, as reflected in the VSTIP bit in the hip register,
31+
whenever (time + htimedelta), truncated to 64 bits, contains a value greater than or equal to vstimecmp,
32+
treating the values as unsigned integers.
33+
If the result of this comparison changes, it is guaranteed to be reflected in VSTIP eventually, but not necessarily immediately.
34+
The interrupt remains posted until vstimecmp becomes greater than (time + htimedelta), typically as a result of writing vstimecmp.
35+
The interrupt will be taken based on the standard interrupt enable and delegation rules while V=1.
36+
37+
- id: csr-vstimecmp-compat
38+
normative: false
39+
text: |
40+
In systems in which a supervisor execution environment (SEE) implemented by an
41+
HS-mode hypervisor provides timer facilities via an SBI function call, this SBI call will
42+
continue to support requests to schedule a timer interrupt. The SEE will simply make
43+
use of vstimecmp, changing its value as appropriate. This ensures compatibility with
44+
existing guest VS-mode software that uses this SEE facility, while new VS-mode
45+
software takes advantage of vstimecmp directly.
46+
47+
fields:
48+
VSTIMECMP:
49+
long_name: Virtual supervisor timer compare value
50+
location_rv32: 31-0
51+
location_rv64: 63-0
52+
type: RW
53+
reset_value: UNDEFINED_LEGAL
54+
description: |
55+
The value in vstimecmp is compared with (time + htimedelta), truncated to 64 bits,
56+
to determine whether a virtual supervisor timer interrupt should be posted in VSTIP.

0 commit comments

Comments
 (0)