|
| 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_Zilsd) = sys_enable_zilsd() & xlen == 32 |
| 10 | + |
| 11 | +/* ****************************************************************** */ |
| 12 | +union clause ast = ZILSD_LD : (bits(12), regidx, regidx) |
| 13 | + |
| 14 | +mapping clause encdec = ZILSD_LD(imm, rs1, rd) |
| 15 | + <-> imm @ encdec_reg(rs1) @ 0b011 @ encdec_reg(rd) @ 0b0000011 |
| 16 | + when extensionEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rd)[0])) |
| 17 | + |
| 18 | +function load_imm(imm : bits(12), base_val : xlenbits, rd : regidx, width : word_width) -> Retired = { |
| 19 | + let offset : xlenbits = sign_extend(imm); |
| 20 | + let width_bytes = size_bytes(width); |
| 21 | + assert(width_bytes <= xlen_bytes); |
| 22 | + |
| 23 | + let vaddr = Virtaddr(base_val + offset); |
| 24 | + if check_misaligned(vaddr, width) |
| 25 | + then { handle_mem_exception(vaddr, E_Load_Addr_Align()); RETIRE_FAIL } |
| 26 | + else match translateAddr(vaddr, Read(Data)) { |
| 27 | + TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }, |
| 28 | + TR_Address(paddr, _) => { |
| 29 | + match mem_read(Read(Data), paddr, width_bytes, false, false, false) { |
| 30 | + Ok(result) => { X(rd) = extend_value(false, result); RETIRE_SUCCESS }, |
| 31 | + Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }, |
| 32 | + } |
| 33 | + }, |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function clause execute ZILSD_LD(imm, rs1, rd) = { |
| 38 | + if rd != zreg then { |
| 39 | + let base_val = X(rs1); |
| 40 | + let _ = load_imm(imm, base_val, rd, WORD); |
| 41 | + load_imm(imm+4, base_val, rd+1, WORD) |
| 42 | + } else { |
| 43 | + RETIRE_SUCCESS |
| 44 | + } |
| 45 | +} |
| 46 | +mapping clause assembly = ZILSD_LD(imm, rs1, rd) <-> "ld" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_signed_12(imm) ^ "(" ^ reg_name(rs1) ^ ")" |
| 47 | + |
| 48 | + |
| 49 | +/* ****************************************************************** */ |
| 50 | +union clause ast = ZILSD_SD : (bits(12), regidx, regidx) |
| 51 | + |
| 52 | +mapping clause encdec = ZILSD_SD(imm7 @ imm5, rs2, rs1) |
| 53 | + <-> imm7 : bits(7) @ encdec_reg(rs2) @ encdec_reg(rs1) @ 0b011 @ imm5 : bits(5) @ 0b0100011 |
| 54 | + when extensionEnabled(Ext_Zilsd) & not(bit_to_bool(encdec_reg(rs2)[0])) |
| 55 | + |
| 56 | +function store_imm(imm : bits(12), rs2_val : xlenbits, base_val : xlenbits, width : word_width) -> Retired = { |
| 57 | + let offset : xlenbits = sign_extend(imm); |
| 58 | + let width_bytes = size_bytes(width); |
| 59 | + assert(width_bytes <= xlen_bytes); |
| 60 | + |
| 61 | + let vaddr = Virtaddr(base_val + offset); |
| 62 | + if check_misaligned(vaddr, width) |
| 63 | + then { handle_mem_exception(vaddr, E_SAMO_Addr_Align()); RETIRE_FAIL } |
| 64 | + else match translateAddr(vaddr, Write(Data)) { |
| 65 | + TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }, |
| 66 | + TR_Address(paddr, _) => { |
| 67 | + match mem_write_ea(paddr, width_bytes, false, false, false) { |
| 68 | + Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }, |
| 69 | + Ok(_) => { |
| 70 | + match mem_write_value(paddr, width_bytes, rs2_val[width_bytes * 8 - 1 .. 0], false, false, false) { |
| 71 | + Ok(true) => RETIRE_SUCCESS, |
| 72 | + Ok(false) => internal_error(__FILE__, __LINE__, "store got false from mem_write_value"), |
| 73 | + Err(e) => { handle_mem_exception(vaddr, e); RETIRE_FAIL } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +function clause execute ZILSD_SD(imm, rs2, rs1) = { |
| 82 | + let base_val = X(rs1); |
| 83 | + let rs2_val = X(rs2); |
| 84 | + let rs2_pair_val = if rs2 != zreg then X(rs2+1) else rs2_val; |
| 85 | + let _ = store_imm(imm, rs2_val, base_val, WORD); |
| 86 | + store_imm(imm+4, rs2_pair_val, base_val, WORD) |
| 87 | +} |
| 88 | + |
| 89 | +mapping clause assembly = ZILSD_SD(offset, rs2, rs1) <-> "sd" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_signed_12(offset) ^ "(" ^ reg_name(rs1) ^ ")" |
0 commit comments