Live data from Hacker News

Write Your Own Virtual Machine (2022)

jmeiners.com

41–50 of 102 posts

Re: Write Your Own Virtual Machine (2022)

#41
post #39

Earlier quoted context omitted.

I answered a similar question by anyfoo downthread, the point about implementing a PIT should explain what I mean, and why I think that emulating a simple real architecture might be more useful while requiring similar effort.

Again, you are coming at this from a software engineering direction, not a computer architecture/engineering one.

Since I have the exact same thought (that you are coming at this from a software engineering direction, not a computer architecture/engineering one), this is unlikely to be further productive :(

You say you want students to be able to write emulators/simulators etc. (you list a bunch of software.engineering tasks). I say writing an LC-3 emulator won't give you any transferable skills for writing, say, a Gameboy Emulator (still a 30yo system), because these educational arhitectures are bad and abstract away precisely the things that you have to get right to do that, leaving you with something trivial to implement: a C array for "memory" and a few bitwise operations.

Since we're largely looking at the same things and coming to orthogonal conclusions, I suggest we agree to disagree on this one.

Re: Write Your Own Virtual Machine (2022)

#42
post #9

Earlier quoted context omitted.

the 80286 has its own problems/inessential complexity if you look at this from the riscv angle, moving from "u-mode only vm that doesn't use paging under the hood" to "u+s-mode vm with sv39" isn't an enormous jump in complexity imo i think i might teach it starting as like, "sv21" (page tables aren't nested), then pose real sv39 and the tree structure as the solution to making a sparse mapping over 512GiB then moving…

Sometimes I dream of a 24-bit generation of computers (in terms of address space and the space of index math) of which https://en.wikipedia.org/wiki/Zilog_eZ80 may be the best realization. You can almost run a real operating system on that chip in the sense of a 24 bit supervisor that could run multiple 16 bit processes (if you could get CP/M to run you have one heck of a userspace) Unfortunately you can't trap the i…

Also PIC24 family of μcontrollers.

Re: Write Your Own Virtual Machine (2022)

#43
Some books that i was pointed to;

1) Virtual Machines: Versatile Platforms for Systems and Processes by Smith and Nair - Seems to be a comprehensive subject overview book.

2) Virtual Machines by Iain Craig - Seems like a more hands-on book with languages and VMs.

3) Virtual Machine Design and Implementation in C/C++ by Bill Blunden - Seems like an hands-on implementation.

If somebody who has read any of the above can add some comments that would be helpful to everybody.

Re: Write Your Own Virtual Machine (2022)

#44
post #23

To be That Guy: this is an emulator, not a VM. While the term can apply in a descriptive sense, and in the pre-hardware-virtualization past there was some ambiguity, the overwhelmingly common usage of "Virtual Machine" in the modern world refers to an environment making use of hardware virtualization features like VT-x et. al.

This is a VM like in JVM ( Java Virtual Machine ). I think you will find Java qualifies for “overwhelmingly common usage”.

Re: Write Your Own Virtual Machine (2022)

#45
post #26
post #23

To be That Guy: this is an emulator, not a VM. While the term can apply in a descriptive sense, and in the pre-hardware-virtualization past there was some ambiguity, the overwhelmingly common usage of "Virtual Machine" in the modern world refers to an environment making use of hardware virtualization features like VT-x et. al.

I don't think that terminology is "overwhelmingly common", and I'd argue that it isn't even entirely correct. The JVM is widely deployed, the Ethereum VM is called the "EVM", https://www.linuxfoundation.org/hubfs/LF%20Research/The_Stat... describes BPF and eBPF repeatedly as "virtual machines", https://webassembly.org/ begins by saying, "WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based…

Disagree with both of you. JVM was always a misnomer, it just stuck because that's just the name they stuck with. Putting "virtual machine" in its name in defiance of the meaning doesn't suddenly make it a virtual machine any more than calling your dog "my son" makes your dog your son. And virtual machines have used software virtialization for the longest time, they aren't always hardware based.

Really, a virtual machine is literally what it says on the tin: something that isn't a physical computer (machine), but presents itself as one. You know, with a virtual CPU or a virtual disk or a virtual keyboard etc., whatever a computer would have. If it doesn't present itself as a machine, it's not a virtual machine.

Calling JVM a virtual machine just because it interprets some bytecode the same way a machine does is like calling me a virtual doctor just because I read text the same way a doctor does.

Re: Write Your Own Virtual Machine (2022)

#46

Earlier quoted context omitted.

Our CS 101 class had such a system. Simple computer/assembler written in BASIC on the PDP. One of the assignments was to do a simple multiply (i.e. add in a loop). Rather than do that, my friend simply altered the program and created a new MUL command. The teacher was not amused.

Teachers don't want extra work. My first 360 assembler class our first assignment: add two numbers, fault, print the crashdump and circle the answer to the ADD in the printout. I wrote an RPN calculator, had it do a series of calculations and print the result. Turned that in. The teacher wrote on it "You have 24 hours to turn in the required assignment"

“Don’t let education get in the way of your learning” seems appropriate here.

Never underestimate how few fucks teachers give about anything beyond their small bubble.

Re: Write Your Own Virtual Machine (2022)

#47
post #5

As a teenager I took an intro CS class at a community college, and the instructor had us design a simple cpu instruction set, and write our own VM and assembler that worked and let me write and run assembly programs. It was shockingly easy, and it was amazing how much is demystified computers for me. I feel like one could learn every level of computing this way- from designing a real cpu for a FPGA, to writing a simp…

I think once you move from early fantasy CPUs to early CPUs in production such as 80286, the complexity immediately moves up drastically. IIRC it involves at least memory segmentation, protected mode (MMU).

Or you could pick the 68000 which is easier to emulate than a 286 because it was 'properly designed' (and not a stopgap solution like the x86 line until the 386 arrived).

Re: Write Your Own Virtual Machine (2022)

#48

Earlier quoted context omitted.

True enough, but having designed a “fantasy cpu” gives you a better frame of reference for understanding the more complex features of a cpu (privilege levels, memory segmentation, virtual addresses, cache hierarchy, etc.) I often feel like those who haven’t done the exercise of understanding the ISA of a “fantasy cpu” have a really hard time understanding those more advanced features. I guess all I am saying is that…

Forget advanced features... Without understanding a CPU it's easy to never really understand pointers, and without pointers, it's hard to understand lots of data structures. I was easily 12 months ahead of other students in my CS education because I learned 6502 assembly in high school. I wish all CS courses started with "make a VM".

This is very true. I had tried learning C multiple times but pointers were always kind of hard. I kind of understood them but not really. I later spent a lot of time making an OS in assembly for my homebrew 6502 computer, and after that pointers made so much sense. It actually took me a little while to realize that these addresses I was passing around were pointers, and I had started to understand them without realizing it.

Re: Write Your Own Virtual Machine (2022)

#49
post #9

Earlier quoted context omitted.

the 80286 has its own problems/inessential complexity if you look at this from the riscv angle, moving from "u-mode only vm that doesn't use paging under the hood" to "u+s-mode vm with sv39" isn't an enormous jump in complexity imo i think i might teach it starting as like, "sv21" (page tables aren't nested), then pose real sv39 and the tree structure as the solution to making a sparse mapping over 512GiB then moving…

Sometimes I dream of a 24-bit generation of computers (in terms of address space and the space of index math) of which https://en.wikipedia.org/wiki/Zilog_eZ80 may be the best realization. You can almost run a real operating system on that chip in the sense of a 24 bit supervisor that could run multiple 16 bit processes (if you could get CP/M to run you have one heck of a userspace) Unfortunately you can't trap the i…

> The 80286 was a turkey because it didn't meet the minimal viable product level of being a target for a 24-bit OS that could virtualize DOS applications. It was already crazy fast and became affordable pretty quickly but it seemed tragic that it couldn't do that.

That's mainly because it was designed before the IBM PC was a success and backwards compatibility with DOS applications important.

Re: Write Your Own Virtual Machine (2022)

#50
post #35

Earlier quoted context omitted.

Interesting. How would you advocate actually gaining that knowledge then? It seems like a student would need to know a significant amount of coding in order to learn those abstractions in an interactive manner. And by learn them I mean learn them (not just following a tutorial), organizing the code for a fully working x86 architecture is no joke. But a student with that level of skill probably doesn't need to learn t…

Very good question. My working assumption throughout was that the people in a computer architecture class already had 1 or 2 semesters of other programming courses where they worked in a high-level language, and are looking to learn how computers work "closer to the hardware". And educational architectures create a completely false impression in this domain. If I had to teach assembly programming to people who never…

The thing is that you are conflating CPU architectures with computer architectures; In academia they are treated as two different educational topics, for good reason.

The first one covers the lowest level of how logic gates are physically wired to produce a Turing-equivalent computing machine. For that purpose, having the simplest possible instruction set is a pedagogical must. It may also cover more advanced topics like parallel and/or segmented instruction pipelines, but they're described in the abstract, not as current state-of-the-art industry practice.

Then, for actually learning how modern computers work you have another separate one-term course for whole machine architecture. There you learn about data and control buses, memory level abstractions, caching, networking, parallel processing... taking for granted a previous understanding of how the underlying electronics can be abstracted away.

Post reply on HN