
Show HN: AVR-VM – VM with JIT-compiler for ATMega32 written in Rust - MackieLoeffel
https://github.com/MackieLoeffel/avr-vm
======
txdv
I remember coding for atmega at university and we had to use these super
shitty windows tools.

This is awesome!

~~~
severino
Well, actually things like an avr-gcc toolchain, and other open source
utilities have existed for a long time, so you can use your operating system
of choice for attiny/atmega development, with no need for Atmel Studio.

------
revelation
This JITs & executes basic blocks but that doesn't seem correct with interrupt
handling. Interrupts can of course occur in the middle of a basic block, which
isn't handled right now from what I can tell?

It is a difficult problem to get cycle correct interrupts, no doubt.

~~~
chrisseaton
I don't know anything about the architecture, but if an external source is
causing the interrupt, how can could you observe that the interrupt was
delayed until the end of a basic block? You can only run for so long before
you reach the end of a basic block, so can you tell the nanosecond difference?
And doesn't the routine triggering the interrupt wait until the interrupt is
serviced, so how can it tell the difference as well?

~~~
MackieLoeffel
Yes, thats exactly the reasoning, why it isn't a problem to handle the
interrupts only between basic blocks. Qemu does something similar. The
ATmega32 makes it easy in this regard, because it doesn't have
exceptions/traps, which have to be executed synchronously (div by 0 isn't a
problem, because there is no div instruction). JIT compiling for a x86 is far
harder, because you have to make sure, that the traps are triggered at the
correct points in time (e.g. a page fault, which happens during the fetching
of an instruction).

~~~
chrisseaton
I only know about it because I do the same thing in dynamic programming
languages.

In Ruby you can redefine methods at any point, but in my implementation I only
check if they have been redefined once per loop in the program. If another
thread wants to redefine a method, it just waits a little while until all the
other threads are ready.

This means we can basically ignore the problem of method redefinition - as we
only allow it when we are ready and then we can handle it slow-time.

------
johnsmith21006
Well this is really impressive. Now maybe not as much as Borland full turbo
Pascal environment in 32k in the old days but anyone worked on one of these
chips you have crazy little resources to work with.

~~~
munificent
The VM emulates the ATMega3 on a regular desktop, it doesn't run on the
microcontroller.

