Things I learned while writing an x86 emulator (2023)
11–20 of 135 posts
Re: Things I learned while writing an x86 emulator (2023)
#12What a cool person. I really enjoy writing assembly, it feels so simple and I really enjoy the vertical aesthetic quality. The closest I've ever come to something like OP (which is to say, not close at all) was when I was trying to help my JS friend understand the stack, and we ended up writing a mini vm with its own little ISA: https://gist.github.com/darighost/2d880fe27510e0c90f75680bfe... This could have gone much…
Re: Things I learned while writing an x86 emulator (2023)
#13Re: Things I learned while writing an x86 emulator (2023)
#14Check out Justine Tunney and her emulator. https://justine.lol/blinkenlights/ The docs are an amazing tour of how the cpu works.
Re: Things I learned while writing an x86 emulator (2023)
#15Re: Things I learned while writing an x86 emulator (2023)
#16Re: Things I learned while writing an x86 emulator (2023)
#17I've written fast emulators for a dozen non-toy architectures and a few JIT translators for a few as well. x86 still gives me PTSD. I have never seen a messier architecture. There is history, and a reason for it, but still ... damn
Studying the x86 architecture is kind of like studying languages with lots of irregularities and vestigial bits, and with competing grammatical paradigms, e.g. French. Other architectures, like RISC-V and ARMv8, are much more consistent.
Re: Things I learned while writing an x86 emulator (2023)
#18Bonus quirk: there's BSF/BSR, for which the Intel SDM states that on zero input, the destination has an undefined value. (AMD documents that the destination is not modified in that case.) And then there's glibc, which happily uses the undocumented fact that the destination is also unmodified on Intel [1]. It took me quite some time to track down the issue in my binary translator. (There's also TZCNT/LZCNT, which is B…
X86 used to be Intel's moat, but what a nightmarish burden to carry.
Re: Things I learned while writing an x86 emulator (2023)
#19Intel architecture is loaded with historical artifacts. The switch in how segment registers were used as you went from real mode to protected mode was an incredible hardware hack to keep older software working. I blame Intel for why so many folks avoid assembly language. I programmed in assembly for years using TI's 84010 graphics chips and the design was gorgeous -- simple RISC instruction set, flat address space, a…
x86 (the worst assembly of any of the top 50 most popular ISAs by a massive margin) and tricky MIPS branch delay slots trivia questions at university have done more to turn off programmers from learning assembly than anything else and it's not even close.
This is one reason I'm hoping that RISC-V kills off x86. It actually has a chance of once again allowing your average programmer to learn useful assembly.
Re: Things I learned while writing an x86 emulator (2023)
#20Hard disagree.
The best way is to create a CPU from gate level, like you do on a decent CS course. (I really enjoyed making a cut down ARM from scratch)