When using old legacy BIOS (consider X86 architecture), the boot loader jumps to a location at the real mode kernel (offset 512 which is defined in header.S assembly file) and starts the real mode code. The real mode code then prepares a stack and heap and jumps to main.c again in real mode. What about UEFI boot mechanism? Is the real mode kernel code still used? Does the boot loader jump to that same part of header.S and give control to that same code in real mode? More exactly, what is the difference of kernel initialization at the moment the boot loader jumps to OS code between legacy BIOS boot and UEFI boot?
Real mode code is not used when the EFI stub mechanism is used. The firmware (executed from flash ROM on the motherboard when the machine is booted) switches the processor to protected mode before loading the kernel image. The kernel image header is constructed to look like a PE executable as mandated by the UEFI specification. For more information see this Intel article.
Edit: added some info demanded in the comment below.
arch/x86/boot/header.S contains the definitions that make the file look like a PE binary when compiled with
CONFIG_EFI_STUB. The firmware calls the entry point placed in the header; the entry point is
arch/x86/boot/compressed/head_64.S. This routine calls
arch/x86/boot/compressed/eboot.c. The former constructs a
boot_params structure, and also loads an initramfs if specified on the command line. The kernel command line is also handled differently: UEFI takes care of it too, but because UEFI uses UCS-2 encoded strings (a subset of Unicode), they are converted to ASCII. Both
head_64.S contain a lot of code that is common between the EFI stub and traditional way of booting.
Ps. UEFI may some day make it possible to get rid of Real Mode in x86 processors for good. It is only used for booting modern operating systems.