hpmcounter4
User-mode Hardware Performance Counter 1
Alias for M-mode CSR mhpmcounter4.
Privilege mode access is controlled with mcounteren.HPM4 <%- if ext?(:S) -%> , scounteren.HPM4 <%- if ext?(:H) -%> , and hcounteren.HPM4 <%- end -%> <%- end -%> as follows:
<%- if ext?(:H) -%>
hpmcounter4 behavior |
||||||
---|---|---|---|---|---|---|
S-mode |
U-mode |
VS-mode |
VU-mode |
|||
0 |
- |
- |
|
|
|
|
1 |
0 |
0 |
read-only |
|
|
|
1 |
1 |
0 |
read-only |
read-only |
|
|
1 |
0 |
1 |
read-only |
|
read-only |
|
1 |
1 |
1 |
read-only |
read-only |
read-only |
read-only |
<%- elsif ext?(:S) -%>
hpmcounter4 behavior |
|||
---|---|---|---|
S-mode |
U-mode |
||
0 |
- |
|
|
1 |
0 |
read-only |
|
1 |
1 |
read-only |
read-only |
<%- else -%>
hpmcounter4 behavior |
|
---|---|
U-mode |
|
0 |
|
1 |
read-only |
<%- end -%>
Attributes
Defining Extension |
|
---|---|
CSR Address |
0xc04 |
Length |
64-bit |
Privilege Mode |
U |
Software read
This CSR may return a value that is different from what is stored in hardware.
if (%%LINK%func;mode;mode%%() == PrivilegeMode::S) {
if (%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b0) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
} else if (%%LINK%func;mode;mode%%() == PrivilegeMode::U) {
if (%%LINK%csr_field;misa.S;CSR[misa].S%% == 1'b1) {
if ((%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% & %%LINK%csr_field;scounteren.HPM4;CSR[scounteren].HPM4%%) == 1'b0) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
} else if (%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b0) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
} else if (%%LINK%func;mode;mode%%() == PrivilegeMode::VS) {
if (%%LINK%csr_field;hcounteren.HPM4;CSR[hcounteren].HPM4%% == 1'b0 && %%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b1) {
%%LINK%func;raise;raise%%(ExceptionCode::VirtualInstruction, %%LINK%func;mode;mode%%(), $encoding);
} else if (%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b0) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
} else if (%%LINK%func;mode;mode%%() == PrivilegeMode::VU) {
if (%%LINK%csr_field;hcounteren.HPM4;CSR[hcounteren].HPM4%% & %%LINK%csr_field;scounteren.HPM4;CSR[scounteren].HPM4%%) == 1'b0) && (%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b1 {
%%LINK%func;raise;raise%%(ExceptionCode::VirtualInstruction, %%LINK%func;mode;mode%%(), $encoding);
} else if (%%LINK%csr_field;mcounteren.HPM4;CSR[mcounteren].HPM4%% == 1'b0) {
%%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
}
return %%LINK%func;read_hpm_counter;read_hpm_counter%%(4);