Live data from Hacker News

Building a Minimal Viable Armv7 Emulator from Scratch

xnacly.me

21–25 of 25 posts

Re: Building a Minimal Viable Armv7 Emulator from Scratch

#21
post #9

For a learning project like this one, this would probably be overkill, but my personal suggestion for instruction decoding is that it really pays in the long term to use a data driven decoder. It's fairly easy to do a handcoded "if bits A..B are 0b1000 and..." decoder for the basic integer parts of the instruction set, but especially as you get into complexities like SIMD and if you need your decoder to be easy to mo…

Getting a bit off topic, but I feel like this task is something that ought to have special language support.

It's a kind of serialization/deserialization, or what I think Python and some others call "pickling". Same task. Turn these raw bit patterns into typed values.

Ada probably comes closest of the major languages to pulling it off. It has separation of the abstract/programmer's view of a data type and the implementation / low representation of that type.

Specify a bunch of records like:

    for Instruction use record
       Condition at 0 range 31 .. 28;
       ImmFlag at 0 range 27 .. 27;
       Opcode at 0 range 24 .. 21;
       CondFlag at 0 range 20 .. 20;
       Rn at 0 range 19 .. 16;
       Rd at 0 range  15 .. 12;
       Operand at 0 range 11 .. 0;
    end record;
Then aim a pointer at your instructions and read them as records/structs.

It works particularly cleanly with a nice RISC encoding like ARM. I'm not actually sure if that would work in Ada. The use representation syntax might not be generic enough.

Re: Building a Minimal Viable Armv7 Emulator from Scratch

#22
post #21
post #9

For a learning project like this one, this would probably be overkill, but my personal suggestion for instruction decoding is that it really pays in the long term to use a data driven decoder. It's fairly easy to do a handcoded "if bits A..B are 0b1000 and..." decoder for the basic integer parts of the instruction set, but especially as you get into complexities like SIMD and if you need your decoder to be easy to mo…

Getting a bit off topic, but I feel like this task is something that ought to have special language support. It's a kind of serialization/deserialization, or what I think Python and some others call "pickling". Same task. Turn these raw bit patterns into typed values. Ada probably comes closest of the major languages to pulling it off. It has separation of the abstract/programmer's view of a data type and the impleme…

That sort of approach works for some very simple instruction encodings, but doesn't really handle:

1) instructions which "bend" the format, like ARM instructions such as STMIA or B which combine multiple fields to make a larger immediate value or mask.

2) recognizing instructions which use special values in fields (like ARM condition = 1111) to represent a special instruction.

3) instruction encodings with split fields, like the split immediate in RISC-V S-type instructions.

4) instruction encodings which have too many instruction-specific quirks to fit into any reasonable schema, like 68000.

Re: Building a Minimal Viable Armv7 Emulator from Scratch

#23
post #21
post #9

For a learning project like this one, this would probably be overkill, but my personal suggestion for instruction decoding is that it really pays in the long term to use a data driven decoder. It's fairly easy to do a handcoded "if bits A..B are 0b1000 and..." decoder for the basic integer parts of the instruction set, but especially as you get into complexities like SIMD and if you need your decoder to be easy to mo…

Getting a bit off topic, but I feel like this task is something that ought to have special language support. It's a kind of serialization/deserialization, or what I think Python and some others call "pickling". Same task. Turn these raw bit patterns into typed values. Ada probably comes closest of the major languages to pulling it off. It has separation of the abstract/programmer's view of a data type and the impleme…

If you think Arm is a "nice RISC encoding" then I think you've mostly been looking at the older integer bits of it :-) As you get into FP and SIMD there are just a lot more useful operations that need to fit into the strictly limited encoding space, and new features that need to be tucked into previously unused corners of the space, and it all gets noticeably less regular (e.g. "these two bits encode the operand size which is 0b00/0b01/0b10 for 8/16/32 bits, but 64 bit operands aren't supported and 0b11 means it's part of an entirely different set of instructions").

Re: Building a Minimal Viable Armv7 Emulator from Scratch

#24
post #20

Earlier quoted context omitted.

They stop spawning but the flakes already on the screen continue to fall until they reach the bottom. It's cute but very annoying IMO and there should be a user control to instantly turn it off.

Its winter, it takes a literal second to fade out

They do not fade out in a second and continue to fall for 10+ seconds until they fade at the bottom of the page. It is also not winter everywhere.

Re: Building a Minimal Viable Armv7 Emulator from Scratch

#25
post #20

Earlier quoted context omitted.

Its winter, it takes a literal second to fade out

They do not fade out in a second and continue to fall for 10+ seconds until they fade at the bottom of the page. It is also not winter everywhere.

It is on that page
Post reply on HN