Git Product home page Git Product logo

jit_x86_emulator's Introduction

JIT_X86_EMULATOR

これはにわかなjit化されたx86エミュレータです。

select

上の画像のプログラム:

BITS 32
    org 0x7c00
start:
    mov edx, 0x03f8
mainloop:
    mov al, '>'    ; プロンプトを表示
    out dx, al
input:
    in al, dx       ; 1文字入力
    cmp al, 'h'
    je puthello     ; hならhelloを表示
    cmp al, 'w'
    je putworld     ; wならworldを表示
    cmp al, 'q'
    je fin          ; qなら終了
    jmp input       ; それ以外なら再入力
puthello:
    mov esi, msghello
    call puts
    jmp mainloop
putworld:
    mov esi, msgworld
    call puts
    jmp mainloop
fin:
    jmp 0

; esiに設定された文字列を表示するサブルーチン
puts:
    mov al, [esi]
    inc esi
    cmp al, 0
    je putsend
    out dx, al
    jmp puts
putsend:
    ret

msghello:
    db "hello", 0x0d, 0x0a, 0
msgworld:
    db "world", 0x0d, 0x0a, 0

4.2章の以下のコードが動きます。(subroutine32.bin)

BITS 32
    org 0x7c00
start:            ; プログラムの開始
    mov esi, msg
    call puts     ; サブルーチンを呼び出す
    jmp 0

puts:
    mov al, [esi]  ; 1文字読み込む
    inc esi
    cmp al, 0     ; 文字列の末尾
    je  puts_end  ; に来たら終了
    mov ah, 0x0e
    mov ebx, 15
    int 0x10      ; BIOS を呼び出す
    jmp puts
puts_end:
    ret           ; サブルーチンから抜ける

msg:
    db "hello, world", 0x0d, 0x0a, 0

ビルド

make

実行

./x86 subroutine32.bin

or

./x86 select.bin

サンプルプログラム

自作エミュレータで学ぶx86アーキテクチャ-コンピュータが動く仕組みを徹底理解! 内田公太 、 上川大介からです。

jitライブラリ

https://github.com/herumi/xbyak

問題点

呼び出し規約の関係で、Windowsでは動作しません。 あと、このJITエミュレータは、 1つの機械語命令をコンパイルするたびに、制御を本体に移しています。 つまり、めちゃくちゃ遅いです。これに関しては、今後改良する予定です。 何故こんなことしたのかと言いますと、動かし切ることをまずは目指したからです。

jit x86 emulatorの作成の参考になった記事

https://jahej.com/alt/2011_06_12_jit-cpu-emulation-a-6502-to-x86-dynamic-recompiler-part-1.html

jit_x86_emulator's People

Contributors

niwakadev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.