Skip to content

ykskb/dax86

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d7c90af · Feb 25, 2021
Jun 4, 2020
Apr 13, 2020
Sep 4, 2019
Jun 9, 2020
Jun 4, 2020
Jul 3, 2020
Jun 10, 2020
Apr 26, 2020
Jun 4, 2020
Jun 9, 2020
Jun 28, 2020
Jun 28, 2020
Jun 4, 2020
Jun 4, 2020
Jun 28, 2020
Jun 28, 2020
Jun 4, 2020
Oct 14, 2019
Jun 10, 2020
Apr 5, 2020
Jun 8, 2020
Jun 8, 2020
Jun 8, 2020
Jan 9, 2020
Oct 14, 2019
Oct 14, 2019
Oct 31, 2019
Sep 24, 2019
Apr 26, 2020
Jun 9, 2020
Jun 28, 2020
Jun 4, 2020
May 26, 2020
May 16, 2020
Jun 10, 2020
Jun 28, 2020
May 26, 2020
Jun 4, 2020
Jun 8, 2020
Jun 4, 2020
Jun 9, 2020
Apr 26, 2020
May 9, 2020
May 9, 2020
Feb 25, 2021
Jun 10, 2020
Jun 26, 2020
May 9, 2020
Jun 26, 2020
Jun 26, 2020
May 26, 2020
May 12, 2020
May 12, 2020
May 26, 2020
Jun 4, 2020
Oct 31, 2019
Oct 31, 2019
Jun 4, 2020
Jan 28, 2020
Jan 28, 2020
Jun 26, 2020
Jun 26, 2020
Jun 10, 2020

Repository files navigation

dax86

x86 (i386) Emulator in C

Why:

  • I wanted to trace how an OS runs on CPUs at archtecture / instruction level.

What:

  • Runs vanilla xv6 (memfs) image from boot.
  • Each instruction is manually implemented and executed sequentially without binary translation or OoOE.
  • Representation of logic is prioritized over the performance. Codes have bunch of comments covering the instructions and the hardware mechanism as well.

Done:

  • Instructions required for running xv6
  • Real mode
  • Protected mode
  • Paging
  • MP configuration
  • Software/Hardware interrupts
  • Device emulation (disk, keyboard, APIC timer, local APIC, IO APIC, UART etc)

To do:

  • FPU-related instructions
  • Exception
  • Virtual 8086 mode
  • TLB

System requirements:

  • Memory: 512MB
  • CPU: scheduler loop will occupy CPU resource. nice command, cgroups or docker resource setting might help here.
Build dax86
make
Run
# basic use
./dax86 [binary_file]

# run xv6 (ctrl + c to stop)
./dax86 xv6memfs.img

# verbose run (prints each op)
./dax86 [binary_file] -v
Setup Environment using Docker

Though dax86 can be built for different targets and run, there's a docker image in case Debian's build-essential package is preferred to the build environment of your host. Mini Debian Jessie is used for the base image.

The command below will build image, run a container with the image and execute shell in interactive mode.

make create-docker

To clean created container and image, run the command below.

make clean-docker
Test
# test all
./test.sh

# test specific one in tests/exec directory
./test.sh [test_name]

# directory test binary (stops at EIP: 0x0)
./dax86 test [binary_file]
Commands to Analyze Test Cases
  • Disassemble Binary
# 32 bit all the way 
ndisasm -b 32 [binary_file]

# 32 bit after 0xFF bytes of real mode instructions
ndisasm -b 32 [binary_file] -k 0,0xFF
  • View Binary
# hex
xxd [bin_file]

# bin
xxd -b [binary_file]

Referenced these publications with many thanks: