Added cleanup of modules on exit.

Still to do: concurrency.
-Interrupts are inconsistent, wrap with semaphore.
-Other mem/reg access (i.e. writes) by modules is also probably inconsistent.
--See example of using clk hwi, A=1 and using C immediately after.
-Relatedly, hw should be able to halt the cpu (for arbitrary time) during hwi.