Don't use malloc mutex before the OS is started

Otherwise it hangs if you use functions that use malloc. This includes printf and the thread creation with dynamic stack allocation.
Also I made the globals static.