fix TLS setup code
Massive ARM changes from Enrico Scholz