| // Copyright 2025 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| // Tests instruction raises fault when vill bit is set. |
| |
| #include <riscv_vector.h> |
| #include <stdint.h> |
| |
| uint32_t faulted __attribute__((section(".data"))) = 0; |
| uint32_t mcause __attribute__((section(".data"))) = 0; |
| uint32_t mtval __attribute__((section(".data"))) = 0; |
| |
| // Fault handler to log fault |
| extern "C" { |
| void kelvin_exception_handler() { |
| faulted = 1; |
| uint32_t local_mcause; |
| asm volatile("csrr %0, mcause" : "=r"(local_mcause)); |
| mcause = local_mcause; |
| uint32_t local_mtval; |
| asm volatile("csrr %0, mtval" : "=r"(local_mtval)); |
| mtval = local_mtval; |
| |
| asm volatile("ebreak"); |
| while (1) {} |
| } |
| } |
| |
| int main(int argc, char **argv) { |
| asm volatile("vadd.vv v0, v1, v2"); |
| return 0; |
| } |