Add support for TLS
Created by: mahkoh
This should be relatively easy. The most straightforward solution is a single syscall, set_thread_pointer(*const u8)
, which sets the thread pointer which is swapped by the kernel on context switches. The ABIs are as follows:
x86
The kernel has an entry in the GDT reserved for the thread pointer. It loads it then with the base address passed by set_thread_pointer
and an unlimited (4G) range. This GDT entry is then loaded into the gs
register. This can be done by userspace, but it's more convenient if the kernel does it.
x86_64
As above, but use the fs
register instead. Note that the fs
register cannot be loaded with mov
. Instead you have to use another instruction which I've forgotten. It's described in the Intel manual. This instruction cannot be used by userspace.
This will allow downstream threading libraries to store certain per-thread information, even though this alone is not yet enough to support the thread local storage generated by the compiler.