Commit Graph

51 Commits

Author SHA1 Message Date
Nguyen Anh Quynh
afffa5d741 merge next to master 2018-07-20 12:36:50 +08:00
Travis Finkenauer
65da43d0b1 Declare global arch arrays with contents (next branch) (#1186)
* Declare global arch arrays with contents (#1171)

This eliminates the need for archs_enable() and eliminates the racey
initialization.

This makes the architecture-specific init and option functions
non-static so that they may be called from a different file.

Cherry-picked 853a2870

* Add cs_arch_disallowed_mode_mask global

Cherry-pick 94bce437:
mips: CS_MODE_MIPS32R6 implies CS_MODE_32

Cherry-pick 8998a3a1:
ppc: fix endian check (#1029)
Fixes bug where endianness could not be set for ppc.

Remove `big_endian` field of `cs_struct`.
Added a helper macro `MODE_IS_BIG_ENDIAN()` to check if
`CS_MODE_BIG_ENDIAN` is set.

Refactored `cs_open()` check for valid mode out of arch-specific code
into arch-independent code. Also added a valid mode check to
`cs_option()`.  The checks use a new global array
`cs_arch_disallowed_mode_mask[]`.

* Make global arrays static

Make all_arch uint32_t to guarantee a certain number of bits (with
adequate room for growth).
2018-06-24 21:05:04 +08:00
Nguyen Anh Quynh
0b874b2fca cleanup 2018-06-22 01:03:26 +08:00
Alberto Garcia Illera
5c3021250d prefix cs_ to global variables to avoid link problems (#1108)
* prefix cs_ to global variables to avoid link problems

* force Capstone to be build using MT

* fix identation
2018-03-29 22:17:37 +08:00
Alberto Garcia Illera
5f173b0562 prefix cs_ to global variables to avoid link problems (#1102) 2018-03-19 22:23:09 +08:00
Richard Henderson
22ead3e0bf Constify backend data (#1040)
* Constify string literals

Use -Wwrite-strings to force string literals to be of
type "const char[]", then fix up all warning fallout.

* Constify common infrastructure

Step one in allowing backend data to be readonly.
Minimal changes to backends for now; just set all pointers
in common structs that aren't modified to const.

* Constify AArch64 backend

Section size changes within libcapstone.so are

-.rodata               602587
-.data.rel.ro          228416
-.data                1003746
+.rodata               769051
+.data.rel.ro          241120
+.data                 824578

* Constify ARM backend

Section size changes within libcapstone.so are

-.rodata               769051
-.data.rel.ro          241120
-.data                 824578
+.rodata               959835
+.data.rel.ro          245120
+.data                 629506

* Constify Mips backend

Section size changes within libcapstone.so are

-.rodata               959835
-.data.rel.ro          245120
-.data                 629506
+.rodata              1069851
+.data.rel.ro          256416
+.data                 508194

* Constify PowerPC backend

Section size changes within libcapstone.so are

-.rodata              1069851
-.data.rel.ro          256416
-.data                 508194
+.rodata              1142715
+.data.rel.ro          272224
+.data                 419490

* Constify Sparc backend

Section size changes within libcapstone.so are

-.rodata              1142715
-.data.rel.ro          272224
-.data                 419490
+.rodata              1175227
+.data.rel.ro          277536
+.data                 381666

* Constify SystemZ backend

Section size changes within libcapstone.so are

-.rodata              1175227
-.data.rel.ro          277536
-.data                 381666
+.rodata              1221883
+.data.rel.ro          278016
+.data                 334498

* Constify X86 backend

Section size changes within libcapstone.so are

-.rodata              1221883
-.data.rel.ro          278016
-.data                 334498
+.rodata              1533531
+.data.rel.ro          281184
+.data                  19714

* Constify XCore backend

Section size changes within libcapstone.so are

-.rodata              1533531
-.data.rel.ro          281184
-.data                  19714
+.rodata              1553026
+.data.rel.ro          281280
+.data                     40
2017-10-22 08:45:40 +08:00
Wolfgang Schwotzer
22b4d0eb41 M680X: Target ready for pull request (#1034)
* Added new M680X target. Supports M6800/1/2/3/9, HD6301

* M680X: Reformat for coding guide lines. Set alphabetical order in HACK.TXT

* M680X: Prepare for python binding. Move cs_m680x, m680x_insn to m680x_info. Chec
> k cpu type, no default.

* M680X: Add python bindings. Added python tests.

* M680X: Added cpu types to usage message.

* cstool: Avoid segfault for invalid <arch+mode>.

* Make test_m680x.c/test_m680x.py output comparable (diff params: -bu). Keep xprint.py untouched.

* M680X: Update CMake/make for m680x support. Update .gitignore.

* M680X: Reduce compiler warnings.

* M680X: Reduce compiler warnings.

* M680X: Reduce compiler warnings.

* M680X: Make test_m680x.c/test_m680x.py output comparable (diff params: -bu).

* M680X: Add ocaml bindings and tests.

* M680X: Add java bindings and tests.

* M680X: Added tests for all indexed addressing modes. C/Python/Ocaml

* M680X: Naming, use page1 for PAGE1 instructions (without prefix).

* M680X: Naming, use page1 for PAGE1 instructions (without prefix).

* M680X: Used M680X_FIRST_OP_IN_MNEM in tests C/python/java/ocaml.

* M680X: Added access property to cs_m680x_op.

* M680X: Added operand size.

* M680X: Remove compiler warnings.

* M680X: Added READ/WRITE access property per operator.

* M680X: Make reg_inherent_hdlr independent of CPU type.

* M680X: Add HD6309 support + bug fixes

* M680X: Remove errors and warning.

* M680X: Add Bcc/LBcc to group BRAREL (relative branch).

* M680X: Add group JUMP to BVS/BVC/LBVS/LBVC. Remove BRAREL from BRN/LBRN.

* M680X: Remove LBRN from group BRAREL.

* M680X: Refactored cpu_type initialization for better readability.

* M680X: Add two operands for insn having two reg. in mnemonic. e.g. ABX.

* M680X: Remove typo in cstool.c

* M680X: Some format improvements in changed_regs.

* M680X: Remove insn id string list from tests (C/python/java/ocaml).

* M680X: SEXW, set access of reg. D to WRITE.

* M680X: Sort changed_regs in increasing m680x_insn order.

* M680X: Add M68HC11 support + Reduced from two to one INDEXED operand.

* M680X: cstool, also write '(in mnemonic)' for second reg. operand.

* M680X: Add BRN/LBRN to group JUMP and BRAREL.

* M680X: For Bcc/LBcc/BRSET/BRCLR set reg. CC to read access.

* M680X: Correctly print negative immediate values with option CS_OPT_UNSIGNED.

* M680X: Rename some instruction handlers.

* M680X: Add M68HC05 support.

* M680X: Dont print prefix '<' for direct addr. mode.

* M680X: Add M68HC08 support + resorted tables + bug fixes.

* M680X: Add Freescale HCS08 support.

* M680X: Changed group names, avoid spaces.

* M680X: Refactoring, rename addessing mode handlers.

* M680X: indexed addr. mode, changed pre/post inc-/decrement representation.

* M680X: Rename some M6809/HD6309 specific functions.

* M680X: Add CPU12 (68HC12/HCS12) support.

* M680X: Correctly display illegal instruction as FCB .

* M680X: bugfix: BRA/BRN/BSR/LBRA/LBRN/LBSR does not read CC reg.

* M680X: bugfix: Correctly check for sufficient code size for M6809 indexed addressing.

* M680X: Better support for changing insn id within handler for addessing mode.

* M680X: Remove warnings.

* M680X: In set_changed_regs_read_write_counts use own access_mode.

* M680X: Split cpu specific tables into separate *.inc files.

* M680X: Remove warnings.

* M680X: Removed address_mode. Addressing mode is available in operand.type

* M680X: Bugfix: BSET/BCLR/BRSET/BRCLR correct read/modify CC reg.

* M680X: Remove register TMP1. It is first visible in CPU12X.

* M680X: Performance improvement + bug fixes.

* M680X: Performance improvement, make cpu_tables const static.

* M680X: Simplify operand decoding by using two handlers.

* M680X: Replace M680X_OP_INDEX by M680X_OP_CONSTANT + bugfix in java/python/ocaml bindings.

* M680X: Format with astyle.

* M680X: Update documentation.

* M680X: Corrected author for m680x specific files.

* M680X: Make max. number of architectures single source.
2017-10-21 21:44:36 +08:00
Travis Finkenauer
8998a3a1d5 ppc: fix endian check (#1029)
* Remove `big_endian` field of `cs_struct`

Added a helper macro `MODE_IS_BIG_ENDIAN()` to check if
`CS_MODE_BIG_ENDIAN` is set.

Refactored `cs_open()` check for valid mode out of arch-specific code
into arch-independent code. Also added a valid mode check to
`cs_option()`.  The checks use a new global array
`arch_disallowed_mode_mask[]`, which is initialized in the arch-specific
`*_enable()` functions.

Fixes bug where endianness could not be set for ppc.

* Fix Mac OS brew for Travis CI
2017-10-20 23:33:24 +08:00
Fotis Loukos
0850d55211 Added support for the TMS320C64x architecture. 2017-04-14 17:00:40 +03:00
Nguyen Anh Quynh
256090a8c8 add CS_OPT_UNSIGNED option to print immediate in unsigned form. only ARM is supported for now (issue #585) 2016-03-14 13:52:23 +08:00
Daniel Collin
2ee675c10a This adds M68K support to Capstone 2015-10-02 20:47:00 +02:00
Nguyen Anh Quynh
8bd0fdb992 arm: reduce the size of ARM_ITStatus.ITStates[] to 8 2015-06-03 22:25:59 +08:00
Nguyen Anh Quynh
ab6cc88cf4 arm: reduce the size of ARM_ITStatus.ITStates[] to 8 2015-06-03 22:25:22 +08:00
Nguyen Anh Quynh
de654dd238 rename MNEMONIC_SIZE to CS_MNEMONIC_SIZE 2015-04-27 09:47:59 +08:00
Nguyen Anh Quynh
0b96545f66 new option CS_OPT_MNEMONIC to customize instruction mnemonic 2015-04-26 22:54:41 +08:00
Nguyen Anh Quynh
efffe787d1 Add new API and start to provide access information for instruction operands
- New API cs_regs_access() that provide registers being read & modified by instruction

- New field cs_x86_op.access provides access info (READ, WRITE) for each operand

- New field cs_x86.eflags provides EFLAGS affected by instruction

- Extend cs_detail.{regs_read, regs_write} from uint8_t to uint16_t type
2015-03-25 15:02:13 +08:00
Nguyen Anh Quynh
bfcaba5851 2015 2015-03-04 17:45:23 +08:00
Nguyen Anh Quynh
c87ccd1b89 mips: fix bugs in the last update 2015-03-02 17:31:44 +08:00
pancake
9c10ace558 Make pkg-config and source consistent with installation 2015-02-24 05:03:04 +01:00
Nguyen Anh Quynh
650f96ce43 add new API cs_group_name() to return group name in string, given the group id 2014-07-08 08:59:27 +08:00
Nguyen Anh Quynh
1085073f8f x86: remove disp_size, imm_size, op_size. add size to each operand. thanks Gabriel Quadros for some nice ideas 2014-06-18 12:16:24 +08:00
Nguyen Anh Quynh
6456481508 x86: add immediate operand (1) for SHL/SHR/ROR/ROL/SAR/SAL in detail mode & Intel syntax 2014-05-19 16:46:31 +08:00
Nguyen Anh Quynh
a5ffdc3a80 x86: properly handle LOCK/REP in the core, so remove buch of hacks 2014-05-07 08:25:24 +08:00
Nguyen Anh Quynh
6023ef7843 Disassembler -> Disassembly 2014-04-29 11:21:04 +08:00
Nguyen Anh Quynh
2cff6f61fc x86: handle instructions with LOCK/REP/REPNE prefix after other prefixes. bear with this until we have a better approach 2014-04-28 11:19:44 +08:00
Nguyen Anh Quynh
d3ffe37c47 API: support SKIPDATA option (off by default) 2014-04-09 23:49:30 +08:00
Nguyen Anh Quynh
2ff665ad4a arm: support asm syntax CS_OPT_SYNTAX_NOREGNAME to print out registers with numbers (ex: 'r11' rather than 'fp') 2014-03-11 00:18:50 +08:00
Nguyen Anh Quynh
7772d859af x86: fix known issue with prefix by combining with previous prefix instruction. this is not perfect, but good enough for now 2014-01-21 11:49:25 +08:00
Nguyen Anh Quynh
edeeb04a1a make vsnprintf() user-defined function pointer, which is passed in via the same CS_OPT_MEM option like malloc/calloc etc 2014-01-15 20:44:03 +08:00
Nguyen Anh Quynh
a8eb7a5ca5 rename memory function pointer types to have cs_ prefix. also rename internal function pointers my_* to have cs_mem_ prefix - suggested by Pancake 2014-01-11 12:55:31 +08:00
Nguyen Anh Quynh
1acfd0b883 move insn_cache into cs_struct to gurantee thread-safe 2014-01-06 10:56:59 +08:00
Nguyen Anh Quynh
c7404075ff move internal memory management declarations from utils.h to cs_priv.h 2014-01-05 11:35:47 +08:00
Nguyen Anh Quynh
b265406960 cache insns for fast lookup in mapping.c. based on the idea of Dang Hoang Vu 2014-01-03 17:08:58 +08:00
Nguyen Anh Quynh
ae3649ff71 rename some C header guards to be without _ as prefix to follow naming convention of C language. suggested by Markus Elfring 2014-01-02 13:15:07 +08:00
Nguyen Anh Quynh
19b0de3c8d moving static doing_mem variable into cs_struct to guarantee thread-safe when handling memory operands 2013-12-31 22:40:04 +08:00
Nguyen Anh Quynh
42c6b1acc7 initial support for PPC 2013-12-30 00:15:25 +08:00
Nguyen Anh Quynh
0755282f04 reduce MAX_ARCH to save some memory. this is for internal usage only, so we can increase it in future if needed without having any compatibility issue 2013-12-22 11:13:07 +08:00
Nguyen Anh Quynh
d345839bce support cs_option() for arm64 module 2013-12-22 11:10:56 +08:00
Nguyen Anh Quynh
39a42eddfb Change the way of supporting arch modularization
- Always use libapstone.so as library name, no matter which archs are compiled in.

- Add new API cs_support() to check if a particular arch is supported.

- Change cs_version(): return hexical version which encodes both major & minor version.
    the return value can be comparable.

- Bump API version to 1.1
2013-12-22 10:40:58 +08:00
Nguyen Anh Quynh
f185180436 cleaner implementation for arch modularization 2013-12-21 12:16:47 +08:00
Nguyen Anh Quynh
4d3e852fbb detail option: provide instruction id even when detail option is OFF 2013-12-14 10:45:09 +08:00
Nguyen Anh Quynh
a209e67f8a support to turn on/off building instruction details 2013-12-14 00:23:41 +08:00
Nguyen Anh Quynh
a01d1546d6 x86: handle outs instruction in 16bit mode 2013-12-12 15:54:30 +08:00
pancake
f0e4eed89d Use const on all read-only buffers 2013-12-11 22:14:42 +01:00
Nguyen Anh Quynh
2215895ebc mips: no need cs_struct.micro_mips, as we can get that from cs_struct.mode 2013-12-11 18:11:49 +08:00
Nguyen Anh Quynh
a253c7a8e8 x86: map EFLAGS to string of 'flags', 'eflags' or 'rflags' depending on current CS_MODE 2013-12-09 10:26:18 +08:00
pancake
c04f873791 Use uint64_t instead of size_t for addresses 2013-12-03 02:51:46 +01:00
Nguyen Anh Quynh
7c7a8bc523 arm: move static variable ITBlock to cs_struct, so make arm code truly thread-safe 2013-12-02 13:16:44 +08:00
Nguyen Anh Quynh
b42a657873 change cs_disasm() and cs_disasm_dyn() to be portable API. fix related code using these API 2013-11-29 17:40:07 +08:00
Nguyen Anh Quynh
3eb9ac9bb9 mingw doesnt accept .errno of cs_struct. this fixes make it happy, and enable Windows cross-compile again 2013-11-27 15:24:47 +08:00