Functions marked with __atribute__((naked)) may only use basic inline assembly and must not use any c code. The functions __enter_thread_mode() and cpu_switch_context_exit() are using C code, so they must not be marked as naked.