https://github.com/niwakadev/jit_x86_emulator
jit x86 emulator
https://github.com/niwakadev/jit_x86_emulator
Last synced: 9 months ago
JSON representation
jit x86 emulator
- Host: GitHub
- URL: https://github.com/niwakadev/jit_x86_emulator
- Owner: NiwakaDev
- License: mit
- Created: 2021-12-15T09:53:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-02T01:00:08.000Z (over 4 years ago)
- Last Synced: 2025-05-29T23:37:47.809Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 83 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JIT_X86_EMULATOR
これはにわかなjit化されたx86エミュレータです。

上の画像のプログラム:
```
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