x86: move _set_gate and its users to a common location