What mode do modern 64-bit Intel chip PCs run the boot sector in?

Solution 1:

All current x86-compatible computers (this includes x64 architecture too, both from Intel and AMD, but not Itanium) execute boot sector code in x86 real mode, exactly like the original IBM PC did 20+ years ago. It is not kernel mode, it's the original segmented mode without memory protection, multitasking, or code privilege levels.

If you can get hold of a floppy drive, put MS-DOS (or FreeDOS) on it, and stuck into today's computer, it will start booting.

It is boot code's task to switch into protected mode, set up memory protection etc. So your guess is partially right. The boot loader starts execution as x86 real mode and switches into protected mode, loads and starts actually executing OS Kernel in "kernel" (ring 0) mode.

For more information, you can visit Wikipedia article on Windows NT startup process, which has quite a few details on this subject.

Solution 2:

what about modern 64-bit architectures?

That depends from the firmware that is on the modern 64-bit machine with the modern 64-bit architecture. haimg's answer would have been the case some five to six years ago for the x86 world, but is out of date for the x86 world today.

Old PC/AT firmwares

Some of those modern 64-bit machines have old PC/AT style firmwares. As noted in other answers, they load and run the bootstrap program from sector #0 of a disc in pretty much the same way as the PC/AT did. This is the old PC/AT bootstrap process.

New EFI firmwares

Other modern 64-bit machines have new EFI firmwares. These don't load a bootstrap program from sector #0 of a disc at all. They bootstrap by the EFI Boot Manager loading and running an EFI boot loader application. Such programs are run in protected mode. This is the EFI bootstrap process.

EFI firmwares in general switch to protected mode within a few instructions of exiting processor reset. Switching to protected mode is done early on in the so-called "SEC Phase" of EFI firmware initialization. Technically, 32-bit and greater x86 processors don't even start in real mode proper, but in what is colloquially known as unreal mode. (The initial segment descriptor for the CS register does not describe the conventional real mode mapping and is what makes this "unreal".)

As such, it could be said that those EFI systems never enter real mode proper at all, when bootstrapping natively to an EFI bootloader (i.e. when they don't employ a compatibility support module), since they switch from unreal mode directly to protected mode and stay in protected mode from then on.

Solution 3:

As far as I know, the boot code always runs in Kernel mode.

For one, it's impossible for anything to decide what mode to use as it's ran from the boot sector, simply because it's the first instructions to be executed by the firmware. There is no way for the code to set what instructions are available to it before it starts running. Thus, by design, the assembly set available for the code on the boot sector is predetermined by the architecture.

Had any underprivileged mode were to be chosen for that, it would have been impossible to ever use instructions from higher privileged modes, which pretty much forces the fact that the boot code runs with the most privileged mode available.

Solution 4:

Intel manual Volume 3 System Programming Guide 325384-053US January 2015:

2.2 MODES OF OPERATION

The processor is placed in real-address mode following power-up or a reset.

Just for the kicks, a nice diagram from the manual:

enter image description here

GRUB starts multiboot OSes in protected mode. Multiboot specification 0.6.96 Machine state:

'CR0' Bit 0 (PE) must be set.

Not sure about GRUB and x86_64.