-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Zcmt extension #757
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*=======================================================================================*/ | ||
/* This Sail RISC-V architecture model, comprising all files and */ | ||
/* directories except where otherwise noted is subject the BSD */ | ||
/* two-clause license in the LICENSE file. */ | ||
/* */ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/*=======================================================================================*/ | ||
|
||
function clause extensionEnabled(Ext_Zcmt) = extensionEnabled(Ext_Zca) & sys_enable_zcmt() & not(sys_enable_zcd()) & (xlen == 32 | xlen == 64) | ||
|
||
type target_address = bits(xlen) | ||
|
||
union FJT_Result = { | ||
FJT_Success : target_address, | ||
FJT_Failure : unit | ||
} | ||
|
||
function fetch_jump_table(table_address : bits(xlen)) -> FJT_Result = { | ||
/* Fetching jump table address needs execute permission */ | ||
match ext_data_get_addr_from_bits(table_address, Execute(), xlen_bytes) { | ||
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); FJT_Failure() }, | ||
Ext_DataAddr_OK(vaddr) => { | ||
if check_misaligned(vaddr, size_bytes(xlen_bytes)) | ||
then { handle_mem_exception(vaddr, E_Load_Addr_Align()); FJT_Failure() } | ||
else match translateAddr(vaddr, Execute()) { | ||
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); FJT_Failure() }, | ||
TR_Address(paddr, _) => | ||
match mem_read(Execute(), paddr, xlen_bytes, false, false, false) { | ||
Ok(result) => { FJT_Success(result) }, | ||
Err(e) => { handle_mem_exception(vaddr, e); FJT_Failure() }, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
union clause ast = CM_JALT : (bits(8)) | ||
|
||
mapping clause encdec_compressed = CM_JALT(index) if extensionEnabled(Ext_Zcmt) & 32 <= unsigned(index) | ||
<-> 0b101 @ 0b000 @ index : bits(8) @ 0b10 if extensionEnabled(Ext_Zcmt) & 32 <= unsigned(index) | ||
|
||
function clause execute (CM_JALT(index)) = { | ||
let base : bits(xlen) = jvt[base] @ 0b000000; | ||
let index : bits(xlen) = zero_extend(index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can delete this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wont compile, I get:
But I think it makes sense, imagine shifting bits to the left. Since the bit width of |
||
if jvt[mode] == 0b000000 then { | ||
let table_address = base + index << log2_xlen_bytes; | ||
match fetch_jump_table(table_address) { | ||
FJT_Failure(_) => { RETIRE_FAIL }, | ||
FJT_Success(target_address) => { X(1) = get_next_pc(); set_next_pc(target_address & ~(zero_extend(0x1))); RETIRE_SUCCESS } | ||
}; | ||
} else { handle_illegal(); RETIRE_FAIL }; | ||
} | ||
|
||
mapping clause assembly = CM_JALT(index) if (xlen == 32 | xlen == 64) <-> | ||
"cm.jalt" ^ spc() ^ hex_bits_8(index) if (xlen == 32 | xlen == 64) | ||
|
||
/* ****************************************************************** */ | ||
union clause ast = CM_JT : (bits(8)) | ||
|
||
mapping clause encdec_compressed = CM_JT(index) if extensionEnabled(Ext_Zcmt) & unsigned(index) < 32 | ||
<-> 0b101 @ 0b000 @ index : bits(8) @ 0b10 if extensionEnabled(Ext_Zcmt) & unsigned(index) < 32 | ||
|
||
function clause execute (CM_JT(index)) = { | ||
nadime15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let base : bits(xlen) = jvt[base] @ 0b000000; | ||
let index : bits(xlen) = zero_extend(index); | ||
if jvt[mode] == 0b000000 then { | ||
let table_address = base + index << log2_xlen_bytes; | ||
match fetch_jump_table(table_address) { | ||
FJT_Failure(_) => { RETIRE_FAIL }, | ||
FJT_Success(target_address) => { set_next_pc(target_address & ~(zero_extend(0x1))); RETIRE_SUCCESS } | ||
}; | ||
} else { handle_illegal(); RETIRE_FAIL }; | ||
} | ||
|
||
mapping clause assembly = CM_JT(index) if (xlen == 32 | xlen == 64) <-> | ||
"cm.jt" ^ spc() ^ hex_bits_8(index) if (xlen == 32 | xlen == 64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just use
result(target_address, unit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain a bit more about this and how I should modify the code?