SunnyShah
SunnyShah

Reputation: 30517

How to make ARM9 custom device emulator?

I am working on ARM 9 processor with 266 Mhz with fpu support and 32 MB RAM, I run linux on it.I want to emulate it on pc ( I have both linux and windows availabe on pc ). I want to profile my cycle counts, run my cross-compiled executables directly in emulator. Is there any opensource project available to create emulator easily, How much change/code/effort does I need to write to make custom emulator with it ? It would be great if you provide me tutorials ot other reference to get kick-start.

Thanks & Regards,

Sunny.

Upvotes: 1

Views: 3393

Answers (2)

shodanex
shodanex

Reputation: 15446

You should give a look at QEMU. I don't understand however, why do you need a complete emulator ?

You can already a lot of profiling without emulator. What are the gains you expect from having a system emulator ?

Upvotes: 2

Peter
Peter

Reputation: 5156

Do you want to emulate just the processor or an entire machine?

Emulate a CPU is very easy, just define a structure containing all CPU registers, create an array to simulate RAM and then just emulate like this:

    cpu_ticks = 0;  // counter for cpu cycles 

    while (true) {

      opcode = RAM[CPU.PC++]; // Fetch opcode and increment program counter

      switch (opcode) {

        case 0x12: // invented opcode for "MOV A,B"
          CPU.A = CPU.B;
          cpu_ticks += 4; // imagine you need 4 ticks for this operation
          set_cpu_flags_mov();
          break;

        case 0x23: // invented opcode for "ADD A, #"
          CPU.A += RAM[CPU. PC++]; // get operand from memory
          cpu_ticks += 8;
          set_cpu_flags_add();
          break;

        case 0x45: // invented opcode for "JP Z, #"
          if (CPU.FLAGS.Z) CPU.PC=RAM[CPU.PC++]; // jump
          else CPU.PC++; // continue
          cpu_ticks += 12;
          set_cpu_flags_jump();
          break;
        ...
      }

      handle_interrupts();

    }

Emulate an entire machine is much much harder... you need to emulate LCD controllers, memory mapped registers, memory banks controllers, DMAs, input devices, sound, I/O stuff... also probably you need a dump from the bios and operative system... I don't know the ARM processor but if it has pipelines, caches and such things, things get more complicated for timing.

If you have all hardware parts fully documented, there's no problem but if you need to reverse engineer or guess how the emulated machine works... you will have a hard time.

Start here: http://infocenter.arm.com/help/index.jsp and download the "Technical Reference Manual" for your processor.

And for general emulation questions: http://www.google.es/search?q=how+to+write+an+emulator

Upvotes: 4

Related Questions