Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know with older machines like 286s, the first 512 bytes loaded from the first sector of the boot drive to 0000:7C00 in memory were run in 16-bit real mode, but what about modern 64-bit architectures?

Edit: I guess this is a wrong question upon thinking about it. The writer of the boot loader is the decider of which mode assembly instructions to use, right? The hardware just does what it's told. Then my question should be, what mode do major OS boot loaders like Windows 7, Mac OS X (the latest) and GRUB on 64-bit machines use?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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 DOS 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.

share|improve this answer
    
haimg, thanks for that link and clarification. @Deshe, sorry to take away best answer. –  Pete Oct 10 '11 at 17:11
    
Now's the time to edit this, otherwise you disagree with your own answer :-) –  Daniel Beck Oct 10 '11 at 17:14

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.