124 points · by ekianjo · 3y ago · 44 comments
This is absolutely huge
This emulator is going to run at something like Pentium II speeds on current RISC-V boards.
That's fine if you want to run late 90s (or earlier) x86 software at the same speed it ran on then. Except that will be i386 code, not x86_64.
RISC-V boards are getting faster pretty quickly, but we're still going to need a better x86_64 emulator to get a Rosetta2-like experience on RISC-V even once the CPUs catch up.
Although I do wish Box64 could support statically compiled binaries as well.
But, I hope they can avoid things like "Intel ME" and "TPM 1/2/...". If these are needed they should fully open the specs to people can inspect them. Also they should be disabled either by jumpers or whatever RISC uses for BIOS.
If you want to draw a PCB, you can! Just like you can make your own USB-to-SATA board with an ASM1153 though, all you do is draw a board to connect a chip to the outside and give it some supporting crystals. An example TPM chip is SLB 9665, and you can get its datasheet here: https://www.infineon.com/dgdl/Infineon-data-sheet-SLB9665_2.... (if link goes stale, use Google)
As for source code: hardware being closed off is not exactly news (otherwise people would be a lot less angry at firmware issues). There are open-source TPM emulators in use by qemu, so you probably could convince a Raspberry Pi Zero or whatever to pretend to be one by using an emulator and speaking over SPI. There's also a report of TPM on a ARM+FPGA board (https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=...) if that's what you want.
The exact pin-out of the slot depends on the motherboard but they are all basically minor variations on the pinout of a 13 pin (14 pin with 1 filled) or 20 pin connector. When you buy your motherboard you can find the full pinout in the manual. That gets you your connector to the motherboard.
For the actual chip itself and the PCB layout, buy an infineon TPM2.0. They cost a few dollars at most. The docs that you can pull off the site include the pinout and operating condition requirements. From that you can build a simple board to run the chip. Hell most of the docs include the plans for one (albeit you might need to change that to fit your mobo.
https://www.infineon.com/cms/en/product/security-smart-card-...
If the supply chain is compromised and you can't trust them, they never needed any new hardware blocks to do bad things. I don't get why people are so obsessed with these new blocks - the level of required trust hasn't really increased.
But QEMU only does one basic block at a time without jumps so it's relatively easy to implement.
(I tested "7z b" and QEMU user mode emulation is about 30% for x86-on-x86, I'm curious to see how it fares for x86-on-RISCV but I don't have a board to test on).
I've got a gist of what a basic block is due to online discussions. I know it is roughly a list of instructions and that jumps are the boundaries.
But I'm looking to understand it on a more fundamental level.
I'm guessing the subject is SSA / single static assignment and compiler theory? Just wanna ask publicly if I'm on the right track, and if I'm following this discussion correctly.
The core idea I think is that control flow complicates the kinds of analysis a lot of optimisation and other compiler passes need to do; so by first breaking the input into pieces which have very restricted possible flows of control ("only entered at the top, only exited at the bottom" is the classic definition) then:
1. You can get quite a long way with optimisations that only work within a basic block, and the restriction to within-a-BB simplifies things a lot because it can entirely ignore control flow
2. Analysis that only cares about control flow can work on a graph of BBs and ignore the individual-statement/instruction details, because the BB graph captures all the detail of what can branch where
e.g. "th.addsl rd, rs1, rs2, imm2" which has an immediate field for the shift instead of separate instructions (which is just documentation really), and shifts rs2 while Zba's sh1add, sh2add, sh3add shift rs1.
Also th.ff0, th.ff1, th.rev, th.tstnbz (same as orc.b but with inverted result)
They also have pre- and post-increment loads and stores with writeback of the incremented pointer, and [rs1 + rs2 << imm2] loads and stores, which can be useful for JITing x86 (or ARM) addressing modes.
https://github.com/T-head-Semi/thead-extension-spec/releases...
Even before the first batch of very high performance RISC-V CPUs hit the market, we're already ready to deal with applications/games that use the legacy x86.