Commit Graph

35 Commits

Author SHA1 Message Date
Lephenixnoir ca1217af1b
lib/load-asm: greatly improve loading time with less strings 2021-03-16 13:40:36 +01:00
Lephenixnoir dea24a2547
print: fix ellipses after non-decodable words 2021-03-16 13:40:01 +01:00
Lephenixnoir c8b28b447f
masive improvements to memory use by compacting core objects
* Store CpuRegister on a single byte
* Store operation sizes (0, 1, 2, 4) on a single byte
* Share the (disp) and (imm) fields of instruction arguments
* Store instructions as char[12] instead of std::string (>32B)
* Store instruction args in Argument[2], not std::vector (>24B)

Size changes:
  CpuRegister:    4B ->  1B
  Argument:      24B ->  8B
  Instruction:  >64B -> 32B

This reduced the malloc size from 3.3M to 177k after a standard 40-line
disassembly (this excludes OS files mapped to memory), and improved the
loading time for the SH3 instruction table by about 30% (100 ms -> 65
ms).
2021-03-16 13:37:55 +01:00
Lephenixnoir fc9b292846
main: print malloc() stats after disassembly in verbose mode 2021-03-16 13:35:23 +01:00
Lephenixnoir c20db6a8ca
minor data storage improvements 2021-03-16 13:19:48 +01:00
Lephenixnoir 4c9b738247
(cosmetics) 2021-03-16 12:29:39 +01:00
Lephenixnoir 23809e40ef
improve help message to reflect implemented functions 2021-03-16 12:27:19 +01:00
Lephenixnoir c36b63870a
info: fix serial number 2021-03-16 12:25:10 +01:00
Lephenixnoir 41dd7ae092
library: don't use the install folder as library anymore 2021-03-16 12:22:55 +01:00
Lephenixnoir 9c49114928
symbols: add os and mpu constraints to symbol tables
Each of these constraints is specified in the header by an [os] or [mpu]
line. For the symbol table to be usable on a disassembly, both
constraints must be met:

* Either [os] is unset, no OS is used for disassembly, or the OS type is
  the same as the [os] constraint (either "fx" or "cg");
* Either [mpu] is unset, the disassembled target has no specified MPU,
  or the MPU type of the target is the same as the [mpu] constraint (eg
  "sh7305").
2020-06-13 11:23:46 +02:00
Lephenixnoir a572f20d4d
os: support fx-CG OS structures
This change adds OS parsing for fx-CG OSes; this includes the
information available in [fxos info] but also makes it possible to
disassemble syscalls using [fxos disasm].

Symbols and addresses, including syscall names, are still shared with
legacy FX versions, which is definitely a no-no.
2020-06-13 10:47:13 +02:00
Lephenixnoir 772a67e35e
print: show ellipses when addresses jump in output 2020-06-11 20:03:42 +02:00
Lephenixnoir 2e58a8850b
support non-decoded instructions
This finally makes it possible to disassemble any interval without
worrying about potential errors. That's some progress.

By the way, now we can fully disassemble fx@3.10. Takes about 6 seconds
for the analysis passes, and ~9 seconds for printing on my machine.
2020-02-29 16:32:25 +01:00
Lephenixnoir c1c1be2d2c
support for mova, and more responsible OS creation 2020-02-29 11:25:03 +01:00
Lephenixnoir ea44c1ffa1 base-library: add minimal library example
Because referencing the bible is not the best idea. It would be best to
not duplicate stuff around, so:

* The base-library is a minimal, never-evolving set of files
* The community documentation is in the fxdoc repository
* The OS files are on the bible's common/ folder (cleaning needed)
2020-02-28 16:50:08 +01:00
Lephenixnoir 3f462a2d07 disasm: support block disassembly (eg 80000000:4k). 2020-02-28 16:42:46 +01:00
Lephenixnoir c5a7071dcc better manage exceptions and instruction-level passes 2020-02-28 16:19:50 +01:00
Lephenixnoir fad6f48152 print: indent code lines less (1 space instead of 2) 2020-02-27 15:13:05 +01:00
Lephenixnoir ff3aec0a34 library: do not try to load directories as data files 2020-02-27 15:11:42 +01:00
Lephenixnoir b8faddce5b
add a detailed README 2020-02-17 23:01:31 +01:00
Lephenixnoir 54a79ca4b4
add support for flexible location specifiers 2020-02-17 22:56:41 +01:00
Lephenixnoir 5178a489be
add disassembly from arbitrary file
Also changes the naked pointer of the Buffer object to a shared_ptr.
Still learning how to use this thing, but I'll manage eventually.
2020-02-16 21:45:16 +01:00
Lephenixnoir 6ca3bc1f03
add the library command for a bit of introspection
The library commands lists the targets and instruction sets that have
been loaded from fxos data files.
2020-02-16 21:23:10 +01:00
Lephenixnoir a51dc7db4c
add syscall headers at the start of functions 2020-02-15 19:32:46 +01:00
Lephenixnoir d5c5fa6aeb
implement the syscall pass, and symbol resolution
New features:
* The syscall pass now resolves syscalls for the input target, provided
  that an OS is mapped on the ROM region.
* Formalized the variations of print's arguments as a sequence (tree, to
  be precise) of /promotions/.
* Added a short notion of Symbol and SymbolTable, and a loader for them.
  Data files of type "symbol" are read as such and provide name to
  syscalls or arbitrary addresses.

Code changes:
* The disassembly operation of the command-line interface is now finally
  in its own file with more room.
* Encoded the tree structure of promotions as a sequence of (mainly
  tail-calling) inter-calling methods in the print pass.
2020-02-15 18:42:14 +01:00
Lephenixnoir 08e26aee2e
improve the semantic model and implement the pcrel pass 2020-02-15 09:22:12 +01:00
Lephenixnoir 4d9edecad9
start with the analysis passes
-> The cfg pass loads the function into memory, annotates leaders and
   jumps, and resolves delay slots.
-> The pcrel pass currently computes locations for pc-relative moves and
   jumps, but does not yet compute the pc-relative moved data.
-> The print pass displays the results of analysis with various layout
   and formatting options.
2020-02-12 07:53:00 +01:00
Lephenixnoir c499ca1f90 define a library abstraction and logging helpers
-> The Library class handles the loading and parsing of data files. This
   is because any fxos application will use this since everyone will
   have only one library.
-> Add a logging function that automatically format()s everything in
   sight with basic logging levels and a verbose mode. Standard logs are
   prefixed with __func__ for debugging purposes.
-> Allow format() to take std::string arguments for %s by statically
   extracting c_str()s.
-> Add a simple timing utility to understand which file load or
   disassembler pass takes up the time.
2020-01-26 12:48:39 +01:00
Lephenixnoir b20731c829 basic setup for running disassembly passes 2019-12-29 19:17:33 +01:00
Lephenixnoir 468495856d
implement more of the meat of the tool
* Separate OS and Target conceptually; now an OS is created on an
  existing target which must have ROM bound.
* Add a configuration file with a data library and description files
  which are automatically loaded at startup.
* As a first application, implement target descriptions. It is now
  possible (given the proper library) to type [fxos info fx@3.10] to get
  information on the fx OS version 3.10.
* Set up the pass infrastructure and the first few easy passes. This
  is still a Work In Progress and not yet called from the command-line.
* Improve the copy/move behavior of classes (C++ concerns).
* Add instruction metadata, which will make it easier to write actual
  useful analysis passes.
2019-12-28 17:18:13 +01:00
Lephenixnoir 8aaed3dd8c basic data structures for the disassembler 2019-12-20 19:33:41 +01:00
Lephenixnoir 5d63fb11e3
implement the abstract domain of relative constants 2019-12-20 11:17:09 +01:00
Lephenixnoir 8812886e58
basic stuff on the disassembler/interpreter, nothing serious yet 2019-12-16 22:14:02 +01:00
Lephenixnoir c9ecb855de
finish the base interfaces
* switch from File to Buffer to manage file contents
* boilerplate for a proprer command-line interface, and complete help
* add a notion of Addressable to avoid losing the source address of very
  information provided by the OS type
* use addressables in the AbstractMemory interface
* fully parse the header and footer of OSes
* bring [fxos info] to the level of the previous implementation
* make most of the OS attributes public
* use char* instead of void* for translation, since void* arithmetic
  triggers a hell of warnings in C++
2019-12-15 18:40:05 +01:00
Lephenixnoir d78f7bca10 initial system: instruction load, target creation
Contains basic stuff to start working:

* Loading files and assembly instruction descriptions
* Create a 64k-entry assembly decoding table
* Standard memory regions and information
* Create targets where files can be mapped at any addresses
* Load OSes and detect a few basic things
2019-12-14 22:33:57 +01:00