|
| 1 | +# yaml-language-server: $schema=../../../schemas/inst_schema.json |
| 2 | + |
| 3 | +$schema: "inst_schema.json#" |
| 4 | +kind: instruction |
| 5 | +name: c.lhu |
| 6 | +long_name: Load unsigned halfword, 16-bit encoding |
| 7 | +description: | |
| 8 | + Loads a 16-bit value from memory into register rd. |
| 9 | + It computes an effective address by adding the zero-extended offset, to the base address in register rs1. |
| 10 | + It expands to `lhu` `rd, offset(rs1)`. |
| 11 | +definedBy: |
| 12 | + anyOf: |
| 13 | + - Zcb |
| 14 | + - Zce |
| 15 | +assembly: xd, imm(xs1) |
| 16 | +encoding: |
| 17 | + match: 100001---0----00 |
| 18 | + variables: |
| 19 | + - name: imm |
| 20 | + location: 5 |
| 21 | + left_shift: 1 |
| 22 | + - name: rd |
| 23 | + location: 4-2 |
| 24 | + - name: rs1 |
| 25 | + location: 9-7 |
| 26 | +access: |
| 27 | + s: always |
| 28 | + u: always |
| 29 | + vs: always |
| 30 | + vu: always |
| 31 | +operation(): | |
| 32 | + if (implemented?(ExtensionName::C) && (CSR[misa].C == 1'b0)) { |
| 33 | + raise(ExceptionCode::IllegalInstruction, mode(), $encoding); |
| 34 | + } |
| 35 | +
|
| 36 | + XReg virtual_address = X[rs1+8] + imm; |
| 37 | +
|
| 38 | + X[rd+8] = zext(read_memory<16>(virtual_address, $encoding), 16); |
| 39 | +
|
| 40 | +sail(): | |
| 41 | + { |
| 42 | + let offset : xlenbits = zero_extend(imm); |
| 43 | + /* Get the address, X(rs1c) + offset. |
| 44 | + Some extensions perform additional checks on address validity. */ |
| 45 | + match ext_data_get_addr(rs1c, offset, Read(Data), width) { |
| 46 | + Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); RETIRE_FAIL }, |
| 47 | + Ext_DataAddr_OK(vaddr) => |
| 48 | + if check_misaligned(vaddr, width) |
| 49 | + then { handle_mem_exception(vaddr, E_Load_Addr_Align()); RETIRE_FAIL } |
| 50 | + else match translateAddr(vaddr, Read(Data)) { |
| 51 | + TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL }, |
| 52 | + TR_Address(paddr, _) => |
| 53 | + match (width) { |
| 54 | + BYTE => |
| 55 | + process_load(rdc, vaddr, mem_read(Read(Data), paddr, 1, aq, rl, false), is_unsigned), |
| 56 | + HALF => |
| 57 | + process_load(rdc, vaddr, mem_read(Read(Data), paddr, 2, aq, rl, false), is_unsigned), |
| 58 | + WORD => |
| 59 | + process_load(rdc, vaddr, mem_read(Read(Data), paddr, 4, aq, rl, false), is_unsigned), |
| 60 | + DOUBLE if sizeof(xlen) >= 64 => |
| 61 | + process_load(rdc, vaddr, mem_read(Read(Data), paddr, 8, aq, rl, false), is_unsigned), |
| 62 | + _ => report_invalid_width(__FILE__, __LINE__, width, "load") |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
0 commit comments