6 ms·
>> Want to really learn how a CPU works? Writing an emulator is the best way to learn about it. The best way to learn how a CPU works would be to write a CPU!
by alok-g 8y ago
>> Want to really learn how a CPU works? Writing an emulator is the best way to learn about it.
The best way to learn how a CPU works would be to write a CPU! I.e., write HDL code for it and test in a hardware simulator.
I have designed a miniature application-specific processor, a compiler* and IDE for it, a disassembler, and an emulator too.
* To be more precise, I hacked a compiler for it using C# .net compiler.
- aap_ 8y agoIndeed. Software emulation is fun and all but real hardware works differently.
- planteen 8y agoYeah, for sure, especially for more modern CPU features like caches and OOO that are very difficult to emulate in software. But you can't share hardware designs (e.g., FPGA bitstreams) like you can software binaries or software source code. A hardware design will require a specific FPGA, board, and probably even a particular version of the synthesis tools if you want to build from source.
- aap_ 8y agoYou can still share the source code. Just requires some assembly then.
- aphistic 8y agoDo you have any recommendations for tools for this?
- paulsmith 8y agoNot tools per se, but check out the Bitwise education project, where Per Vognsen is coding an entire hardware and software stack from scratch, live on stream. https://github.com/pervognsen/bitwise https://github.com/pervognsen/bitwise
- alok-g 8y agoI had developed using professional IC design tools (specifically Modelsim and Xilinx) for the processor. However, free tools are available like http://iverilog.icarus.com/ http://iverilog.icarus.com/ The actual processor was implemented on a Xilinx FPGA, and it was about 2K lines of HDL code, carrying about 25 application-specific instructions which I had designed also. For the compiler, disassembler, IDE, emulator, I created in C# and .NET. While I did not use these, there are also ASIPs: https://en.m.wikipedia.org/wiki/Application-specific_instruction_set_processor https://en.m.wikipedia.org/wiki/Application-specific_instruc...
- bahmboo 8y agoThe hardware is the intent of the design, the emulator is the expression of the actual behavior. eg a game that inadvertently relies on a cache miss.
- tEMporality7 8y agoI think that would be way too difficult than writing an emulator.
- alok-g 8y agoYou'll be surprised how easy it is to create a simple processor once you understand basic concepts. The one I had designed had about 25 application-specific instructions and had about 2K lines of HDL code for full implementation.