cmips
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
disgen fixing up some whitespace Aug 13, 2014
images new srec kernel Oct 22, 2013
include
src minor fixups Aug 13, 2014
LICENSE updated readme Aug 13, 2014
Makefile added gif Aug 14, 2014
README.md Update README.md Aug 14, 2014
example.gif added gif Aug 14, 2014

README.md

cmips

Tiny mips 4kc emulator (smallest and easiest emulator to hack on that I know of - It boots linux in a few thousands lines of C code.) I wrote this emulator in the month or so after I graduated university and before I started work.

Let me know if it has helped you in any way, I appreciate any feedback.

Building and Running

How to compile and run the emulator.

example gif

I have not put my custom linux kernel board support code online yet, so I included a precompiled kernel in the images folder. I have tested on linux (main platform) and cygwin in windows.

Motivations

  1. To test my skills and learn about processors and operating systems.
  2. To compile to javascript (asm.js) with emscripten to test it vs Fabrice Bellard's http://bellard.org/jslinux/ (I started this, but didnt finish writing a terminal emulator.)
  3. To embed in other applications like games, simulators and sandboxes so people can have a realistic processor to play with. It doesn't really have any dependencies, so if you rewrite the serial port code, and embed the step function in your program loop somehow, it will work very easily.

Status

Currently boots a custom built linux kernel. timers don't work quite right, so calculating bogomips takes a while during boot, and time readings are off. It currently supports a uart chip, and uses the cpu timer. It may eventually support pluggable framebuffer, mtd flash, 8250 uart, real time clock if there are reasons to extend it. It uses the linux emulation of floating point instructions.

There is no way to quit the emulator currently with the keyboard because I set the terminal to raw mode and was lazy.

(Pull requests and issues welcome.)

Tests

test suite I used for bootstrapping located at https://github.com/andrewchambers/met. The linux kernel itself is more comprehensive.

I used creduce and csmith as a way of fuzzing my emulator initially too.

Misc

The disgen.py program is just a python script which converts a json representation of the opcodes into a giant switch case for disassembling and executing.

Info

I used buildroot to build the image, and wrote a custom linux kernel board support package for the mips kernel following: http://linux.junsun.net/porting-howto/ Unfortunately it was a bit out of date, so I had to improvise.

Those who wish to try similar projects, I learnt alot by working with my friend on a predecessor javascript emulator and a gameboy emulator. I mainly used the mips 4kc manual I got from wikipedia, and I read parts of the qemu code if things were not totally clear.

The uart code is inspired from http://s-macke.github.io/jor1k/.

The people on #linux-mips also helped me when I hit a bug in the mips linux kernel which prevented booting.