Первая инструкция

Маленькое открытие. После RESET# x86 процессоры начинают выполнение команд в реальном режиме (AKA real mode). CS и IP при этом устанавливаются в 0xf000 и 0xfff0 соответственно. Значит первая инструкция должна находится в пределах первого мегабайта, по адресу 0x000ffff0. Правильно? Не правильно. На самом деле, первая инструкция живет по адресу 0xfffffff0, так как база селектора CS после сброса устанавливается в 0xffff0000.

Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A: System Programming Guide, Part 1 8.1.4 First Instruction Executed:

The first instruction that is fetched and executed following a hardware reset is located at physical address FFFFFFF0H. This address is 16 bytes below the processor’s uppermost physical address. The EPROM containing the software-initialization code must be located at this address.

The address FFFFFFF0H is beyond the 1-MByte addressable range of the processor while in real-address mode. The processor is initialized to this starting address as follows. The CS register has two parts: the visible segment selector part and the hidden base address part. In real-address mode, the base address is normally formed by shifting the 16-bit segment selector value 4 bits to the left to produce a 20-bit base address. However, during a hardware reset, the segment selector in the CS register is loaded with F000H and the base address is loaded with FFFF0000H. The starting address is thus formed by adding the base address to the value in the EIP register (that is, FFFF0000 + FFF0H = FFFFFFF0H).

comments powered by Disqus