Coder Social home page Coder Social logo

llvm8's Introduction

llvm8

Lifting CHIP8 to LLVM and recompiling to any architecture.

What is this?

llvm8 aims to lift a CHIP8 ROM to LLVM which gives us the capability to recompile the ROM to any LLVM-supported architecture. This allows us to run old ROMs without the use of emulation. This is also called static recompilation.

How does it work?

Here's a rough overview of what is going on:

  1. Disassenble ROM file
  2. Lift instructions to LLVM
  3. Write original ROM file to a global array in the LLVM bitcode
  4. Simulate CHIP8 architecture registers through global variables
  5. Link against external/lib.cpp which contains GUI code and general high level handlers for the ROM

How do I build this?

Download this LLVM distribution created by mrexodia. I installed the files to C:\LLVM10\, if you use a different path make sure to change the path below and the paths set in make.bat and make.sh.

git clone https://github.com/ioncodes/llvm8
cd llvm8
mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH=C:/LLVM10 ..

Open up the solution in your IDE and build it! The binary is called llvm8{.exe}.

How do I use this?

llvm8 requires you to tell it which bytes are actually executable instructions (and not data), you can do so by providing a comma seperated list to --code. When in doubt just use 0-{FILE_SIZE_HERE}. To find out the code paths use any CHIP8 disassembler or this emulator. To recompile a ROM execute the following command:

# this assumes that llvm.exe is placed in the project root folder.
llvm.exe --rom ./roms/boot.ch8 --code "0-88"

This will write a new file called boot.ch8.ll. To recompile this to Windows or macOS use the make.bat and make.sh scripts respectively:

make.bat boot.ch8.ll

This will recompile it to a native image and start it up for debugging purposes.

What is missing?

A lot of instructions are currently missing (for example call & ret). I used a few test ROMs I found online to create a recompiler that works with most test ROMs I used. There is also no keyboard support but implementing that is just a matter of plugging SDLs keyboard support to the ROM registers.
There's also a bug where the UI can not be created on macOS but you can just enable the NOGUI flag in external/lib.cpp and it will output to the terminal instead.

Images?

llvm8's People

Contributors

ioncodes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.