Coder Social home page Coder Social logo

forcebru / pyvm Goto Github PK

View Code? Open in Web Editor NEW
106.0 7.0 15.0 2.87 MB

A virtual machine written in Python that executes x86 binaries according to the Intel Software Developer Manual

License: MIT License

Python 48.96% C 25.54% Assembly 24.62% Makefile 0.88%
emulator x86 pure-python

pyvm's People

Contributors

forcebru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvm's Issues

Latest commit is actually slower

This is the code used for testing:

import timeit
from io import StringIO

print("Testing...")
t = timeit.repeat(
        "vm.execute_elf('C/bin/bubblesort.elf');vm.execute_elf('C/bin/quicksort.elf');vm.execute_elf('C/bin/insertionsort.elf');vm.execute_elf('C/bin/memcpy_test.elf')",
        "void=StringIO();vm=VM(0x0017801d, void, void, void)",
        globals={'VM': VM.VM, 'StringIO': StringIO}, number=10, repeat=10)

avg = lambda x: sum(x) / len(x)
print(f"NEW: {min(t):.4f}, {avg(t):.4f}, {max(t):.4f}")
# OLD: 26.6493, 28.4966, 29.9140
# NEW: 28.6566, 29.1709, 29.9998

Here the change was introduced here:

if reg_check is not None:
(the reg_check argument to process_ModRM) and was meant to interrupt parsing of ModRM if its REG field didn't match the criteria. Otherwise it would've parsed the whole thing and wasted time.

Apparently, this doesn't really speed things up, so it should be removed or re-implemented.

Prepare for release 0.1-beta

TODO list:

  • Update README with directory structure (or probably add READMEs to other directories and link to them from the main one?)
  • Add more example C programs (maybe some with floating-point calculations?)
  • Comment the code

Latest commit breaks debug messages

Commit 831d87b breaks debug messages.

Many of them use hex(loc) if type else reg_names[loc][sz] to output either the name of the register or the address in hex. First of all, this is super ugly and should be refactored.

Now that type is either vm.reg or vm.mem, it'll always be truthy, so, hex(loc) will be always evaluated, which is incorrect.

16-bit addressing not supported at all

ModR/M byte processing is currently only for 32-bit addressing, and there's a whole table of possible values of the ModR/M byte for 16-bit addressing, which isn't supported at all.

Should probably implement that? Cuz stuff like lea ax, [bx] doesn't work since it's 16-bit addressing.

`C/bin/calculator` doesn't work

The movzx instruction attempts to access invalid memory from [ebp - 1]. ebp is loaded with some value from memory before that, and this value is weird. The address seems to depend on the first inputted operand.

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.