6 ms·
Where does one start with such thing? I mean, where do I read how to emulate CPU (or at least how CPU works, so I would be able to come up with how to emulate i
by zero-g 11y ago
Where does one start with such thing? I mean, where do I read how to emulate CPU (or at least how CPU works, so I would be able to come up with how to emulate it by myself), how does PS/2 work, how to boot an image from BIOS?
- mtharrison 11y agoYeah, I always feel the same when I see similar things. How do you even start?
- khedoros 11y agoPersonally, I had some courses on computer architectures, and those covered the theory of how CPUs are constructed, how they run programs, etc. I decided to write an NES emulator. So: - Find Wikipedia articles, and learn that it used a variant of the MOS Technology 6502, which was used in a lot of computers in the 80s. - Find some digitized assembly programming manuals from the time (I think the one I used was distributed with the Commodore 64, and ended up having several typos introduced by OCR). - Write a tool to recognize, decode, and print out an operation when you feed it a little data - You basically need to set up a loop of fetching instructions, interpreting them, then doing what they say. An actual CPU runs in a similar loop, and it generally doesn't stop until power is removed, I think that after the classes I took, I read a lot of what other emulator writers said. This article is a basic look at the structure of an emulator, the theory behind them, and some different designs: http://fms.komkon.org/EMUL8/HOWTO.html http://fms.komkon.org/EMUL8/HOWTO.html
- TheOtherHobbes 11y agoOne of my friends at uni wrote a Z80 emulator/assembler in PDP-10 assembler as a hobby project - and he was studying chemistry, not CS... I don't understand why a basic understanding of CPU architectures isn't a CS fundamental everywhere. Even if you have no interest in emulating a CPU or an OS, you really do need to know what registers are, how caches work, what interrupts do, and how basic IO happens. At the very least it's a practical demonstration of one particular kind of VM, and - if you want to - you can generalise from that to VMs of your own design. For web apps, not understanding these things can get expensive. Cycles, even cloud cycles, aren't free, and if you take zero interest in optimisation and efficiency you're literally throwing money away.
- khedoros 11y agoAgreed. It's important to understand how the hardware works, at least at the theoretical level. If you don't understand what the machine is doing, it's hard to say that you really understand how your program works.
- toyg 11y agoUniversity courses? I'm pretty sure CPUs were a huge part of my first year of CS.
- Someone1234 11y agoMe too, but there's a huge gap between the often simplified CPUs they teach you on at Uni' and programming for the querks in x86, or any of the buses/peripherals/interfaces. I didn't learn much more than assembly 101. I doubt I could emulate much real hardware. Certainly not a PC of all things... A gameboy looks more accessible...
- mhurron 11y agoWow, advocating higher education on HN. Feeling bold today?
- toyg 11y agoI've not really enjoyed my time in higher-ed (and I have little to show for it), but sometimes it's really the only place where unfashionable but fundamental topics are covered in depth. My comment was meant as a pointer (i.e. "check out lecture recordings etc") rather than a quip.
- ohRightForgot 11y agoReally? Because it sounded exactly like a snarky troll.
- 0xffff2 11y agoLearning about CPU internals was a huge part of your first year in CS? Where did you go to school? At my school and every other school I'm remotely familiar with, the knowledge needed to emulate a CPU would be covered in upper division computer engineering courses, and not covered by CS undergrads at all, certainly not in their first year.
- khedoros 11y ago
- copy 11y agoFirst you write a disassembler, then an interpreter for 16 bit mode. At that point you can already almost run FreeDOS. Here are some resources: http://css.csail.mit.edu/6.858/2014/readings/i386/toc.htm http://css.csail.mit.edu/6.858/2014/readings/i386/toc.htm The official intel manuals http://sandpile.org/ http://sandpile.org/ http://ref.x86asm.net/geek.html http://ref.x86asm.net/geek.html http://stanislavs.org/helppc/idx_hardware.html http://stanislavs.org/helppc/idx_hardware.html http://www.ctyme.com/intr/int.htm http://www.ctyme.com/intr/int.htm http://wiki.osdev.org/Main_Page http://wiki.osdev.org/Main_Page
- stephenboyd 11y agoIf the reference manuals are overwhelming, I'd recommend to start by reading Code: The Hidden Language of Computer Hardware and Software by Charles Petzold. It covers how computers work for a general audience, from logic gates and boolean algebra, up to assembly, opcodes on the Intel 8080 processor, and how operating systems work. It was one of the most consequential books I've read, and I'd recommend it to both professional programmers and anyone else who is intellectually curious.