├── LICENSE ├── README.md ├── decoder.py ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── riscv-decoder.pro └── riscv-decoder.pro.user /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RISCV 机器码指令拆分器 2 | 3 | 众所周知,RISCV 的机器码字段布局有很多种,如果手动根据 opcode 分析各个字段的值是一件累人的工作。 4 | 5 | 这个由 Qt6.2 开发的软件以及如下python脚本,能帮助我们把一条 32 位的十六进制机器码根据 opcode 合理地拆分各个字段。 6 | 7 |
8 | 9 |

Qt软件使用截图

10 |
11 | 12 | python脚本需从命令行调用,因使用了`prettytable`库以获得更规整的视觉效果,需要首先用pip安装: 13 | 14 | ````shell 15 | pip install prettytable 16 | ```` 17 | 18 | 然后指定python解释器调用该脚本,参数为对`.o`文件使用`objdump -D`命令生成的反汇编文件名,要求使用相对路径(因脚本中会拼接为绝对路径),同一目录下键入文件名即可。命令中`my_objdump.s`为示例的反汇编文件名。 19 | 20 | ```shell 21 | python3 decoder.py my_objdump.s 22 | ``` 23 | 24 | 该脚本使用输出的示例如下: 25 | 26 | ```assembly 27 | Disassembly of section .text: 28 | 29 | 0000000000000000 : 30 | 0: 00050793 mv a5,a0 31 | bit-level representation: 32 | 00000000000001010000011110010011 33 | +--------------+-------+--------+-------+---------+ 34 | | imm[11:0] | rs1 | funct3 | rd | opcode | 35 | +--------------+-------+--------+-------+---------+ 36 | | 000000000000 | 01010 | 000 | 01111 | 0010011 | 37 | +--------------+-------+--------+-------+---------+ 38 | ... 39 | ``` 40 | 41 | 可以在上述命令后添加重定向命令以直接获得完整的文本,如将命令更改为: 42 | 43 | ```shell 44 | python3 decoder.py my_objdump.s > my_decoder.s 45 | ``` 46 | 47 | 此时`my_decoder.s`文件中的文本,即如上述示例,已经插入了机器指令的二进制表示,以及各字段分解的表格。 48 | 49 | --- 50 | 51 | 目前已经支持的指令包括 `RV32I Base Instruction Set`(除去 `FENCE`,`ECALL`,`EBREAK`),`RV64I Base Instruction Set`和各自的standard extension(可在此表中对照),暂不支持 16 位压缩指令。 52 | 53 | riscv64-linux-gnu-gcc 的 `-c` 指令会默认生成带压缩指令的机器码,可以使用如下编译指令使产生的`test.o`目标模块文件中`.text`代码段中只含32位指令: 54 | 55 | ``` 56 | riscv64-linux-gnu-gcc -c -march=rv64g test.s 57 | ``` 58 | 59 | ## 注意 60 | 61 | + release 中打包了经过编译、开箱即用的软件,如果没有 Qt 环境可以自取。 62 | + 对于`j`或是`li`这样的伪指令,本软件会按照其机器码对应的原指令直接拆分(即`jal`和`addi`) 63 | + 本软件并不能由机器码指令输出对应的汇编指令,这样设计是考虑到 `objdump` 已经完成了这一工作,因此,本软件应配合 `objdump` 使用。 64 | + 软件中 RV32I 和 RV64I 的主要区别在于,在 RV32I 中,`SLLI`,`SRLI`,`SRAI` 的 `shamt` 字段占 5 位,而在 RV64I 中占 6 位。具体数据来自于上面提到的表。 65 | + 如果您发现了错误,请在 Issues 中告知我,十分感谢;也欢迎您提交 pr 来丰富本软件的功能,或使其支持其他指令集。 66 | -------------------------------------------------------------------------------- /decoder.py: -------------------------------------------------------------------------------- 1 | import re 2 | import os 3 | import sys 4 | from prettytable import PrettyTable 5 | 6 | 7 | def pretty_print_instruction(ins: str) -> None: 8 | ins_dict, header = riscv_instruction_parser(ins) 9 | print("bit-level representation:\n\t"+ins_dict["bin"]) 10 | if not header: 11 | return 12 | table = PrettyTable() 13 | for h in header: 14 | table.add_column(h, [ins_dict[h]]) 15 | print(table) 16 | print() 17 | 18 | def riscv_instruction_parser(ins: str): 19 | result = {} 20 | if len(ins) == 8: 21 | ins_bin = format(int(ins, 16), '032b') 22 | result.update({"bin": ins_bin}) 23 | opcode = ins_bin[-7:] 24 | rd = ins_bin[-12:-7] 25 | funct3 = ins_bin[-15:-12] 26 | rs1 = ins_bin[-20:-15] 27 | rs2 = ins_bin[-25:-20] 28 | funct7 = ins_bin[-32:-25] 29 | if opcode in ["0000011", "0001111", "0010011","0011011", "1100111"]: # I 30 | imm = funct7+rs2 31 | result.update({ 32 | "imm[11:0]": imm, 33 | "rs1": rs1, 34 | "funct3": funct3, 35 | "rd": rd, 36 | "opcode": opcode 37 | }) 38 | header = ["imm[11:0]", "rs1", "funct3", "rd", "opcode"] 39 | elif opcode in ["0010111", "0110111"]: # U 40 | result.update({ 41 | "imm[31:12]": funct7+rs2+rs1+funct3, 42 | "rd": rd, 43 | "opcode": opcode 44 | }) 45 | header = ["imm[31:12]", "rd", "opcode"] 46 | elif opcode == "0100011": # S 47 | result.update({ 48 | "imm[11:5]": funct7, 49 | "rs2": rs2, 50 | "rs1": rs1, 51 | "funct3": funct3, 52 | "imm[4:0]": rd, 53 | "opcode": opcode 54 | }) 55 | header = ["imm[11:5]", "rs2", "rs1", 56 | "funct3", "imm[4:0]", "opcode"] 57 | elif opcode in ["0110011", "0111011"]: # R 58 | result.update({ 59 | "funct7": funct7, 60 | "rs2": rs2, 61 | "rs1": rs1, 62 | "funct3": funct3, 63 | "rd": rd, 64 | "opcode": opcode 65 | }) 66 | header = ["funct7", "rs2", "rs1", "funct3", "rd", "opcode"] 67 | elif opcode == "1100011": # SB 68 | result.update({ 69 | "imm[12|10:5]": funct7, 70 | "rs2": rs2, 71 | "rs1": rs1, 72 | "funct3": funct3, 73 | "imm[4:1|11]": rd, 74 | "opcode": opcode 75 | }) 76 | header = ["imm[12|10:5]", "rs2", "rs1", 77 | "funct3", "imm[4:1|11]", "opcode"] 78 | elif opcode == "1101111": # UJ 79 | result.update({ 80 | "imm[20|10:1|11|19:12]": funct7+rs2+rs1+funct3, 81 | "rd": rd, 82 | "opcode": opcode 83 | }) 84 | header = ["imm[20|10:1|11|19:12]", "rd", "opcode"] 85 | else: 86 | header = [] 87 | elif len(ins) == 4: 88 | ins_bin = format(int(ins, 16), '016b') 89 | result.update({"bin": ins_bin}) 90 | op = ins_bin[-2:] 91 | rs2 = ins_bin[-7:-2] 92 | rd_rs1 = ins_bin[-12:-7] 93 | funct4 = ins_bin[-16:-12] 94 | header = [] 95 | # print(ins_bin) 96 | 97 | return result, header 98 | 99 | 100 | def main(): 101 | rv_ins_flag = re.compile("[0-9a-fA-F]:\s[0-9a-fA-F]{4}") 102 | rv_32bit_ins = re.compile("[0-9a-fA-F]{8}") 103 | rv_16bit_ins = re.compile("[0-9a-fA-F]{4}") 104 | if len(sys.argv) == 1: 105 | print("Missing option [filename] for decoding!") 106 | print("""usage: python decoder.py filename\n\nOption 'filename' should be relative path to the file for decoding. 107 | And it should be disassembled code by objdump.""") 108 | else: 109 | filename = sys.argv[1] 110 | with open(file=os.path.join(os.getcwd(), filename), encoding="utf-8") as f: 111 | for line in f: 112 | print(line, end="") 113 | if rv_ins_flag.search(line) is None: 114 | continue 115 | riscv_ins = rv_32bit_ins.search(line) 116 | if riscv_ins is not None: 117 | ins = line[riscv_ins.start(): riscv_ins.end()] 118 | pretty_print_instruction(ins) 119 | 120 | else: 121 | continue 122 | # 暂不支持压缩指令 123 | riscv_ins = rv_16bit_ins.search(line) 124 | ins = line[riscv_ins.start(): riscv_ins.end()] 125 | pretty_print_instruction(ins) 126 | if __name__ == '__main__': 127 | main() -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent) 6 | , ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | this->setFixedSize(this->width(), this->height()); 10 | 11 | ui->textBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 12 | ui->textBrowser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 13 | 14 | connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::decode); 15 | } 16 | 17 | void MainWindow::decode(){ 18 | bool valid = false; 19 | QString raw = ui->lineEdit->text(); 20 | qint64 val = raw.toLongLong(&valid, 16); 21 | 22 | if(valid == false){ 23 | QMessageBox::critical( 24 | this, 25 | "错误", 26 | "不是合法的十六进制数", 27 | QMessageBox::Ok, 28 | QMessageBox::Ok 29 | ); 30 | return; 31 | } 32 | if(raw.length() == 8){ 33 | handle32(val); 34 | } 35 | else{ 36 | QMessageBox::critical( 37 | this, 38 | "错误", 39 | "不是预期的riscv指令", 40 | QMessageBox::Ok, 41 | QMessageBox::Ok 42 | ); 43 | } 44 | } 45 | 46 | void MainWindow::handle32(qint64 val){ 47 | QString ins = QString("%1").arg(val, 32, 2, QLatin1Char('0')); 48 | ui->textBrowser->setText(ins + "\n"); 49 | QString opcode = ins.mid(25, -1); 50 | 51 | if(opcode == "0110011" or opcode == "0111011"){ 52 | ui->textBrowser->setText( 53 | "bin:" + ins + "\n" + 54 | "funct7:" + ins.mid(0, 7) + "\n" + 55 | "funct3:" + ins.mid(17, 3) + "\n" + 56 | "rs1:" + ins.mid(12, 5) + "\n" + 57 | "rs2:" + ins.mid(7, 5) + "\n" + 58 | "rd:" + ins.mid(20, 5) + "\n" + 59 | "opcode:" + opcode 60 | ); 61 | } 62 | else if(opcode == "1100011"){ 63 | ui->textBrowser->setText( 64 | "bin:" + ins + "\n" + 65 | "funct3:" + ins.mid(17, 3) + "\n" + 66 | "rs1:" + ins.mid(12, 5) + "\n" + 67 | "rs2:" + ins.mid(7, 5) + "\n" + 68 | "imm:" + ins.mid(0, 1) + ins.mid(24,1) + ins.mid(1,6) + ins.mid(20,4) + "\n" + 69 | "opcode:" + opcode 70 | ); 71 | } 72 | else if(opcode == "0000011"){ 73 | ui->textBrowser->setText( 74 | "bin:" + ins + "\n" + 75 | "funct3:" + ins.mid(17, 3) + "\n" + 76 | "rs1:" + ins.mid(12, 5) + "\n" + 77 | "rd:" + ins.mid(20, 5) + "\n" + 78 | "imm:" + ins.mid(0, 12) + "\n" + 79 | "opcode:" + opcode 80 | ); 81 | } 82 | else if(opcode == "0100011"){ 83 | ui->textBrowser->setText( 84 | "bin:" + ins + "\n" + 85 | "funct3:" + ins.mid(17, 3) + "\n" + 86 | "rs1:" + ins.mid(12, 5) + "\n" + 87 | "rs2:" + ins.mid(7, 5) + "\n" + 88 | "imm:" + ins.mid(0, 7) + ins.mid(20, 5) + "\n" + 89 | "opcode:" + opcode 90 | ); 91 | } 92 | else if(opcode == "0010011" or opcode == "0011011"){ 93 | QString funct3 =ins.mid(17, 3); 94 | if(funct3 == "001" or funct3 == "101"){ 95 | if(ui->comboBox->currentText() == "RV64I"){ 96 | ui->textBrowser->setText( 97 | "bin:" + ins + "\n" + 98 | "funct6:" + ins.mid(0, 6) + "\n" + 99 | "funct3:" + ins.mid(17, 3) + "\n" + 100 | "rs1:" + ins.mid(12, 5) + "\n" + 101 | "shamt:" + ins.mid(6, 6) + "\n" + 102 | "rd:" + ins.mid(20, 5) + "\n" + 103 | "opcode:" + opcode 104 | ); 105 | } 106 | else{ 107 | ui->textBrowser->setText( 108 | "bin:" + ins + "\n" + 109 | "funct6:" + ins.mid(0, 7) + "\n" + 110 | "funct3:" + ins.mid(17, 3) + "\n" + 111 | "rs1:" + ins.mid(12, 5) + "\n" + 112 | "shamt:" + ins.mid(7, 5) + "\n" + 113 | "rd:" + ins.mid(20, 5) + "\n" + 114 | "opcode:" + opcode 115 | ); 116 | } 117 | } 118 | else { 119 | ui->textBrowser->setText( 120 | "bin:" + ins + "\n" + 121 | "funct3:" + ins.mid(17, 3) + "\n" + 122 | "rs1:" + ins.mid(12, 5) + "\n" + 123 | "rd:" + ins.mid(20, 5) + "\n" + 124 | "imm:" + ins.mid(0, 12) + "\n" + 125 | "opcode:" + opcode 126 | ); 127 | } 128 | } 129 | else if(opcode == "0010111" or opcode == "0110111"){ 130 | ui->textBrowser->setText( 131 | "bin:" + ins + "\n" + 132 | "rd:" + ins.mid(20, 5) + "\n" + 133 | "imm:" + ins.mid(0, 20) + "\n" + 134 | "opcode:" + opcode 135 | ); 136 | } 137 | else if(opcode == "1101111"){ 138 | ui->textBrowser->setText( 139 | "bin:" + ins + "\n" + 140 | "rd:" + ins.mid(20, 5) + "\n" + 141 | "imm:" + ins.mid(0, 1) + ins.mid(12, 8) + ins.mid(11, 1) + ins.mid(1, 10) + "\n" + 142 | "opcode:" + opcode 143 | ); 144 | } 145 | else if(opcode == "1100111"){ 146 | ui->textBrowser->setText( 147 | "bin:" + ins + "\n" + 148 | "funct3:" + ins.mid(17, 3) + "\n" + 149 | "rs1:" + ins.mid(12, 5) + "\n" + 150 | "rd:" + ins.mid(20, 5) + "\n" + 151 | "imm:" + ins.mid(0, 12) + "\n" + 152 | "opcode:" + opcode 153 | ); 154 | } 155 | } 156 | 157 | MainWindow::~MainWindow() 158 | { 159 | delete ui; 160 | } 161 | 162 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class MainWindow; } 9 | QT_END_NAMESPACE 10 | 11 | class MainWindow : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | void handle32(qint64); 19 | 20 | private: 21 | Ui::MainWindow *ui; 22 | public slots: 23 | void decode(); 24 | }; 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 270 10 | 265 11 | 12 | 13 | 14 | riscv-decoder 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 30 22 | 111 23 | 21 24 | 25 | 26 | 27 | 28 | 29 | 30 | 200 31 | 30 32 | 61 33 | 21 34 | 35 | 36 | 37 | 解码 38 | 39 | 40 | 41 | 42 | 43 | 10 44 | 10 45 | 111 46 | 16 47 | 48 | 49 | 50 | 输入十六进制机器码 51 | 52 | 53 | 54 | 55 | 56 | 10 57 | 60 58 | 251 59 | 192 60 | 61 | 62 | 63 | 64 | 65 | 66 | 130 67 | 30 68 | 61 69 | 21 70 | 71 | 72 | 73 | 74 | RV64I 75 | 76 | 77 | 78 | 79 | RV32I 80 | 81 | 82 | 83 | 84 | 85 | 86 | 150 87 | 10 88 | 41 89 | 16 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /riscv-decoder.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | mainwindow.h 17 | 18 | FORMS += \ 19 | mainwindow.ui 20 | 21 | # Default rules for deployment. 22 | qnx: target.path = /tmp/$${TARGET}/bin 23 | else: unix:!android: target.path = /opt/$${TARGET}/bin 24 | !isEmpty(target.path): INSTALLS += target 25 | -------------------------------------------------------------------------------- /riscv-decoder.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {a34181e0-2e4a-4d56-b184-c8500eb902a9} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | false 41 | true 42 | false 43 | 0 44 | true 45 | true 46 | 0 47 | 8 48 | true 49 | false 50 | 1 51 | true 52 | true 53 | true 54 | *.md, *.MD, Makefile 55 | false 56 | true 57 | 58 | 59 | 60 | ProjectExplorer.Project.PluginSettings 61 | 62 | 63 | true 64 | false 65 | true 66 | true 67 | true 68 | true 69 | 70 | 71 | 0 72 | true 73 | 74 | -fno-delayed-template-parsing 75 | 76 | true 77 | Builtin.BuildSystem 78 | 79 | true 80 | true 81 | Builtin.DefaultTidyAndClazy 82 | 4 83 | 84 | 85 | 86 | true 87 | 88 | 89 | 90 | 91 | ProjectExplorer.Project.Target.0 92 | 93 | Desktop 94 | Desktop Qt 6.2.4 MinGW 64-bit 95 | Desktop Qt 6.2.4 MinGW 64-bit 96 | qt.qt6.624.win64_mingw_kit 97 | 1 98 | 0 99 | 0 100 | 101 | 0 102 | D:\File\Code\build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Debug 103 | D:/File/Code/build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Debug 104 | 105 | 106 | true 107 | QtProjectManager.QMakeBuildStep 108 | false 109 | 110 | 111 | 112 | true 113 | Qt4ProjectManager.MakeStep 114 | 115 | 2 116 | Build 117 | Build 118 | ProjectExplorer.BuildSteps.Build 119 | 120 | 121 | 122 | true 123 | Qt4ProjectManager.MakeStep 124 | clean 125 | 126 | 1 127 | Clean 128 | Clean 129 | ProjectExplorer.BuildSteps.Clean 130 | 131 | 2 132 | false 133 | 134 | 135 | Debug 136 | Qt4ProjectManager.Qt4BuildConfiguration 137 | 2 138 | 139 | 140 | D:\File\Code\build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Release 141 | D:/File/Code/build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Release 142 | 143 | 144 | true 145 | QtProjectManager.QMakeBuildStep 146 | false 147 | 148 | 149 | 150 | true 151 | Qt4ProjectManager.MakeStep 152 | 153 | 2 154 | Build 155 | Build 156 | ProjectExplorer.BuildSteps.Build 157 | 158 | 159 | 160 | true 161 | Qt4ProjectManager.MakeStep 162 | clean 163 | 164 | 1 165 | Clean 166 | Clean 167 | ProjectExplorer.BuildSteps.Clean 168 | 169 | 2 170 | false 171 | 172 | 173 | Release 174 | Qt4ProjectManager.Qt4BuildConfiguration 175 | 0 176 | 0 177 | 178 | 179 | 0 180 | D:\File\Code\build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Profile 181 | D:/File/Code/build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Profile 182 | 183 | 184 | true 185 | QtProjectManager.QMakeBuildStep 186 | false 187 | 188 | 189 | 190 | true 191 | Qt4ProjectManager.MakeStep 192 | 193 | 2 194 | Build 195 | Build 196 | ProjectExplorer.BuildSteps.Build 197 | 198 | 199 | 200 | true 201 | Qt4ProjectManager.MakeStep 202 | clean 203 | 204 | 1 205 | Clean 206 | Clean 207 | ProjectExplorer.BuildSteps.Clean 208 | 209 | 2 210 | false 211 | 212 | 213 | Profile 214 | Qt4ProjectManager.Qt4BuildConfiguration 215 | 0 216 | 0 217 | 0 218 | 219 | 3 220 | 221 | 222 | 0 223 | Deploy 224 | Deploy 225 | ProjectExplorer.BuildSteps.Deploy 226 | 227 | 1 228 | 229 | false 230 | ProjectExplorer.DefaultDeployConfiguration 231 | 232 | 1 233 | 234 | true 235 | true 236 | true 237 | 238 | 2 239 | 240 | Qt4ProjectManager.Qt4RunConfiguration:D:/File/Code/riscv-decoder/riscv-decoder.pro 241 | D:/File/Code/riscv-decoder/riscv-decoder.pro 242 | false 243 | true 244 | true 245 | false 246 | true 247 | D:/File/Code/build-riscv-decoder-Desktop_Qt_6_2_4_MinGW_64_bit-Release 248 | 249 | 1 250 | 251 | 252 | 253 | ProjectExplorer.Project.TargetCount 254 | 1 255 | 256 | 257 | ProjectExplorer.Project.Updater.FileVersion 258 | 22 259 | 260 | 261 | Version 262 | 22 263 | 264 | 265 | --------------------------------------------------------------------------------