-
Notifications
You must be signed in to change notification settings - Fork 73
H extention #735
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
base: xs-dev
Are you sure you want to change the base?
H extention #735
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -773,7 +773,8 @@ decode QUADRANT { | |||||||||||||
| 0x2: decode AMOFUNCT { | ||||||||||||||
| 0x2: LoadReserved::lr_w({{ | ||||||||||||||
| Rd_sd = Mem_sw; | ||||||||||||||
| }}, inst_flags=IsLoadReserved, mem_flags=LLSC); | ||||||||||||||
| }}, inst_flags=IsLoadReserved, | ||||||||||||||
| mem_flags=[LLSC, 'ARCH_BITS & XlateFlags::LR']); | ||||||||||||||
| 0x3: StoreCond::sc_w({{ | ||||||||||||||
| Mem_uw = Rs2_uw; | ||||||||||||||
| }}, {{ | ||||||||||||||
|
|
@@ -846,7 +847,8 @@ decode QUADRANT { | |||||||||||||
| 0x3: decode AMOFUNCT { | ||||||||||||||
| 0x2: LoadReserved::lr_d({{ | ||||||||||||||
| Rd_sd = Mem_sd; | ||||||||||||||
| }}, mem_flags=LLSC, inst_flags=IsLoadReserved); | ||||||||||||||
| }}, mem_flags=[LLSC, 'ARCH_BITS & XlateFlags::LR'], | ||||||||||||||
| inst_flags=IsLoadReserved); | ||||||||||||||
| 0x3: StoreCond::sc_d({{ | ||||||||||||||
| Mem = Rs2; | ||||||||||||||
| }}, {{ | ||||||||||||||
|
|
@@ -2040,13 +2042,6 @@ decode QUADRANT { | |||||||||||||
| }}, IsDirectControl, IsUncondControl); | ||||||||||||||
|
|
||||||||||||||
| 0x1c: decode FUNCT3 { | ||||||||||||||
| format LoadH { | ||||||||||||||
| 0x04: decode HFUNCT2{ | ||||||||||||||
| 0x643: hlvx_hu({{ | ||||||||||||||
| Rd = Mem_uh; | ||||||||||||||
| }},inst_flags = IsHInst); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| format SystemOp { | ||||||||||||||
| 0x0: decode FUNCT7 { | ||||||||||||||
| 0x0: decode RS2 { | ||||||||||||||
|
|
@@ -2154,6 +2149,47 @@ decode QUADRANT { | |||||||||||||
| } | ||||||||||||||
| xc->tcBase()->getMMUPtr()->demapPage(Rs1, Rs2); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
|
|
||||||||||||||
| 0xb: sinval_vvma({{ | ||||||||||||||
| warn("sinval_vvma not implemented"); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
|
|
||||||||||||||
| 0xc: decode RS2{ | ||||||||||||||
| 0x0: sfence_w_inval({{ | ||||||||||||||
| warn("sfence_w_inval not implemented"); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
|
|
||||||||||||||
| 0x1: sfence_inval_ir({{ | ||||||||||||||
| warn("sfence_inval_ir not implemented"); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+2153
to
+2165
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. Avoid no-op invalidation instructions. These paths only warn and continue, which can leave stale translations and break guest behavior. Either implement the invalidation or fail fast until it’s supported. 🛠️ Suggested fail-fast behavior until invalidation is implemented- warn("sinval_vvma not implemented");
+ return std::make_shared<IllegalInstFault>(
+ "sinval_vvma not implemented", machInst);
...
- warn("sfence_w_inval not implemented");
+ return std::make_shared<IllegalInstFault>(
+ "sfence_w_inval not implemented", machInst);
...
- warn("sfence_inval_ir not implemented");
+ return std::make_shared<IllegalInstFault>(
+ "sfence_inval_ir not implemented", machInst);
...
- warn("hinval_vvma not implemented");
+ return std::make_shared<IllegalInstFault>(
+ "hinval_vvma not implemented", machInst);
...
- warn("hinval_gvma unimplemented");
+ return std::make_shared<IllegalInstFault>(
+ "hinval_gvma not implemented", machInst);Also applies to: 2189-2191, 2242-2244 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| 0x11: hfence_vvma({{ | ||||||||||||||
| auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV); | ||||||||||||||
| RegVal misa = xc->readMiscReg(MISCREG_ISA); | ||||||||||||||
|
|
||||||||||||||
| if ((misa & ISA_EXT_H_MASK) == 0) { | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "hfence needs RVH", | ||||||||||||||
| machInst); | ||||||||||||||
| } | ||||||||||||||
| if (xc->readMiscReg(MISCREG_VIRMODE) == 1) { | ||||||||||||||
| return std::make_shared<HVFault>(); | ||||||||||||||
| } | ||||||||||||||
| if (pm < PRV_S) { | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "hfence needs at least S priv", | ||||||||||||||
| machInst); | ||||||||||||||
| } | ||||||||||||||
| xc->tcBase()->getMMUPtr()->demapPage(Rs1, Rs2); | ||||||||||||||
| return NoFault; | ||||||||||||||
|
|
||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
|
|
||||||||||||||
| 0x13: hinval_vvma({{ | ||||||||||||||
| warn("hinval_vvma not implemented"); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
|
|
||||||||||||||
| 0x18: mret({{ | ||||||||||||||
| if (xc->readMiscReg(MISCREG_PRV) != PRV_M) { | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
|
|
@@ -2174,29 +2210,39 @@ decode QUADRANT { | |||||||||||||
| xc->setMiscReg(MISCREG_VIRMODE,status_mpv); | ||||||||||||||
| } | ||||||||||||||
| }}, IsSerializeAfter, IsNonSpeculative, IsReturn); | ||||||||||||||
| 0x31: priv({{ | ||||||||||||||
| auto pm = (PrivilegeMode)xc->readMiscReg( | ||||||||||||||
| MISCREG_PRV); | ||||||||||||||
| auto vir = (PrivilegeMode)xc->readMiscReg( | ||||||||||||||
| MISCREG_VIRMODE); | ||||||||||||||
| STATUS status = xc->readMiscReg(MISCREG_STATUS); | ||||||||||||||
| xc->tcBase()->getMMUPtr()->demapPage(Rs1, Rs2); | ||||||||||||||
| 0x31: decode FUNCT3 { | ||||||||||||||
| 0x0: hfence_gvma({{ | ||||||||||||||
| auto pm = (PrivilegeMode)xc->readMiscReg( | ||||||||||||||
| MISCREG_PRV); | ||||||||||||||
| STATUS status = xc->readMiscReg(MISCREG_STATUS); | ||||||||||||||
| RegVal misa = xc->readMiscReg(MISCREG_ISA); | ||||||||||||||
|
|
||||||||||||||
| if(vir){ | ||||||||||||||
| panic("add priv vir code\n"); | ||||||||||||||
| if ((misa & ISA_EXT_H_MASK) == 0) { | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "hfence needs RVH", | ||||||||||||||
| machInst); | ||||||||||||||
| } | ||||||||||||||
| if (xc->readMiscReg(MISCREG_VIRMODE) == 1) { | ||||||||||||||
| return std::make_shared<HVFault>(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| if(pm == PRV_U){ | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "h-priv pm == prv_u", machInst); | ||||||||||||||
| if (pm < PRV_S || | ||||||||||||||
| (pm == PRV_S && status.tvm == 1)) { | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "hfence in U or TVM on", | ||||||||||||||
| machInst); | ||||||||||||||
| } | ||||||||||||||
| xc->tcBase()->getMMUPtr()->demapPage(Rs1, Rs2); | ||||||||||||||
| return NoFault; | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| if(!(pm == PRV_M ||(pm == PRV_S && !vir && status.tvm ==0))){ | ||||||||||||||
| return std::make_shared<IllegalInstFault>( | ||||||||||||||
| "h-priv pm == prv_u", machInst); | ||||||||||||||
| }}, IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| }},IsNonSpeculative, IsSerializeAfter, No_OpClass); | ||||||||||||||
| 0x33: decode FUNCT3 { | ||||||||||||||
| 0x0: hinval_gvma({{ | ||||||||||||||
| warn("hinval_gvma unimplemented"); | ||||||||||||||
| }}, IsSerializeAfter, IsNonSpeculative, No_OpClass); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| format CSROp { | ||||||||||||||
|
|
@@ -2347,6 +2393,82 @@ decode QUADRANT { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| 0x4: decode FUNCT7{ | ||||||||||||||
| 0x30: decode RS2 { | ||||||||||||||
| 0x0: HyperLoad::hlv_b({{ | ||||||||||||||
| Rd_sd = Mem_sb; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x1: HyperLoad::hlv_bu({{ | ||||||||||||||
| Rd = Mem_ub; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| } | ||||||||||||||
| 0x31: HyperStore::hsv_b({{ | ||||||||||||||
| Mem_ub = Rs2_ub; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x32: decode RS2 { | ||||||||||||||
| 0x0: HyperLoad::hlv_h({{ | ||||||||||||||
| Rd_sd = Mem_sh; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x1: HyperLoad::hlv_hu({{ | ||||||||||||||
| Rd = Mem_uh; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x3: HyperLoad::hlvx_hu({{ | ||||||||||||||
| Rd = Mem_uh; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT', | ||||||||||||||
| 'ARCH_BITS & XlateFlags::HLVX' | ||||||||||||||
| ]); | ||||||||||||||
| } | ||||||||||||||
| 0x33: HyperStore::hsv_h({{ | ||||||||||||||
| Mem_uh = Rs2_uh | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
|
Comment on lines
+2432
to
+2434
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. Fix missing semicolon in This will break generated C++. 🐛 Proposed fix- Mem_uh = Rs2_uh
+ Mem_uh = Rs2_uh;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x34: decode RS2 { | ||||||||||||||
| 0x0: HyperLoad::hlv_w({{ | ||||||||||||||
| Rd_sd = Mem_sw; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x1: HyperLoad::hlv_wu({{ | ||||||||||||||
| Rd = Mem_uw; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x3: HyperLoad::hlvx_wu({{ | ||||||||||||||
| Rd = Mem_uw; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT', | ||||||||||||||
| 'ARCH_BITS & XlateFlags::HLVX' | ||||||||||||||
| ]); | ||||||||||||||
| } | ||||||||||||||
| 0x35: HyperStore::hsv_w({{ | ||||||||||||||
| Mem_uw = Rs2_uw; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x36: HyperLoad::hlv_d({{ | ||||||||||||||
| Rd_sd = Mem_sd; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
| 0x37: HyperStore::hsv_d({{ | ||||||||||||||
| Mem_ud = Rs2_ud; | ||||||||||||||
| }}, mem_flags=[ | ||||||||||||||
| 'ARCH_BITS & XlateFlags::FORCE_VIRT' | ||||||||||||||
| ]); | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| 0x1e: M5Op::M5Op(); | ||||||||||||||
|
|
||||||||||||||
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.
When a guest/OS uses
sinval.vvmaafter updating page tables, this implementation only logs a warning and returnsNoFault, so no TLB/translation invalidation occurs and no illegal-instruction trap is raised. That means stale translations can be reused, leading to accesses using old mappings or permissions after address-space changes (e.g., context switches or unmaps). If the invalidation isn’t implemented yet, this should at least raise an illegal instruction so software doesn’t continue with silently incorrect translations.Useful? React with 👍 / 👎.