System calls

why user is not able to switch from user to kernel mode by writing the function whose code is identical to system call.

A system call usually involves a single machine language instruction that behaves very much like an interrupt. Anyone can invoke it. But it jumps to a specific routine in the kernel called syscall. syscall can only do system calls. The jump to syscall also switch into kernel mode. There is not a way to to switch to kernel mode and jump to arbitrary point in the kernel. You must jump to syscall. (At least this is what happens on a reasonably designed computer.) Also, there is no way to switch kernel mode and continue executing user code even if you are the kernel. In kernel mode you must be running code in kernel address space.