-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactoring the RISCV architecture to Auto-Sync on LLVM #2756
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
Open
moste00
wants to merge
29
commits into
capstone-engine:next
Choose a base branch
from
moste00:refactor_riscv_autosync
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
19895d4
Refactoring RISCV: INC generatione done, RISCV added to arch_config.j…
moste00 ef5ee9b
the C++ translator runs successfully and first output under arch/RISC…
moste00 bcb4be3
fixed Disassembler.c, in the process of fixing InstPrinter
moste00 50b9d9a
more compile errors fixed, RISCVInstPrinter error-free
moste00 a47a67e
plugins compiles and runs, several test failures were fixed, current …
moste00 a601b36
compressed instructions compression and uncompression logic was gener…
moste00 df700f0
massive fix handling various issues, test failures down to 35
moste00 f422714
test failures down to 2, related to inline option arch directives
moste00 9a4a8e2
added options to `cstool`, and started working on details test, 39/10…
moste00 046308f
more successful details test, added CSR operand type and changed csto…
moste00 440825e
more progress
moste00 4ce5e34
failures decreased to 2
moste00 250f91d
milestone: test failures 0
moste00 331ff17
add additional files generated from ASUpdate and update CMakeLists
moste00 f616aea
fix most issues tests except the one about c_srli allowing illegal sh…
moste00 082a238
fixed c_srli bug by updating the generated files from a fixed LLVM ve…
moste00 cdff665
made branch addresses absolute
moste00 a6b2604
fix DIET build by #ifdef-ing code that uses struct fields not availab…
moste00 378a2b3
fix Python build failure
moste00 9d2ae24
fix formatting
moste00 80dedbe
fixed formatting 2
moste00 c00ceb1
Remove the call group from JAL and JALR instructions because they're …
moste00 528ed62
final formatting issue
moste00 6b3d2f0
add the option for real details even for aliases
moste00 d30985b
various fixes and adding double imms
moste00 30e0532
fix bad python module FP comparison code and formatting
moste00 47861b2
another formatting fix
moste00 5c59a78
fix NAN issue on ARM
moste00 4db5b98
fix typo in RISCV_getFeatureBits in enum names, and fix the tests tha…
moste00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* Capstone Disassembly Engine, http://www.capstone-engine.org */ | ||
| /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */ | ||
| /* Rot127 <unisono@quyllur.org> 2022-2023 */ | ||
| /* Automatically translated source file from LLVM. */ | ||
|
|
||
| /* LLVM-commit: <commit> */ | ||
| /* LLVM-tag: <tag> */ | ||
|
|
||
| /* Only small edits allowed. */ | ||
| /* For multiple similar edits, please create a Patch for the translator. */ | ||
|
|
||
| /* Capstone's C++ file translator: */ | ||
| /* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */ | ||
|
|
||
| //===-- RISCVBaseInfo.cpp - Top level definitions for RISC-V MC -----------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file contains small standalone enum definitions for the RISC-V target | ||
| // useful for the compiler back-end and the MC libraries. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <stdlib.h> | ||
| #include <capstone/platform.h> | ||
|
|
||
| #include "RISCVBaseInfo.h" | ||
|
|
||
| #define CONCAT(a, b) CONCAT_(a, b) | ||
| #define CONCAT_(a, b) a##_##b | ||
|
|
||
| typedef struct { | ||
| unsigned value; | ||
| bool isFractional; | ||
| } VLMULDecodeResult; | ||
| VLMULDecodeResult decodeVLMUL(RISCVII_VLMUL VLMUL) | ||
| { | ||
| switch (VLMUL) { | ||
| default: | ||
| CS_ASSERT(0 && "Unexpected LMUL value!"); | ||
| case RISCVII_LMUL_1: | ||
| case RISCVII_LMUL_2: | ||
| case RISCVII_LMUL_4: | ||
| case RISCVII_LMUL_8: { | ||
| VLMULDecodeResult result = { .value = 1 << (unsigned)(VLMUL), | ||
| .isFractional = false }; | ||
| return result; | ||
| } | ||
| case RISCVII_LMUL_F2: | ||
| case RISCVII_LMUL_F4: | ||
| case RISCVII_LMUL_F8: { | ||
| VLMULDecodeResult result = { .value = 1 << (8 - | ||
| (unsigned)(VLMUL)), | ||
| .isFractional = true }; | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void printVType(unsigned VType, SStream *OS) | ||
| { | ||
| unsigned Sew = RISCVVType_getSEW(VType); | ||
| SStream_concat(OS, "%s", "e"); | ||
| printUInt64(OS, Sew); | ||
|
|
||
| unsigned LMul; | ||
| bool Fractional; | ||
| VLMULDecodeResult result = decodeVLMUL(RISCVVType_getVLMUL(VType)); | ||
| LMul = result.value; | ||
| Fractional = result.isFractional; | ||
|
|
||
| if (Fractional) | ||
| SStream_concat0(OS, ", mf"); | ||
| else | ||
| SStream_concat0(OS, ", m"); | ||
| printUInt64(OS, LMul); | ||
|
|
||
| if (RISCVVType_isTailAgnostic(VType)) | ||
| SStream_concat0(OS, ", ta"); | ||
| else | ||
| SStream_concat0(OS, ", tu"); | ||
|
|
||
| if (RISCVVType_isMaskAgnostic(VType)) | ||
| SStream_concat0(OS, ", ma"); | ||
| else | ||
| SStream_concat0(OS, ", mu"); | ||
| } | ||
|
|
||
| typedef struct { | ||
| uint8_t first; | ||
| uint8_t second; | ||
| } LoadFP32ImmArrElement; | ||
|
|
||
| // Lookup table for fli.s for entries 2-31. | ||
| static const LoadFP32ImmArrElement LoadFP32ImmArr[] = { | ||
| { 0b01101111, 0b00 }, { 0b01110000, 0b00 }, { 0b01110111, 0b00 }, | ||
| { 0b01111000, 0b00 }, { 0b01111011, 0b00 }, { 0b01111100, 0b00 }, | ||
| { 0b01111101, 0b00 }, { 0b01111101, 0b01 }, { 0b01111101, 0b10 }, | ||
| { 0b01111101, 0b11 }, { 0b01111110, 0b00 }, { 0b01111110, 0b01 }, | ||
| { 0b01111110, 0b10 }, { 0b01111110, 0b11 }, { 0b01111111, 0b00 }, | ||
| { 0b01111111, 0b01 }, { 0b01111111, 0b10 }, { 0b01111111, 0b11 }, | ||
| { 0b10000000, 0b00 }, { 0b10000000, 0b01 }, { 0b10000000, 0b10 }, | ||
| { 0b10000001, 0b00 }, { 0b10000010, 0b00 }, { 0b10000011, 0b00 }, | ||
| { 0b10000110, 0b00 }, { 0b10000111, 0b00 }, { 0b10001110, 0b00 }, | ||
| { 0b10001111, 0b00 }, { 0b11111111, 0b00 }, { 0b11111111, 0b10 }, | ||
| }; | ||
|
|
||
| float getFPImm(unsigned Imm) | ||
| { | ||
| CS_ASSERT(Imm != 1 && Imm != 30 && Imm != 31 && | ||
|
Collaborator
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.
|
||
| "Unsupported immediate"); | ||
|
|
||
| // Entry 0 is -1.0, the only negative value. Entry 16 is 1.0. | ||
| uint32_t Sign = 0; | ||
| if (Imm == 0) { | ||
| Sign = 0b1; | ||
| Imm = 16; | ||
| } | ||
|
|
||
| uint32_t Exp = LoadFP32ImmArr[Imm - 2].first; | ||
| uint32_t Mantissa = LoadFP32ImmArr[Imm - 2].second; | ||
|
|
||
| uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 21; | ||
| float result; | ||
| memcpy(&result, &I, sizeof(float)); | ||
| return result; | ||
| } | ||
|
|
||
| void RISCVZC_printSpimm(int64_t Spimm, SStream *OS) | ||
| { | ||
| printInt32(OS, Spimm); | ||
| } | ||
|
|
||
| // namespace llvm | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.