Hacker News new | past | comments | ask | show | jobs | submit login
CPU emulator in web browser (Arm/Mips/X86/Sparc) (alexaltea.github.io)
138 points by hacking_news on Feb 5, 2017 | hide | past | favorite | 20 comments



The x86 example is particularly cute:

    xadd  eax, edx
    loop  -3
implements the Fibonacci series in two machine instructions (notice eax and edx have 514229, 832040 in them after you run the example, the 29th and 30th Fibonacci numbers). I first saw that in a book a friend got me for christmas; a hard copy of this site: https://www.xorpd.net/pages/xchg_rax/snip_00.html


I'm glad someone caught the reference. Indeed, I took it from the [xchg rax,rax] book.

Also, I have to apologize for the many bugs the demos have at the moment (annoying editor, missing features), I intended to post a Shown HN post at a later point in time. During the next days I will be taking care of these matters. By the way, these demos rely in Capstone.js/Keystone.js to assemble/disassemble machine code (if anyone is interested, similar demos can be found at https://phi.nz/).


i wonder how performance of this (emscripten of Unicorn) compares with this much more flexible ARM emulator from a few years ago (which I am much more excited to use for things as I can easily customize the instruction fetch and memory access routines; it is even straightforward how to just hook system calls).

https://github.com/ozaki-r/arm-js

http://biged.github.io/arm-js/arm-js.html

^ The latter link is a demo; click "Boot" in the upper left.


Probably that Arm-js emulator you mention is faster: Unicorn is based on QEMU, which internally does the translation by translating the guest machine code to an IR. After optimizing it, this IR usually gets compiled back to the host machine code, but thanks to the TCI [1] the IR can be directly interpreted anywhere without the need of a compiler backend. All these steps incur on an additional overhead that wouldn't be there if one interpreted ARM code directly.

[1] http://wiki.qemu.org/Features/TCI


You say "you" multiple times, but I did not implement this other emulator: I simply found it yesterday while evaluating options for emulating armv7 on top of JavaScriptCore.

On the other side: this CPU emulator is written using high-level JavaScript, and I think some of its control flow is implemented using exception handling, whereas compiling Unicorn to asm.js will get reconstituted in modern broswers back to reasonable native code (and qemu is designed to be fast). I don't think it is clear cut which is faster.

(I would do a benchmark, but for my use case I actually am working with interpreted JS, which is massively different, and I had already evaluated that Unicorn.js wasn't flexible enough for my intent, so it is more of a curiosity than a question I would spend time to answer myself.)


My bad, I realized my mistake and was editing my message right before your answer.

Indeed, performance is not clear and probably depends a lot on the browser's JavaScript engine. I will try to find that out in the future with some benchmark.


Demo for ARM: https://alexaltea.github.io/unicorn.js/demo.html?arch=arm

This is based on the Unicorn emulator (open source): https://github.com/unicorn-engine/unicorn


Does anyone know where you can

    1) find SPARC systems
    2) find what you need to do to initialize all components on a SPARC system
I'd love to write an OS for a SPARC machine one day


> where you can find SPARC systems

In case by "find" you mean "where are SPARCs still being used"... It is something of a niche, but all our missions in the European Space Agency use LEON processors; a design based on SPARC [1].

And since you mentioned OSes, usually it is either bare-metal stuff or RTEMS [2].

[1] https://en.wikipedia.org/wiki/LEON [2] https://www.rtems.org/


Ebay "SPARCstation"? Shipping tends to be expensive as they are heavy, and you need to make sure you get a complete system. You can probably find a version of Netbsd or OpenBSD that boots and has source, from which you can reverse-engineer the startup.


Some of Netgear's ReadyNAS devices had (slow by today's standards) SPARC chips in them[1]; I have a ReadyNAS Duo with a SPARC chip in it. They also have a Debian-based OS for SPARC.

[1] Search for "SPARC" in http://www.downloads.netgear.com/files/GDC/RND2110/Duov1_NV+....


I wonder how hard it would be to run SunOS 4.1.4, the last great Sun operating system before it all went downhill? [1]

[1] http://www.art.net/~hopkins/Don/unix-haters/slowlaris/worst-...


I picked up an old UltraSPARC Sun server a while back for $10. Never got it running as I didn't understand serial connections and it was annoyingly loud.


You can put one on an FPGA. The OpenSPARC cores are GPL.


eBay, and probably by reading the NetBSD/SPARC source.


> With all that said, QEMU is an awesome project, which Unicorn was born from. However, Unicorn is not just QEMU, but offering a lot more because it has been designed & implemented especially for CPU emulation.

Couldn't they extend Qemu, or there was a reason for making a separate project?


From these slides it seems it started as a qemu fork: https://www.blackhat.com/docs/us-15/materials/us-15-Nguyen-U...

would like to know more about unicorn as well.


Very cool. Needs RISC-V.

And 68000 :-)


They have a showcase page at Unicorn website, with a bunch of really exciting tools: http://www.unicorn-engine.org/showcase/


Apropo Emulator.

1. Is there any way to run SGI/IRIX and some IRIX software?

2. Would a simple IRIX Software run on BSD/MIPS? I heard they are quite similar.

This project seems to be discontinued: https://www.vanheusden.com/miep/

They claim to be able to have an emulator, but as far as I know, expensive as f.... http://www.vhware.co.il/

Any other ideas?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: