|
| 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 extensionEnabled(Ext_Zcmt) = extensionEnabled(Ext_Zca) & sys_enable_zcmt() & not(sys_enable_zcd()) & (xlen == 32 | xlen == 64) |
| 10 | + |
| 11 | +type target_address = bits(xlen) |
| 12 | + |
| 13 | +union FJT_Result = { |
| 14 | + FJT_Success : target_address, |
| 15 | + FJT_Failure : unit |
| 16 | +} |
| 17 | + |
| 18 | +function fetch_jump_table(table_address : bits(xlen)) -> FJT_Result = { |
| 19 | + /* Fetching jump table address needs execute permission */ |
| 20 | + match ext_data_get_addr_from_bits(table_address, Execute(), xlen_bytes) { |
| 21 | + Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); FJT_Failure() }, |
| 22 | + Ext_DataAddr_OK(vaddr) => { |
| 23 | + if check_misaligned(vaddr, size_bytes(xlen_bytes)) |
| 24 | + then { handle_mem_exception(vaddr, E_Load_Addr_Align()); FJT_Failure() } |
| 25 | + else match translateAddr(vaddr, Execute()) { |
| 26 | + TR_Failure(e, _) => { handle_mem_exception(vaddr, e); FJT_Failure() }, |
| 27 | + TR_Address(paddr, _) => |
| 28 | + match mem_read(Execute(), paddr, xlen_bytes, false, false, false) { |
| 29 | + Ok(result) => { FJT_Success(result) }, |
| 30 | + Err(e) => { handle_mem_exception(vaddr, e); FJT_Failure() }, |
| 31 | + }, |
| 32 | + } |
| 33 | + }, |
| 34 | + }; |
| 35 | +} |
| 36 | + |
| 37 | +union clause ast = CM_JALT : (bits(8)) |
| 38 | + |
| 39 | +mapping clause encdec_compressed = CM_JALT(index) if extensionEnabled(Ext_Zcmt) & 32 <= unsigned(index) |
| 40 | + <-> 0b101 @ 0b000 @ index : bits(8) @ 0b10 if extensionEnabled(Ext_Zcmt) & 32 <= unsigned(index) |
| 41 | + |
| 42 | +function clause execute (CM_JALT(index)) = { |
| 43 | + let base : bits(xlen) = jvt.bits & ~(zero_extend(0x3F)); |
| 44 | + let index : bits(xlen) = zero_extend(index); |
| 45 | + if jvt[mode] == 0b000000 then { |
| 46 | + let table_address : bits(xlen) = match xlen { |
| 47 | + 32 => base + index << 2, |
| 48 | + 64 => base + index << 3, |
| 49 | + _ => internal_error(__FILE__, __LINE__, "Unsupported xlen") |
| 50 | + }; |
| 51 | + match fetch_jump_table(table_address) { |
| 52 | + FJT_Failure(_) => { |
| 53 | + return RETIRE_FAIL |
| 54 | + }, |
| 55 | + FJT_Success(target_address) => { |
| 56 | + X(0b00001) = get_next_pc(); |
| 57 | + set_next_pc(target_address & ~(zero_extend(0x1))); |
| 58 | + } |
| 59 | + }; |
| 60 | + }; |
| 61 | + RETIRE_SUCCESS |
| 62 | +} |
| 63 | + |
| 64 | +mapping clause assembly = CM_JALT(index) if (xlen == 32 | xlen == 64) <-> |
| 65 | + "cm.jalt" ^ spc() ^ hex_bits_8(index) if (xlen == 32 | xlen == 64) |
| 66 | + |
| 67 | +/* ****************************************************************** */ |
| 68 | +union clause ast = CM_JT : (bits(8)) |
| 69 | + |
| 70 | +mapping clause encdec_compressed = CM_JT(index) if extensionEnabled(Ext_Zcmt) & unsigned(index) < 32 |
| 71 | + <-> 0b101 @ 0b000 @ index : bits(8) @ 0b10 if extensionEnabled(Ext_Zcmt) & unsigned(index) < 32 |
| 72 | + |
| 73 | +function clause execute (CM_JT(index)) = { |
| 74 | + let base : bits(xlen) = jvt.bits & ~(zero_extend(0x3F)); |
| 75 | + let index : bits(xlen) = zero_extend(index); |
| 76 | + if jvt[mode] == 0b000000 then { |
| 77 | + let table_address : bits(xlen) = match xlen { |
| 78 | + 32 => base + index << 2, |
| 79 | + 64 => base + index << 3, |
| 80 | + _ => internal_error(__FILE__, __LINE__, "Unsupported xlen") |
| 81 | + }; |
| 82 | + match fetch_jump_table(table_address) { |
| 83 | + FJT_Failure(_) => { |
| 84 | + return RETIRE_FAIL |
| 85 | + }, |
| 86 | + FJT_Success(target_address) => { |
| 87 | + set_next_pc(target_address & ~(zero_extend(0x1))); |
| 88 | + } |
| 89 | + }; |
| 90 | + }; |
| 91 | + RETIRE_SUCCESS |
| 92 | +} |
| 93 | + |
| 94 | +mapping clause assembly = CM_JT(index) if (xlen == 32 | xlen == 64) <-> |
| 95 | + "cm.jt" ^ spc() ^ hex_bits_8(index) if (xlen == 32 | xlen == 64) |
0 commit comments